[java] Support Unnamed Classes and Instance Main Methods for Java 21 Preview
JEP 445
This commit is contained in:
@ -1131,11 +1131,23 @@ ASTCompilationUnit CompilationUnit() :
|
||||
{
|
||||
[ LOOKAHEAD( ( Annotation() )* "package" ) PackageDeclaration() ( EmptyDeclaration() )* ]
|
||||
( ImportDeclaration() ( EmptyDeclaration() )* )*
|
||||
|
||||
// ModularCompilationUnit:
|
||||
// the module decl lookahead needs to be before the type declaration branch,
|
||||
// looking for annotations + "open" | "module" will fail faster if it's *not*
|
||||
// a module (most common case)
|
||||
[ LOOKAHEAD(ModuleDeclLahead()) ModuleDeclaration() ( EmptyDeclaration() )* ]
|
||||
|
||||
// OrdinaryCompilationUnit: -> TopLevelClassOrInterfaceDeclaration
|
||||
( TypeDeclaration() ( EmptyDeclaration() )* )*
|
||||
|
||||
// UnnamedClassCompilationUnit:
|
||||
[
|
||||
( LOOKAHEAD(3) ClassMemberDeclarationNoMethod() )*
|
||||
ModifierList() MethodDeclaration()
|
||||
( ClassOrInterfaceBodyDeclaration() )*
|
||||
]
|
||||
|
||||
<EOF>
|
||||
{
|
||||
jjtThis.setComments(token_source.comments);
|
||||
@ -1143,6 +1155,20 @@ ASTCompilationUnit CompilationUnit() :
|
||||
}
|
||||
}
|
||||
|
||||
// see ClassOrInterfaceBodyDeclaration()
|
||||
void ClassMemberDeclarationNoMethod() #void:
|
||||
{}
|
||||
{
|
||||
ModifierList()
|
||||
( LOOKAHEAD(3) ClassOrInterfaceDeclaration()
|
||||
| LOOKAHEAD({isKeyword("enum")}) EnumDeclaration()
|
||||
| LOOKAHEAD({isKeyword("record")}) RecordDeclaration()
|
||||
| LOOKAHEAD( [ TypeParameters() ] <IDENTIFIER> "(" ) ConstructorDeclaration()
|
||||
| LOOKAHEAD( Type() <IDENTIFIER> (AnnotationList() "[" "]")* ( "," | "=" | ";" ) ) FieldDeclaration()
|
||||
| LOOKAHEAD(2) AnnotationTypeDeclaration()
|
||||
)
|
||||
}
|
||||
|
||||
private void ModuleDeclLahead() #void:
|
||||
{}
|
||||
{
|
||||
|
Reference in New Issue
Block a user