Class SignatureWriter


  • public class SignatureWriter
    extends SignatureVisitor
    A SignatureVisitor that generates signature literals, as defined in the Java Virtual Machine Specification (JVMS).
    See Also:
    JVMS 4.7.9.1
    • Field Detail

      • stringBuilder

        private final java.lang.StringBuilder stringBuilder
        The builder used to construct the visited signature.
      • hasFormals

        private boolean hasFormals
        Whether the visited signature contains formal type parameters.
      • hasParameters

        private boolean hasParameters
        Whether the visited signature contains method parameter types.
      • argumentStack

        private int argumentStack
        The stack used to keep track of class types that have arguments. Each element of this stack is a boolean encoded in one bit. The top of the stack is the least significant bit. Pushing false = *2, pushing true = *2+1, popping = /2.

        Class type arguments must be surrounded with '<' and '>' and, because

        1. class types can be nested (because type arguments can themselves be class types),
        2. SignatureWriter always returns 'this' in each visit* method (to avoid allocating new SignatureWriter instances),

        we need a stack to properly balance these 'parentheses'. A new element is pushed on this stack for each new visited type, and popped when the visit of this type ends (either is visitEnd, or because visitInnerClassType is called).

    • Constructor Detail

      • SignatureWriter

        public SignatureWriter()
        Constructs a new SignatureWriter.
    • Method Detail

      • visitFormalTypeParameter

        public void visitFormalTypeParameter​(java.lang.String name)
        Description copied from class: SignatureVisitor
        Visits a formal type parameter.
        Overrides:
        visitFormalTypeParameter in class SignatureVisitor
        Parameters:
        name - the name of the formal parameter.
      • visitBaseType

        public void visitBaseType​(char descriptor)
        Description copied from class: SignatureVisitor
        Visits a signature corresponding to a primitive type.
        Overrides:
        visitBaseType in class SignatureVisitor
        Parameters:
        descriptor - the descriptor of the primitive type, or 'V' for void .
      • visitTypeVariable

        public void visitTypeVariable​(java.lang.String name)
        Description copied from class: SignatureVisitor
        Visits a signature corresponding to a type variable.
        Overrides:
        visitTypeVariable in class SignatureVisitor
        Parameters:
        name - the name of the type variable.
      • visitClassType

        public void visitClassType​(java.lang.String name)
        Description copied from class: SignatureVisitor
        Starts the visit of a signature corresponding to a class or interface type.
        Overrides:
        visitClassType in class SignatureVisitor
        Parameters:
        name - the internal name of the class or interface.
      • visitInnerClassType

        public void visitInnerClassType​(java.lang.String name)
        Description copied from class: SignatureVisitor
        Visits an inner class.
        Overrides:
        visitInnerClassType in class SignatureVisitor
        Parameters:
        name - the local name of the inner class in its enclosing class.
      • visitTypeArgument

        public SignatureVisitor visitTypeArgument​(char wildcard)
        Description copied from class: SignatureVisitor
        Visits a type argument of the last visited class or inner class type.
        Overrides:
        visitTypeArgument in class SignatureVisitor
        Parameters:
        wildcard - '+', '-' or '='.
        Returns:
        a non null visitor to visit the signature of the type argument.
      • visitEnd

        public void visitEnd()
        Description copied from class: SignatureVisitor
        Ends the visit of a signature corresponding to a class or interface type.
        Overrides:
        visitEnd in class SignatureVisitor
      • toString

        public java.lang.String toString()
        Returns the signature that was built by this signature writer.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the signature that was built by this signature writer.
      • endFormals

        private void endFormals()
        Ends the formal type parameters section of the signature.
      • endArguments

        private void endArguments()
        Ends the type arguments of a class or inner class type.