diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 5264cea500..960c45c9d4 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -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() : {} { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTReferenceType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTReferenceType.java index 74f56040b5..9373a886e3 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTReferenceType.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTReferenceType.java @@ -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}. * *
  *
- *  ReferenceType ::= {@linkplain ASTPrimitiveType PrimitiveType} {@linkplain ASTAnnotation Annotation}* ( "[" "]" )+
- *                  | {@linkplain ASTClassOrInterfaceType ClassOrInterfaceType} {@linkplain ASTAnnotation Annotation}* ( "[" "]" )*
+ *  ReferenceType ::= {@linkplain ASTClassOrInterfaceType ClassOrInterfaceType}
+ *                  | {@linkplain ASTArrayType}
  *
  * 
- * */ -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 void jjtAccept(SideEffectingVisitor 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 { } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java index 5ac6d9fdc4..46ff398bfc 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java @@ -10,70 +10,13 @@ package net.sourceforge.pmd.lang.java.ast; * *
  *
- * Type ::= {@linkplain ASTReferenceType ReferenceType} | {@linkplain ASTPrimitiveType PrimitiveType}
+ * Type ::= {@linkplain ASTReferenceType ReferenceType}
+ *        | {@linkplain ASTPrimitiveType PrimitiveType}
  *
  * 
* * 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 void jjtAccept(SideEffectingVisitor 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(); }