From ef940ab0dfae9e9a4565833c2c48dd6e747c334d Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 28 Apr 2016 18:31:58 +0300 Subject: [PATCH] Add new 'HiddenInResolution' kind It's used to hide additional built-ins members loaded from JDK Such methods can be overridden and called only with 'super'-receiver --- .../synthetic/SamAdapterFunctionsScope.kt | 2 ++ .../calls/tower/NewResolutionOldInference.kt | 8 +++--- .../kotlin/resolve/deprecationUtil.kt | 8 ++++-- .../descriptors/FunctionDescriptor.java | 6 +++++ .../impl/FunctionDescriptorImpl.java | 26 +++++++++++++++++++ .../impl/PropertyAccessorDescriptorImpl.java | 5 ++++ .../kotlin/renderer/DescriptorRendererImpl.kt | 10 +++++-- .../ErrorSimpleFunctionDescriptorImpl.java | 6 +++++ 8 files changed, 64 insertions(+), 7 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index 49566b06a0d..ba7d0af57a5 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf +import org.jetbrains.kotlin.resolve.isHiddenInResolution import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.SyntheticScope import org.jetbrains.kotlin.storage.StorageManager @@ -46,6 +47,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope if (!function.hasJavaOriginInHierarchy()) return null //TODO: should we go into base at all? if (!SingleAbstractMethodUtils.isSamAdapterNecessary(function)) return null if (function.returnType == null) return null + if (function.isHiddenInResolution()) return null return MyFunctionDescriptor.create(function) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 46b9f04a7cd..abb58b9d44a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -171,7 +171,7 @@ class NewResolutionOldInference( val candidateTrace = TemporaryBindingTrace.create(basicCallContext.trace, "Context for resolve candidate") val resolvedCall = ResolvedCallImpl.create(candidate, candidateTrace, tracing, basicCallContext.dataFlowInfoForArguments) - if (candidate.descriptor.isHiddenInResolution()) { + if (candidate.descriptor.isHiddenInResolution(basicCallContext.isSuperCall)) { return@mapNotNull MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), resolvedCall) } @@ -312,7 +312,7 @@ class NewResolutionOldInference( return MyCandidate(ResolutionCandidateStatus(listOf(ExtensionWithStaticTypeWithDynamicReceiver)), candidateCall) } - if (towerCandidate.descriptor.isHiddenInResolution()) { + if (towerCandidate.descriptor.isHiddenInResolution(basicCallContext.isSuperCall)) { return MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), candidateCall) } @@ -424,4 +424,6 @@ internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResol else -> ResolutionCandidateApplicability.INAPPLICABLE } return PreviousResolutionError(level) -} \ No newline at end of file +} + +private val BasicCallResolutionContext.isSuperCall: Boolean get() = call.explicitReceiver is SuperCallReceiverValue diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt index dd792c4370b..6285c01cabf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt @@ -178,7 +178,11 @@ enum class DeprecationLevelValue { WARNING, ERROR, HIDDEN } -fun DeclarationDescriptor.isHiddenInResolution(): Boolean { - if (this is FunctionDescriptor && this.isHiddenToOvercomeSignatureClash) return true +@JvmOverloads +fun DeclarationDescriptor.isHiddenInResolution(isSuperCall: Boolean = false): Boolean { + if (this is FunctionDescriptor) { + if (isHiddenToOvercomeSignatureClash) return true + if (isHiddenForResolutionEverywhereBesideSupercalls && !isSuperCall) return true + } return getDeprecation()?.deprecationLevel == DeprecationLevelValue.HIDDEN } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java index 110dff05bef..ae50e6c901b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.descriptors; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.annotations.Annotations; +import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.TypeSubstitution; @@ -77,6 +78,8 @@ public interface FunctionDescriptor extends CallableMemberDescriptor { boolean isExternal(); + boolean isHiddenForResolutionEverywhereBesideSupercalls(); + @NotNull CopyBuilder newCopyBuilder(); @@ -129,6 +132,9 @@ public interface FunctionDescriptor extends CallableMemberDescriptor { @NotNull CopyBuilder setHiddenToOvercomeSignatureClash(); + @NotNull + CopyBuilder setHiddenForResolutionEverywhereBesideSupercalls(); + @NotNull CopyBuilder setAdditionalAnnotations(@NotNull Annotations additionalAnnotations); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index b185464b9bc..a15b5df364a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -44,6 +44,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo private boolean isInline = false; private boolean isTailrec = false; private boolean isHidden = false; + private boolean isHiddenForResolutionEverywhereBesideSupercalls = false; private boolean hasStableParameterNames = true; private boolean hasSynthesizedParameterNames = false; private Collection overriddenFunctions = null; @@ -131,6 +132,10 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo isHidden = hidden; } + private void setHiddenForResolutionEverywhereBesideSupercalls(boolean hiddenForResolutionEverywhereBesideSupercalls) { + isHiddenForResolutionEverywhereBesideSupercalls = hiddenForResolutionEverywhereBesideSupercalls; + } + public void setReturnType(@NotNull KotlinType unsubstitutedReturnType) { if (this.unsubstitutedReturnType != null) { // TODO: uncomment and fix tests @@ -236,6 +241,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo public void setOverriddenDescriptors(@NotNull Collection overriddenDescriptors) { //noinspection unchecked overriddenFunctions = (Collection) overriddenDescriptors; + for (FunctionDescriptor function : overriddenFunctions) { + if (function.isHiddenForResolutionEverywhereBesideSupercalls()) { + isHiddenForResolutionEverywhereBesideSupercalls = true; + break; + } + } } @Override @@ -291,6 +302,11 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo return extensionReceiverParameter.getType(); } + @Override + public boolean isHiddenForResolutionEverywhereBesideSupercalls() { + return isHiddenForResolutionEverywhereBesideSupercalls; + } + public class CopyConfiguration implements SimpleFunctionDescriptor.CopyBuilder { protected @NotNull TypeSubstitution substitution; protected @NotNull DeclarationDescriptor newOwner; @@ -310,6 +326,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo private boolean isHiddenToOvercomeSignatureClash; private List newTypeParameters = null; private Annotations additionalAnnotations = null; + private boolean isHiddenForResolutionEverywhereBesideSupercalls; public CopyConfiguration( @NotNull TypeSubstitution substitution, @@ -333,6 +350,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo this.newReturnType = newReturnType; this.name = name; this.isHiddenToOvercomeSignatureClash = isHiddenToOvercomeSignatureClash(); + this.isHiddenForResolutionEverywhereBesideSupercalls = isHiddenForResolutionEverywhereBesideSupercalls(); } @Override @@ -447,6 +465,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo return this; } + @Override + @NotNull + public CopyConfiguration setHiddenForResolutionEverywhereBesideSupercalls() { + isHiddenForResolutionEverywhereBesideSupercalls = true; + return this; + } + @NotNull @Override public CopyConfiguration setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) { @@ -574,6 +599,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo substitutedDescriptor.setHasStableParameterNames(hasStableParameterNames); substitutedDescriptor.setHasSynthesizedParameterNames(hasSynthesizedParameterNames); substitutedDescriptor.setHidden(configuration.isHiddenToOvercomeSignatureClash); + substitutedDescriptor.setHiddenForResolutionEverywhereBesideSupercalls(configuration.isHiddenForResolutionEverywhereBesideSupercalls); if (configuration.signatureChange || getInitialSignatureDescriptor() != null) { FunctionDescriptor initialSignature = (getInitialSignatureDescriptor() != null ? getInitialSignatureDescriptor() : this); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java index 2c8c945ee07..df1b2b4d6c3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java @@ -209,4 +209,9 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript public boolean isHiddenToOvercomeSignatureClash() { return false; } + + @Override + public boolean isHiddenForResolutionEverywhereBesideSupercalls() { + return false; + } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 52ddeabe10c..6c65985b70d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -584,8 +584,14 @@ internal class DescriptorRendererImpl( renderOverride(function, builder) renderMemberKind(function, builder) - if (verbose && function.isHiddenToOvercomeSignatureClash) { - builder.append("/*isHiddenToOvercomeSignatureClash*/ ") + if (verbose) { + if (function.isHiddenToOvercomeSignatureClash) { + builder.append("/*isHiddenToOvercomeSignatureClash*/ ") + } + + if (function.isHiddenForResolutionEverywhereBesideSupercalls) { + builder.append("/*isHiddenForResolutionEverywhereBesideSupercalls*/ ") + } } builder.append(renderKeyword("fun")).append(" ") diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java index 4360f1b5f70..3b7c79c93d0 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java @@ -165,6 +165,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI return this; } + @NotNull + @Override + public CopyBuilder setHiddenForResolutionEverywhereBesideSupercalls() { + return this; + } + @NotNull @Override public CopyBuilder setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) {