Interface ElementSignature


public sealed interface ElementSignature
Signature of a TypedElementInfo.

The TypedElementInfoBlueprint.signature() is intended to compare fields, methods, and constructors across type hierarchy - for example when looking for a method that we override.

The following information is used for equals and hash-code:

  • Field: field name
  • Constructor: parameter types
  • Method: method name, parameter types
  • Parameter: this signature is not useful, as we cannot depend on parameter names
The signature has well-defined hashCode and equals methods, so it can be safely used as a key in a Map.

This interface is sealed, an instance can only be obtained from TypedElementInfoBlueprint.signature().

See Also:
  • Method Details

    • createField

      static ElementSignature createField(TypeName type, String name)
      A field signature.
      Parameters:
      type - type of the field
      name - name of the field
      Returns:
      a new field signature
    • createConstructor

      static ElementSignature createConstructor(List<TypeName> parameters)
      A constructor signature.
      Parameters:
      parameters - list of types of parameters
      Returns:
      a new constructor signature
    • createMethod

      static ElementSignature createMethod(TypeName returnType, String name, List<TypeName> parameters)
      A method signature.
      Parameters:
      returnType - return type of the method
      name - name of the method
      parameters - parameter types of the method
      Returns:
      a new method signature
    • type

      TypeName type()
      Type of the element. Resolves as follows:
      • Field: type of the field
      • Constructor: void
      • Method: method return type
      • Parameter: parameter type
      Returns:
      type of this element, never used for equals or hashCode
    • name

      String name()
      Name of the element. For constructor, this always returns <init>, for parameters, this method may return the real parameter name or an index parameter name depending on the source of the information (during annotation processing, this would be the actual parameter name, when classpath scanning, this would be something like param0.
      Returns:
      name of this element
    • parameterTypes

      List<TypeName> parameterTypes()
      Types of parameters if this represents a method or a constructor, empty List otherwise.
      Returns:
      parameter types
    • text

      String text()
      A text representation of this signature.
      • Field: field name (such as myNiceField
      • Constructor: comma separated parameter types (no generics) in parentheses (such as (java.lang.String,java.util.List))
      • Method: method name, parameter types (no generics) in parentheses (such as methodName(java.lang.String,java.util.List)
      • Parameter: parameter name (such as myParameter or param0 - not very useful, as parameter names are not carried over to compiled code in Java
      Returns:
      text representation