Add nodes for array type dimensions

This commit is contained in:
Clément Fournier
2018-11-05 21:20:43 +01:00
committed by Andreas Dangel
parent 4f48e3a33e
commit 6378080a37
4 changed files with 136 additions and 6 deletions

View File

@ -1911,6 +1911,34 @@ void Initializer() :
}
/* JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.3
ReferenceType:
ClassOrInterfaceType
TypeVariable
ArrayType
ClassOrInterfaceType:
ClassType
InterfaceType
ClassType:
{Annotation} Identifier [TypeArguments]
ClassOrInterfaceType . {Annotation} Identifier [TypeArguments]
InterfaceType:
ClassType
TypeVariable:
{Annotation} Identifier
ArrayType:
PrimitiveType Dims
ClassOrInterfaceType Dims
TypeVariable Dims
Dims:
{Annotation} [ ] {{Annotation} [ ]}
*/
/*
* Type, name and expression syntax follows.
* Type is the same as "UnannType" in JLS
@ -1922,18 +1950,48 @@ void Type():
Token t;
}
{
LOOKAHEAD(2) ReferenceType()
LOOKAHEAD(PrimitiveType() Dims()) ReferenceType()
| PrimitiveType()
}
void Dims() #ArrayTypeDims:
{}
{
/* @A [] @B []
node<ASTDims> {
it.dimSize shouldBe 2
child<ASTDim> {
child<ASTAnnotation>(ignoreChildren=true) {
it.nameImage shouldBe "A"
}
}
child<ASTDim> {
child<ASTAnnotation>(ignoreChildren=true) {
it.nameImage shouldBe "B"
}
}
}
*/
( // LOOKAHEAD((TypeAnnotation())* "[" "]")
((TypeAnnotation())* "[" "]") #ArrayTypeDim
)+
}
void ReferenceType():
{}
{
// The grammar here is mildly wrong, the annotations can be before each []
// This will wait for #997
PrimitiveType() (TypeAnnotation())* ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })+
|
( ClassOrInterfaceType()) (TypeAnnotation())* ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })*
// TypeVariable is ambiguous with ClassOrInterfaceType
// Unless! we add a small symbol table to the parser,
// keeping track of the in-scope type variables (they're all
// necessarily lexically accessible)
( PrimitiveType() Dims() ) #ArrayType
| ( ClassOrInterfaceType() [ LOOKAHEAD(2) Dims() ] ) #ArrayType(>1)
}
void ClassOrInterfaceType():

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTNullLiteral.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArrayType extends AbstractJavaTypeNode {
public ASTArrayType(int id) {
super(id);
}
public ASTArrayType(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTNullLiteral.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArrayTypeDim extends AbstractJavaTypeNode {
public ASTArrayTypeDim(int id) {
super(id);
}
public ASTArrayTypeDim(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. ASTNullLiteral.java */
package net.sourceforge.pmd.lang.java.ast;
public class ASTArrayTypeDims extends AbstractJavaTypeNode {
public ASTArrayTypeDims(int id) {
super(id);
}
public ASTArrayTypeDims(JavaParser p, int id) {
super(p, id);
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}