Skip to content

Commit

Permalink
- adjusted parsing annotations that could belong to the package in st…
Browse files Browse the repository at this point in the history
…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
Bohdankm22 committed Jul 6, 2017
1 parent 8ef4562 commit 765aa12
Showing 1 changed file with 88 additions and 2 deletions.
90 changes: 88 additions & 2 deletions javaparser-core/src/main/javacc/java.jj
Original file line number Diff line number Diff line change
Expand Up @@ -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) ";" )*
Expand All @@ -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.
Expand All @@ -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); }
|
Expand All @@ -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;
}
}
)+


Expand Down Expand Up @@ -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():
{
Expand Down Expand Up @@ -880,6 +907,65 @@ ModifierHolder Modifiers():
}
}

/*

This comment has been minimized.

Copy link
@mernst

mernst Jul 6, 2017

Member

End each sentence with a period, to make it easier to read.

This comment has been minimized.

Copy link
@Bohdankm22

Bohdankm22 Jul 28, 2017

Author Collaborator

This code was removed in later commits.

* This is copied from method Modifiers() that used in the javaparser project

This comment has been minimized.

Copy link
@mernst

mernst Jul 6, 2017

Member

Be specific about which changes are required. (At the very least say where to find the original, to see the exact changes, but it's better to summarize them.)

This comment has been minimized.

Copy link
@Bohdankm22

Bohdankm22 Jul 28, 2017

Author Collaborator

This code was removed in later commits.

* Changes were required to adjust it for parsing stub files in the Checker Framework
*/
ModifierHolder ModifiersForStubUnit(NodeList<AnnotationExpr> annotationsArg):
{

This comment has been minimized.

Copy link
@mernst

mernst Jul 6, 2017

Member

Inconsistent indentation -- don't use tabs.

This comment has been minimized.

Copy link
@Bohdankm22

Bohdankm22 Jul 28, 2017

Author Collaborator

This code was removed in later commits.

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.
*/
Expand Down

0 comments on commit 765aa12

Please sign in to comment.