Add 'subClassDescriptor' parameter to ExternalOverridabilityCondition
This commit is contained in:
+5
-1
@@ -30,7 +30,11 @@ import java.util.List;
|
||||
public class SamAdapterOverridabilityCondition implements ExternalOverridabilityCondition {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result isOverridable(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
public Result isOverridable(
|
||||
@NotNull CallableDescriptor superDescriptor,
|
||||
@NotNull CallableDescriptor subDescriptor,
|
||||
@Nullable ClassDescriptor subClassDescriptor
|
||||
) {
|
||||
if (!(subDescriptor instanceof SimpleFunctionDescriptor) || !(superDescriptor instanceof SimpleFunctionDescriptor)) {
|
||||
return Result.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class DelegationResolver<T : CallableMemberDescriptor> private constructor(
|
||||
possiblyOverriddenBy.any { isOverridableBy(it, candidate) }
|
||||
|
||||
private fun isOverridableBy(memberOne: CallableDescriptor, memberTwo: CallableDescriptor): Boolean =
|
||||
OverridingUtil.DEFAULT.isOverridableBy(memberOne, memberTwo).result == OVERRIDABLE
|
||||
OverridingUtil.DEFAULT.isOverridableBy(memberOne, memberTwo, null).result == OVERRIDABLE
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +200,8 @@ public class OverrideResolver {
|
||||
for (D otherD : candidates) {
|
||||
CallableDescriptor other = transform.fun(otherD);
|
||||
if (me.getOriginal() == other.getOriginal()
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(other, me).getResult() == OVERRIDABLE
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(me, other).getResult() == OVERRIDABLE) {
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(other, me, null).getResult() == OVERRIDABLE
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(me, other, null).getResult() == OVERRIDABLE) {
|
||||
continue outerLoop;
|
||||
}
|
||||
}
|
||||
@@ -1027,7 +1027,7 @@ public class OverrideResolver {
|
||||
//noinspection unchecked
|
||||
all.addAll((Collection) supertype.getMemberScope().getContributedVariables(declared.getName(), NoLookupLocation.WHEN_CHECK_OVERRIDES));
|
||||
for (CallableMemberDescriptor fromSuper : all) {
|
||||
if (OverridingUtil.DEFAULT.isOverridableBy(fromSuper, declared).getResult() == OVERRIDABLE) {
|
||||
if (OverridingUtil.DEFAULT.isOverridableBy(fromSuper, declared, null).getResult() == OVERRIDABLE) {
|
||||
if (Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSuper, declared)) {
|
||||
throw new IllegalStateException("Descriptor " + fromSuper + " is overridable by " + declared +
|
||||
" and visible but does not appear in its getOverriddenDescriptors()");
|
||||
|
||||
@@ -156,7 +156,7 @@ public class KotlinOverridingTest extends KotlinLiteFixture {
|
||||
private void assertOverridabilityRelation(String superFun, String subFun, boolean expectedIsError) {
|
||||
FunctionDescriptor a = makeFunction(superFun);
|
||||
FunctionDescriptor b = makeFunction(subFun);
|
||||
OverridingUtil.OverrideCompatibilityInfo overridableWith = OverridingUtil.DEFAULT.isOverridableBy(a, b);
|
||||
OverridingUtil.OverrideCompatibilityInfo overridableWith = OverridingUtil.DEFAULT.isOverridableBy(a, b, null);
|
||||
assertEquals(
|
||||
overridableWith.getDebugMessage(),
|
||||
expectedIsError,
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.RawSubstitution
|
||||
@@ -25,7 +26,7 @@ import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
|
||||
class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
|
||||
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor): Result {
|
||||
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor, subClassDescriptor: ClassDescriptor?): Result {
|
||||
if (subDescriptor !is JavaMethodDescriptor) return Result.UNKNOWN
|
||||
|
||||
var erasedSuper = superDescriptor.substitute(RawSubstitution.buildSubstitutor()) ?: return Result.UNKNOWN
|
||||
|
||||
+2
-1
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
||||
|
||||
class FieldOverridabilityCondition : ExternalOverridabilityCondition {
|
||||
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor): Result {
|
||||
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor, subClassDescriptor: ClassDescriptor?): Result {
|
||||
if (subDescriptor !is PropertyDescriptor || superDescriptor !is PropertyDescriptor) return Result.UNKNOWN
|
||||
if (subDescriptor.name != superDescriptor.name) return Result.UNKNOWN
|
||||
|
||||
|
||||
+7
-1
@@ -17,7 +17,9 @@
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
|
||||
public interface ExternalOverridabilityCondition {
|
||||
enum Result {
|
||||
@@ -25,5 +27,9 @@ public interface ExternalOverridabilityCondition {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Result isOverridable(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor);
|
||||
Result isOverridable(
|
||||
@NotNull CallableDescriptor superDescriptor,
|
||||
@NotNull CallableDescriptor subDescriptor,
|
||||
@Nullable ClassDescriptor subClassDescriptor
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,23 +62,29 @@ public class OverridingUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OverrideCompatibilityInfo isOverridableBy(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
return isOverridableBy(superDescriptor, subDescriptor, false);
|
||||
public OverrideCompatibilityInfo isOverridableBy(
|
||||
@NotNull CallableDescriptor superDescriptor,
|
||||
@NotNull CallableDescriptor subDescriptor,
|
||||
@Nullable ClassDescriptor subClassDescriptor
|
||||
) {
|
||||
return isOverridableBy(superDescriptor, subDescriptor, subClassDescriptor, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OverrideCompatibilityInfo isOverridableByIncludingReturnType(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
return isOverridableBy(superDescriptor, subDescriptor, true);
|
||||
return isOverridableBy(superDescriptor, subDescriptor, null, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private OverrideCompatibilityInfo isOverridableBy(
|
||||
@NotNull CallableDescriptor superDescriptor,
|
||||
@NotNull CallableDescriptor subDescriptor,
|
||||
@Nullable ClassDescriptor subClassDescriptor,
|
||||
boolean checkReturnType
|
||||
) {
|
||||
for (ExternalOverridabilityCondition externalCondition : EXTERNAL_CONDITIONS) {
|
||||
ExternalOverridabilityCondition.Result result = externalCondition.isOverridable(superDescriptor, subDescriptor);
|
||||
ExternalOverridabilityCondition.Result result =
|
||||
externalCondition.isOverridable(superDescriptor, subDescriptor, subClassDescriptor);
|
||||
switch (result) {
|
||||
case OVERRIDABLE:
|
||||
return OverrideCompatibilityInfo.success();
|
||||
@@ -281,7 +287,7 @@ public class OverridingUtil {
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> bound = new ArrayList<CallableMemberDescriptor>(descriptorsFromSuper.size());
|
||||
for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
|
||||
OverrideCompatibilityInfo.Result result = DEFAULT.isOverridableBy(fromSupertype, fromCurrent).getResult();
|
||||
OverrideCompatibilityInfo.Result result = DEFAULT.isOverridableBy(fromSupertype, fromCurrent, current).getResult();
|
||||
|
||||
boolean isVisible = Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSupertype, current);
|
||||
switch (result) {
|
||||
@@ -429,8 +435,8 @@ public class OverridingUtil {
|
||||
continue;
|
||||
}
|
||||
|
||||
OverrideCompatibilityInfo.Result result1 = DEFAULT.isOverridableBy(candidate, overrider).getResult();
|
||||
OverrideCompatibilityInfo.Result result2 = DEFAULT.isOverridableBy(overrider, candidate).getResult();
|
||||
OverrideCompatibilityInfo.Result result1 = DEFAULT.isOverridableBy(candidate, overrider, null).getResult();
|
||||
OverrideCompatibilityInfo.Result result2 = DEFAULT.isOverridableBy(overrider, candidate, null).getResult();
|
||||
if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
|
||||
overridable.add(candidate);
|
||||
iterator.remove();
|
||||
|
||||
@@ -65,7 +65,7 @@ public fun ClassDescriptor.findCallableMemberBySignature(signature: CallableMemb
|
||||
.filterIsInstance<CallableMemberDescriptor>()
|
||||
.firstOrNull {
|
||||
it.getContainingDeclaration() == this
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(it as CallableDescriptor, signature).getResult() == OVERRIDABLE
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(it as CallableDescriptor, signature, null).getResult() == OVERRIDABLE
|
||||
} as? CallableMemberDescriptor
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user