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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
private val BasicCallResolutionContext.isSuperCall: Boolean get() = call.explicitReceiver is SuperCallReceiverValue
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<? extends FunctionDescriptor> newCopyBuilder();
|
||||
|
||||
@@ -129,6 +132,9 @@ public interface FunctionDescriptor extends CallableMemberDescriptor {
|
||||
@NotNull
|
||||
CopyBuilder<D> setHiddenToOvercomeSignatureClash();
|
||||
|
||||
@NotNull
|
||||
CopyBuilder<D> setHiddenForResolutionEverywhereBesideSupercalls();
|
||||
|
||||
@NotNull
|
||||
CopyBuilder<D> setAdditionalAnnotations(@NotNull Annotations additionalAnnotations);
|
||||
|
||||
|
||||
+26
@@ -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<? extends FunctionDescriptor> 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<? extends CallableMemberDescriptor> overriddenDescriptors) {
|
||||
//noinspection unchecked
|
||||
overriddenFunctions = (Collection<? extends FunctionDescriptor>) 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<FunctionDescriptor> {
|
||||
protected @NotNull TypeSubstitution substitution;
|
||||
protected @NotNull DeclarationDescriptor newOwner;
|
||||
@@ -310,6 +326,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
private boolean isHiddenToOvercomeSignatureClash;
|
||||
private List<TypeParameterDescriptor> 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);
|
||||
|
||||
+5
@@ -209,4 +209,9 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript
|
||||
public boolean isHiddenToOvercomeSignatureClash() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHiddenForResolutionEverywhereBesideSupercalls() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(" ")
|
||||
|
||||
+6
@@ -165,6 +165,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CopyBuilder<SimpleFunctionDescriptor> setHiddenForResolutionEverywhereBesideSupercalls() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CopyBuilder<SimpleFunctionDescriptor> setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) {
|
||||
|
||||
Reference in New Issue
Block a user