Cleanup primitive type

This commit is contained in:
Clément Fournier
2020-07-26 17:48:42 +02:00
parent 2ace5798f4
commit 067102a9c5
5 changed files with 17 additions and 13 deletions

View File

@ -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);}
}

View File

@ -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;
}
}

View File

@ -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();
/**

View File

@ -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());

View File

@ -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 {