mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
GenericHighlightingTest fixed
This commit is contained in:
+13
-21
@@ -38,7 +38,6 @@ import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -389,8 +388,7 @@ public class GenericsHighlightUtil {
|
||||
public static HighlightInfo checkElementInTypeParameterExtendsList(@NotNull PsiReferenceList referenceList,
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull JavaResolveResult resolveResult,
|
||||
@NotNull PsiElement element,
|
||||
@NotNull MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods) {
|
||||
@NotNull PsiElement element) {
|
||||
final PsiJavaCodeReferenceElement[] referenceElements = referenceList.getReferenceElements();
|
||||
PsiClass extendFrom = (PsiClass)resolveResult.getElement();
|
||||
if (extendFrom == null) return null;
|
||||
@@ -413,7 +411,7 @@ public class GenericsHighlightUtil {
|
||||
if (errorResult == null && JavaVersionService.getInstance().isAtLeast(referenceList, JavaSdkVersion.JDK_1_7) &&
|
||||
referenceElements.length > 1) {
|
||||
//todo suppress erased methods which come from the same class
|
||||
return checkOverrideEquivalentMethods(aClass,duplicateMethods);
|
||||
return checkOverrideEquivalentMethods(aClass);
|
||||
}
|
||||
return errorResult;
|
||||
}
|
||||
@@ -467,14 +465,14 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkOverrideEquivalentMethods(@NotNull PsiClass aClass, @NotNull MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods) {
|
||||
public static HighlightInfo checkOverrideEquivalentMethods(@NotNull PsiClass aClass) {
|
||||
final Collection<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
|
||||
PsiManager manager = aClass.getManager();
|
||||
Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods =
|
||||
new THashMap<MethodSignature, MethodSignatureBackedByPsiMethod>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
|
||||
|
||||
for (HierarchicalMethodSignature signature : signaturesWithSupers) {
|
||||
HighlightInfo info = checkSameErasureNotSubSignatureInner(signature, manager, aClass, sameErasureMethods,duplicateMethods);
|
||||
HighlightInfo info = checkSameErasureNotSubSignatureInner(signature, manager, aClass, sameErasureMethods);
|
||||
if (info != null) return info;
|
||||
}
|
||||
|
||||
@@ -525,11 +523,10 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkSameErasureNotSubSignatureInner(final HierarchicalMethodSignature signature,
|
||||
final PsiManager manager,
|
||||
final PsiClass aClass,
|
||||
final Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods,
|
||||
@NotNull MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods) {
|
||||
private static HighlightInfo checkSameErasureNotSubSignatureInner(@NotNull HierarchicalMethodSignature signature,
|
||||
@NotNull PsiManager manager,
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods) {
|
||||
PsiMethod method = signature.getMethod();
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
|
||||
if (!facade.getResolveHelper().isAccessible(method, aClass, null)) return null;
|
||||
@@ -541,7 +538,7 @@ public class GenericsHighlightUtil {
|
||||
MethodSignatureUtil.findMethodBySuperMethod(aClass, sameErasure.getMethod(), false) != null ||
|
||||
!(InheritanceUtil.isInheritorOrSelf(sameErasure.getMethod().getContainingClass(), method.getContainingClass(), true) ||
|
||||
InheritanceUtil.isInheritorOrSelf(method.getContainingClass(), sameErasure.getMethod().getContainingClass(), true))) {
|
||||
info = checkSameErasureNotSubSignatureOrSameClass(sameErasure, signature, aClass, method,duplicateMethods);
|
||||
info = checkSameErasureNotSubSignatureOrSameClass(sameErasure, signature, aClass, method);
|
||||
if (info != null) return info;
|
||||
}
|
||||
}
|
||||
@@ -550,7 +547,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
List<HierarchicalMethodSignature> supers = signature.getSuperSignatures();
|
||||
for (HierarchicalMethodSignature superSignature : supers) {
|
||||
info = checkSameErasureNotSubSignatureInner(superSignature, manager, aClass, sameErasureMethods,duplicateMethods);
|
||||
info = checkSameErasureNotSubSignatureInner(superSignature, manager, aClass, sameErasureMethods);
|
||||
if (info != null) return info;
|
||||
|
||||
if (superSignature.isRaw() && !signature.isRaw()) {
|
||||
@@ -558,8 +555,6 @@ public class GenericsHighlightUtil {
|
||||
PsiType[] erasedTypes = superSignature.getErasedParameterTypes();
|
||||
for (int i = 0; i < erasedTypes.length; i++) {
|
||||
if (!Comparing.equal(parameterTypes[i], erasedTypes[i])) {
|
||||
//duplicateMethods.removeAllValues(signatureToErase);
|
||||
//duplicateMethods.add(signatureToErase,method);
|
||||
return getSameErasureMessage(false, method, superSignature.getMethod(),
|
||||
HighlightNamesUtil.getClassDeclarationTextRange(aClass));
|
||||
}
|
||||
@@ -574,8 +569,7 @@ public class GenericsHighlightUtil {
|
||||
private static HighlightInfo checkSameErasureNotSubSignatureOrSameClass(final MethodSignatureBackedByPsiMethod signatureToCheck,
|
||||
final HierarchicalMethodSignature superSignature,
|
||||
final PsiClass aClass,
|
||||
final PsiMethod superMethod,
|
||||
@NotNull MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods) {
|
||||
final PsiMethod superMethod) {
|
||||
final PsiMethod checkMethod = signatureToCheck.getMethod();
|
||||
if (superMethod.equals(checkMethod)) return null;
|
||||
PsiClass checkContainingClass = checkMethod.getContainingClass();
|
||||
@@ -625,8 +619,6 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
if (superContainingClass != null && !superContainingClass.isInterface() && checkContainingClass.isInterface() && !aClass.equals(superContainingClass)) return null;
|
||||
//duplicateMethods.removeAllValues(checkMethod.getSignature(PsiSubstitutor.EMPTY)); // do not highlight other methods
|
||||
//duplicateMethods.add(checkMethod.getSignature(PsiSubstitutor.EMPTY),checkMethod);
|
||||
if (aClass.equals(checkContainingClass)) {
|
||||
boolean sameClass = aClass.equals(superContainingClass);
|
||||
return getSameErasureMessage(sameClass, checkMethod, superMethod, HighlightNamesUtil.getMethodDeclarationTextRange(checkMethod));
|
||||
@@ -636,9 +628,9 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static HighlightInfo getSameErasureMessage(final boolean sameClass, final PsiMethod method, final PsiMethod superMethod,
|
||||
private static HighlightInfo getSameErasureMessage(final boolean sameClass, @NotNull PsiMethod method, @NotNull PsiMethod superMethod,
|
||||
TextRange textRange) {
|
||||
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
|
||||
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ?
|
||||
"generics.methods.have.same.erasure.hide" :
|
||||
"generics.methods.have.same.erasure.override";
|
||||
|
||||
@@ -61,7 +61,6 @@ import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -2509,8 +2508,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
@Nullable
|
||||
static HighlightInfo checkElementInReferenceList(@NotNull PsiJavaCodeReferenceElement ref,
|
||||
@NotNull PsiReferenceList referenceList,
|
||||
@NotNull JavaResolveResult resolveResult,
|
||||
@NotNull MostlySingularMultiMap<MethodSignature,PsiMethod> duplicateMethods) {
|
||||
@NotNull JavaResolveResult resolveResult) {
|
||||
PsiElement resolved = resolveResult.getElement();
|
||||
HighlightInfo highlightInfo = null;
|
||||
PsiElement refGrandParent = referenceList.getParent();
|
||||
@@ -2518,7 +2516,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
PsiClass aClass = (PsiClass)resolved;
|
||||
if (refGrandParent instanceof PsiClass) {
|
||||
if (refGrandParent instanceof PsiTypeParameter) {
|
||||
highlightInfo = GenericsHighlightUtil.checkElementInTypeParameterExtendsList(referenceList, (PsiClass)refGrandParent, resolveResult, ref,duplicateMethods);
|
||||
highlightInfo = GenericsHighlightUtil.checkElementInTypeParameterExtendsList(referenceList, (PsiClass)refGrandParent, resolveResult, ref);
|
||||
}
|
||||
else {
|
||||
highlightInfo = HighlightClassUtil.checkExtendsClassAndImplementsInterface(referenceList, resolveResult, ref);
|
||||
|
||||
+3
-7
@@ -807,7 +807,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(HighlightClassUtil.checkClassDoesNotCallSuperConstructorOrHandleExceptions(aClass, myRefCountHolder, myResolveHelper));
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkOverrideEquivalentInheritedMethods(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(aClass,getDuplicateMethods(aClass)));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCyclicInheritance(aClass));
|
||||
}
|
||||
catch (IndexNotReadyException ignored) {
|
||||
@@ -950,16 +950,12 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (resolved != null && parent instanceof PsiReferenceList) {
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
PsiReferenceList referenceList = (PsiReferenceList)parent;
|
||||
PsiElement refParent = referenceList.getParent();
|
||||
|
||||
MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods = refParent instanceof PsiClass ? getDuplicateMethods(
|
||||
(PsiClass)refParent) : MostlySingularMultiMap.<MethodSignature, PsiMethod>emptyMap();
|
||||
myHolder.add(HighlightUtil.checkElementInReferenceList(ref, referenceList, result, duplicateMethods));
|
||||
myHolder.add(HighlightUtil.checkElementInReferenceList(ref, referenceList, result));
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof PsiAnonymousClass && ref.equals(((PsiAnonymousClass)parent).getBaseClassReference())) {
|
||||
myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods((PsiClass)parent, getDuplicateMethods((PsiClass)parent)));
|
||||
myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods((PsiClass)parent));
|
||||
}
|
||||
|
||||
if (resolved instanceof PsiVariable) {
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ import java.util.List;
|
||||
|
||||
interface A
|
||||
{
|
||||
<<error descr="'addAll(Collection<? extends E>)' in 'java.util.Collection' clashes with 'addAll(Collection<? extends E>)' in 'java.util.List'; both methods have same erasure, yet neither overrides the other"></error>T extends List<?> & Collection<? extends Cloneable>> void foo(T x);
|
||||
<<error descr="'add(E)' in 'java.util.List' clashes with 'add(E)' in 'java.util.Collection'; both methods have same erasure, yet neither overrides the other"></error>T extends List<?> & Collection<? extends Cloneable>> void foo(T x);
|
||||
}
|
||||
Reference in New Issue
Block a user