Class TypeOperations
java.lang.Object
io.micronaut.sourcegen.model.TypeOperations
The operations on the types of the model that the hierarchy walk, override resolution and the generators share:
unwrapping annotations, raw types, erasure, substitution, walking the variables a type names, expanding chains of
bounds, and a type as one of its supertypes.
Each operation is defined once here, so that the places reading a type agree on what it erases to or which variables it names.
- Since:
- 2.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable ClassTypeDefasSupertype(ClassTypeDef type, String supertypeName, @Nullable TypeHierarchy.Lookup lookup) A type as one of its supertypes, with the type arguments it inherits that supertype with - from the model, reflection or annotation-processing type of each on the way.static booleancontainsVariableOtherThan(TypeDef type, Set<String> variables) Whether a type names a type variable that is not one of the given ones.declaredBounds(String name, List<TypeDef.TypeVariable> methodVariables, List<TypeDef.TypeVariable> typeVariables) The bounds the nearest declaration of a variable in scope gives it: the method's variable of the name shadows the type's.static ClassTypeDefdeclaredClass(ClassTypeDef type) The class a type is of, as it is declared: without its type arguments, and without the enclosing type a member of a parameterized type carries -MemberofOuter<String>.Member<Integer>.static TypeDefErases a type whose variables carry their bounds: a variable is the erasure of its leftmost bound (JLS 4.6), andObjectwithout one.static TypeDefErases a type (JLS 4.6).static TypeDeferase(TypeDef type, List<TypeDef.TypeVariable> methodVariables, List<TypeDef.TypeVariable> typeVariables) Erases a type in the scope of the variables a method and its type declare: a variable named without its bounds erases to the bound its nearest declaration gives it - the method's before the type's.static Class<?> Erases a reflective type: a variable is the erasure of its leftmost bound, a parameterized type its raw class.expandBounds(TypeDef.TypeVariable variable, Function<TypeDef.TypeVariable, @Nullable TypeDef.TypeVariable> declaration) Expands the bounds of a variable: each bound that is itself a variable in scope is replaced by that variable's bounds, along a chain of any length -U extends VwithV extends Numberis bounded byNumber.static booleanmentionsVariable(TypeDef type, Predicate<String> matches) Whether a type names a type variable: itself, or in its type arguments, the component of an array, the bounds of a wildcard, or the enclosing type of a member -Outer<X>.MembernamesX.static TypeDefThe raw type of a parameterized type, or of the component of an array of one:List[]ofList<String>[].static ClassTypeDefrawClass(ClassTypeDef type) The class of a parameterized type:ListofList<String>.static TypeDefrawClassOf(TypeDef type) A type without its annotations, and a class type without its type arguments, asrawClass(ClassTypeDef)takes them:Listof@A List<String>.static TypeDefsubstitute(TypeDef type, Map<String, TypeDef> substitution) Substitutes type variables by name, at any depth of the type: in the type arguments, the component of an array, the bounds of a wildcard, and the enclosing type of a member.static List<TypeDef.TypeVariable> typeVariablesOf(@Nullable ObjectDef objectDef) The type variables a definition declares: those of a class, an interface or a record.static TypeDefUnwraps an annotated type, at any depth.variablesOf(TypeDef type) The names of the variables a type names, in the order they are named.
-
Method Details
-
unwrap
-
rawClass
The class of a parameterized type:ListofList<String>. A member of a parameterized type keeps the enclosing type it carries.- Parameters:
type- The type- Returns:
- The type without its type arguments
-
rawClassOf
A type without its annotations, and a class type without its type arguments, asrawClass(ClassTypeDef)takes them:Listof@A List<String>. Any other type is only unwrapped.- Parameters:
type- The type- Returns:
- The unwrapped type, raw where it is a class type
-
declaredClass
The class a type is of, as it is declared: without its type arguments, and without the enclosing type a member of a parameterized type carries -MemberofOuter<String>.Member<Integer>.- Parameters:
type- The type- Returns:
- The declared class
-
raw
-
erase
-
erase
public static TypeDef erase(TypeDef type, List<TypeDef.TypeVariable> methodVariables, List<TypeDef.TypeVariable> typeVariables) Erases a type in the scope of the variables a method and its type declare: a variable named without its bounds erases to the bound its nearest declaration gives it - the method's before the type's.- Parameters:
type- The typemethodVariables- The variables the method declarestypeVariables- The variables the type declares- Returns:
- The erased type
-
erase
public static TypeDef erase(TypeDef type, Function<String, @Nullable TypeDef> declared, @Nullable ClassTypeDef thisType) Erases a type (JLS 4.6). A variable is the erasure of its leftmost bound -ObjectforT extends Object & Comparable<T>, as the bytecode writers describe it - taken from the reference where it carries its bounds, else from its declaration in scope. A variable bounded by itself through others -A extends BandB extends A- erases toObject. A parameterized type is its class, without the enclosing type a member carries; a wildcard is the erasure of its upper bound; and an array keeps its rank with its component erased.- Parameters:
type- The typedeclared- The leftmost bound of a variable in scope by its name, ornullwhere it declares nonethisType- The typeTypeDef.THISstands for, ornullto keep it- Returns:
- The erased type
-
erase
-
declaredBounds
public static List<TypeDef> declaredBounds(String name, List<TypeDef.TypeVariable> methodVariables, List<TypeDef.TypeVariable> typeVariables) The bounds the nearest declaration of a variable in scope gives it: the method's variable of the name shadows the type's.- Parameters:
name- The name of the variablemethodVariables- The variables the method declarestypeVariables- The variables the type declares- Returns:
- The bounds, empty where no variable of the name is declared or it has none
-
typeVariablesOf
The type variables a definition declares: those of a class, an interface or a record.- Parameters:
objectDef- The definition, ornull- Returns:
- The variables, empty for any other definition
-
substitute
Substitutes type variables by name, at any depth of the type: in the type arguments, the component of an array, the bounds of a wildcard, and the enclosing type of a member. A nullable variable is substituted by the nullable replacement.- Parameters:
type- The typesubstitution- The types to substitute for the variables, by their names- Returns:
- The substituted type, without its annotations
-
mentionsVariable
Whether a type names a type variable: itself, or in its type arguments, the component of an array, the bounds of a wildcard, or the enclosing type of a member -Outer<X>.MembernamesX.- Parameters:
type- The typematches- Tells the names of the variables looked for- Returns:
- true where a variable of a matching name is named
-
containsVariableOtherThan
-
variablesOf
-
expandBounds
public static List<TypeDef> expandBounds(TypeDef.TypeVariable variable, Function<TypeDef.TypeVariable, @Nullable TypeDef.TypeVariable> declaration) Expands the bounds of a variable: each bound that is itself a variable in scope is replaced by that variable's bounds, along a chain of any length -U extends VwithV extends Numberis bounded byNumber. A variable reached again along the chain ends it.- Parameters:
variable- The variabledeclaration- The variable in scope a reference stands for, with the bounds it is declared with, ornullfor one that is not expanded, and is a bound itself- Returns:
- The bounds that are not expanded, as they are declared, in declaration order
-
asSupertype
public static @Nullable ClassTypeDef asSupertype(ClassTypeDef type, String supertypeName, @Nullable TypeHierarchy.Lookup lookup) A type as one of its supertypes, with the type arguments it inherits that supertype with - from the model, reflection or annotation-processing type of each on the way. A raw type inherits its supertypes raw (JLS 4.8).- Parameters:
type- The typesupertypeName- The binary name of the supertypelookup- Looks up the definition or the element of a type only known by name, ornull- Returns:
- The supertype, parameterized where it is inherited so, or
nullwhere it is not inherited
-