Class TypeHierarchy
Both the bridges a bytecode writer adds and the signatures a source generator overrides with are resolved from this walk. A supertype represented only by a name has no method metadata, so it is skipped unless a lookup of its element is given.
- Since:
- 2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA method declared by a supertype, as declared: the type variables of the supertype are not substituted.static interfaceVisits an inherited method.static final classA type of the hierarchy with the type arguments it is inherited with.static interfaceLooks up what is known of a type the hierarchy names only by its name: the compiler's element, as a function of the binary name, and the definition of the model written with it - a member type naming its enclosing one, or a sibling by its simple name.static final classThe variables a generic method of an inherited type declares of its own, in the scope of the type: they shadow the type's variables of the same name, and are bound by nothing the type is inherited with. -
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 @Nullable ClassTypeDefasSupertype(ClassTypeDef type, String supertypeName, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup) 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 StringbinaryName(ClassTypeDef classTypeDef, @Nullable ObjectDef objectDef) Returns the binary name a reference to a type resolves to in the scope of the type being written.static @Nullable ClassTypeDefThe enclosing type a substituted or reflected member carries, without reading that of an element.static booleancontainsVariableOtherThan(TypeDef type, Set<String> variables) Whether a type refers to a type variable that is not one of the given ones.static TypeHierarchy.InheritedTypeThe definition itself as a type of the hierarchy, to erase its own type variables.static TypeHierarchy.InheritedTypedeclaring(ObjectDef objectDef, List<TypeDef.TypeVariable> enclosingVariables) The definition itself as a type of the hierarchy, to erase its own type variables and those of the types enclosing it that are in its scope - the variables of the enclosing class of an inner class.static @Nullable ClassTypeDefenclosingOf(ClassTypeDef type) The enclosing type of a member class, with its type arguments:Outer<String>ofOuter<String>.Member.static StringerasedName(TypeDef erased) The name of an erased type, to compare erasures: the binary name of a class, the name of a primitive, and the component name followed by[]per dimension of an array.static StringerasedName(TypeDef erased, @Nullable ObjectDef objectDef) The name of an erased type in the scope of a definition, which resolves a simple name of the definition or of one of its member types, asbinaryName(ClassTypeDef, ObjectDef)does.static booleaninherits(ClassTypeDef type, String supertypeName, @Nullable TypeHierarchy.Lookup lookup) Whether a type has the other among its supertypes, from the model, reflection or annotation-processing type of each - so that a type generated in the same round, which cannot be loaded, is known as well.static booleaninherits(ClassTypeDef type, String supertypeName, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup) Whether a type has the other among its supertypes, from the model, reflection or annotation-processing type of each - so that a type generated in the same round, which cannot be loaded, is known as well.static ClassTypeDefmemberClass(ClassTypeDef type) The member class of a type carrying its enclosing type, or the type itself.static ClassTypeDefmemberType(ClassTypeDef enclosing, ClassTypeDef member) A member class named with a parameterized enclosing type,Outer<String>.Member; its own type arguments are those of aClassTypeDef.Parameterizedof it.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.methodScope(List<TypeDef.TypeVariable> variables) The variables a method declares as they read in its scope: each with its bounds,Objectfor one declared without - so that a reference to one by its name alone erases to what the method declares it with, and not to the bound of a variable of the class of the same name - and a bound naming another variable of the method with that variable's bounds.static StringThe package of a definition.static TypeDefsubstituted(TypeDef type, Map<String, TypeDef> substitution) Substitutes type variables by name, at any depth of the type.superTypesOf(ObjectDef objectDef) The direct supertypes of a definition.typeArguments(ClassTypeDef type, @Nullable TypeHierarchy.Lookup lookup) The type arguments a type binds the variables of its class with, and those its enclosing types bind:T,Uof anOuter<Integer>.Inner<String>areIntegerandString.static TypeDefConverts a reflective type, keeping the type arguments of a parameterized one.static TypeDefUnwraps an annotated type.static voidvisitInheritedMethods(ObjectDef objectDef, @Nullable TypeHierarchy.Lookup lookup, TypeHierarchy.InheritedMethodVisitor visitor) Visits the methods of every supertype of a definition, breadth first, each supertype once.static voidvisitInheritedMethods(ObjectDef objectDef, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup, TypeHierarchy.InheritedMethodVisitor visitor) Visits the methods of every supertype of a definition, breadth first, each supertype once.
-
Method Details
-
visitInheritedMethods
public static void visitInheritedMethods(ObjectDef objectDef, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup, TypeHierarchy.InheritedMethodVisitor visitor) Visits the methods of every supertype of a definition, breadth first, each supertype once.- Parameters:
objectDef- The definitionclassElementLookup- Looks up the element of a supertype only known by name, ornullvisitor- The visitor
-
visitInheritedMethods
public static void visitInheritedMethods(ObjectDef objectDef, @Nullable TypeHierarchy.Lookup lookup, TypeHierarchy.InheritedMethodVisitor visitor) Visits the methods of every supertype of a definition, breadth first, each supertype once.- Parameters:
objectDef- The definitionlookup- Looks up the definition or the element of a supertype only known by namevisitor- The visitor- Since:
- 2.3
-
declaring
The definition itself as a type of the hierarchy, to erase its own type variables.- Parameters:
objectDef- The definition- Returns:
- The type
-
declaring
public static TypeHierarchy.InheritedType declaring(ObjectDef objectDef, List<TypeDef.TypeVariable> enclosingVariables) The definition itself as a type of the hierarchy, to erase its own type variables and those of the types enclosing it that are in its scope - the variables of the enclosing class of an inner class.- Parameters:
objectDef- The definitionenclosingVariables- The variables of the enclosing types in scope, the nearest first- Returns:
- The type
- Since:
- 2.3
-
methodScope
The variables a method declares as they read in its scope: each with its bounds,Objectfor one declared without - so that a reference to one by its name alone erases to what the method declares it with, and not to the bound of a variable of the class of the same name - and a bound naming another variable of the method with that variable's bounds.- Parameters:
variables- The variables the method declares- Returns:
- The variables by their names
- Since:
- 2.3
-
superTypesOf
-
unwrap
-
containsVariableOtherThan
-
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
- Since:
- 2.3
-
packageOf
-
erasedName
The name of an erased type, to compare erasures: the binary name of a class, the name of a primitive, and the component name followed by[]per dimension of an array.- Parameters:
erased- A type as returned byTypeHierarchy.InheritedType.erase(TypeDef)- Returns:
- The name
-
erasedName
The name of an erased type in the scope of a definition, which resolves a simple name of the definition or of one of its member types, asbinaryName(ClassTypeDef, ObjectDef)does.- Parameters:
erased- A type as returned byTypeHierarchy.InheritedType.erase(TypeDef)objectDef- The definition, ornull- Returns:
- The name
-
binaryName
Returns the binary name a reference to a type resolves to in the scope of the type being written.The model is immutable, so
ObjectDefBuilder.addInnerType(ObjectDef)can only qualify the copy of a member type it stores; the definition the caller holds on to keeps the simple name it was built with, and a reference taken from it reads asInnerrather thancom.example.Outer$Inner. Java source has scoping that makes such a reference resolve anyway - javac readsInnerinsideOuteras its member type - while a class file has none: every name in it is a binary name. This applies the same scoping, so that the generators accept the same definition.An unqualified name is resolved against the type being written and the member types it declares, which is the scope a definition knows about. A name that is already qualified, and one that matches nothing in scope, is left as it is.
- Parameters:
classTypeDef- The referenced typeobjectDef- The contextual object, if any- Returns:
- The binary name
-
inherits
public static boolean inherits(ClassTypeDef type, String supertypeName, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup) Whether a type has the other among its supertypes, from the model, reflection or annotation-processing type of each - so that a type generated in the same round, which cannot be loaded, is known as well.- Parameters:
type- The typesupertypeName- The binary name of the supertypeclassElementLookup- Looks up the element of a type only known by name, ornull- Returns:
- true if the type is the supertype or inherits it
-
inherits
public static boolean inherits(ClassTypeDef type, String supertypeName, @Nullable TypeHierarchy.Lookup lookup) Whether a type has the other among its supertypes, from the model, reflection or annotation-processing type of each - so that a type generated in the same round, which cannot be loaded, is known as well.- Parameters:
type- The typesupertypeName- The binary name of the supertypelookup- Looks up the definition or the element of a type only known by name- Returns:
- true if the type is the supertype or inherits it
- Since:
- 2.3
-
asSupertype
public static @Nullable ClassTypeDef asSupertype(ClassTypeDef type, String supertypeName, @Nullable Function<String, @Nullable io.micronaut.inject.ast.ClassElement> classElementLookup) 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.- Parameters:
type- The typesupertypeName- The binary name of the supertypeclassElementLookup- Looks up 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
-
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- Returns:
- The supertype, parameterized where it is inherited so, or
nullwhere it is not inherited - Since:
- 2.3
-
enclosingOf
The enclosing type of a member class, with its type arguments:Outer<String>ofOuter<String>.Member. A compiler element names it in its type mirror, a substituted or reflected member carries it.- Parameters:
type- The class type, not parameterized: the raw type of a parameterized one- Returns:
- The enclosing type, or
nullwhere the type is no member of a parameterized type - Since:
- 2.3
-
carriedEnclosingOf
The enclosing type a substituted or reflected member carries, without reading that of an element.- Parameters:
type- The class type- Returns:
- The enclosing type it carries, or
null - Since:
- 2.3
-
memberClass
The member class of a type carrying its enclosing type, or the type itself.- Parameters:
type- The class type- Returns:
- The member class
- Since:
- 2.3
-
memberType
A member class named with a parameterized enclosing type,Outer<String>.Member; its own type arguments are those of aClassTypeDef.Parameterizedof it.- Parameters:
enclosing- The enclosing typemember- The member class- Returns:
- The member type
- Since:
- 2.3
-
typeArguments
public static Map<String,TypeDef> typeArguments(ClassTypeDef type, @Nullable TypeHierarchy.Lookup lookup) The type arguments a type binds the variables of its class with, and those its enclosing types bind:T,Uof anOuter<Integer>.Inner<String>areIntegerandString. A raw type binds none of its own.- Parameters:
type- The typelookup- Looks up the definition or the element of a type only known by name, ornull- Returns:
- The arguments by the variables they bind
- Since:
- 2.3
-
typeDefOf
-
substituted
-