Class Signature

java.lang.Object
org.aspectj.org.eclipse.jdt.core.Signature

public final class Signature extends Object
Provides methods for encoding and decoding type and method signature strings.

Signatures obtained from parsing source files (i.e. files with one of the Java-like extensions) differ subtly from ones obtained from pre-compiled binary (".class") files in class names are usually left unresolved in the former. For example, the normal resolved form of the type "String" embeds the class's package name ("Ljava.lang.String;" or "Ljava/lang/String;"), whereas the unresolved form contains only what is written "QString;".

Generic types introduce to the Java language in J2SE 1.5 add three new facets to signatures: type variables, parameterized types with type arguments, and formal type parameters. Rich signatures containing these facets only occur when dealing with code that makes overt use of the new language features. All other code, and certainly all Java code written or compiled with J2SE 1.4 or earlier, involved only simple signatures.

Note that the "Q", "!", "|" and "&" formats are specific to Eclipse; the remainder are specified in the JVM spec.

Due to historical reasons Eclipse uses "|" format for Intersection and "&" for Union which is opposite to their usage in source code.

The syntax for a type signature is:

 
 TypeSignature ::=
     "B"  // byte
   | "C"  // char
   | "D"  // double
   | "F"  // float
   | "I"  // int
   | "J"  // long
   | "S"  // short
   | "V"  // void
   | "Z"  // boolean
   | "T" + Identifier + ";" // type variable
   | "[" + TypeSignature  // array X[]
   | "!" + TypeSignature  // capture-of ?
   | "|" + TypeSignature + (":" + TypeSignature)+ // intersection type
   | ResolvedClassTypeSignature
   | UnresolvedClassTypeSignature

 ResolvedClassTypeSignature ::= // resolved named type (in compiled code)
     "L" + Identifier + OptionalTypeArguments
           ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";"
     | OptionalTypeParameters + "L" + Identifier +
           ( ( "." | "/" ) + Identifier )* + ";"

 UnresolvedClassTypeSignature ::= // unresolved named type (in source code)
     "Q" + Identifier + OptionalTypeArguments
           ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";"
     | OptionalTypeParameters "Q" + Identifier +
           ( ( "." | "/" ) + Identifier )* + ";"

 OptionalTypeArguments ::=
     "<" + TypeArgument+ + ">"
   |

 TypeArgument ::=
   | TypeSignature
   | "*" // wildcard ?
   | "+" TypeSignature // wildcard ? extends X
   | "-" TypeSignature // wildcard ? super X

 OptionalTypeParameters ::=
     "<" + FormalTypeParameterSignature+ + ">"
   |
 
 

Examples:

  • "[[I" denotes int[][]
  • "Ljava.lang.String;" denotes java.lang.String in compiled code
  • "QString;" denotes String in source code
  • "Qjava.lang.String;" denotes java.lang.String in source code
  • "[QString;" denotes String[] in source code
  • "QMap<QString;*>;" denotes Map<String,?> in source code
  • "Qjava.util.List<V>;" denotes java.util.List<V> in source code
  • "<E>Ljava.util.List;" denotes <E>java.util.List in source code

The syntax for a method signature is:

 
 MethodSignature ::= OptionalTypeParameters + "(" + ParamTypeSignature* + ")" + ReturnTypeSignature
 ParamTypeSignature ::= TypeSignature
 ReturnTypeSignature ::= TypeSignature
 
 

Examples:

  • "()I" denotes int foo()
  • "([Ljava.lang.String;)V" denotes void foo(java.lang.String[]) in compiled code
  • "(QString;)QObject;" denotes Object foo(String) in source code

The syntax for a formal type parameter signature is:

 
 FormalTypeParameterSignature ::=
     TypeVariableName + OptionalClassBound + InterfaceBound*
 TypeVariableName ::= Identifier
 OptionalClassBound ::=
     ":"
   | ":" + TypeSignature
 InterfaceBound ::=
     ":" + TypeSignature
 
 

Examples:

  • "X:" denotes X
  • "X:QReader;" denotes X extends Reader in source code
  • "X:QReader;:QSerializable;" denotes X extends Reader & Serializable in source code

This class provides static methods and constants only.

Note: An empty signature is considered to be syntactically incorrect. So most methods will throw an IllegalArgumentException if an empty signature is provided.