mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show error for enums without constants but with abstract methods
This commit is contained in:
+17
@@ -1190,6 +1190,23 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkEnumWithoutConstantsCantHaveAbstractMethods(final PsiClass aClass) {
|
||||
if (!aClass.isEnum()) return null;
|
||||
for (PsiField field : aClass.getFields()) {
|
||||
if (field instanceof PsiEnumConstant) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
for (PsiMethod method : aClass.getMethods()) {
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
final String description = "Enum declaration without enum constants cannot have abstract methods";
|
||||
final TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HighlightInfo checkSelectStaticClassFromParameterizedType(final PsiElement resolved, final PsiJavaCodeReferenceElement ref) {
|
||||
if (resolved instanceof PsiClass && ((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiElement qualifier = ref.getQualifier();
|
||||
|
||||
+1
@@ -384,6 +384,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.areSupersAccessible(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkDuplicateTopLevelClass(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkEnumMustNotBeLocal(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkEnumWithoutConstantsCantHaveAbstractMethods(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkImplicitThisReferenceBeforeSuper(aClass, myJavaSdkVersion));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkClassAndPackageConflict(aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkPublicClassInRightFile(aClass));
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<error descr="Enum declaration without enum constants cannot have abstract methods">enum MyEnumTest</error> {
|
||||
;
|
||||
public abstract void m();
|
||||
}
|
||||
+1
@@ -68,6 +68,7 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testUnsupportedFeatures7() { doTest(false, false); }
|
||||
public void testEnumInitializers() { doTest(false, false); }
|
||||
public void testEnumSynthetics() { doTest(false, false); }
|
||||
public void testEnumWithoutConstants() { doTest(false, false); }
|
||||
public void testIDEA79251() { doTest(false, false); }
|
||||
public void testIDEA65473() { doTest(false, false); }
|
||||
public void testIDEA61415() { doTest(false, false); }
|
||||
|
||||
Reference in New Issue
Block a user