forked from javaparser/javaparser
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adjusted parsing annotations that could belong to the package in st…
…ub files as well as to the class. This change is require because stub files could contain additional package declarations and it is valid to have annotations on package in Java.
- Loading branch information
1 parent
8ef4562
commit 765aa12
Showing
1 changed file
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,6 +694,8 @@ StubUnit StubUnit(): | |
ModifierHolder modifier; | ||
TypeDeclaration tn = null; | ||
ModuleDeclaration module = null; | ||
NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); | ||
AnnotationExpr annotation = null; | ||
} | ||
{ | ||
( LOOKAHEAD(2) ";" )* | ||
|
@@ -713,8 +715,10 @@ StubUnit StubUnit(): | |
* Number of compilation units in a stub file is 1+ | ||
*/ | ||
( | ||
/* This annotations could belong to the package declarations as well as to class declaration */ | ||
(LOOKAHEAD("@") annotation = Annotation() {annotations = add(annotations, annotation);} )* | ||
/* Additional package declaration is not require, but still possible */ | ||
(pakage = PackageDeclaration())? | ||
(pakage = PackageDeclarationForStubUnit(annotations))? | ||
|
||
/* | ||
* The only required import statements are the ones to import type annotations. | ||
|
@@ -733,7 +737,7 @@ StubUnit StubUnit(): | |
/** | ||
* Declaration specifiers (e.g., public, final, volatile) may be omitted. | ||
*/ | ||
modifier = Modifiers() | ||
modifier = ModifiersForStubUnit(annotations) | ||
( | ||
tn = ClassOrInterfaceDeclaration(modifier) { types = add(types, tn); } | ||
| | ||
|
@@ -751,6 +755,13 @@ StubUnit StubUnit(): | |
cu = new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module); | ||
compilationUnits.add(cu); | ||
} | ||
// Need to make annotations null in order to read new annotations properly | ||
{ | ||
annotation = null; | ||
if (annotations != null) { | ||
annotations = null; | ||
} | ||
} | ||
)+ | ||
|
||
|
||
|
@@ -812,6 +823,22 @@ PackageDeclaration PackageDeclaration(): | |
{ return new PackageDeclaration(range(begin, token()), annotations, name); } | ||
} | ||
|
||
PackageDeclaration PackageDeclarationForStubUnit(NodeList<AnnotationExpr> annotationsArg): | ||
{ | ||
NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); | ||
Name name; | ||
JavaToken begin; | ||
} | ||
{ | ||
{ | ||
if (annotationsArg != null) { | ||
annotations.addAll(annotationsArg); | ||
} | ||
} | ||
"package" {begin = token();} name = Name() ";" | ||
{ return new PackageDeclaration(range(begin, token()), annotations, name); } | ||
} | ||
|
||
|
||
ImportDeclaration ImportDeclaration(): | ||
{ | ||
|
@@ -880,6 +907,65 @@ ModifierHolder Modifiers(): | |
} | ||
} | ||
|
||
/* | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
* This is copied from method Modifiers() that used in the javaparser project | ||
This comment has been minimized.
Sorry, something went wrong.
mernst
Member
|
||
* Changes were required to adjust it for parsing stub files in the Checker Framework | ||
*/ | ||
ModifierHolder ModifiersForStubUnit(NodeList<AnnotationExpr> annotationsArg): | ||
{ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
JavaToken begin = INVALID; | ||
EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); | ||
NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); | ||
AnnotationExpr ann; | ||
} | ||
{ | ||
( | ||
LOOKAHEAD(2) | ||
/* | ||
* This action is require, because annotations could be read before executing this block | ||
* Hence all the annotation should accummulate | ||
*/ | ||
{ | ||
if (annotationsArg != null) { | ||
annotations.addAll(annotationsArg); | ||
} | ||
} | ||
( | ||
"public" { addModifier(this, modifiers, Modifier.PUBLIC); begin = begin.orIfInvalid(token()); } | ||
| | ||
"static" { addModifier(this, modifiers, Modifier.STATIC); begin = begin.orIfInvalid(token()); } | ||
| | ||
"protected" { addModifier(this, modifiers, Modifier.PROTECTED); begin = begin.orIfInvalid(token()); } | ||
| | ||
"private" { addModifier(this, modifiers, Modifier.PRIVATE); begin = begin.orIfInvalid(token()); } | ||
| | ||
"final" { addModifier(this, modifiers, Modifier.FINAL); begin = begin.orIfInvalid(token()); } | ||
| | ||
"abstract" { addModifier(this, modifiers, Modifier.ABSTRACT); begin = begin.orIfInvalid(token()); } | ||
| | ||
"synchronized" { addModifier(this, modifiers, Modifier.SYNCHRONIZED); begin = begin.orIfInvalid(token()); } | ||
| | ||
"native" { addModifier(this, modifiers, Modifier.NATIVE); begin = begin.orIfInvalid(token()); } | ||
| | ||
"transient" { addModifier(this, modifiers, Modifier.TRANSIENT); begin = begin.orIfInvalid(token()); } | ||
| | ||
"volatile" { addModifier(this, modifiers, Modifier.VOLATILE); begin = begin.orIfInvalid(token()); } | ||
| | ||
"strictfp" { addModifier(this, modifiers, Modifier.STRICTFP); begin = begin.orIfInvalid(token()); } | ||
| | ||
"transitive" { addModifier(this, modifiers, Modifier.TRANSITIVE); begin = begin.orIfInvalid(token()); } | ||
| | ||
"default" { addModifier(this, modifiers, Modifier.DEFAULT); begin = begin.orIfInvalid(token()); } | ||
| | ||
ann = Annotation() { annotations = add(annotations, ann); begin = begin.orIfInvalid(ann.getTokenRange().get().getBegin()); } | ||
) | ||
)* | ||
|
||
{ | ||
return new ModifierHolder(begin, modifiers, annotations); | ||
} | ||
} | ||
|
||
/* | ||
* Declaration syntax follows. | ||
*/ | ||
|
End each sentence with a period, to make it easier to read.