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.kotlin.codegen.StackValue;
021    import org.jetbrains.org.objectweb.asm.Type;
022    
023    public class CapturedParamInfo extends ParameterInfo {
024    
025        public static final CapturedParamInfo STUB = new CapturedParamInfo(CapturedParamDesc.createDesc(new CapturedParamOwner() {
026            @Override
027            public Type getType() {
028                return Type.getObjectType("STUB");
029            }
030        }, "STUB", Type.getObjectType("STUB")), true, -1, -1);
031    
032        public final CapturedParamDesc desc;
033    
034        private final String newFieldName;
035    
036        public CapturedParamInfo(@NotNull CapturedParamDesc desc, boolean skipped, int index, int remapIndex) {
037            this(desc, desc.getFieldName(), skipped, index, remapIndex);
038        }
039    
040        public CapturedParamInfo(@NotNull CapturedParamDesc desc, @NotNull String newFieldName, boolean skipped, int index, int remapIndex) {
041            super(desc.getType(), skipped, index, remapIndex);
042            this.desc = desc;
043            this.newFieldName = newFieldName;
044        }
045    
046        public CapturedParamInfo(@NotNull CapturedParamDesc desc, @NotNull String newFieldName, boolean skipped, int index, StackValue remapIndex) {
047            super(desc.getType(), skipped, index, remapIndex);
048            this.desc = desc;
049            this.newFieldName = newFieldName;
050        }
051    
052        @NotNull
053        public String getNewFieldName() {
054            return newFieldName;
055        }
056    
057        @NotNull
058        public String getOriginalFieldName() {
059            return desc.getFieldName();
060        }
061    
062        @NotNull
063        public CapturedParamInfo newIndex(int newIndex) {
064            return clone(newIndex, getRemapValue());
065        }
066    
067        @NotNull
068        public CapturedParamInfo clone(int newIndex, StackValue newRamapIndex) {
069            CapturedParamInfo capturedParamInfo = new CapturedParamInfo(desc, newFieldName, isSkipped, newIndex, newRamapIndex);
070            capturedParamInfo.setLambda(lambda);
071            return capturedParamInfo;
072        }
073    
074        @NotNull
075        public String getContainingLambdaName() {
076            return desc.getContainingLambdaName();
077        }
078    }