IDEA-69981 ("Redundant array creation" inspection does not warn on enum constant)

This commit is contained in:
Bas Leijdekkers
2011-05-20 16:46:53 +02:00
parent 0e58d431cd
commit c15ff45554
4 changed files with 28 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,7 +125,16 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
if (arrayElements.length > 0) {
copyArgumentList.addRange(arrayElements[0], arrayElements[arrayElements.length - 1]);
}
final JavaResolveResult resolveResult = copy.resolveMethodGenerics();
final JavaResolveResult resolveResult;
if (callExpression instanceof PsiEnumConstant) {
final PsiEnumConstant enumConstant = (PsiEnumConstant)callExpression;
final PsiClass containingClass = enumConstant.getContainingClass();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(enumConstant.getProject());
final PsiClassType classType = facade.getElementFactory().createType(containingClass);
resolveResult = facade.getResolveHelper().resolveConstructor(classType, copyArgumentList, enumConstant);
} else {
resolveResult = copy.resolveMethodGenerics();
}
return resolveResult.isValidResult() && resolveResult.getElement() == oldRefMethod;
}
catch (IncorrectOperationException e) {
@@ -170,4 +179,3 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
return "RedundantArrayCreation";
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant array creation</problem_class>
<description>Redundant array creation for calling varargs method</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
public enum Test {
A(new String[]{"1", "2"});
Test(String... ss) {
}
}
@@ -21,4 +21,5 @@ public class RedundantArrayForVarargsCallInspectionTest extends InspectionTestCa
public void testIDEADEV15215() throws Exception { doTest(); }
public void testIDEADEV25923() throws Exception { doTest(); }
public void testNestedArray() throws Exception { doTest(); }
public void testCheckEnumConstant() throws Exception { doTest(); }
}