Refactor not to use anon classes
Kotlin reflect doesn't like it
This commit is contained in:
@ -210,16 +210,6 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
|
@ -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
|
||||
|
@ -57,33 +57,7 @@ public final class TypeSystem {
|
||||
*
|
||||
* <p>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, P> T acceptVisitor(JTypeVisitor<T, P> 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, P> T acceptVisitor(JTypeVisitor<T, P> visitor, P p) {
|
||||
return visitor.visitNullType(this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,12 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.kotest</groupId>
|
||||
<artifactId>kotest-runner-console-jvm</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
|
6
pom.xml
6
pom.xml
@ -847,6 +847,12 @@
|
||||
<version>${kotest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.kotest</groupId>
|
||||
<artifactId>kotest-runner-console-jvm</artifactId>
|
||||
<version>${kotest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.kotest</groupId>
|
||||
<artifactId>kotest-assertions-core-jvm</artifactId>
|
||||
|
Reference in New Issue
Block a user