IDEA-120636 Wrong "enum cannot be instantiated"

This commit is contained in:
Anna Kozlova
2014-02-12 15:07:28 +01:00
parent aa96d2f5ff
commit 2076c69eeb
3 changed files with 18 additions and 1 deletions
@@ -715,7 +715,7 @@ public class GenericsHighlightUtil {
@Nullable
public static HighlightInfo checkEnumInstantiation(PsiNewExpression expression, PsiClass aClass) {
if (aClass != null && aClass.isEnum()) {
if (aClass != null && aClass.isEnum() && expression.getArrayDimensions().length == 0 && expression.getArrayInitializer() == null) {
String description = JavaErrorMessages.message("enum.types.cannot.be.instantiated");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
}
@@ -0,0 +1,16 @@
import java.util.*;
public class MyEnum {
enum Test {A,B}
public static Test[] accepted1() {
List<Test> list = new ArrayList<Test>();
return list.toArray(new Test[list.size()]);
}
public static Test[] accepted2() {
return new Test[]{};
}
Test t = <error descr="Enum types cannot be instantiated">new Test()</error>;
}
@@ -61,4 +61,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
public void testUnhandledExceptions() { doTest(true, false); }
public void testUnhandledExceptionsValueOf() { doTest(true, false); }
public void testUnsupportedFeatures7() { doTest(false, false); }
public void testEnumInitializers() { doTest(false, false); }
}