Class JvmsTypeSignatureBuilder

java.lang.Object
org.openrewrite.java.internal.JvmsTypeSignatureBuilder
All Implemented Interfaces:
JavaTypeSignatureBuilder

public class JvmsTypeSignatureBuilder extends Object implements JavaTypeSignatureBuilder
A JavaTypeSignatureBuilder that produces cache keys using JVMS ยง4 descriptors for methods and variables, ensuring direct compatibility with type tables built from class files (where ASM provides the descriptors).

Type signatures (class, parameterized, generic, array, primitive) use the same format as DefaultJavaTypeSignatureBuilder since these are used as FQN-based cache keys (the FQN passed to JavaTypeFactory.computeClass(java.lang.String, long, org.openrewrite.java.tree.JavaType.FullyQualified.Kind, java.util.function.Consumer<org.openrewrite.java.tree.JavaType.Class>)).

Method signatures: declaringFQN.methodName:(paramDescriptors)returnDescriptor
Example: java.lang.String.substring:(II)Ljava/lang/String;

Variable signatures: ownerFQN.fieldName:fieldDescriptor
Example: java.lang.String.CASE_INSENSITIVE_ORDER:Ljava/util/Comparator;

  • Constructor Details

    • JvmsTypeSignatureBuilder

      public JvmsTypeSignatureBuilder()
  • Method Details

    • signature

      public String signature(@Nullable Object type)
      Specified by:
      signature in interface JavaTypeSignatureBuilder
      Parameters:
      type - A type object.
      Returns:
      The type signature. If t is null, the signature is {undefined}.
    • arraySignature

      public String arraySignature(Object type)
      Specified by:
      arraySignature in interface JavaTypeSignatureBuilder
      Parameters:
      type - An array type.
      Returns:
      Formatted like Integer[].
    • classSignature

      public String classSignature(Object type)
      Specified by:
      classSignature in interface JavaTypeSignatureBuilder
      Parameters:
      type - A class type.
      Returns:
      Formatted like java.util.List.
    • genericSignature

      public String genericSignature(Object type)
      Description copied from interface: JavaTypeSignatureBuilder
      When generic type variables are cyclic, like U extends Cyclic<? extends U>, represent the cycle with the bound name, like Generic{U extends Cyclic<? extends U>}.

      When the bound is Object (regardless of whether that bound is implicit or explicit in the source code),the type variable is considered invariant and the bound is omitted. So Generic{List<?>} is favored over Generic{List<? extends java.lang.Object>}.

      Specified by:
      genericSignature in interface JavaTypeSignatureBuilder
      Parameters:
      type - A generic type.
      Returns:
      Formatted like Generic{U extends java.lang.Comparable} (covariant) or Generic{U super java.lang.Comparable} (contravariant).
    • parameterizedSignature

      public String parameterizedSignature(Object type)
      Specified by:
      parameterizedSignature in interface JavaTypeSignatureBuilder
      Parameters:
      type - A parameterized type.
      Returns:
      Formatted like java.util.List<java.util.List<Integer>>.
    • primitiveSignature

      public String primitiveSignature(Object type)
      Specified by:
      primitiveSignature in interface JavaTypeSignatureBuilder
      Parameters:
      type - A primitive type.
      Returns:
      Formatted like Integer.
    • methodSignature

      public String methodSignature(JavaType.Method method)
    • variableSignature

      public String variableSignature(JavaType.Variable variable)
    • methodDescriptor

      public static String methodDescriptor(JavaType.Method method)
    • fieldDescriptor

      public static String fieldDescriptor(@Nullable JavaType type)