Record Class MethodHierarchy

java.lang.Object
java.lang.Record
io.micronaut.reflection.MethodHierarchy
Record Components:
local - The method as the caller names it
declared - What the declaring type itself declares, local when that is not known apart
inherited - The declarations the method overrides or implements, the nearest first
annotationMetadata - The annotations of every level merged, the local one winning
arguments - The parameters of every level merged, the local one winning
returnArgument - The return value of every level merged, the local one winning

public record MethodHierarchy(MethodHierarchy.Declaration local, MethodHierarchy.Declaration declared, List<MethodHierarchy.Declaration> inherited, AnnotationMetadata annotationMetadata, Argument<?>[] arguments, Argument<?> returnArgument) extends Record
What a method hierarchy declares: the method as a caller names it, what its declaring type itself declares, the declarations it overrides or implements, and the three merged into one view.

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
  • Constructor Details

  • Method Details

    • resolve

      public static MethodHierarchy resolve(BeanIntrospector introspector, Method method)
      Resolves the hierarchy of a method named by a Method.
      Parameters:
      introspector - The introspector of the types of the hierarchy
      method - 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 hierarchy
      type - The type reading the method
      name - The method name
      parameterTypes - 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 hierarchy
      local - The method as the caller names it
      name - 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 ReflectiveIntrospection answers whether the type declares the method, and its declaration is exact. 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 introspector
      type - The type
      name - The method name
      parameterTypes - The parameter types
      Returns:
      The declaration, empty when the type has no introspection or the introspection does not describe the method
    • mergeArgument

      public static Argument<?> mergeArgument(List<Argument<?>> levels)
      Merges the annotations of the levels of an argument, its type arguments included, the last level winning.
      Parameters:
      levels - The levels, the local one last
      Returns:
      The merged argument
    • mergeMetadata

      public static AnnotationMetadata mergeMetadata(List<AnnotationMetadata> levels)
      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

      public boolean equals(Object obj)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • local

      Returns the value of the local record component.
      Returns:
      the value of the local record component
    • declared

      public MethodHierarchy.Declaration declared()
      Returns the value of the declared record component.
      Returns:
      the value of the declared record component
    • inherited

      public List<MethodHierarchy.Declaration> inherited()
      Returns the value of the inherited record component.
      Returns:
      the value of the inherited record component
    • annotationMetadata

      public AnnotationMetadata annotationMetadata()
      Returns the value of the annotationMetadata record component.
      Returns:
      the value of the annotationMetadata record component
    • arguments

      public Argument<?>[] arguments()
      Returns the value of the arguments record component.
      Returns:
      the value of the arguments record component
    • returnArgument

      public Argument<?> returnArgument()
      Returns the value of the returnArgument record component.
      Returns:
      the value of the returnArgument record component