mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-highlighting] IJ-CR-165049 IDEA-374019 Don't show error about 'main' method if there is an error with braces
- don't highlight if there is package statement - skip duplicated nested class for implicit classes GitOrigin-RevId: eadb287b7e52bfedd04340b8841597b9d6839ee5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab4901834d
commit
708f2a6328
@@ -197,7 +197,10 @@ final class ClassChecker {
|
||||
}
|
||||
parent = element;
|
||||
|
||||
if (element instanceof PsiDeclarationStatement) element = PsiTreeUtil.getChildOfType(element, PsiClass.class);
|
||||
if (element instanceof PsiDeclarationStatement){ element = PsiTreeUtil.getChildOfType(element, PsiClass.class);}
|
||||
|
||||
if (element instanceof PsiImplicitClass) return;
|
||||
|
||||
if (element instanceof PsiClass psiClass && name.equals(psiClass.getName())) {
|
||||
myVisitor.report(JavaErrorKinds.CLASS_DUPLICATE.create(aClass, psiClass));
|
||||
}
|
||||
@@ -403,6 +406,8 @@ final class ClassChecker {
|
||||
PsiMethod[] methods = implicitClass.getMethods();
|
||||
boolean hasMainMethod = ContainerUtil.exists(methods, method -> "main".equals(method.getName()) && PsiMethodUtil.isMainMethod(method));
|
||||
if (!hasMainMethod) {
|
||||
//don't show errors if there is a package, this package will be highlighted
|
||||
if (file.getPackageStatement() != null) return;
|
||||
//don't show errors if the file contains broken {}
|
||||
if(hasErrorElementWithBraces(file)) return;
|
||||
myVisitor.report(JavaErrorKinds.CLASS_IMPLICIT_NO_MAIN_METHOD.create(file, implicitClass));
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package com.example;
|
||||
|
||||
public class A {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<error descr="Package statement is not allowed for implicitly declared class">package a;</error>
|
||||
|
||||
int ab;
|
||||
|
||||
class AB {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<error descr="Implicitly declared class contains no 'main' method">public class SameNameInnerClass {
|
||||
|
||||
}
|
||||
|
||||
int a = 1;</error>
|
||||
@@ -1,5 +1,5 @@
|
||||
<error descr="Implicitly declared class contains no 'main' method"><error descr="Package statement is not allowed for implicitly declared class">package pack.bar;</error>
|
||||
<error descr="Package statement is not allowed for implicitly declared class">package pack.bar;</error>
|
||||
|
||||
void foo() {
|
||||
|
||||
}</error>
|
||||
}
|
||||
@@ -176,6 +176,14 @@ class ImplicitClassHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testBrokenFileNoHighlightingWithPackage() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testSameNameInnerClass() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
private fun doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java")
|
||||
myFixture.checkHighlighting()
|
||||
|
||||
Reference in New Issue
Block a user