Class TypesFromReflection
- java.lang.Object
-
- net.sourceforge.pmd.lang.java.types.TypesFromReflection
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JTypeMirror
fromReflect(Type reflected, TypeSystem ts)
static @Nullable JTypeMirror
fromReflect(TypeSystem ts, @NonNull Type reflected, LexicalScope lexicalScope, Substitution subst)
Builds a type from reflection.static JTypeMirror
fromReflect(org.apache.commons.lang3.reflect.Typed<?> reflected, TypeSystem ts)
Builds a type from reflection.static @Nullable JClassSymbol
loadSymbol(TypeSystem ctr, String className)
static @Nullable JTypeMirror
loadType(TypeSystem ctr, String className)
Load a class.static @Nullable JTypeMirror
loadType(TypeSystem ctr, String className, net.sourceforge.pmd.lang.java.symbols.internal.UnresolvedClassStore unresolvedStore)
Load a class.
-
-
-
Method Detail
-
fromReflect
public static JTypeMirror fromReflect(org.apache.commons.lang3.reflect.Typed<?> reflected, TypeSystem ts)
Builds a type from reflection. This overload expects a ground type, ie it will fail if the given type mentions type variables. This can be used to get a type quickly, eg:// note the anonymous class body JTypeMirror streamOfInt = fromReflect(new TypeLiteral<Stream<Integer>>() {}, node.getTypeSystem()); if (node.getTypeMirror().equals(streamOfInt)) addViolation(node, "Use IntStream instead of Stream<Integer>"); // going the long way: TypeSystem ts = node.getTypeSystem(); JTypeMirror streamOfInt = ts.typeOf(ts.getClassSymbol(Stream.class), false) .withTypeParameters(listOf(ts.INT.box()));
- Parameters:
ts
- Type system that will build the typereflected
- ATyped
instance, eg aTypeLiteral
.- Throws:
IllegalArgumentException
- If the given type mentions type variablesNullPointerException
- If the type, or the type system, are null
-
fromReflect
public static JTypeMirror fromReflect(Type reflected, TypeSystem ts)
-
fromReflect
public static @Nullable JTypeMirror fromReflect(TypeSystem ts, @NonNull Type reflected, LexicalScope lexicalScope, Substitution subst)
Builds a type from reflection. This takes care of preserving the identity of type variables.- Parameters:
ts
- Type systemreflected
- A type instance obtained from reflectionlexicalScope
- An index for the in-scope type variables. All type variables occurring in the type must be referenced.subst
- Substitution to apply to tvars- Returns:
- A type, or null if the type system's symbol resolver cannot map the types to its own representation
- Throws:
IllegalArgumentException
- If there are free type variables in the type. Any type variable should be accessible in the lexical scope parameter.NullPointerException
- If any parameter is null
-
loadType
public static @Nullable JTypeMirror loadType(TypeSystem ctr, String className)
Load a class. Supports loading array types like 'java.lang.String[]' and converting a canonical name to a binary name (eg 'java.util.Map.Entry' -> 'java.util.Map$Entry').
-
loadType
public static @Nullable JTypeMirror loadType(TypeSystem ctr, String className, net.sourceforge.pmd.lang.java.symbols.internal.UnresolvedClassStore unresolvedStore)
Load a class. Supports loading array types like 'java.lang.String[]' and converting a canonical name to a binary name (eg 'java.util.Map.Entry' -> 'java.util.Map$Entry'). Types that are not on the classpath may be replaced by placeholder types if theUnresolvedClassStore
parameter is non-null.
-
loadSymbol
public static @Nullable JClassSymbol loadSymbol(TypeSystem ctr, String className)
-
-