From 067102a9c5d1175b1cdb763d3256b39e4a860721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 26 Jul 2020 17:48:42 +0200 Subject: [PATCH] Cleanup primitive type --- pmd-java/etc/grammar/Java.jjt | 4 +--- .../pmd/lang/java/ast/ASTPrimitiveType.java | 16 +++++++--------- .../sourceforge/pmd/lang/java/ast/ASTType.java | 2 ++ .../lang/java/internal/JavaDesignerBindings.java | 6 ++++++ .../java/types/internal/ast/PolyResolution.java | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 17f6d13d10..72faaa08dd 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1431,7 +1431,7 @@ FloatingPointType: void PrimitiveType() : {} { - ( "boolean" {jjtThis.setKind(PrimitiveTypeKind.BOOLEAN);} + "boolean" {jjtThis.setKind(PrimitiveTypeKind.BOOLEAN);} | "char" {jjtThis.setKind(PrimitiveTypeKind.CHAR);} | "byte" {jjtThis.setKind(PrimitiveTypeKind.BYTE);} | "short" {jjtThis.setKind(PrimitiveTypeKind.SHORT);} @@ -1439,8 +1439,6 @@ void PrimitiveType() : | "long" {jjtThis.setKind(PrimitiveTypeKind.LONG);} | "float" {jjtThis.setKind(PrimitiveTypeKind.FLOAT);} | "double" {jjtThis.setKind(PrimitiveTypeKind.DOUBLE);} - ) - {setLastTokenImage(jjtThis);} } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPrimitiveType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPrimitiveType.java index 54bed3c275..24dcb62883 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPrimitiveType.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPrimitiveType.java @@ -5,11 +5,9 @@ package net.sourceforge.pmd.lang.java.ast; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.java.symboltable.ClassScope; -import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; import net.sourceforge.pmd.lang.java.types.JPrimitiveType; import net.sourceforge.pmd.lang.java.types.JPrimitiveType.PrimitiveTypeKind; @@ -45,7 +43,6 @@ public final class ASTPrimitiveType extends AbstractJavaTypeNode implements ASTT void setKind(PrimitiveTypeKind kind) { assert this.kind == null : "Cannot set kind multiple times"; this.kind = kind; - setImage(kind.getSimpleName()); } public PrimitiveTypeKind getKind() { @@ -53,9 +50,15 @@ public final class ASTPrimitiveType extends AbstractJavaTypeNode implements ASTT return kind; } + @Override + @Deprecated + public String getImage() { + return null; + } + @Override public String getTypeImage() { - return getImage(); + return getKind().getSimpleName(); } @@ -68,9 +71,4 @@ public final class ASTPrimitiveType extends AbstractJavaTypeNode implements ASTT public @NonNull JPrimitiveType getTypeMirror() { return (JPrimitiveType) super.getTypeMirror(); } - - @Override - public @Nullable JavaTypeDefinition getTypeDefinition() { - return null; - } } 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 8cfa022a64..b4e9d7f926 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 @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.ast; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.Experimental; +import net.sourceforge.pmd.lang.ast.xpath.NoAttribute; /** @@ -34,6 +35,7 @@ public interface ASTType extends TypeNode, Annotatable, LeftRecursiveNode { * a method return a qualified name with help of the symbol table. */ @Experimental + @NoAttribute String getTypeImage(); /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaDesignerBindings.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaDesignerBindings.java index 195d8e6c5c..f7e3154953 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaDesignerBindings.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaDesignerBindings.java @@ -20,6 +20,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTInfixExpression; import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodReference; +import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType; import net.sourceforge.pmd.lang.java.ast.ASTRecordConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTVariableAccess; import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; @@ -147,6 +148,11 @@ public final class JavaDesignerBindings extends DefaultDesignerBindings { return new Attribute(node, "SimpleName", node.getSimpleName()); } + @Override + public Attribute visit(ASTPrimitiveType node, Void data) { + return new Attribute(node, "Kind", node.getKind().getSimpleName()); + } + @Override public Attribute visit(ASTMethodDeclaration node, Void data) { return new Attribute(node, "Name", node.getName()); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/ast/PolyResolution.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/ast/PolyResolution.java index 4310e80ccb..ead40b85e1 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/ast/PolyResolution.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/ast/PolyResolution.java @@ -314,7 +314,7 @@ final class PolyResolution { return ((ASTAssignmentExpression) context).getLeftOperand().getTypeMirror(); } else if (context instanceof ASTVariableDeclarator) { ASTType type = ((ASTVariableDeclarator) context).getVarId().getTypeNode(); - return Objects.requireNonNull(type, "For inferred type contextOf() should not return it").getTypeMirror(); + return Objects.requireNonNull(type, "For inferred type contextOf() should not return null").getTypeMirror(); } else if (context instanceof ASTCastExpression) { return ((ASTCastExpression) context).getCastType().getTypeMirror(); } else {