Fix annotated module declaration

This commit is contained in:
Clément Fournier
2019-05-25 07:24:55 +02:00
parent fa91d47f7b
commit ae8ba5128b
3 changed files with 27 additions and 6 deletions

View File

@ -1606,17 +1606,27 @@ ASTCompilationUnit CompilationUnit() :
{ {
[ LOOKAHEAD( ( Annotation() )* "package" ) PackageDeclaration() ( EmptyStatement() )* ] [ LOOKAHEAD( ( Annotation() )* "package" ) PackageDeclaration() ( EmptyStatement() )* ]
( ImportDeclaration() ( EmptyStatement() )* )* ( ImportDeclaration() ( EmptyStatement() )* )*
( LOOKAHEAD(2) TypeDeclaration() ( EmptyStatement() )* )* // the module decl lookahead needs to be before the type declaration branch,
[ LOOKAHEAD({isKeyword("open") || isKeyword("module") || getToken(1).kind == AT}) ModuleDeclaration() ( EmptyStatement() )* ] // looking for annotations + "open" | "module" will fail faster if it's *not*
// a module (most common case)
[ LOOKAHEAD(ModuleDeclLahead()) ModuleDeclaration() ( EmptyStatement() )* ]
( TypeDeclaration() ( EmptyStatement() )* )*
( < "\u001a" > )? ( < "\u001a" > )?
( < "~[]" > )? ( < "~[]" > )? // what's this for? Do you mean ( < ~[] > )*, i.e. "any character"?
<EOF> <EOF>
{
jjtThis.setComments(token_source.comments);
return jjtThis;
}
}
private void ModuleDeclLahead() #void:
{}
{ {
jjtThis.setComments(token_source.comments); (Annotation())* LOOKAHEAD({isKeyword("open") || isKeyword("module")}) <IDENTIFIER>
return jjtThis;
}
} }
void PackageDeclaration() : void PackageDeclaration() :
{} {}
{ {

View File

@ -263,6 +263,11 @@ public class JDKVersionTest {
parseJava9(loadSource("jdk9_module_info.java")); parseJava9(loadSource("jdk9_module_info.java"));
} }
@Test
public void testAnnotatedModule() {
parseJava9(loadSource("jdk9_module_info_with_annot.java"));
}
@Test(expected = ParseException.class) @Test(expected = ParseException.class)
public final void jdk9TryWithResourcesInJava8() { public final void jdk9TryWithResourcesInJava8() {
parseJava18(loadSource("jdk9_try_with_resources.java")); parseJava18(loadSource("jdk9_try_with_resources.java"));

View File

@ -0,0 +1,6 @@
/*
* See §7.7 Module Declarations in JLS
*/
@Deprecated(since = "11", forRemoval = true)
module jdk.pack {
}