mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-53369 Groovy Editor -> Map Keys In Parenthetical Expressions All Considered Identical
This commit is contained in:
@@ -33,6 +33,7 @@ import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -365,31 +366,28 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
|
||||
@Override
|
||||
public void visitListOrMap(GrListOrMap listOrMap) {
|
||||
final Map<GrNamedArgument, List<GrNamedArgument>> map = DuplicatesUtil.factorDuplicates(listOrMap.getNamedArguments(), new TObjectHashingStrategy<GrNamedArgument>() {
|
||||
public int computeHashCode(GrNamedArgument arg) {
|
||||
final GrArgumentLabel label = arg.getLabel();
|
||||
if (label == null) return 0;
|
||||
MultiMap<String, GrNamedArgument> map = new MultiMap<String, GrNamedArgument>();
|
||||
|
||||
for (GrNamedArgument element : listOrMap.getNamedArguments()) {
|
||||
final GrArgumentLabel label = element.getLabel();
|
||||
if (label != null) {
|
||||
final String name = label.getName();
|
||||
if (name == null) return 0;
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(GrNamedArgument arg1, GrNamedArgument arg2) {
|
||||
final GrArgumentLabel label1 = arg1.getLabel();
|
||||
final GrArgumentLabel label2 = arg2.getLabel();
|
||||
if (label1 == null || label2 == null) {
|
||||
return label1 == null && label2 == null;
|
||||
if (name != null) {
|
||||
map.putValue(name, element);
|
||||
}
|
||||
final String name1 = label1.getName();
|
||||
final String name2 = label2.getName();
|
||||
if (name1 == null || name2 == null) {
|
||||
return name1 == null && name2 == null;
|
||||
}
|
||||
return name1.equals(name2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
processDuplicates(map, myHolder);
|
||||
for (String key : map.keySet()) {
|
||||
final Collection<GrNamedArgument> arguments = map.get(key);
|
||||
if (arguments.size() > 1) {
|
||||
final List<GrNamedArgument> args = new ArrayList<GrNamedArgument>(arguments);
|
||||
for (int i = 1; i < args.size(); i++) {
|
||||
GrNamedArgument namedArgument = args.get(i);
|
||||
myHolder.createWarningAnnotation(namedArgument.getLabel(), GroovyBundle.message("duplicate.element.in.the.map"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -734,15 +732,6 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
protected static void processDuplicates(Map<GrNamedArgument, List<GrNamedArgument>> map, AnnotationHolder holder) {
|
||||
for (List<GrNamedArgument> args : map.values()) {
|
||||
for (int i = 1; i < args.size(); i++) {
|
||||
GrNamedArgument namedArgument = args.get(i);
|
||||
holder.createWarningAnnotation(namedArgument, GroovyBundle.message("duplicate.element.in.the.map"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerAbstractMethodFix(Annotation annotation, GrMethod method, boolean makeClassAbstract) {
|
||||
if (method.getBlock() == null) {
|
||||
annotation.registerFix(new AddMethodBodyFix(method));
|
||||
|
||||
@@ -224,6 +224,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testSuperConstructorInvocation() throws Exception {doTest();}
|
||||
|
||||
public void testDuplicateMapKeys() throws Exception {doTest();}
|
||||
|
||||
public void testIndexPropertyAccess() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
x = [ (person.firstNameKey):person.firstName, (person.lastNameKey):person.lastName ]
|
||||
x = [2:1, <warning descr="Duplicate element in the map">2</warning>:2]
|
||||
Reference in New Issue
Block a user