do highlighting when the file name of the unnamed class is not a vaild identifier IDEA-333231

GitOrigin-RevId: 25df95741ad34a814e8e61bd0928a01b98589ce6
This commit is contained in:
Roman Ivanov
2023-10-12 16:25:44 +02:00
committed by intellij-monorepo-bot
parent a90b477494
commit 426dfe92a6
6 changed files with 32 additions and 16 deletions

View File

@@ -45,8 +45,9 @@ public final class JavaUnnamedClassUtil {
String name = containingFile.getName();
int extensionIndex = name.lastIndexOf(".java");
if (extensionIndex == -1) return null;
// TODO check that the name is valid identifier
return name.substring(0, extensionIndex);
String jvmName = name.substring(0, extensionIndex);
if (!StringUtil.isJavaIdentifier(jvmName)) return null;
return jvmName;
}
/**

View File

@@ -577,6 +577,7 @@ 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.has.invalid.file.name=Unnamed class's file name is not a valid identifier
error.package.statement.not.allowed.for.unnamed.class=Package statement is not allowed for unnamed class
error.initializers.are.not.allowed.in.unnamed.classes=Initializers are not allowed in unnamed classes
remove.unused.import.quickfix.text=Remove unused import