Make Type and ReferenceType #void
This commit is contained in:
Clément Fournier
committed by
Andreas Dangel
parent
dafa4a4d44
commit
4ec95b527d
@ -1945,7 +1945,8 @@ Dims:
|
||||
*
|
||||
* See https://docs.oracle.com/javase/specs/jls/se10/html/jls-8.html#jls-UnannType
|
||||
*/
|
||||
void Type():
|
||||
// TODO make void
|
||||
void Type() #void:
|
||||
{
|
||||
Token t;
|
||||
}
|
||||
@ -1971,7 +1972,8 @@ void ArrayTypeDim():
|
||||
(TypeAnnotation())* "[" "]"
|
||||
}
|
||||
|
||||
void ReferenceType():
|
||||
// TODO make void
|
||||
void ReferenceType() #void:
|
||||
{}
|
||||
{
|
||||
|
||||
@ -2018,6 +2020,22 @@ void WildcardBounds():
|
||||
("extends" | "super") (TypeAnnotation())* ReferenceType()
|
||||
}
|
||||
|
||||
/* JLS https://docs.oracle.com/javase/specs/jls/se10/html/jls-4.html#jls-PrimitiveType
|
||||
|
||||
PrimitiveType:
|
||||
{Annotation} NumericType
|
||||
{Annotation} boolean
|
||||
NumericType:
|
||||
IntegralType
|
||||
FloatingPointType
|
||||
IntegralType:
|
||||
(one of)
|
||||
byte short int long char
|
||||
FloatingPointType:
|
||||
(one of)
|
||||
float double
|
||||
*/
|
||||
|
||||
void PrimitiveType() :
|
||||
{}
|
||||
{
|
||||
|
@ -7,66 +7,15 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
/**
|
||||
* Represents a reference type, i.e. a {@linkplain ASTClassOrInterfaceType class or interface type},
|
||||
* or an array type.
|
||||
* or an {@linkplain ASTArrayType array type}.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* ReferenceType ::= {@linkplain ASTPrimitiveType PrimitiveType} {@linkplain ASTAnnotation Annotation}* ( "[" "]" )+
|
||||
* | {@linkplain ASTClassOrInterfaceType ClassOrInterfaceType} {@linkplain ASTAnnotation Annotation}* ( "[" "]" )*
|
||||
* ReferenceType ::= {@linkplain ASTClassOrInterfaceType ClassOrInterfaceType}
|
||||
* | {@linkplain ASTArrayType}
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
public class ASTReferenceType extends AbstractJavaTypeNode implements Dimensionable {
|
||||
|
||||
private int arrayDepth;
|
||||
|
||||
public ASTReferenceType(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTReferenceType(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the visitor. *
|
||||
*/
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void bumpArrayDepth() {
|
||||
arrayDepth++;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getArrayDepth() {
|
||||
if (isArray()) {
|
||||
if (arrayDepth > 0) {
|
||||
return arrayDepth;
|
||||
} else {
|
||||
ASTArrayType arrayType = (ASTArrayType) jjtGetChild(0);
|
||||
return arrayType.getArrayDepth();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isArray() {
|
||||
return arrayDepth > 0 || jjtGetChild(0) instanceof ASTArrayType;
|
||||
}
|
||||
public interface ASTReferenceType extends ASTType {
|
||||
|
||||
}
|
||||
|
@ -10,70 +10,13 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* Type ::= {@linkplain ASTReferenceType ReferenceType} | {@linkplain ASTPrimitiveType PrimitiveType}
|
||||
* Type ::= {@linkplain ASTReferenceType ReferenceType}
|
||||
* | {@linkplain ASTPrimitiveType PrimitiveType}
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* Note: it is not exactly the same the "UnnanType" defined in JLS.
|
||||
*/
|
||||
public class ASTType extends AbstractJavaTypeNode {
|
||||
public ASTType(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTType(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the visitor. *
|
||||
*/
|
||||
@Override
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
|
||||
visitor.visit(this, data);
|
||||
}
|
||||
|
||||
|
||||
public String getTypeImage() {
|
||||
ASTClassOrInterfaceType refType = getFirstDescendantOfType(ASTClassOrInterfaceType.class);
|
||||
if (refType != null) {
|
||||
return refType.getImage();
|
||||
}
|
||||
return getFirstDescendantOfType(ASTPrimitiveType.class).getImage();
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public int getArrayDepth() {
|
||||
if (jjtGetNumChildren() != 0
|
||||
&& (jjtGetChild(0) instanceof ASTReferenceType || jjtGetChild(0) instanceof ASTPrimitiveType)) {
|
||||
return ((Dimensionable) jjtGetChild(0)).getArrayDepth();
|
||||
}
|
||||
return 0; // this is not an array
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use {@link #isArrayType()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isArray() {
|
||||
return isArrayType();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this type is an array type.
|
||||
*
|
||||
*/
|
||||
public boolean isArrayType() {
|
||||
return getArrayDepth() > 0;
|
||||
}
|
||||
public interface ASTType extends JavaNode {
|
||||
String getTypeImage();
|
||||
}
|
||||
|
Reference in New Issue
Block a user