Class TypeOps
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA result for a convertibility check. -
Method Summary
Modifier and TypeMethodDescriptionstatic Predicate<JMethodSymbol> accessibleMethodFilter(String name, @NonNull JClassSymbol symbol) static booleanstatic booleanTwo method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.static booleanareRelated(@NonNull JTypeMirror t, JTypeMirror s) Returns true if both types have a common supertype that is not Object.static booleanareSameTypes(List<JTypeMirror> ts, List<JTypeMirror> ss) static booleanareSameTypesInInference(List<JTypeMirror> ts, List<JTypeMirror> ss) static @Nullable JClassTypeasClassType(@Nullable JTypeMirror t) Returns t if it is a class or interface type.static List<JTypeMirror> Returns the components of t if it is an intersection type, otherwise returns t.static @Nullable JClassTypeasOuterSuper(JTypeMirror t, JClassSymbol sym) Return the base type of t or any of its outer types that starts with the given type.static @Nullable JTypeMirrorasSuper(@NonNull JTypeMirror t, @NonNull JClassSymbol s) static List<JTypeMirror> erase(Collection<? extends JTypeMirror> ts) Returns a list with the erasures of the given types, may be unmodifiable.static List<JMethodSig> filterAccessible(List<JMethodSig> visible, @NonNull JClassSymbol accessSite) static @Nullable JMethodSigfindFunctionalInterfaceMethod(@Nullable JTypeMirror type) Finds the method of the given type that can be overridden as a lambda expression.static @Nullable JTypeMirrorgetArrayComponent(@Nullable JTypeMirror t) static NameResolver<JVariableSig.FieldSig> getMemberFieldResolver(JTypeMirror c, @NonNull String accessPackageName, @Nullable JClassSymbol access, String name) static JTypeMirrorMethods and fields of a type variable come from its upper bound, which must be captured.static List<JMethodSig> getMethodsOf(JTypeMirror type, String name, boolean staticOnly, @NonNull JClassSymbol enclosing) static @Nullable JClassTypegetReceiverType(@NonNull JClassType containerType, JClassSymbol sym) Return the first enclosing type of the container type that has the given symbol in its supertypes.static Set<JTypeMirror> getSuperTypeSet(@NonNull JTypeMirror t) Returns the set of all supertypes of the given type.static booleanhasUnresolvedSymbol(@Nullable JTypeMirror t) Return true if the argument is aJClassTypewith an unresolved symbol.static booleanhasUnresolvedSymbolOrArray(@Nullable JTypeMirror t) Return true if the argument is aJClassTypewith an unresolved symbol, or an array whose element type has an unresolved symbol.static booleanhaveSameTypeParams(JMethodSig m1, JMethodSig m2) static booleanisContextDependent(JExecutableSymbol symbol) Return true if the method is context dependent.static booleanDeprecated.Since 7.11.0.static TypeOps.ConvertibilityisConvertible(@NonNull JTypeMirror t, @NonNull JTypeMirror s) static TypeOps.ConvertibilityisConvertible(@NonNull JTypeMirror t, @NonNull JTypeMirror s, boolean capture) Deprecated.static TypeOps.ConvertibilityisConvertibleNoCapture(@NonNull JTypeMirror t, @NonNull JTypeMirror s) static TypeOps.Convertibilitystatic booleanisOverridableIn(JExecutableSymbol m, JTypeDeclSymbol origin) Returns true if the given method can be overridden in the origin class.static booleanReturns true if m1 is return-type substitutable with m2.static booleanisSameType(JMethodSig t, JMethodSig s) Return true if t and s are the same method type.static booleanisSameType(JTypeMirror t, JTypeMirror s) Return true if t and s are the same type, ignoring any type annotations appearing within them.static booleanReturn true if t and s are the same type, considering any type annotations appearing within them.static booleanisSpecialUnresolved(@NonNull JTypeMirror t) Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR.static booleanisSpecialUnresolvedOrArray(@Nullable JTypeMirror t) Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR, or an array of such types.static booleanisStrictSubtype(@NonNull JTypeMirror t, @NonNull JTypeMirror s) static booleanisSubSignature(JMethodSig m1, JMethodSig m2) The signature of a method m1 is a subsignature of the signature of a method m2 if either: - m2 has the same signature as m1, or - the signature of m1 is the same as the erasure (§4.6) of the signature of m2.static booleanisUnresolved(@NonNull JTypeMirror t) Returns true if the type isTypeSystem.UNKNOWN,TypeSystem.ERROR, or a class type with unresolved symbol.static booleanisUnresolvedOrArray(@NonNull JTypeMirror t) Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR, or a class type with unresolved symbol, or an array of such types.static booleanisUnresolvedOrNull(@Nullable JTypeMirror t) static Iterable<JMethodSig> lazyFilterAccessible(List<JMethodSig> visible, @NonNull JClassSymbol accessSite) static booleanmentions(@NonNull JTypeVisitable type, @NonNull net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar parent) static booleanmentionsAny(JTypeVisitable t, Collection<? extends SubstVar> vars) static Set<JTypeMirror> mostSpecific(Collection<? extends JTypeMirror> set) Returns a subset S of the parameter, whose components have no strict supertype in S.static @Nullable JClassTypenonWildcardParameterization(@NonNull JClassType type) Returns the non-wildcard parameterization of the given functional interface type.static booleanoverrides(JMethodSig m1, JMethodSig m2, JTypeMirror origin) Returns true if m1 overrides m2, when both are view as members of class origin. m1 and m2 may be declared in supertypes of origin, possibly unrelated (default methods), which is why we need that third parameter.static JTypeMirrorReturns the upwards projection of the given type, with respect to the set of capture variables that are found in it.static List<JTypeMirror> subst(List<? extends JTypeMirror> ts, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) Substitute on a list of types.static JTypeMirrorsubst(@Nullable JTypeMirror type, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) Replace the type variables occurring in the given type to their image by the given function.static List<JClassType> substClasses(List<JClassType> ts, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) substInBoundsOnly(List<JTypeVar> ts, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst)
-
Method Details
-
isSameType
Return true if t and s are the same method type. This compares their declaring type, and then their signature.- See Also:
-
isSameType
Return true if t and s are the same type, ignoring any type annotations appearing within them. This is the implementation of the equals method ofJTypeMirror. -
isSameTypeWithSameAnnotations
Return true if t and s are the same type, considering any type annotations appearing within them. -
areSameTypes
-
areSameTypesInInference
-
getSuperTypeSet
Returns the set of all supertypes of the given type.- See Also:
-
isConvertible
-
isConvertible
@Deprecated public static TypeOps.Convertibility isConvertible(@NonNull JTypeMirror t, @NonNull JTypeMirror s, boolean capture) Deprecated. -
isConvertibleNoCapture
public static TypeOps.Convertibility isConvertibleNoCapture(@NonNull JTypeMirror t, @NonNull JTypeMirror s) -
isConvertiblePure
-
allArgsAreUnboundedWildcards
-
isStrictSubtype
-
subst
public static JTypeMirror subst(@Nullable JTypeMirror type, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) Replace the type variables occurring in the given type to their image by the given function. Substitutions are not applied recursively.- Parameters:
type- Type to substitutesubst- Substitution function, eg aSubstitution
-
subst
public static List<JTypeMirror> subst(List<? extends JTypeMirror> ts, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) Substitute on a list of types. -
substClasses
public static List<JClassType> substClasses(List<JClassType> ts, Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) -
substInBoundsOnly
-
projectUpwards
Returns the upwards projection of the given type, with respect to the set of capture variables that are found in it. This is some supertype of T which does not mention those capture variables. This is used for local variable type inference. https://docs.oracle.com/javase/specs/jls/se11/html/jls-4.html#jls-4.10.5 -
isReturnTypeSubstitutable
Returns true if m1 is return-type substitutable with m2. The notion of return-type-substitutability supports covariant returns, that is, the specialization of the return type to a subtype. https://docs.oracle.com/javase/specs/jls/se9/html/jls-8.html#jls-8.4.5 -
haveSameTypeParams
-
areOverrideEquivalent
Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1. This does not look at the origin of the methods (their declaring class).This is a prerequisite for one method to override the other, but not the only condition. See
overrides(JMethodSig, JMethodSig, JTypeMirror). See JLS§8 -
isSubSignature
The signature of a method m1 is a subsignature of the signature of a method m2 if either: - m2 has the same signature as m1, or - the signature of m1 is the same as the erasure (§4.6) of the signature of m2. -
overrides
Returns true if m1 overrides m2, when both are view as members of class origin. m1 and m2 may be declared in supertypes of origin, possibly unrelated (default methods), which is why we need that third parameter. By convention a method overrides itself.This method ignores the static modifier. If both methods are static, then this method tests for hiding. Otherwise, this method properly tests for overriding. Note that it is an error for a static method to override an instance method, or the reverse.
-
isOverridableIn
Returns true if the given method can be overridden in the origin class. This only checks access modifiers and not eg whether the method is final or static. Regardless of whether the method is final it is overridden - whether this is a compile error or not is another matter.Like
overrides(JMethodSig, JMethodSig, JTypeMirror), this does not check the static modifier, and tests for hiding if the method is static.- Parameters:
m- Method to testorigin- Site of the potential override
-
nonWildcardParameterization
Returns the non-wildcard parameterization of the given functional interface type. Returns null if such a parameterization does not exist.This is used to remove wildcards from the type of a functional interface. https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.9
- Parameters:
type- A parameterized functional interface type
-
findFunctionalInterfaceMethod
Finds the method of the given type that can be overridden as a lambda expression. That is more complicated than "the unique abstract method", it's actually a function type which can override all abstract methods of the SAM at once. https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.9If the parameter is not mappable to a class type with
asClassType(JTypeMirror), or if the functional method does not exist, returns null. -
asClassType
Returns t if it is a class or interface type. If it is an intersection type, returns the induced class or interface type. Returns null otherwise, including if the parameter is null. -
asSuper
- See Also:
-
asOuterSuper
Return the base type of t or any of its outer types that starts with the given type. If none exists, return null. -
getReceiverType
public static @Nullable JClassType getReceiverType(@NonNull JClassType containerType, JClassSymbol sym) Return the first enclosing type of the container type that has the given symbol in its supertypes. Return null if this is not found. -
mostSpecific
Returns a subset S of the parameter, whose components have no strict supertype in S.S = { V | V in set, and for all W ≠ V in set, it is not the case that W <: V } -
asList
Returns the components of t if it is an intersection type, otherwise returns t. -
erase
Returns a list with the erasures of the given types, may be unmodifiable. -
mentions
public static boolean mentions(@NonNull JTypeVisitable type, @NonNull net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar parent) -
mentionsAny
-
accessibleMethodFilter
public static Predicate<JMethodSymbol> accessibleMethodFilter(String name, @NonNull JClassSymbol symbol) -
lazyFilterAccessible
public static Iterable<JMethodSig> lazyFilterAccessible(List<JMethodSig> visible, @NonNull JClassSymbol accessSite) -
filterAccessible
public static List<JMethodSig> filterAccessible(List<JMethodSig> visible, @NonNull JClassSymbol accessSite) -
getMemberSource
Methods and fields of a type variable come from its upper bound, which must be captured. Capturing a type var does NOT capture its upper bound, so we must treat this case here. -
getMethodsOf
public static List<JMethodSig> getMethodsOf(JTypeMirror type, String name, boolean staticOnly, @NonNull JClassSymbol enclosing) -
getMemberFieldResolver
public static NameResolver<JVariableSig.FieldSig> getMemberFieldResolver(JTypeMirror c, @NonNull String accessPackageName, @Nullable JClassSymbol access, String name) -
areRelated
Returns true if both types have a common supertype that is not Object. Primitive types are only related to themselves.- Parameters:
t- Non-null types- Non-null type- Throws:
NullPointerException- if a parameter is null
-
isUnresolved
Returns true if the type isTypeSystem.UNKNOWN,TypeSystem.ERROR, or a class type with unresolved symbol.- Parameters:
t- Non-null type- Throws:
NullPointerException- if the parameter is null
-
isUnresolvedOrArray
Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR, or a class type with unresolved symbol, or an array of such types.- Parameters:
t- Non-null type- Throws:
NullPointerException- if the parameter is null
-
isSpecialUnresolved
Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR.- Parameters:
t- Non-null type- Throws:
NullPointerException- if the parameter is null
-
isSpecialUnresolvedOrArray
Returns true if the type isTypeSystem.UNKNOWN, orTypeSystem.ERROR, or an array of such types.- Parameters:
t- Non-null type- Throws:
NullPointerException- if the parameter is null
-
hasUnresolvedSymbol
Return true if the argument is aJClassTypewith an unresolved symbol. -
hasUnresolvedSymbolOrArray
Return true if the argument is aJClassTypewith an unresolved symbol, or an array whose element type has an unresolved symbol. -
isUnresolvedOrNull
-
getArrayComponent
-
isContextDependent
Deprecated.Since 7.11.0. UseisContextDependent(JExecutableSymbol)instead which is more flexible.Return true if the method is context dependent. That means its return type is influenced by the surrounding context during type inference. Generic constructors are always context dependent. -
isContextDependent
Return true if the method is context dependent. That means its return type is influenced by the surrounding context during type inference. Generic constructors are always context dependent.
-