org.jetbrains
annotations
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/SentinelType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/SentinelType.java
index c536a34090..d502997d52 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/SentinelType.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/SentinelType.java
@@ -9,19 +9,36 @@ import java.util.Set;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
/**
* A "type" that exists outside of the main type hierarchy. This is only
* used to have some sentinel values, to eg represent failure or errors.
*/
-class SentinelType implements JTypeMirror {
+final class SentinelType implements JTypeMirror {
private final TypeSystem ts;
private final String name;
+ private final JTypeDeclSymbol symbol;
SentinelType(TypeSystem ts, String name) {
this.ts = ts;
this.name = name;
+ this.symbol = null;
+ }
+
+ SentinelType(TypeSystem ts, String name, JTypeDeclSymbol symbol) {
+ this.ts = ts;
+ this.name = name;
+ this.symbol = symbol;
+ }
+
+ @Nullable
+ @Override
+ public JTypeDeclSymbol getSymbol() {
+ return symbol;
}
@Override
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeSystem.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeSystem.java
index 59dbfc3f09..ffbde3d93c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeSystem.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeSystem.java
@@ -57,33 +57,7 @@ public final class TypeSystem {
*
* This implementation uses this as the type of the 'null' literal.
*/
- public final JTypeMirror NULL_TYPE = new JTypeMirror() {
-
- @Override
- public JTypeMirror subst(Function super SubstVar, ? extends @NonNull JTypeMirror> subst) {
- return this;
- }
-
- @Override
- public TypeSystem getTypeSystem() {
- return TypeSystem.this;
- }
-
- @Override
- public @Nullable JClassSymbol getSymbol() {
- return null;
- }
-
- @Override
- public T acceptVisitor(JTypeVisitor visitor, P p) {
- return visitor.visitNullType(this, p);
- }
-
- @Override
- public String toString() {
- return "null";
- }
- };
+ public final JTypeMirror NULL_TYPE = new NullType();
// primitives
@@ -203,21 +177,11 @@ public final class TypeSystem {
primitivesByKind.put(PrimitiveTypeKind.DOUBLE, DOUBLE);
JClassSymbol unresolvedTypeSym = symbolFactory.makeUnresolvedReference("/*unresolved*/", 0);
- UNRESOLVED_TYPE = new SentinelType(this, "/*unresolved*/") {
- @Override
- public JTypeDeclSymbol getSymbol() {
- return unresolvedTypeSym;
- }
- };
+ UNRESOLVED_TYPE = new SentinelType(this, "/*unresolved*/", unresolvedTypeSym);
JClassSymbol primitiveVoidSym = ReflectedSymbols.getClassSymbol(symbolFactory, void.class);
assert primitiveVoidSym != null : "void";
- NO_TYPE = new SentinelType(this, "void") {
- @Override
- public JTypeDeclSymbol getSymbol() {
- return primitiveVoidSym;
- }
- };
+ NO_TYPE = new SentinelType(this, "void", primitiveVoidSym);
// reuse instances for common types
@@ -736,4 +700,31 @@ public final class TypeSystem {
return new TypeVarImpl(this, symbol);
}
+ private class NullType implements JTypeMirror {
+
+ @Override
+ public JTypeMirror subst(Function super SubstVar, ? extends @NonNull JTypeMirror> subst) {
+ return this;
+ }
+
+ @Override
+ public TypeSystem getTypeSystem() {
+ return TypeSystem.this;
+ }
+
+ @Override
+ public @Nullable JClassSymbol getSymbol() {
+ return null;
+ }
+
+ @Override
+ public T acceptVisitor(JTypeVisitor visitor, P p) {
+ return visitor.visitNullType(this, p);
+ }
+
+ @Override
+ public String toString() {
+ return "null";
+ }
+ }
}
diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml
index e43450b5a9..324b012a29 100644
--- a/pmd-lang-test/pom.xml
+++ b/pmd-lang-test/pom.xml
@@ -121,6 +121,12 @@
compile
+