mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: not a redundant method override when annotations have different parameters (IDEA-164186)
This commit is contained in:
+6
-34
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.inheritance;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
@@ -35,10 +36,6 @@ import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RedundantMethodOverrideInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -244,38 +241,13 @@ public class RedundantMethodOverrideInspection extends BaseInspection {
|
||||
else if (list2 == null) {
|
||||
return false;
|
||||
}
|
||||
final Set<String> annotations1 = new HashSet<>();
|
||||
for (PsiAnnotation annotation : list1.getAnnotations()) {
|
||||
annotations1.add(annotation.getQualifiedName());
|
||||
}
|
||||
final Set<String> annotations2 = new HashSet<>();
|
||||
for (PsiAnnotation annotation : list2.getAnnotations()) {
|
||||
annotations2.add(annotation.getQualifiedName());
|
||||
}
|
||||
final Set<String> uniques = disjunction(annotations1, annotations2);
|
||||
uniques.remove(CommonClassNames.JAVA_LANG_OVERRIDE);
|
||||
if (!uniques.isEmpty()) {
|
||||
if (list1.hasModifierProperty(PsiModifier.STRICTFP) != list2.hasModifierProperty(PsiModifier.STRICTFP) ||
|
||||
list1.hasModifierProperty(PsiModifier.SYNCHRONIZED) != list2.hasModifierProperty(PsiModifier.SYNCHRONIZED) ||
|
||||
list1.hasModifierProperty(PsiModifier.PUBLIC) != list2.hasModifierProperty(PsiModifier.PUBLIC) ||
|
||||
list1.hasModifierProperty(PsiModifier.PROTECTED) != list2.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
return false;
|
||||
}
|
||||
return list1.hasModifierProperty(PsiModifier.STRICTFP) == list2.hasModifierProperty(PsiModifier.STRICTFP) &&
|
||||
list1.hasModifierProperty(PsiModifier.SYNCHRONIZED) == list2.hasModifierProperty(PsiModifier.SYNCHRONIZED) &&
|
||||
list1.hasModifierProperty(PsiModifier.PUBLIC) == list2.hasModifierProperty(PsiModifier.PUBLIC) &&
|
||||
list1.hasModifierProperty(PsiModifier.PROTECTED) == list2.hasModifierProperty(PsiModifier.PROTECTED);
|
||||
}
|
||||
|
||||
private static <T> Set<T> disjunction(Collection<T> set1, Collection<T> set2) {
|
||||
final Set<T> result = new HashSet<>();
|
||||
for (T t : set1) {
|
||||
if (!set2.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
for (T t : set2) {
|
||||
if (!set1.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return AnnotationUtil.equal(list1.getAnnotations(), list2.getAnnotations());
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -128,3 +128,20 @@ class ComplexParameterEquivalent extends Params {
|
||||
return ((p1) + p2.hashCode());
|
||||
}
|
||||
}
|
||||
/////////////////
|
||||
@interface Anno {
|
||||
int value();
|
||||
}
|
||||
class Annotations1 {
|
||||
|
||||
@Anno(1)
|
||||
void m() {}
|
||||
}
|
||||
class Annotations2 extends Annotations1{
|
||||
|
||||
@Anno(2)
|
||||
@Override
|
||||
void m() {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user