cleanup after refactoring
merge property- and named-function- related code in OverrideResolver
This commit is contained in:
+4
-4
@@ -1196,14 +1196,14 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
Set<NamedFunctionDescriptor> functionsFromSupertypes = getFunctionsFromSupertypes(scopeData, methodName);
|
Set<NamedFunctionDescriptor> functionsFromSupertypes = getFunctionsFromSupertypes(scopeData, methodName);
|
||||||
|
|
||||||
OverrideResolver.generateOverridesInFunctionGroup(methodName, functionsFromSupertypes, functionsFromCurrent, classDescriptor, new OverrideResolver.DescriptorSink<NamedFunctionDescriptor>() {
|
OverrideResolver.generateOverridesInFunctionGroup(methodName, functionsFromSupertypes, functionsFromCurrent, classDescriptor, new OverrideResolver.DescriptorSink() {
|
||||||
@Override
|
@Override
|
||||||
public void addToScope(@NotNull NamedFunctionDescriptor fakeOverride) {
|
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||||
functions.add(fakeOverride);
|
functions.add((FunctionDescriptor) fakeOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void conflict(@NotNull NamedFunctionDescriptor fromSuper, @NotNull NamedFunctionDescriptor fromCurrent) {
|
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
|
|||||||
@Override
|
@Override
|
||||||
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
||||||
|
|
||||||
|
void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden);
|
||||||
|
|
||||||
enum Kind {
|
enum Kind {
|
||||||
DECLARATION,
|
DECLARATION,
|
||||||
FAKE_OVERRIDE,
|
FAKE_OVERRIDE,
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOverriddenFunction(@NotNull FunctionDescriptor overriddenFunction) {
|
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overriddenFunction) {
|
||||||
throw new UnsupportedOperationException("Constructors cannot override anything");
|
throw new UnsupportedOperationException("Constructors cannot override anything");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -140,8 +140,9 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
|||||||
return visibility;
|
return visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOverriddenFunction(@NotNull FunctionDescriptor overriddenFunction) {
|
@Override
|
||||||
overriddenFunctions.add(overriddenFunction);
|
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overriddenFunction) {
|
||||||
|
overriddenFunctions.add((FunctionDescriptor) overriddenFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -225,7 +226,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
|||||||
);
|
);
|
||||||
if (copyOverrides) {
|
if (copyOverrides) {
|
||||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||||
substitutedDescriptor.addOverriddenFunction(overriddenFunction.substitute(substitutor));
|
substitutedDescriptor.addOverriddenDescriptor(overriddenFunction.substitute(substitutor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return substitutedDescriptor;
|
return substitutedDescriptor;
|
||||||
|
|||||||
+5
@@ -133,4 +133,9 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
|||||||
}
|
}
|
||||||
return overriddenAccessors;
|
return overriddenAccessors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,8 +275,9 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOverriddenDescriptor(PropertyDescriptor overridden) {
|
@Override
|
||||||
overriddenProperties.add(overridden);
|
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||||
|
overriddenProperties.add((PropertyDescriptor) overridden);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -150,14 +150,10 @@ public class OverloadResolver {
|
|||||||
{
|
{
|
||||||
MultiMap<String, CallableMemberDescriptor> functionsByName = MultiMap.create();
|
MultiMap<String, CallableMemberDescriptor> functionsByName = MultiMap.create();
|
||||||
|
|
||||||
for (FunctionDescriptor function : classDescriptor.getFunctions()) {
|
for (CallableMemberDescriptor function : classDescriptor.getCallableMembers()) {
|
||||||
functionsByName.putValue(function.getName(), function);
|
functionsByName.putValue(function.getName(), function);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PropertyDescriptor property : classDescriptor.getProperties()) {
|
|
||||||
functionsByName.putValue(property.getName(), property);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ConstructorDescriptor nestedClassConstructor : nestedClassConstructors) {
|
for (ConstructorDescriptor nestedClassConstructor : nestedClassConstructors) {
|
||||||
functionsByName.putValue(nestedClassConstructor.getContainingDeclaration().getName(), nestedClassConstructor);
|
functionsByName.putValue(nestedClassConstructor.getContainingDeclaration().getName(), nestedClassConstructor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,102 +85,81 @@ public class OverrideResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NamedFunctionDescriptor> functionsFromSupertypes = getDescriptorsFromSupertypes(classDescriptor, NamedFunctionDescriptor.class);
|
List<CallableMemberDescriptor> functionsFromSupertypes = getDescriptorsFromSupertypes(classDescriptor);
|
||||||
List<PropertyDescriptor> propertiesFromSupertypes = getDescriptorsFromSupertypes(classDescriptor, PropertyDescriptor.class);
|
|
||||||
|
|
||||||
MultiMap<String, NamedFunctionDescriptor> functionsFromSupertypesByName = groupDescriptorsByName(functionsFromSupertypes);
|
MultiMap<String, CallableMemberDescriptor> functionsFromSupertypesByName = groupDescriptorsByName(functionsFromSupertypes);
|
||||||
MultiMap<String, PropertyDescriptor> propertiesFromSupertypesByName = groupDescriptorsByName(propertiesFromSupertypes);
|
|
||||||
|
MultiMap<String, CallableMemberDescriptor> functionsFromCurrentByName = groupDescriptorsByName(classDescriptor.getCallableMembers());
|
||||||
|
|
||||||
MultiMap<String, NamedFunctionDescriptor> functionsFromCurrentByName = groupDescriptorsByName(classDescriptor.getFunctions());
|
|
||||||
MultiMap<String, PropertyDescriptor> propertiesFromCurrentByName = groupDescriptorsByName(classDescriptor.getProperties());
|
|
||||||
|
|
||||||
Set<String> functionNames = new HashSet<String>();
|
Set<String> functionNames = new HashSet<String>();
|
||||||
functionNames.addAll(functionsFromSupertypesByName.keySet());
|
functionNames.addAll(functionsFromSupertypesByName.keySet());
|
||||||
functionNames.addAll(functionsFromCurrentByName.keySet());
|
functionNames.addAll(functionsFromCurrentByName.keySet());
|
||||||
|
|
||||||
Set<String> propertyNames = new HashSet<String>();
|
|
||||||
propertyNames.addAll(propertiesFromSupertypesByName.keySet());
|
|
||||||
propertyNames.addAll(propertiesFromCurrentByName.keySet());
|
|
||||||
|
|
||||||
|
|
||||||
for (String functionName : functionNames) {
|
for (String functionName : functionNames) {
|
||||||
generateOverridesInFunctionGroup(functionName,
|
generateOverridesInFunctionGroup(functionName,
|
||||||
functionsFromSupertypesByName.get(functionName),
|
functionsFromSupertypesByName.get(functionName),
|
||||||
functionsFromCurrentByName.get(functionName),
|
functionsFromCurrentByName.get(functionName),
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
new DescriptorSink<NamedFunctionDescriptor>() {
|
new DescriptorSink() {
|
||||||
@Override
|
@Override
|
||||||
public void addToScope(@NotNull NamedFunctionDescriptor fakeOverride) {
|
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||||
classDescriptor.getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(fakeOverride);
|
if (fakeOverride instanceof PropertyDescriptor) {
|
||||||
|
classDescriptor.getScopeForMemberLookupAsWritableScope().addPropertyDescriptor((PropertyDescriptor) fakeOverride);
|
||||||
|
} else if (fakeOverride instanceof NamedFunctionDescriptor) {
|
||||||
|
classDescriptor.getScopeForMemberLookupAsWritableScope().addFunctionDescriptor((NamedFunctionDescriptor) fakeOverride);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(fakeOverride.getClass().getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void conflict(@NotNull NamedFunctionDescriptor fromSuper, @NotNull NamedFunctionDescriptor fromCurrent) {
|
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
|
||||||
JetNamedFunction jetDeclaration = (JetNamedFunction) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, fromCurrent);
|
JetDeclaration jetProperty = (JetDeclaration) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, fromCurrent);
|
||||||
context.getTrace().report(Errors.CONFLICTING_OVERLOADS.on(jetDeclaration, fromCurrent, fromCurrent.getContainingDeclaration().getName()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String propertyName : propertyNames) {
|
|
||||||
generateOverridesInPropertyGroup(propertyName,
|
|
||||||
propertiesFromSupertypesByName.get(propertyName),
|
|
||||||
propertiesFromCurrentByName.get(propertyName),
|
|
||||||
classDescriptor,
|
|
||||||
new DescriptorSink<PropertyDescriptor>() {
|
|
||||||
@Override
|
|
||||||
public void addToScope(@NotNull PropertyDescriptor fakeOverride) {
|
|
||||||
classDescriptor.getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(fakeOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void conflict(@NotNull PropertyDescriptor fromSuper, @NotNull PropertyDescriptor fromCurrent) {
|
|
||||||
JetProperty jetProperty = (JetProperty) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, fromCurrent);
|
|
||||||
context.getTrace().report(Errors.CONFLICTING_OVERLOADS.on(jetProperty, fromCurrent, fromCurrent.getContainingDeclaration().getName()));
|
context.getTrace().report(Errors.CONFLICTING_OVERLOADS.on(jetProperty, fromCurrent, fromCurrent.getContainingDeclaration().getName()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DescriptorSink<D extends CallableMemberDescriptor> {
|
public interface DescriptorSink {
|
||||||
void addToScope(@NotNull D fakeOverride);
|
void addToScope(@NotNull CallableMemberDescriptor fakeOverride);
|
||||||
|
|
||||||
void conflict(@NotNull D fromSuper, @NotNull D fromCurrent);
|
void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateOverridesInFunctionGroup(
|
public static void generateOverridesInFunctionGroup(
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@NotNull Collection<NamedFunctionDescriptor> functionsFromSupertypes,
|
@NotNull Collection<? extends CallableMemberDescriptor> functionsFromSupertypes,
|
||||||
@NotNull Collection<NamedFunctionDescriptor> functionsFromCurrent,
|
@NotNull Collection<? extends CallableMemberDescriptor> functionsFromCurrent,
|
||||||
@NotNull ClassDescriptor current,
|
@NotNull ClassDescriptor current,
|
||||||
@NotNull DescriptorSink<NamedFunctionDescriptor> sink) {
|
@NotNull DescriptorSink sink) {
|
||||||
|
|
||||||
List<NamedFunctionDescriptor> fakeOverrides = Lists.newArrayList();
|
List<CallableMemberDescriptor> fakeOverrides = Lists.newArrayList();
|
||||||
|
|
||||||
for (NamedFunctionDescriptor functionFromSupertype : functionsFromSupertypes) {
|
for (CallableMemberDescriptor functionFromSupertype : functionsFromSupertypes) {
|
||||||
|
|
||||||
boolean overrides = false;
|
boolean overrides = false;
|
||||||
|
|
||||||
for (NamedFunctionDescriptor functionFromCurrent : functionsFromCurrent) {
|
for (CallableMemberDescriptor functionFromCurrent : functionsFromCurrent) {
|
||||||
OverridingUtil.OverrideCompatibilityInfo.ErrorKind overridable = OverridingUtil.isOverridableBy(functionFromSupertype, functionFromCurrent).isOverridable();
|
OverridingUtil.OverrideCompatibilityInfo.ErrorKind overridable = OverridingUtil.isOverridableBy(functionFromSupertype, functionFromCurrent).isOverridable();
|
||||||
if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||||
((FunctionDescriptorImpl) functionFromCurrent).addOverriddenFunction(functionFromSupertype);
|
functionFromCurrent.addOverriddenDescriptor(functionFromSupertype);
|
||||||
overrides = true;
|
overrides = true;
|
||||||
} else if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.CONFLICT) {
|
} else if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.CONFLICT) {
|
||||||
sink.conflict(functionFromSupertype, functionFromCurrent);
|
sink.conflict(functionFromSupertype, functionFromCurrent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NamedFunctionDescriptor fakeOverride : fakeOverrides) {
|
for (CallableMemberDescriptor fakeOverride : fakeOverrides) {
|
||||||
if (OverridingUtil.isOverridableBy(functionFromSupertype, fakeOverride).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
if (OverridingUtil.isOverridableBy(functionFromSupertype, fakeOverride).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||||
((FunctionDescriptorImpl) fakeOverride).addOverriddenFunction(functionFromSupertype);
|
fakeOverride.addOverriddenDescriptor(functionFromSupertype);
|
||||||
overrides = true;
|
overrides = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overrides) {
|
if (!overrides) {
|
||||||
NamedFunctionDescriptor fakeOverride = functionFromSupertype.copy(current, false, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
CallableMemberDescriptor fakeOverride = functionFromSupertype.copy(current, false, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||||
((FunctionDescriptorImpl) fakeOverride).addOverriddenFunction(functionFromSupertype);
|
fakeOverride.addOverriddenDescriptor(functionFromSupertype);
|
||||||
|
|
||||||
fakeOverrides.add(fakeOverride);
|
fakeOverrides.add(fakeOverride);
|
||||||
|
|
||||||
@@ -188,45 +167,6 @@ public class OverrideResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateOverridesInPropertyGroup(
|
|
||||||
@NotNull String name,
|
|
||||||
@NotNull Collection<PropertyDescriptor> propertiesFromSupertypes,
|
|
||||||
@NotNull Collection<PropertyDescriptor> propertiesFromCurrent,
|
|
||||||
@NotNull ClassDescriptor current,
|
|
||||||
@NotNull DescriptorSink<PropertyDescriptor> sink) {
|
|
||||||
|
|
||||||
List<PropertyDescriptor> fakeOverrides = Lists.newArrayList();
|
|
||||||
|
|
||||||
for (PropertyDescriptor propertyFromSupertype : propertiesFromSupertypes) {
|
|
||||||
boolean overrides = false;
|
|
||||||
for (PropertyDescriptor propertyFromCurrent : propertiesFromCurrent) {
|
|
||||||
OverridingUtil.OverrideCompatibilityInfo.ErrorKind overridable = OverridingUtil.isOverridableBy(propertyFromSupertype, propertyFromCurrent).isOverridable();
|
|
||||||
if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
|
||||||
propertyFromCurrent.addOverriddenDescriptor(propertyFromSupertype);
|
|
||||||
overrides = true;
|
|
||||||
} else if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.CONFLICT) {
|
|
||||||
sink.conflict(propertyFromSupertype, propertyFromCurrent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PropertyDescriptor fakeOverride : fakeOverrides) {
|
|
||||||
if (OverridingUtil.isOverridableBy(propertyFromSupertype, fakeOverride).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
|
||||||
((PropertyDescriptor) fakeOverride).addOverriddenDescriptor(propertyFromSupertype);
|
|
||||||
overrides = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!overrides) {
|
|
||||||
PropertyDescriptor fakeOverride = propertyFromSupertype.copy(current, false, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
|
||||||
fakeOverride.addOverriddenDescriptor(propertyFromSupertype);
|
|
||||||
|
|
||||||
fakeOverrides.add(fakeOverride);
|
|
||||||
|
|
||||||
sink.addToScope(fakeOverride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static <T extends DeclarationDescriptor> MultiMap<String, T> groupDescriptorsByName(Collection<T> properties) {
|
private static <T extends DeclarationDescriptor> MultiMap<String, T> groupDescriptorsByName(Collection<T> properties) {
|
||||||
@@ -238,21 +178,20 @@ public class OverrideResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static <T extends DeclarationDescriptor> List<T> getDescriptorsFromSupertypes(
|
private static List<CallableMemberDescriptor> getDescriptorsFromSupertypes(ClassDescriptor classDescriptor) {
|
||||||
ClassDescriptor classDescriptor, Class<T> descriptorClass) {
|
Set<CallableMemberDescriptor> r = Sets.newHashSet();
|
||||||
Set<T> r = Sets.newHashSet();
|
|
||||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
r.addAll(getDescriptorsOfType(supertype.getMemberScope(), descriptorClass));
|
r.addAll(getDescriptorsOfType(supertype.getMemberScope()));
|
||||||
}
|
}
|
||||||
return new ArrayList<T>(r);
|
return new ArrayList<CallableMemberDescriptor>(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends DeclarationDescriptor> List<T> getDescriptorsOfType(
|
private static <T extends DeclarationDescriptor> List<CallableMemberDescriptor> getDescriptorsOfType(
|
||||||
JetScope scope, Class<T> descriptorClass) {
|
JetScope scope) {
|
||||||
List<T> r = Lists.newArrayList();
|
List<CallableMemberDescriptor> r = Lists.newArrayList();
|
||||||
for (DeclarationDescriptor decl : scope.getAllDescriptors()) {
|
for (DeclarationDescriptor decl : scope.getAllDescriptors()) {
|
||||||
if (descriptorClass.isInstance(decl)) {
|
if (decl instanceof PropertyDescriptor || decl instanceof NamedFunctionDescriptor) {
|
||||||
r.add((T) decl);
|
r.add((CallableMemberDescriptor) decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Reference in New Issue
Block a user