mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] highlights package statements in module files
This commit is contained in:
+3
@@ -983,6 +983,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
public void visitPackageStatement(PsiPackageStatement statement) {
|
||||
super.visitPackageStatement(statement);
|
||||
myHolder.add(AnnotationsHighlightUtil.checkPackageAnnotationContainingFile(statement, myFile));
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_9)) {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(ModuleHighlightUtil.checkPackageStatement(statement, myFile));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
@@ -92,6 +92,17 @@ public class ModuleHighlightUtil {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
static HighlightInfo checkPackageStatement(@NotNull PsiPackageStatement statement, @NotNull PsiFile file) {
|
||||
if (PsiUtil.isModuleFile(file)) {
|
||||
String message = JavaErrorMessages.message("module.no.package");
|
||||
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).description(message).create();
|
||||
QuickFixAction.registerQuickFixAction(info, new DeleteElementFix(statement));
|
||||
return info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkFileName(@NotNull PsiJavaModule element, @NotNull PsiFile file) {
|
||||
if (!MODULE_INFO_FILE.equals(file.getName())) {
|
||||
|
||||
@@ -391,6 +391,7 @@ underscore.identifier.warn=Use of '_' as an identifier might not be supported in
|
||||
underscore.identifier.error=As of Java 9, '_' is a keyword, and may not be used as an identifier
|
||||
underscore.lambda.identifier=Use of '_' as a lambda parameter name is not allowed
|
||||
|
||||
module.no.package=A module file should not have 'package' statement
|
||||
module.file.wrong.name=Module declaration should be in a file named 'module-info.java'
|
||||
module.file.duplicate='module-info.java' already exists in the module
|
||||
module.duplicate.requires=Duplicate requires: {0}
|
||||
|
||||
@@ -28,6 +28,14 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
addFile("module-info.java", "module M3 { }", M3)
|
||||
}
|
||||
|
||||
fun testPackageStatement() {
|
||||
highlight("package pkg;")
|
||||
highlight("""
|
||||
<error descr="A module file should not have 'package' statement">package pkg;</error>
|
||||
module M { }""".trimIndent())
|
||||
fixes("<caret>package pkg;\nmodule M { }", "DeleteElementFix")
|
||||
}
|
||||
|
||||
fun testSoftKeywords() {
|
||||
addFile("pkg/module/C.java", "package pkg.module;\npublic class C { }")
|
||||
myFixture.configureByText("module-info.java", "module M { exports pkg.module; }")
|
||||
|
||||
Reference in New Issue
Block a user