mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] add highlighting when package is present in unnamed class
GitOrigin-RevId: 64e5c38ba1c56741857d2f3331562bbe7f2f65cb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a0383188c6
commit
c40178aaec
+6
@@ -1176,6 +1176,12 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_9)) {
|
||||
if (!myHolder.hasErrorResults()) add(ModuleHighlightUtil.checkPackageStatement(statement, myFile, myJavaModule));
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
if (HighlightingFeature.UNNAMED_CLASSES.isAvailable(myFile) && JavaUnnamedClassUtil.isFileWithUnnamedClass(myFile)) {
|
||||
add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(
|
||||
JavaErrorBundle.message("text.package.statement.not.allowed.for.unnamed.class")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.PsiUnnamedClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class JavaUnnamedClassUtil {
|
||||
public static boolean isFileWithUnnamedClass(@NotNull PsiFile file) {
|
||||
if (file instanceof PsiJavaFile) {
|
||||
PsiJavaFile javaFile = (PsiJavaFile)file;
|
||||
PsiClass[] classes = javaFile.getClasses();
|
||||
if (classes.length == 1 && classes[0] instanceof PsiUnnamedClass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -575,4 +575,5 @@ too.many.array.dimensions=Too many array dimensions
|
||||
error.cannot.infer.pattern.type=Cannot infer pattern type: {0}
|
||||
error.extra.semicolons.between.import.statements.not.allowed=Extra semicolons between import statements are not allowed
|
||||
error.guard.allowed.after.patterns.only=Guard is allowed after patterns only
|
||||
error.unnamed.class.contains.no.main.method=Unnamed class contains no 'main' method
|
||||
error.unnamed.class.contains.no.main.method=Unnamed class contains no 'main' method
|
||||
text.package.statement.not.allowed.for.unnamed.class=Package statement is not allowed for unnamed class
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<error descr="Unnamed class contains no 'main' method"><error descr="Package statement is not allowed for unnamed class">package pack.bar;</error>
|
||||
|
||||
void foo() {
|
||||
|
||||
}</error>
|
||||
+1
-1
@@ -16,7 +16,7 @@ class UnnamedClassHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
})
|
||||
}
|
||||
|
||||
fun testNoMainMethod() {
|
||||
fun testWithPackageStatement() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user