Record Class MethodHierarchy
- Record Components:
local- The method as the caller names itdeclared- What the declaring type itself declares,localwhen that is not known apartinherited- The declarations the method overrides or implements, the nearest firstannotationMetadata- The annotations of every level merged, the local one winningarguments- The parameters of every level merged, the local one winningreturnArgument- The return value of every level merged, the local one winning
A specification that describes a method — the constraint metadata of Jakarta Validation, the resource metadata of JAX-RS — reads a method together with the methods it overrides, and has rules about which level of the hierarchy may declare what. Answering those rules needs the levels apart, not merged: this type resolves them.
The hierarchy is read from the bean introspections of the super types, so it is as complete as the
introspections are. A ReflectiveIntrospection tells which annotations a type itself declares, and its
declarations are marked exact; a generated introspection reports the metadata of
a method with the annotations of the methods it overrides already merged in, so its declarations are not.
- Since:
- 5.2.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne declaration of a method by one type of a hierarchy. -
Constructor Summary
ConstructorsConstructorDescriptionMethodHierarchy(MethodHierarchy.Declaration local, MethodHierarchy.Declaration declared, List<MethodHierarchy.Declaration> inherited, AnnotationMetadata annotationMetadata, Argument<?>[] arguments, Argument<?> returnArgument) Creates an instance of aMethodHierarchyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theannotationMetadatarecord component.Argument<?>[]Returns the value of theargumentsrecord component.declared()Returns the value of thedeclaredrecord component.static Optional<MethodHierarchy.Declaration> declaredBy(BeanIntrospector introspector, Class<?> type, String name, Class<?>... parameterTypes) The declaration of a method by a type itself, read from the introspection of that type.booleanIndicates whether some other object is "equal to" this one.inthashCode()Returns a hash code value for this object.Returns the value of theinheritedrecord component.local()Returns the value of thelocalrecord component.static Argument<?> mergeArgument(List<Argument<?>> levels) Merges the annotations of the levels of an argument, its type arguments included, the last level winning.static AnnotationMetadatamergeMetadata(List<AnnotationMetadata> levels) Merges the levels of metadata of a hierarchy into one, every annotation of it declared.booleanparallel()Whether the method is declared in parallel branches of the hierarchy: by two types neither of which extends or implements the other, as a class implementing two interfaces that both declare it.static MethodHierarchyresolve(BeanIntrospector introspector, MethodHierarchy.Declaration local, String name) Resolves the hierarchy of a method already read as a declaration, the walk starting at the type declaring it.static MethodHierarchyresolve(BeanIntrospector introspector, Class<?> type, String name, Class<?>... parameterTypes) Resolves the hierarchy of a method named by the type reading it, which is the type declaring it or one inheriting it.static MethodHierarchyresolve(BeanIntrospector introspector, Method method) Resolves the hierarchy of a method named by aMethod.Argument<?> Returns the value of thereturnArgumentrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
MethodHierarchy
public MethodHierarchy(MethodHierarchy.Declaration local, MethodHierarchy.Declaration declared, List<MethodHierarchy.Declaration> inherited, AnnotationMetadata annotationMetadata, Argument<?>[] arguments, Argument<?> returnArgument) Creates an instance of aMethodHierarchyrecord class.- Parameters:
local- the value for thelocalrecord componentdeclared- the value for thedeclaredrecord componentinherited- the value for theinheritedrecord componentannotationMetadata- the value for theannotationMetadatarecord componentarguments- the value for theargumentsrecord componentreturnArgument- the value for thereturnArgumentrecord component
-
-
Method Details
-
resolve
Resolves the hierarchy of a method named by aMethod.- Parameters:
introspector- The introspector of the types of the hierarchymethod- The method- Returns:
- The hierarchy
-
resolve
public static MethodHierarchy resolve(BeanIntrospector introspector, Class<?> type, String name, Class<?>... parameterTypes) Resolves the hierarchy of a method named by the type reading it, which is the type declaring it or one inheriting it.- Parameters:
introspector- The introspector of the types of the hierarchytype- The type reading the methodname- The method nameparameterTypes- The parameter types- Returns:
- The hierarchy
- Throws:
IllegalArgumentException- When the type has no such method
-
resolve
public static MethodHierarchy resolve(BeanIntrospector introspector, MethodHierarchy.Declaration local, String name) Resolves the hierarchy of a method already read as a declaration, the walk starting at the type declaring it.- Parameters:
introspector- The introspector of the types of the hierarchylocal- The method as the caller names itname- The method name- Returns:
- The hierarchy
-
declaredBy
public static Optional<MethodHierarchy.Declaration> declaredBy(BeanIntrospector introspector, Class<?> type, String name, Class<?>... parameterTypes) The declaration of a method by a type itself, read from the introspection of that type.A
ReflectiveIntrospectionanswers whether the type declares the method, and its declaration isexact. A generated introspection is asked for the bean method of that name declared by the type; its metadata merges the annotations of the methods it overrides, so the declaration it yields is not exact. Once a generated introspection reports the annotations a method declares apart from the ones it inherits, that branch answers exactly too, and the declaring type filter it applies here becomes redundant rather than wrong.- Parameters:
introspector- The introspectortype- The typename- The method nameparameterTypes- The parameter types- Returns:
- The declaration, empty when the type has no introspection or the introspection does not describe the method
-
mergeArgument
-
mergeMetadata
Merges the levels of metadata of a hierarchy into one, every annotation of it declared.- Parameters:
levels- The levels, the one to win last- Returns:
- The merged metadata
-
parallel
public boolean parallel()Whether the method is declared in parallel branches of the hierarchy: by two types neither of which extends or implements the other, as a class implementing two interfaces that both declare it. A method a class declares, a super class overrides and the type overrides again is declared along one line, not in parallel. Each declaration is read from the introspection of the type declaring it, so a type that merely inherits the method does not count as a declaration of its own.- Returns:
- Whether two unrelated types of the hierarchy declare the method
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
hashCode
-
toString
-
local
-
declared
-
inherited
-
annotationMetadata
Returns the value of theannotationMetadatarecord component.- Returns:
- the value of the
annotationMetadatarecord component
-
arguments
-
returnArgument
Returns the value of thereturnArgumentrecord component.- Returns:
- the value of the
returnArgumentrecord component
-