mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight all pairs of methods with same erasures (IDEA-124116)
This commit is contained in:
+14
-6
@@ -42,6 +42,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -326,7 +327,8 @@ public class GenericsHighlightUtil {
|
||||
if (errorResult == null && languageLevel.isAtLeast(LanguageLevel.JDK_1_7) &&
|
||||
referenceElements.length > 1) {
|
||||
//todo suppress erased methods which come from the same class
|
||||
return checkOverrideEquivalentMethods(languageLevel, aClass);
|
||||
final Collection<HighlightInfo> result = checkOverrideEquivalentMethods(languageLevel, aClass);
|
||||
return result != null && result.size() > 0 ? result.iterator().next() : null;
|
||||
}
|
||||
return errorResult;
|
||||
}
|
||||
@@ -380,23 +382,29 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkOverrideEquivalentMethods(@NotNull LanguageLevel languageLevel,
|
||||
@NotNull PsiClass aClass) {
|
||||
public static Collection<HighlightInfo> checkOverrideEquivalentMethods(@NotNull LanguageLevel languageLevel,
|
||||
@NotNull PsiClass aClass) {
|
||||
List<HighlightInfo> result = new ArrayList<HighlightInfo>();
|
||||
final Collection<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
|
||||
PsiManager manager = aClass.getManager();
|
||||
Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods =
|
||||
new THashMap<MethodSignature, MethodSignatureBackedByPsiMethod>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
|
||||
|
||||
final Set<MethodSignature> foundProblems = new THashSet<MethodSignature>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
|
||||
for (HierarchicalMethodSignature signature : signaturesWithSupers) {
|
||||
HighlightInfo info = checkSameErasureNotSubSignatureInner(signature, manager, aClass, sameErasureMethods);
|
||||
if (info != null) return info;
|
||||
if (info != null && foundProblems.add(signature)) {
|
||||
result.add(info);
|
||||
}
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
info = HighlightMethodUtil.checkMethodIncompatibleReturnType(signature, signature.getSuperSignatures(), true, HighlightNamesUtil.getClassDeclarationTextRange(aClass));
|
||||
if (info != null) return info;
|
||||
if (info != null) {
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return result.isEmpty() ? null : result;
|
||||
}
|
||||
|
||||
static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(@NotNull LanguageLevel languageLevel,
|
||||
|
||||
+2
-3
@@ -888,8 +888,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(HighlightClassUtil.checkClassDoesNotCallSuperConstructorOrHandleExceptions(aClass, myRefCountHolder, myResolveHelper));
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkOverrideEquivalentInheritedMethods(aClass, myFile));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass
|
||||
));
|
||||
if (!myHolder.hasErrorResults()) myHolder.addAll(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCyclicInheritance(aClass));
|
||||
}
|
||||
catch (IndexNotReadyException ignored) {
|
||||
@@ -1045,7 +1044,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
|
||||
if (parent instanceof PsiAnonymousClass && ref.equals(((PsiAnonymousClass)parent).getBaseClassReference())) {
|
||||
PsiClass aClass = (PsiClass)parent;
|
||||
myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass));
|
||||
myHolder.addAll(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass));
|
||||
}
|
||||
|
||||
if (resolved instanceof PsiVariable) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.List;
|
||||
|
||||
class MyClass {
|
||||
<error descr="'method1(Comparable<Integer>)' clashes with 'method1(Comparable<Boolean>)'; both methods have same erasure">void method1 (Comparable<Integer> c)</error> {}
|
||||
void method1(Comparable<Boolean> c) {}
|
||||
|
||||
<error descr="'method2(List<Integer>)' clashes with 'method2(List<Boolean>)'; both methods have same erasure">void method2(List<Integer> l)</error> {}
|
||||
void method2(List<Boolean> l) {}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testEnum() { doTest(LanguageLevel.JDK_1_5, JavaSdkVersion.JDK_1_5, false); }
|
||||
public void testEnum56239() { doTest(LanguageLevel.JDK_1_6, JavaSdkVersion.JDK_1_6, false); }
|
||||
public void testSameErasure() { doTest5(false); }
|
||||
public void testPairsWithSameErasure() { doTest5(false); }
|
||||
public void testMethods() { doTest5(false); }
|
||||
public void testFields() { doTest5(false); }
|
||||
public void testStaticImports() { doTest5(true); }
|
||||
|
||||
Reference in New Issue
Block a user