diff --git a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java index 18496c684a7e..306c5fb974b8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/miscGenerics/RedundantArrayForVarargsCallInspection.java @@ -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"; } } - diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/expected.xml b/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/expected.xml new file mode 100644 index 000000000000..d4c072df88f4 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 3 + Redundant array creation + Redundant array creation for calling varargs method + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/src/Test.java b/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/src/Test.java new file mode 100644 index 000000000000..abef220717ae --- /dev/null +++ b/java/java-tests/testData/inspection/redundantArrayForVarargs/checkEnumConstant/src/Test.java @@ -0,0 +1,7 @@ + +public enum Test { + A(new String[]{"1", "2"}); + + Test(String... ss) { + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java index 5ce54ee7ce04..0258c1a86a1e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantArrayForVarargsCallInspectionTest.java @@ -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(); } }