Class Signatures


  • public class Signatures
    extends java.lang.Object
    This class is compiled against 1.5 or later to provide access to the generic signatures. It can convert a Class, Field, Method or constructor to a generic signature and it can normalize a signature. Both are methods. Normalized signatures can be string compared and match even if the type variable names differ. @version $Id: cf12175aae65bac45771d15b455807c13d2f486e $
    • Constructor Summary

      Constructors 
      Constructor Description
      Signatures()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getSignature​(java.lang.Class<?> c)
      Calculate the generic signature of a Class.
      java.lang.String getSignature​(java.lang.Object c)
      Calculate the generic signature of a Class,Method,Field, or Constructor.
      java.lang.String getSignature​(java.lang.reflect.Constructor<?> c)
      Calculate the generic signature of a Constructor.
      java.lang.String getSignature​(java.lang.reflect.Field f)
      Calculate the generic signature of a Field.
      java.lang.String getSignature​(java.lang.reflect.Method m)
      Calculate the generic signature of a Method.
      boolean hasGenerics()
      Check if the environment has generics, i.e.
      java.lang.String normalize​(java.lang.String signature)
      Normalize a signature to make sure the name of the variables are always the same.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Signatures

        public Signatures()
    • Method Detail

      • hasGenerics

        public boolean hasGenerics()
                            throws java.lang.Exception
        Check if the environment has generics, i.e. later than Java 5 VM.
        Returns:
        true if generics are supported
        Throws:
        java.lang.Exception
      • getSignature

        public java.lang.String getSignature​(java.lang.Object c)
                                      throws java.lang.Exception
        Calculate the generic signature of a Class,Method,Field, or Constructor.
        Throws:
        java.lang.Exception
      • getSignature

        public java.lang.String getSignature​(java.lang.Class<?> c)
                                      throws java.lang.Exception
        Calculate the generic signature of a Class. A Class consists of:
         class ::= declaration? reference reference*
         
        Throws:
        java.lang.Exception
      • getSignature

        public java.lang.String getSignature​(java.lang.reflect.Method m)
                                      throws java.lang.Exception
        Calculate the generic signature of a Method. A Method consists of:
         method ::= declaration? '(' reference* ')' reference
         
        Throws:
        java.lang.Exception
      • getSignature

        public java.lang.String getSignature​(java.lang.reflect.Constructor<?> c)
                                      throws java.lang.Exception
        Calculate the generic signature of a Constructor. A Constructor consists of:
          constructor ::= declaration? '(' reference* ')V'
         
        Parameters:
        c -
        Throws:
        java.lang.Exception
      • getSignature

        public java.lang.String getSignature​(java.lang.reflect.Field f)
                                      throws java.lang.Exception
        Calculate the generic signature of a Field. A Field consists of:
         constructor ::= reference
         
        Throws:
        java.lang.Exception
      • normalize

        public java.lang.String normalize​(java.lang.String signature)
        Normalize a signature to make sure the name of the variables are always the same. We change the names of the type variables to _n, where n is an integer. n is incremented for every new name and already used names are replaced with the _n name.
        Returns:
        a normalized signature