mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
enum, abstract and final should be an error somewhere (IDEA-186642)
This commit is contained in:
-17
@@ -1303,23 +1303,6 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static HighlightInfo checkSelectStaticClassFromParameterizedType(final PsiElement resolved, final PsiJavaCodeReferenceElement ref) {
|
||||
if (resolved instanceof PsiClass && ((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiElement qualifier = ref.getQualifier();
|
||||
|
||||
+4
-1
@@ -113,7 +113,10 @@ public class HighlightClassUtil {
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassMustBeAbstract(final PsiClass aClass, final TextRange textRange) {
|
||||
if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) || aClass.getRBrace() == null || aClass.isEnum() && hasEnumConstantsWithInitializer(aClass)) {
|
||||
if (aClass.isEnum()) {
|
||||
if (hasEnumConstantsWithInitializer(aClass)) return null;
|
||||
}
|
||||
else if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) || aClass.getRBrace() == null ) {
|
||||
return null;
|
||||
}
|
||||
return checkClassWithAbstractMethods(aClass, textRange);
|
||||
|
||||
-1
@@ -416,7 +416,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkClassSupersAccessibility(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));
|
||||
|
||||
+6
-1
@@ -1,4 +1,9 @@
|
||||
<error descr="Enum declaration without enum constants cannot have abstract methods">enum MyEnumTest</error> {
|
||||
<error descr="Class 'MyEnumTest' must either be declared abstract or implement abstract method 'm()' in 'MyEnumTest'">enum MyEnumTest</error> {
|
||||
;
|
||||
public abstract void m();
|
||||
}
|
||||
|
||||
<error descr="Class 'WithoutConstantInitializer' must either be declared abstract or implement abstract method 'm()' in 'WithoutConstantInitializer'">enum WithoutConstantInitializer</error> {
|
||||
FIRST;
|
||||
public abstract void m();
|
||||
}
|
||||
Reference in New Issue
Block a user