diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 09ae28ab47c..13e485de88f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1419,7 +1419,7 @@ public class ExpressionCodegen extends KtVisitor impleme assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText(); return genClosure( - declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration), samType, null, null + declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, declaration), samType, null, null ); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 30ae9a74c42..01780577de6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -120,7 +120,7 @@ public class FunctionCodegen { if (owner.getContextKind() != OwnerKind.DEFAULT_IMPLS || function.hasBody()) { generateMethod(JvmDeclarationOriginKt.OtherOrigin(function, functionDescriptor), functionDescriptor, - new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function)); + new FunctionGenerationStrategy.FunctionDefault(state, function)); } generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), functionDescriptor, owner.getContextKind(), diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionGenerationStrategy.java index 13f5551cb77..a5410c95993 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionGenerationStrategy.java @@ -33,15 +33,14 @@ public abstract class FunctionGenerationStrategy { @NotNull MemberCodegen parentCodegen ); - public static class FunctionDefault extends CodegenBased { + public static class FunctionDefault extends CodegenBased { private final KtDeclarationWithBody declaration; public FunctionDefault( @NotNull GenerationState state, - @NotNull CallableDescriptor descriptor, @NotNull KtDeclarationWithBody declaration ) { - super(state, descriptor); + super(state); this.declaration = declaration; } @@ -51,13 +50,11 @@ public abstract class FunctionGenerationStrategy { } } - public abstract static class CodegenBased extends FunctionGenerationStrategy { + public abstract static class CodegenBased extends FunctionGenerationStrategy { protected final GenerationState state; - protected final T callableDescriptor; - public CodegenBased(@NotNull GenerationState state, @NotNull T callableDescriptor) { + public CodegenBased(@NotNull GenerationState state) { this.state = state; - this.callableDescriptor = callableDescriptor; } @Override diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java index 69c8cc341f2..4a49c08189b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java @@ -36,9 +36,10 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.*; -public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased { +public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased { private final ResolvedCall resolvedCall; private final FunctionDescriptor referencedFunction; + private final FunctionDescriptor functionDescriptor; private final Type receiverType; // non-null for bound references private final StackValue receiverValue; @@ -49,9 +50,10 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat @Nullable Type receiverType, @Nullable StackValue receiverValue ) { - super(state, functionDescriptor); + super(state); this.resolvedCall = resolvedCall; this.referencedFunction = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); + this.functionDescriptor = functionDescriptor; this.receiverType = receiverType; this.receiverValue = receiverValue; assert receiverType != null || receiverValue == null @@ -82,7 +84,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat { argumentMap = new LinkedHashMap(fakeArguments.size()); int index = 0; - List parameters = callableDescriptor.getValueParameters(); + List parameters = functionDescriptor.getValueParameters(); for (ValueArgument argument : fakeArguments) { argumentMap.put(parameters.get(index), new ExpressionValueArgument(argument)); index++; @@ -154,7 +156,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat (referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0) - (receiverType != null ? 1 : 0); - List parameters = CollectionsKt.drop(callableDescriptor.getValueParameters(), receivers); + List parameters = CollectionsKt.drop(functionDescriptor.getValueParameters(), receivers); for (int i = 0; i < parameters.size(); i++) { ValueParameterDescriptor parameter = parameters.get(i); ValueArgument fakeArgument = fakeArguments.get(i); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 848c241e38a..ede976e20d6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -931,7 +931,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) { if (isInterface(descriptor) || isAnnotationClass(descriptor)) return; - ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor(); + final ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor(); if (constructorDescriptor == null) return; ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor); @@ -940,10 +940,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { JvmDeclarationOrigin origin = JvmDeclarationOriginKt .OtherOrigin(primaryConstructor != null ? primaryConstructor : myClass, constructorDescriptor); functionCodegen.generateMethod(origin, constructorDescriptor, constructorContext, - new FunctionGenerationStrategy.CodegenBased(state, constructorDescriptor) { + new FunctionGenerationStrategy.CodegenBased(state) { @Override public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { - generatePrimaryConstructorImpl(callableDescriptor, codegen, delegationFieldsInfo, primaryConstructor); + generatePrimaryConstructorImpl(constructorDescriptor, codegen, delegationFieldsInfo, primaryConstructor); } } ); @@ -954,7 +954,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { new DefaultParameterValueSubstitutor(state).generatePrimaryConstructorOverloadsIfNeeded(constructorDescriptor, v, kind, myClass); } - private void generateSecondaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) { + private void generateSecondaryConstructor(@NotNull final ConstructorDescriptor constructorDescriptor) { if (!canHaveDeclaredConstructors(descriptor)) return; ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor); @@ -964,10 +964,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { functionCodegen.generateMethod( JvmDeclarationOriginKt.OtherOrigin(constructor, constructorDescriptor), constructorDescriptor, constructorContext, - new FunctionGenerationStrategy.CodegenBased(state, constructorDescriptor) { + new FunctionGenerationStrategy.CodegenBased(state) { @Override public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { - generateSecondaryConstructorImpl(callableDescriptor, codegen); + generateSecondaryConstructorImpl(constructorDescriptor, codegen); } } ); @@ -1335,7 +1335,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { functionCodegen.generateMethod( JvmDeclarationOriginKt.DelegationToTraitImpl(descriptorToDeclaration(traitFun), traitFun), inheritedFun, - new FunctionGenerationStrategy.CodegenBased(state, inheritedFun) { + new FunctionGenerationStrategy.CodegenBased(state) { @Override public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { DeclarationDescriptor containingDeclaration = traitFun.getContainingDeclaration(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt index fe6153aadfc..a1795e59c2b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt @@ -114,7 +114,7 @@ class InterfaceImplBodyCodegen( functionCodegen.generateMethod( DelegationToTraitImpl(DescriptorToSourceUtils.descriptorToDeclaration(descriptor), descriptor), descriptor, - object : FunctionGenerationStrategy.CodegenBased(state, descriptor) { + object : FunctionGenerationStrategy.CodegenBased(state) { override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) { val iv = codegen.v @@ -126,7 +126,7 @@ class InterfaceImplBodyCodegen( throw AssertionError( "Method from super interface has a different signature.\n" + "This method:\n%s\n%s\n%s\nSuper method:\n%s\n%s\n%s".format( - callableDescriptor, signature, myParameters, delegateTo, method, calleeParameters + descriptor, signature, myParameters, delegateTo, method, calleeParameters ) ) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmStaticGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmStaticGenerator.kt index 02849909cce..695fc23887a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmStaticGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmStaticGenerator.kt @@ -43,7 +43,7 @@ class JvmStaticGenerator( codegen.functionCodegen.generateMethod( Synthetic(originElement, staticFunctionDescriptor), staticFunctionDescriptor, - object : FunctionGenerationStrategy.CodegenBased(state, descriptor) { + object : FunctionGenerationStrategy.CodegenBased(state) { override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) { val iv = codegen.v val classDescriptor = descriptor.containingDeclaration as ClassDescriptor @@ -57,7 +57,7 @@ class JvmStaticGenerator( } if (descriptor is PropertyAccessorDescriptor) { val propertyValue = codegen.intermediateValueForProperty(descriptor.correspondingProperty, false, null, StackValue.none()) - if (callableDescriptor is PropertyGetterDescriptor) { + if (descriptor is PropertyGetterDescriptor) { propertyValue.put(signature.returnType, iv) } else { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index 84db748ae40..8df801d3ebb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -579,7 +579,7 @@ public abstract class MemberCodegen(state, accessor) { + new FunctionGenerationStrategy.CodegenBased(state) { @Override public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { markLineNumberForElement(element, codegen.v); @@ -595,9 +595,11 @@ public abstract class MemberCodegen { + class PropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { + private final PropertyAccessorDescriptor callableDescriptor; public PropertyAccessorStrategy(@NotNull PropertyAccessorDescriptor callableDescriptor) { - super(MemberCodegen.this.state, callableDescriptor); + super(MemberCodegen.this.state); + this.callableDescriptor = callableDescriptor; } @Override diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 865642018e5..eee51bb64db 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -430,7 +430,7 @@ public class PropertyCodegen { } } else { - strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessorDescriptor, accessor); + strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessor); } functionCodegen.generateMethod(JvmDeclarationOriginKt.OtherOrigin(accessor != null ? accessor : p, accessorDescriptor), accessorDescriptor, strategy); @@ -467,15 +467,17 @@ public class PropertyCodegen { } - private static class DefaultPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { + private static class DefaultPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { + private final PropertyAccessorDescriptor propertyAccessorDescriptor; public DefaultPropertyAccessorStrategy(@NotNull GenerationState state, @NotNull PropertyAccessorDescriptor descriptor) { - super(state, descriptor); + super(state); + propertyAccessorDescriptor = descriptor; } @Override public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { InstructionAdapter v = codegen.v; - PropertyDescriptor propertyDescriptor = callableDescriptor.getCorrespondingProperty(); + PropertyDescriptor propertyDescriptor = propertyAccessorDescriptor.getCorrespondingProperty(); StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, true, null, StackValue.LOCAL_0); PsiElement jetProperty = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor); @@ -483,22 +485,22 @@ public class PropertyCodegen { codegen.markLineNumber((KtElement) jetProperty, false); } - if (callableDescriptor instanceof PropertyGetterDescriptor) { + if (propertyAccessorDescriptor instanceof PropertyGetterDescriptor) { Type type = signature.getReturnType(); property.put(type, v); v.areturn(type); } - else if (callableDescriptor instanceof PropertySetterDescriptor) { - List valueParameters = callableDescriptor.getValueParameters(); - assert valueParameters.size() == 1 : "Property setter should have only one value parameter but has " + callableDescriptor; + else if (propertyAccessorDescriptor instanceof PropertySetterDescriptor) { + List valueParameters = propertyAccessorDescriptor.getValueParameters(); + assert valueParameters.size() == 1 : "Property setter should have only one value parameter but has " + propertyAccessorDescriptor; int parameterIndex = codegen.lookupLocalIndex(valueParameters.get(0)); - assert parameterIndex >= 0 : "Local index for setter parameter should be positive or zero: " + callableDescriptor; + assert parameterIndex >= 0 : "Local index for setter parameter should be positive or zero: " + propertyAccessorDescriptor; Type type = codegen.typeMapper.mapType(propertyDescriptor); property.store(StackValue.local(parameterIndex, type), codegen.v); v.visitInsn(RETURN); } else { - throw new IllegalStateException("Unknown property accessor: " + callableDescriptor); + throw new IllegalStateException("Unknown property accessor: " + propertyAccessorDescriptor); } } } @@ -545,12 +547,14 @@ public class PropertyCodegen { return codegen.invokeFunction(resolvedCall, delegatedProperty); } - private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { + private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased { private final int index; + private final PropertyAccessorDescriptor propertyAccessorDescriptor; public DelegatedPropertyAccessorStrategy(@NotNull GenerationState state, @NotNull PropertyAccessorDescriptor descriptor, int index) { - super(state, descriptor); + super(state); this.index = index; + propertyAccessorDescriptor = descriptor; } @Override @@ -559,10 +563,10 @@ public class PropertyCodegen { BindingContext bindingContext = state.getBindingContext(); ResolvedCall resolvedCall = - bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor); + bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, propertyAccessorDescriptor); assert resolvedCall != null : "Resolve call should be recorded for delegate call " + signature.toString(); - StackValue lastValue = invokeDelegatedPropertyConventionMethod(callableDescriptor.getCorrespondingProperty(), + StackValue lastValue = invokeDelegatedPropertyConventionMethod(propertyAccessorDescriptor.getCorrespondingProperty(), codegen, state.getTypeMapper(), resolvedCall, index, 1); Type asmType = signature.getReturnType(); lastValue.put(asmType, v); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index bf9c1cab85b..ce8c0f22181 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -509,7 +509,7 @@ public class InlineCodegen extends CallGenerator { ); } else { - strategy = new FunctionGenerationStrategy.FunctionDefault(state, descriptor, (KtDeclarationWithBody) expression); + strategy = new FunctionGenerationStrategy.FunctionDefault(state, (KtDeclarationWithBody) expression); } FunctionCodegen.generateMethodBody(adapter, descriptor, context, jvmMethodSignature, strategy, parentCodegen);