A little renaming to make code more clear
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
@@ -27,10 +26,12 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DESCRIPTOR_TO_DECLARATION;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -157,8 +158,8 @@ public class OverloadResolver {
|
||||
|
||||
private void checkOverloadsInAClass(
|
||||
MutableClassDescriptor classDescriptor, JetClassOrObject klass,
|
||||
Collection<ConstructorDescriptor> nestedClassConstructors)
|
||||
{
|
||||
Collection<ConstructorDescriptor> nestedClassConstructors
|
||||
) {
|
||||
MultiMap<String, CallableMemberDescriptor> functionsByName = MultiMap.create();
|
||||
|
||||
for (CallableMemberDescriptor function : classDescriptor.getCallableMembers()) {
|
||||
@@ -183,24 +184,25 @@ public class OverloadResolver {
|
||||
return;
|
||||
}
|
||||
|
||||
for (CallableMemberDescriptor function : functions) {
|
||||
for (CallableMemberDescriptor function2 : functions) {
|
||||
if (function == function2) {
|
||||
for (CallableMemberDescriptor member : functions) {
|
||||
for (CallableMemberDescriptor member2 : functions) {
|
||||
if (member == member2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
OverloadUtil.OverloadCompatibilityInfo overloadable = OverloadUtil.isOverloadable(function, function2);
|
||||
OverloadUtil.OverloadCompatibilityInfo overloadable = OverloadUtil.isOverloadable(member, member2);
|
||||
if (!overloadable.isSuccess()) {
|
||||
JetDeclaration member = (JetDeclaration) trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, function);
|
||||
if (member == null) {
|
||||
assert trace.get(DELEGATED, function);
|
||||
JetDeclaration jetDeclaration = (JetDeclaration) trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, member);
|
||||
if (jetDeclaration == null) {
|
||||
assert trace.get(DELEGATED, member);
|
||||
return;
|
||||
}
|
||||
|
||||
if (function instanceof PropertyDescriptor) {
|
||||
trace.report(Errors.REDECLARATION.on(function, trace.getBindingContext()));
|
||||
} else {
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(member, function, functionContainer));
|
||||
if (member instanceof PropertyDescriptor) {
|
||||
trace.report(Errors.REDECLARATION.on(trace.get(DESCRIPTOR_TO_DECLARATION, member), member.getName()));
|
||||
}
|
||||
else {
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(jetDeclaration, member, functionContainer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class OverloadUtil {
|
||||
}
|
||||
|
||||
OverridingUtil.OverrideCompatibilityInfo overrideCompatibilityInfo = OverridingUtil.isOverridableByImpl(a, b, false);
|
||||
switch (overrideCompatibilityInfo.isOverridable()) {
|
||||
switch (overrideCompatibilityInfo.getResult()) {
|
||||
case OVERRIDABLE:
|
||||
case CONFLICT:
|
||||
return OverloadCompatibilityInfo.someError();
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -34,6 +33,7 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
@@ -159,17 +159,18 @@ public class OverrideResolver {
|
||||
boolean overrides = false;
|
||||
|
||||
for (CallableMemberDescriptor functionFromCurrent : functionsFromCurrent) {
|
||||
OverridingUtil.OverrideCompatibilityInfo.ErrorKind overridable = OverridingUtil.isOverridableBy(functionFromSupertype, functionFromCurrent).isOverridable();
|
||||
if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||
OverridingUtil.OverrideCompatibilityInfo.Result result = OverridingUtil.isOverridableBy(functionFromSupertype, functionFromCurrent).getResult();
|
||||
if (result == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
functionFromCurrent.addOverriddenDescriptor(functionFromSupertype);
|
||||
overrides = true;
|
||||
} else if (overridable == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.CONFLICT) {
|
||||
}
|
||||
else if (result == OverridingUtil.OverrideCompatibilityInfo.Result.CONFLICT) {
|
||||
sink.conflict(functionFromSupertype, functionFromCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
for (CallableMemberDescriptor fakeOverride : fakeOverrides) {
|
||||
if (OverridingUtil.isOverridableBy(functionFromSupertype, fakeOverride).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||
if (OverridingUtil.isOverridableBy(functionFromSupertype, fakeOverride).getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
fakeOverride.addOverriddenDescriptor(functionFromSupertype);
|
||||
overrides = true;
|
||||
}
|
||||
@@ -352,8 +353,8 @@ public class OverrideResolver {
|
||||
for (CallableMemberDescriptor another : filteredMembers) {
|
||||
// if (one == another) continue;
|
||||
factoredMembers.put(one, one);
|
||||
if (OverridingUtil.isOverridableBy(one, another).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE
|
||||
|| OverridingUtil.isOverridableBy(another, one).isOverridable() == OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||
if (OverridingUtil.isOverridableBy(one, another).getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
|| OverridingUtil.isOverridableBy(another, one).getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
factoredMembers.put(one, another);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ public class OverridingUtil {
|
||||
for (D otherD : candidates) {
|
||||
CallableDescriptor other = transform.fun(otherD);
|
||||
if (me.getOriginal() == other.getOriginal()
|
||||
&& isOverridableBy(other, me).isOverridable() == OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE
|
||||
&& isOverridableBy(me, other).isOverridable() == OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE) {
|
||||
&& isOverridableBy(other, me).getResult() == OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
&& isOverridableBy(me, other).getResult() == OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
continue outerLoop;
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class OverridingUtil {
|
||||
return OverrideCompatibilityInfo.typeParameterNumberMismatch();
|
||||
}
|
||||
}
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(null, null, OverrideCompatibilityInfo.ErrorKind.CONFLICT);
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(null, null, OverrideCompatibilityInfo.Result.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class OverridingUtil {
|
||||
JetType subValueParameter = subValueParameters.get(i);
|
||||
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(superValueParameter, subValueParameter, axioms)) {
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameter, subValueParameter, OverrideCompatibilityInfo.ErrorKind.INCOMPATIBLE);
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameter, subValueParameter, OverrideCompatibilityInfo.Result.INCOMPATIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class OverridingUtil {
|
||||
JetType subValueParameterType = getUpperBound(subValueParameters.get(i));
|
||||
// TODO: compare erasure
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(superValueParameterType, subValueParameterType)) {
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, OverrideCompatibilityInfo.ErrorKind.INCOMPATIBLE);
|
||||
return OverrideCompatibilityInfo.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, OverrideCompatibilityInfo.Result.INCOMPATIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,13 +265,13 @@ public class OverridingUtil {
|
||||
|
||||
public static class OverrideCompatibilityInfo {
|
||||
|
||||
public enum ErrorKind {
|
||||
public enum Result {
|
||||
OVERRIDABLE,
|
||||
INCOMPATIBLE,
|
||||
CONFLICT,
|
||||
}
|
||||
|
||||
private static final OverrideCompatibilityInfo SUCCESS = new OverrideCompatibilityInfo(ErrorKind.OVERRIDABLE, "SUCCESS");
|
||||
private static final OverrideCompatibilityInfo SUCCESS = new OverrideCompatibilityInfo(Result.OVERRIDABLE, "SUCCESS");
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo success() {
|
||||
@@ -280,55 +280,55 @@ public class OverridingUtil {
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo nameMismatch() {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "nameMismatch"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "nameMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo typeParameterNumberMismatch() {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "typeParameterNumberMismatch"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "typeParameterNumberMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo valueParameterNumberMismatch() {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "valueParameterNumberMismatch"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "valueParameterNumberMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo boundsMismatch(TypeParameterDescriptor superTypeParameter, TypeParameterDescriptor subTypeParameter) {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "boundsMismatch"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "boundsMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo valueParameterTypeMismatch(JetType superValueParameter, JetType subValueParameter, ErrorKind errorKind) {
|
||||
return new OverrideCompatibilityInfo(errorKind, "valueParameterTypeMismatch"); // TODO
|
||||
public static OverrideCompatibilityInfo valueParameterTypeMismatch(JetType superValueParameter, JetType subValueParameter, Result result) {
|
||||
return new OverrideCompatibilityInfo(result, "valueParameterTypeMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo memberKindMismatch() {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "memberKindMismatch"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "memberKindMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo returnTypeMismatch(JetType substitutedSuperReturnType, JetType unsubstitutedSubReturnType) {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.CONFLICT, "returnTypeMismatch: " + unsubstitutedSubReturnType + " >< " + substitutedSuperReturnType); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.CONFLICT, "returnTypeMismatch: " + unsubstitutedSubReturnType + " >< " + substitutedSuperReturnType); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo varOverriddenByVal() {
|
||||
return new OverrideCompatibilityInfo(ErrorKind.INCOMPATIBLE, "varOverriddenByVal"); // TODO
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "varOverriddenByVal"); // TODO
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final ErrorKind overridable;
|
||||
private final Result overridable;
|
||||
private final String message;
|
||||
|
||||
public OverrideCompatibilityInfo(ErrorKind success, String message) {
|
||||
public OverrideCompatibilityInfo(Result success, String message) {
|
||||
this.overridable = success;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ErrorKind isOverridable() {
|
||||
public Result getResult() {
|
||||
return overridable;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public class JetOverridingTest extends JetLiteFixture {
|
||||
FunctionDescriptor a = makeFunction(superFun);
|
||||
FunctionDescriptor b = makeFunction(subFun);
|
||||
OverridingUtil.OverrideCompatibilityInfo overridableWith = OverridingUtil.isOverridableBy(a, b);
|
||||
assertEquals(overridableWith.getMessage(), expectedIsError, overridableWith.isOverridable() != OverridingUtil.OverrideCompatibilityInfo.ErrorKind.OVERRIDABLE);
|
||||
assertEquals(overridableWith.getMessage(), expectedIsError, overridableWith.getResult() != OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE);
|
||||
}
|
||||
|
||||
private FunctionDescriptor makeFunction(String funDecl) {
|
||||
|
||||
Reference in New Issue
Block a user