001    /*
002     * Copyright 2010-2015 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.kotlin.codegen.inline;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.org.objectweb.asm.Type;
022    
023    import java.util.HashMap;
024    import java.util.List;
025    import java.util.Map;
026    
027    public class AnonymousObjectGeneration {
028    
029        private final String ownerInternalName;
030    
031        private final String constructorDesc;
032    
033        private final Map<Integer, LambdaInfo> lambdasToInline;
034    
035        private final boolean isSameModule;
036    
037        private Type newLambdaType;
038    
039        private String newConstructorDescriptor;
040    
041        private List<CapturedParamDesc> allRecapturedParameters;
042    
043        private Map<String, LambdaInfo> capturedLambdasToInline;
044    
045        private final boolean capturedOuterRegenerated;
046        private final boolean needReification;
047        private final boolean alreadyRegenerated;
048        private final boolean isStaticOrigin;
049    
050        AnonymousObjectGeneration(
051                @NotNull String ownerInternalName,
052                boolean needReification,
053                boolean isSameModule,
054                @NotNull Map<Integer, LambdaInfo> lambdasToInline,
055                boolean capturedOuterRegenerated,
056                boolean alreadyRegenerated,
057                @Nullable String constructorDesc,
058                boolean isStaticOrigin
059        ) {
060            this.ownerInternalName = ownerInternalName;
061            this.constructorDesc = constructorDesc;
062            this.lambdasToInline = lambdasToInline;
063            this.isSameModule = isSameModule;
064            this.capturedOuterRegenerated = capturedOuterRegenerated;
065            this.needReification = needReification;
066            this.alreadyRegenerated = alreadyRegenerated;
067            this.isStaticOrigin = isStaticOrigin;
068        }
069    
070        public AnonymousObjectGeneration(
071                @NotNull String ownerInternalName, boolean isSameModule, boolean needReification,
072                boolean alreadyRegenerated,
073                boolean isStaticOrigin
074        ) {
075            this(
076                    ownerInternalName, needReification, isSameModule,
077                    new HashMap<Integer, LambdaInfo>(), false, alreadyRegenerated, null, isStaticOrigin
078            );
079        }
080    
081        public String getOwnerInternalName() {
082            return ownerInternalName;
083        }
084    
085        public boolean shouldRegenerate() {
086            return !alreadyRegenerated && (
087                    !lambdasToInline.isEmpty() || !isSameModule || capturedOuterRegenerated || needReification
088            );
089        }
090    
091        public Map<Integer, LambdaInfo> getLambdasToInline() {
092            return lambdasToInline;
093        }
094    
095        public Type getNewLambdaType() {
096            return newLambdaType;
097        }
098    
099        public void setNewLambdaType(Type newLambdaType) {
100            this.newLambdaType = newLambdaType;
101        }
102    
103        public String getNewConstructorDescriptor() {
104            return newConstructorDescriptor;
105        }
106    
107        public void setNewConstructorDescriptor(String newConstructorDescriptor) {
108            this.newConstructorDescriptor = newConstructorDescriptor;
109        }
110    
111        public List<CapturedParamDesc> getAllRecapturedParameters() {
112            return allRecapturedParameters;
113        }
114    
115        public void setAllRecapturedParameters(List<CapturedParamDesc> allRecapturedParameters) {
116            this.allRecapturedParameters = allRecapturedParameters;
117        }
118    
119        public Map<String, LambdaInfo> getCapturedLambdasToInline() {
120            return capturedLambdasToInline;
121        }
122    
123        public void setCapturedLambdasToInline(Map<String, LambdaInfo> capturedLambdasToInline) {
124            this.capturedLambdasToInline = capturedLambdasToInline;
125        }
126    
127        @Nullable
128        public String getConstructorDesc() {
129            return constructorDesc;
130        }
131    
132        public boolean isStaticOrigin() {
133            return isStaticOrigin;
134        }
135    }