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 private boolean skipInConstructor; 037 038 public CapturedParamInfo(@NotNull CapturedParamDesc desc, boolean skipped, int index, int remapIndex) { 039 this(desc, desc.getFieldName(), skipped, index, remapIndex); 040 } 041 042 public CapturedParamInfo(@NotNull CapturedParamDesc desc, @NotNull String newFieldName, boolean skipped, int index, int remapIndex) { 043 super(desc.getType(), skipped, index, remapIndex, index); 044 this.desc = desc; 045 this.newFieldName = newFieldName; 046 } 047 048 public CapturedParamInfo(@NotNull CapturedParamDesc desc, @NotNull String newFieldName, boolean skipped, int index, StackValue remapIndex) { 049 super(desc.getType(), skipped, index, remapIndex, index); 050 this.desc = desc; 051 this.newFieldName = newFieldName; 052 } 053 054 @NotNull 055 public String getNewFieldName() { 056 return newFieldName; 057 } 058 059 @NotNull 060 public String getOriginalFieldName() { 061 return desc.getFieldName(); 062 } 063 064 @NotNull 065 public CapturedParamInfo newIndex(int newIndex) { 066 return clone(newIndex, getRemapValue()); 067 } 068 069 @NotNull 070 public CapturedParamInfo clone(int newIndex, StackValue newRamapIndex) { 071 CapturedParamInfo capturedParamInfo = new CapturedParamInfo(desc, newFieldName, isSkipped, newIndex, newRamapIndex); 072 capturedParamInfo.setLambda(lambda); 073 capturedParamInfo.setSkipInConstructor(skipInConstructor); 074 return capturedParamInfo; 075 } 076 077 @NotNull 078 public String getContainingLambdaName() { 079 return desc.getContainingLambdaName(); 080 } 081 082 public boolean isSkipInConstructor() { 083 return skipInConstructor; 084 } 085 086 public void setSkipInConstructor(boolean skipInConstructor) { 087 this.skipInConstructor = skipInConstructor; 088 } 089 }