From 74760acf660453515bd775b0d3852f508b8e2c96 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 7 Aug 2015 02:58:54 +0300 Subject: [PATCH] Parameter names of Java methods: store enum field instead of two booleans --- .../sam/SamAdapterFunctionDescriptor.java | 6 +-- .../descriptors/JavaMethodDescriptor.java | 44 +++++++++++++------ .../java/lazy/descriptors/LazyJavaScope.kt | 3 +- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java index 20c5158fa42..5701e1696d5 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java @@ -37,11 +37,9 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; @NotNull Kind kind, @NotNull JavaMethodDescriptor declaration ) { - super(containingDeclaration, original, declaration.getAnnotations(), - declaration.getName(), kind, declaration.getSource()); + super(containingDeclaration, original, declaration.getAnnotations(), declaration.getName(), kind, declaration.getSource()); this.declaration = declaration; - setHasStableParameterNames(declaration.hasStableParameterNames()); - setHasSynthesizedParameterNames(declaration.hasSynthesizedParameterNames()); + setParameterNamesStatus(declaration.hasStableParameterNames(), declaration.hasSynthesizedParameterNames()); } @NotNull diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java index 4ef5f52f642..f6bd6ee7333 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java @@ -28,8 +28,29 @@ import org.jetbrains.kotlin.types.TypeSubstitutor; import java.util.List; public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implements JavaCallableMemberDescriptor { - private Boolean hasStableParameterNames = null; - private Boolean hasSynthesizedParameterNames = null; + private enum ParameterNamesStatus { + NON_STABLE_DECLARED(false, false), + STABLE_DECLARED(true, false), + NON_STABLE_SYNTHESIZED(false, true), + STABLE_SYNTHESIZED(true, true), // TODO: this makes no sense + ; + + public final boolean isStable; + public final boolean isSynthesized; + + ParameterNamesStatus(boolean isStable, boolean isSynthesized) { + this.isStable = isStable; + this.isSynthesized = isSynthesized; + } + + @NotNull + public static ParameterNamesStatus get(boolean stable, boolean synthesized) { + return stable ? (synthesized ? STABLE_SYNTHESIZED : STABLE_DECLARED) : + (synthesized ? NON_STABLE_SYNTHESIZED : NON_STABLE_DECLARED); + } + } + + private ParameterNamesStatus parameterNamesStatus = null; protected JavaMethodDescriptor( @NotNull DeclarationDescriptor containingDeclaration, @@ -54,22 +75,18 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement @Override public boolean hasStableParameterNames() { - assert hasStableParameterNames != null : "hasStableParameterNames was not set: " + this; - return hasStableParameterNames; - } - - public void setHasStableParameterNames(boolean hasStableParameterNames) { - this.hasStableParameterNames = hasStableParameterNames; + assert parameterNamesStatus != null : "Parameter names status was not set: " + this; + return parameterNamesStatus.isStable; } @Override public boolean hasSynthesizedParameterNames() { - assert hasSynthesizedParameterNames != null : "hasSynthesizedParameterNames was not set: " + this; - return hasSynthesizedParameterNames; + assert parameterNamesStatus != null : "Parameter names status was not set: " + this; + return parameterNamesStatus.isSynthesized; } - public void setHasSynthesizedParameterNames(boolean hasSynthesizedParameterNames) { - this.hasSynthesizedParameterNames = hasSynthesizedParameterNames; + public void setParameterNamesStatus(boolean hasStableParameterNames, boolean hasSynthesizedParameterNames) { + this.parameterNamesStatus = ParameterNamesStatus.get(hasStableParameterNames, hasSynthesizedParameterNames); } @NotNull @@ -87,8 +104,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement kind, SourceElement.NO_SOURCE ); - result.setHasStableParameterNames(hasStableParameterNames()); - result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames()); + result.setParameterNamesStatus(hasStableParameterNames(), hasSynthesizedParameterNames()); return result; } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt index 8505592a02a..9e9cadc6c6d 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt @@ -129,8 +129,7 @@ public abstract class LazyJavaScope( method.getVisibility() ) - functionDescriptorImpl.setHasStableParameterNames(effectiveSignature.hasStableParameterNames()) - functionDescriptorImpl.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames) + functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames(), valueParameters.hasSynthesizedNames) if (record) { c.javaResolverCache.recordMethod(method, functionDescriptorImpl)