Interface GenericSignature

All Known Implementing Classes:
ClassInfo, FieldInfo, MethodInfo, RecordComponentInfo

public interface GenericSignature
Implementations of this interface have a generic signature, as defined in JVMS 17, chapter 4.7.9.1.
  • Field Details

  • Method Details

    • requiresGenericSignature

      boolean requiresGenericSignature()
      Returns whether this declaration must have a generic signature. That is, whether the Java compiler when compiling this declaration had to emit the Signature bytecode attribute.
      Returns:
      whether this declaration must have a generic signature
    • genericSignature

      default String genericSignature()
      Returns a generic signature of this declaration, possibly without any generic-related information. That is, produces a correct generic signature even if this declaration is not generic and does not use any type variables.

      Note that the return value does not come directly from bytecode. Jandex does not store the signature strings. Instead, the return value is reconstructed from the Jandex object model.

      Returns:
      a generic signature of this declaration, never null
    • genericSignature

      String genericSignature(Function<String,Type> typeVariableSubstitution)
      Returns a generic signature of this declaration, possibly without any generic-related information. That is, produces a correct generic signature even if this declaration is not generic and does not use any type variables.

      Signatures of type variables are substituted for signatures of types provided by the substitution function typeVariableSubstitution. If the substitution function returns null for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable signature is used unmodified.

      Note that the return value does not come directly from bytecode. Jandex does not store the signature strings. Instead, the return value is reconstructed from the Jandex object model.

      Parameters:
      typeVariableSubstitution - a substitution function from type variable identifiers to types
      Returns:
      a generic signature of this declaration with type variables substituted, never null
    • genericSignatureIfRequired

      default String genericSignatureIfRequired()
      Returns a generic signature of this declaration if required.
      Returns:
      a generic signature of this declaration, or null if this declaration doesn't have to have one
    • genericSignatureIfRequired

      default String genericSignatureIfRequired(Function<String,Type> typeVariableSubstitution)
      Returns a generic signature of this declaration if required. Type variable signatures are substituted.
      Parameters:
      typeVariableSubstitution - a substitution function from type variable identifiers to types
      Returns:
      a generic signature of this declaration with type variables substituted, or null if this declaration does not have to have one
    • forTypeParameters

      static void forTypeParameters(List<TypeVariable> typeParameters, Function<String,Type> typeVariableSubstitution, StringBuilder result)
      Appends a generic signature of a type parameter list, including the < at the beginning and > at the end, to given StringBuilder.

      Signatures of type variables are substituted for signatures of types provided by the substitution function typeVariableSubstitution. If the substitution function returns null for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable signature is used unmodified.

      Parameters:
      typeParameters - a list of type parameters whose generic signature is appended to result
      typeVariableSubstitution - a substitution function from type variable identifiers to types
      result - the StringBuilder to which the generic signature is appended
    • forType

      static void forType(Type type, Function<String,Type> typeVariableSubstitution, StringBuilder result)
      Appends a generic signature of a single type to given StringBuilder.

      Signatures of type variables are substituted for signatures of types provided by the substitution function typeVariableSubstitution. If the substitution function returns null for some type variable identifier, or if it returns the type variable itself, no substitution happens and the type variable signature is used unmodified.

      Parameters:
      type - a type parameters whose generic signature is appended to result
      typeVariableSubstitution - a substitution function from type variable identifiers to types
      result - the StringBuilder to which the generic signature is appended