public final class Signature extends Object
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.
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<TV;>;"
denotes java.util.List<V>
in source code"<E;>Ljava.util.List;"
denotes <E>java.util.List
in source codeThe 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 codeThe 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 codeThis 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.
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY_TYPE_SIGNATURE
Kind constant for an array type signature.
|
static int |
BASE_TYPE_SIGNATURE
Kind constant for a base (primitive or void) type signature.
|
static char |
C_ARRAY
Character constant indicating an array type in a signature.
|
static char |
C_BOOLEAN
Character constant indicating the primitive type boolean in a signature.
|
static char |
C_BYTE
Character constant indicating the primitive type byte in a signature.
|
static char |
C_CAPTURE
Character constant indicating a capture of a wildcard type in a
signature.
|
static char |
C_CHAR
Character constant indicating the primitive type char in a signature.
|
static char |
C_COLON
Character constant indicating the colon in a signature.
|
static char |
C_DOLLAR
Character constant indicating the dollar in a signature.
|
static char |
C_DOT
Character constant indicating the dot in a signature.
|
static char |
C_DOUBLE
Character constant indicating the primitive type double in a signature.
|
static char |
C_EXCEPTION_START
Character constant indicating an exception in a signature.
|
static char |
C_EXTENDS
Character constant indicating a bound wildcard type argument
in a signature with extends clause.
|
static char |
C_FLOAT
Character constant indicating the primitive type float in a signature.
|
static char |
C_GENERIC_END
Character constant indicating the end of a generic type list in a
signature.
|
static char |
C_GENERIC_START
Character constant indicating the start of a formal type parameter
(or type argument) list in a signature.
|
static char |
C_INT
Character constant indicating the primitive type int in a signature.
|
static char |
C_INTERSECTION
Character constant indicating an intersection type in a
signature.
|
static char |
C_LONG
Character constant indicating the primitive type long in a signature.
|
static char |
C_NAME_END
Character constant indicating the end of a named type in a signature.
|
static char |
C_PARAM_END
Character constant indicating the end of a parameter type list in a
signature.
|
static char |
C_PARAM_START
Character constant indicating the start of a parameter type list in a
signature.
|
static char |
C_RESOLVED
Character constant indicating the start of a resolved, named type in a
signature.
|
static char |
C_SEMICOLON
Character constant indicating the semicolon in a signature.
|
static char |
C_SHORT
Character constant indicating the primitive type short in a signature.
|
static char |
C_STAR
Character constant indicating an unbound wildcard type argument
in a signature.
|
static char |
C_SUPER
Character constant indicating a bound wildcard type argument
in a signature with super clause.
|
static char |
C_TYPE_VARIABLE
Character constant indicating the start of a resolved type variable in a
signature.
|
static char |
C_UNRESOLVED
Character constant indicating the start of an unresolved, named type in a
signature.
|
static char |
C_VOID
Character constant indicating result type void in a signature.
|
static int |
CAPTURE_TYPE_SIGNATURE
Kind constant for the capture of a wildcard type signature.
|
static int |
CLASS_TYPE_SIGNATURE
Kind constant for a class type signature.
|
static int |
INTERSECTION_TYPE_SIGNATURE
Kind constant for the intersection type signature.
|
static String |
SIG_BOOLEAN
String constant for the signature of the primitive type boolean.
|
static String |
SIG_BYTE
String constant for the signature of the primitive type byte.
|
static String |
SIG_CHAR
String constant for the signature of the primitive type char.
|
static String |
SIG_DOUBLE
String constant for the signature of the primitive type double.
|
static String |
SIG_FLOAT
String constant for the signature of the primitive type float.
|
static String |
SIG_INT
String constant for the signature of the primitive type int.
|
static String |
SIG_LONG
String constant for the signature of the primitive type long.
|
static String |
SIG_SHORT
String constant for the signature of the primitive type short.
|
static String |
SIG_VOID
String constant for the signature of result type void.
|
static int |
TYPE_VARIABLE_SIGNATURE
Kind constant for a type variable signature.
|
static int |
WILDCARD_TYPE_SIGNATURE
Kind constant for a wildcard type signature.
|
Modifier and Type | Method and Description |
---|---|
static char[] |
createArraySignature(char[] typeSignature,
int arrayCount)
Creates a new type signature with the given amount of array nesting added
to the given type signature.
|
static String |
createArraySignature(String typeSignature,
int arrayCount)
Creates a new type signature with the given amount of array nesting added
to the given type signature.
|
static char[] |
createCharArrayTypeSignature(char[] typeName,
boolean isResolved)
Creates a new type signature from the given type name encoded as a character
array.
|
static String |
createIntersectionTypeSignature(char[][] typeSignatures)
Creates a new intersection type signature from the given type signatures.
|
static String |
createIntersectionTypeSignature(String[] typeSignatures)
Creates a new intersection type signature from the given type signatures.
|
static char[] |
createMethodSignature(char[][] parameterTypes,
char[] returnType)
Creates a method signature from the given parameter and return type
signatures.
|
static String |
createMethodSignature(String[] parameterTypes,
String returnType)
Creates a method signature from the given parameter and return type
signatures.
|
static char[] |
createTypeParameterSignature(char[] typeParameterName,
char[][] boundSignatures)
Creates a new type parameter signature with the given name and bounds.
|
static String |
createTypeParameterSignature(String typeParameterName,
String[] boundSignatures)
Creates a new type parameter signature with the given name and bounds.
|
static String |
createTypeSignature(char[] typeName,
boolean isResolved)
Creates a new type signature from the given type name encoded as a character
array.
|
static String |
createTypeSignature(String typeName,
boolean isResolved)
Creates a new type signature from the given type name.
|
static int |
getArrayCount(char[] typeSignature)
Returns the array count (array nesting depth) of the given type signature.
|
static int |
getArrayCount(String typeSignature)
Returns the array count (array nesting depth) of the given type signature.
|
static char[] |
getElementType(char[] typeSignature)
Returns the type signature without any array nesting.
|
static String |
getElementType(String typeSignature)
Returns the type signature without any array nesting.
|
static char[][] |
getIntersectionTypeBounds(char[] intersectionTypeSignature)
Extracts the type bounds' signatures from the given intersection type signature.
|
static String[] |
getIntersectionTypeBounds(String intersectionTypeSignature)
Extracts the type bounds' signatures from the given intersection type signature.
|
static int |
getParameterCount(char[] methodSignature)
Returns the number of parameter types in the given method signature.
|
static int |
getParameterCount(String methodSignature)
Returns the number of parameter types in the given method signature.
|
static char[][] |
getParameterTypes(char[] methodSignature)
Extracts the parameter type signatures from the given method signature.
|
static String[] |
getParameterTypes(String methodSignature)
Extracts the parameter type signatures from the given method signature.
|
static char[] |
getQualifier(char[] name)
Returns a char array containing all but the last segment of the given
dot-separated qualified name.
|
static String |
getQualifier(String name)
Returns a string containing all but the last segment of the given
dot-separated qualified name.
|
static char[] |
getReturnType(char[] methodSignature)
Extracts the return type from the given method signature.
|
static String |
getReturnType(String methodSignature)
Extracts the return type from the given method signature.
|
static char[] |
getSignatureQualifier(char[] typeSignature)
Returns package fragment of a type signature.
|
static String |
getSignatureQualifier(String typeSignature)
Returns package fragment of a type signature.
|
static char[] |
getSignatureSimpleName(char[] typeSignature)
Returns type fragment of a type signature.
|
static String |
getSignatureSimpleName(String typeSignature)
Returns type fragment of a type signature.
|
static char[] |
getSimpleName(char[] name)
Returns the last segment of the given dot-separated qualified name.
|
static String |
getSimpleName(String name)
Returns the last segment of the given dot-separated qualified name.
|
static char[][] |
getSimpleNames(char[] name)
Returns all segments of the given dot-separated qualified name.
|
static String[] |
getSimpleNames(String name)
Returns all segments of the given dot-separated qualified name.
|
static char[][] |
getThrownExceptionTypes(char[] methodSignature)
Extracts the thrown exception type signatures from the given method signature if any
The method signature is expected to be dot-based.
|
static String[] |
getThrownExceptionTypes(String methodSignature)
Extracts the thrown exception type signatures from the given method signature if any
The method signature is expected to be dot-based.
|
static char[][] |
getTypeArguments(char[] parameterizedTypeSignature)
Extracts the type argument signatures from the given type signature.
|
static String[] |
getTypeArguments(String parameterizedTypeSignature)
Extracts the type argument signatures from the given type signature.
|
static char[] |
getTypeErasure(char[] parameterizedTypeSignature)
Extracts the type erasure signature from the given parameterized type signature.
|
static String |
getTypeErasure(String parameterizedTypeSignature)
Extracts the type erasure signature from the given parameterized type signature.
|
static char[][] |
getTypeParameterBounds(char[] formalTypeParameterSignature)
Extracts the class and interface bounds from the given formal type
parameter signature.
|
static String[] |
getTypeParameterBounds(String formalTypeParameterSignature)
Extracts the class and interface bounds from the given formal type
parameter signature.
|
static char[][] |
getTypeParameters(char[] methodOrTypeSignature)
Extracts the type parameter signatures from the given method or type signature.
|
static String[] |
getTypeParameters(String methodOrTypeSignature)
Extracts the type parameter signatures from the given method or type signature.
|
static int |
getTypeSignatureKind(char[] typeSignature)
Returns the kind of type signature encoded by the given string.
|
static int |
getTypeSignatureKind(String typeSignature)
Returns the kind of type signature encoded by the given string.
|
static char[] |
getTypeVariable(char[] formalTypeParameterSignature)
Extracts the type variable name from the given formal type parameter
signature.
|
static String |
getTypeVariable(String formalTypeParameterSignature)
Extracts the type variable name from the given formal type parameter
signature.
|
static char[] |
removeCapture(char[] methodOrTypeSignature)
Removes any capture information from the given type or method signature
and returns the resulting signature.
|
static String |
removeCapture(String methodOrTypeSignature)
Removes any capture information from the given type or method signature
and returns the resulting signature.
|
static char[] |
toCharArray(char[] signature)
Converts the given type signature to a readable string.
|
static char[] |
toCharArray(char[] methodSignature,
char[] methodName,
char[][] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType)
Converts the given method signature to a readable form.
|
static char[] |
toCharArray(char[] methodSignature,
char[] methodName,
char[][] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType,
boolean isVargArgs)
Converts the given method signature to a readable form.
|
static char[] |
toQualifiedName(char[][] segments)
Converts the given array of qualified name segments to a qualified name.
|
static String |
toQualifiedName(String[] segments)
Converts the given array of qualified name segments to a qualified name.
|
static String |
toString(String signature)
Converts the given type signature to a readable string.
|
static String |
toString(String methodSignature,
String methodName,
String[] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType)
Converts the given method signature to a readable string.
|
static String |
toString(String methodSignature,
String methodName,
String[] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType,
boolean isVarArgs)
Converts the given method signature to a readable string.
|
public static final int ARRAY_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final int BASE_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final char C_ARRAY
'['
.public static final char C_BOOLEAN
'Z'
.public static final char C_BYTE
'B'
.public static final char C_CAPTURE
'!'
.public static final char C_CHAR
'C'
.public static final char C_COLON
':'
.public static final char C_DOLLAR
'$'
.public static final char C_DOT
'.'
.public static final char C_DOUBLE
'D'
.public static final char C_EXCEPTION_START
'^'
.public static final char C_EXTENDS
'+'
.public static final char C_FLOAT
'F'
.public static final char C_GENERIC_END
'>'
.public static final char C_GENERIC_START
'<'
.public static final char C_INT
'I'
.public static final char C_INTERSECTION
'|'
.public static final char C_LONG
'J'
.public static final char C_NAME_END
';'
.public static final char C_PARAM_END
')'
.public static final char C_PARAM_START
'('
.public static final char C_RESOLVED
'L'
.public static final char C_SEMICOLON
';'
.public static final char C_SHORT
'S'
.public static final char C_STAR
'*'
.public static final char C_SUPER
'-'
.public static final char C_TYPE_VARIABLE
'T'
.public static final char C_UNRESOLVED
'Q'
.public static final char C_VOID
'V'
.public static final int CAPTURE_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final int CLASS_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final int INTERSECTION_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final String SIG_BOOLEAN
"Z"
.public static final String SIG_BYTE
"B"
.public static final String SIG_CHAR
"C"
.public static final String SIG_DOUBLE
"D"
.public static final String SIG_FLOAT
"F"
.public static final String SIG_INT
"I"
.public static final String SIG_LONG
"J"
.public static final String SIG_SHORT
"S"
.public static final String SIG_VOID
"V"
.public static final int TYPE_VARIABLE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static final int WILDCARD_TYPE_SIGNATURE
getTypeSignatureKind(String)
,
Constant Field Valuespublic static char[] createArraySignature(char[] typeSignature, int arrayCount)
typeSignature
- the type signaturearrayCount
- the desired number of levels of array nestingpublic static String createArraySignature(String typeSignature, int arrayCount)
typeSignature
- the type signaturearrayCount
- the desired number of levels of array nestingpublic static char[] createCharArrayTypeSignature(char[] typeName, boolean isResolved)
createTypeSignature(new String(typeName),isResolved).toCharArray()
,
although more efficient for callers with character arrays rather than strings.
If the type name is qualified, then it is expected to be dot-based.typeName
- the possibly qualified type nameisResolved
- true
if the type name is to be considered
resolved (for example, a type name from a binary class file), and
false
if the type name is to be considered unresolved
(for example, a type name found in source code)createTypeSignature(java.lang.String,boolean)
public static String createIntersectionTypeSignature(char[][] typeSignatures)
The encoded type signature is dot-based.
typeSignatures
- the given type signaturespublic static String createIntersectionTypeSignature(String[] typeSignatures)
The encoded type signature is dot-based.
typeSignatures
- the given type signaturespublic static char[] createMethodSignature(char[][] parameterTypes, char[] returnType)
parameterTypes
- the list of parameter type signaturesreturnType
- the return type signaturepublic static String createMethodSignature(String[] parameterTypes, String returnType)
createMethodSignature(parameterTypes, returnType)
.parameterTypes
- the list of parameter type signaturesreturnType
- the return type signaturecreateMethodSignature(char[][], char[])
public static char[] createTypeParameterSignature(char[] typeParameterName, char[][] boundSignatures)
typeParameterName
- the type parameter nameboundSignatures
- the signatures of associated bounds or empty array if nonepublic static String createTypeParameterSignature(String typeParameterName, String[] boundSignatures)
typeParameterName
- the type parameter nameboundSignatures
- the signatures of associated bounds or empty array if nonepublic static String createTypeSignature(char[] typeName, boolean isResolved)
createTypeSignature(new String(typeName),isResolved)
, although
more efficient for callers with character arrays rather than strings. If the
type name is qualified, then it is expected to be dot-based.typeName
- the possibly qualified type nameisResolved
- true
if the type name is to be considered
resolved (for example, a type name from a binary class file), and
false
if the type name is to be considered unresolved
(for example, a type name found in source code)createTypeSignature(java.lang.String,boolean)
public static String createTypeSignature(String typeName, boolean isResolved)
For example:
createTypeSignature("int", hucairz) -> "I"
createTypeSignature("java.lang.String", true) -> "Ljava.lang.String;"
createTypeSignature("String", false) -> "QString;"
createTypeSignature("java.lang.String", false) -> "Qjava.lang.String;"
createTypeSignature("int []", false) -> "[I"
typeName
- the possibly qualified type nameisResolved
- true
if the type name is to be considered
resolved (for example, a type name from a binary class file), and
false
if the type name is to be considered unresolved
(for example, a type name found in source code)public static int getArrayCount(char[] typeSignature) throws IllegalArgumentException
typeSignature
- the type signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static int getArrayCount(String typeSignature) throws IllegalArgumentException
typeSignature
- the type signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static char[] getElementType(char[] typeSignature) throws IllegalArgumentException
For example:
getElementType({'[', '[', 'I'}) --> {'I'}.
typeSignature
- the type signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static String getElementType(String typeSignature) throws IllegalArgumentException
For example:
getElementType("[[I") --> "I".
typeSignature
- the type signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static char[][] getIntersectionTypeBounds(char[] intersectionTypeSignature) throws IllegalArgumentException
intersectionTypeSignature
- the intersection type signatureIllegalArgumentException
- if the signature is syntactically incorrectpublic static String[] getIntersectionTypeBounds(String intersectionTypeSignature) throws IllegalArgumentException
intersectionTypeSignature
- the intersection type signatureIllegalArgumentException
- if the signature is syntactically incorrectpublic static int getParameterCount(char[] methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static int getParameterCount(String methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static char[][] getParameterTypes(char[] methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String[] getParameterTypes(String methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[] getQualifier(char[] name)
For example:
getQualifier({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g'}
getQualifier({'O', 'u', 't', 'e', 'r', '.', 'I', 'n', 'n', 'e', 'r'}) -> {'O', 'u', 't', 'e', 'r'}
getQualifier({'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'L', 'i', 's', 't', '<', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', '>'}) -> {'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l'}
name
- the nameNullPointerException
- if name is nullpublic static String getQualifier(String name)
For example:
getQualifier("java.lang.Object") -> "java.lang"
getQualifier("Outer.Inner") -> "Outer"
getQualifier("java.util.List<java.lang.String>") -> "java.util"
name
- the nameNullPointerException
- if name is nullpublic static char[] getReturnType(char[] methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String getReturnType(String methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[] getSignatureQualifier(char[] typeSignature)
For example:
getSignatureQualifier({'L', 'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'M', 'a', 'p', '$', 'E', 'n', 't', 'r', 'y', ';'}) -> {'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l'}
typeSignature
- the type signaturepublic static String getSignatureQualifier(String typeSignature)
For example:
getSignatureQualifier("Ljava.util.Map$Entry") -> "java.util"
typeSignature
- the type signaturepublic static char[] getSignatureSimpleName(char[] typeSignature)
For example:
getSignatureSimpleName({'L', 'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'M', 'a', 'p', '$', 'E', 'n', 't', 'r', 'y', ';'}) -> {'M', 'a', 'p', '.', 'E', 'n', 't', 'r', 'y'}
typeSignature
- the type signaturepublic static String getSignatureSimpleName(String typeSignature)
For example:
getSignatureSimpleName("Ljava.util.Map$Entry") -> "Map.Entry"
typeSignature
- the type signaturepublic static char[] getSimpleName(char[] name)
For example:
getSimpleName({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'O', 'b', 'j', 'e', 'c', 't'}
name
- the nameNullPointerException
- if name is nullpublic static String getSimpleName(String name)
For example:
getSimpleName("java.lang.Object") -> "Object"
getSimpleName("java.util.Map<java.lang.String, java.lang.Object>") -> "Map<String,Object>"
name
- the nameNullPointerException
- if name is nullpublic static char[][] getSimpleNames(char[] name)
For example:
getSimpleNames({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {{'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'O', 'b', 'j', 'e', 'c', 't'}}
getSimpleNames({'O', 'b', 'j', 'e', 'c', 't'}) -> {{'O', 'b', 'j', 'e', 'c', 't'}}
getSimpleNames({}) -> {}
getSimpleNames({'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'L', 'i', 's', 't', '<', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', '>'}) -> {{'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'L', 'i', 's', 't', '<', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g'}}
name
- the nameNullPointerException
- if name is nullpublic static String[] getSimpleNames(String name)
For example:
getSimpleNames("java.lang.Object") -> {"java", "lang", "Object"}
getSimpleNames("Object") -> {"Object"}
getSimpleNames("") -> {}
getSimpleNames("java.util.List<java.lang.String>") ->
{"java", "util", "List<java.lang.String>"}
name
- the nameNullPointerException
- if name is nullpublic static char[][] getThrownExceptionTypes(char[] methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String[] getThrownExceptionTypes(String methodSignature) throws IllegalArgumentException
methodSignature
- the method signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[][] getTypeArguments(char[] parameterizedTypeSignature) throws IllegalArgumentException
parameterizedTypeSignature
- the parameterized type signatureIllegalArgumentException
- if the signature is syntactically incorrectpublic static String[] getTypeArguments(String parameterizedTypeSignature) throws IllegalArgumentException
parameterizedTypeSignature
- the parameterized type signatureIllegalArgumentException
- if the signature is syntactically incorrectpublic static char[] getTypeErasure(char[] parameterizedTypeSignature) throws IllegalArgumentException
parameterizedTypeSignature
- the parameterized type signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String getTypeErasure(String parameterizedTypeSignature) throws IllegalArgumentException
parameterizedTypeSignature
- the parameterized type signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[][] getTypeParameterBounds(char[] formalTypeParameterSignature) throws IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String[] getTypeParameterBounds(String formalTypeParameterSignature) throws IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[][] getTypeParameters(char[] methodOrTypeSignature) throws IllegalArgumentException
methodOrTypeSignature
- the method or type signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String[] getTypeParameters(String methodOrTypeSignature) throws IllegalArgumentException
methodOrTypeSignature
- the method or type signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static int getTypeSignatureKind(char[] typeSignature)
typeSignature
- the type signature stringARRAY_TYPE_SIGNATURE
, CLASS_TYPE_SIGNATURE
,
BASE_TYPE_SIGNATURE
, or TYPE_VARIABLE_SIGNATURE
,
or (since 3.1) WILDCARD_TYPE_SIGNATURE
or CAPTURE_TYPE_SIGNATURE
,
or (since 3.7) INTERSECTION_TYPE_SIGNATURE
IllegalArgumentException
- if this is not a type signaturepublic static int getTypeSignatureKind(String typeSignature)
typeSignature
- the type signature stringARRAY_TYPE_SIGNATURE
, CLASS_TYPE_SIGNATURE
,
BASE_TYPE_SIGNATURE
, or TYPE_VARIABLE_SIGNATURE
,
or (since 3.1) WILDCARD_TYPE_SIGNATURE
or CAPTURE_TYPE_SIGNATURE
or (since 3.7) INTERSECTION_TYPE_SIGNATURE
IllegalArgumentException
- if this is not a type signaturepublic static char[] getTypeVariable(char[] formalTypeParameterSignature) throws IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static String getTypeVariable(String formalTypeParameterSignature) throws IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signatureIllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[] removeCapture(char[] methodOrTypeSignature)
For example (using equivalent string-based method):
removeCapture("LTest<!+Ljava.lang.Throwable;>;")
will return: "LTest<+Ljava.lang.Throwable;>;"
methodOrTypeSignature
- the signature which may have been capturedNullPointerException
- if methodOrTypeSignature
is nullpublic static String removeCapture(String methodOrTypeSignature)
For example:
removeCapture("LTest<!+Ljava.lang.Throwable;>;")
will return: "LTest<+Ljava.lang.Throwable;>;"
methodOrTypeSignature
- the signature which may have been capturedNullPointerException
- if methodOrTypeSignature
is nullpublic static char[] toCharArray(char[] signature) throws IllegalArgumentException
For example:
toString({'[', 'L', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', ';'}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', '[', ']'}
toString({'I'}) -> {'i', 'n', 't'}
toString({'+', 'L', 'O', 'b', 'j', 'e', 'c', 't', ';'}) -> {'?', ' ', 'e', 'x', 't', 'e', 'n', 'd', 's', ' ', 'O', 'b', 'j', 'e', 'c', 't'}
Note: This method assumes that a type signature containing a '$'
is an inner type signature. While this is correct in most cases, someone could
define a non-inner type name containing a '$'
. Handling this
correctly in all cases would have required resolving the signature, which
generally not feasible.
signature
- the type signatureIllegalArgumentException
- if the signature is syntactically incorrectpublic static char[] toCharArray(char[] methodSignature, char[] methodName, char[][] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType)
For example:
toString("([Ljava.lang.String;)V", "main", new String[] {"args"}, false, true) -> "void main(String[] args)"
methodSignature
- the method signature to convertmethodName
- the name of the method to insert in the result, or
null
if no method name is to be includedparameterNames
- the parameter names to insert in the result, or
null
if no parameter names are to be included; if supplied,
the number of parameter names must match that of the method signaturefullyQualifyTypeNames
- true
if type names should be fully
qualified, and false
to use only simple namesincludeReturnType
- true
if the return type is to be
includedIllegalArgumentException
- if the method signature is syntactically incorrectpublic static char[] toCharArray(char[] methodSignature, char[] methodName, char[][] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType, boolean isVargArgs)
For example:
toString("([Ljava.lang.String;)V", "main", new String[] {"args"}, false, true) -> "void main(String[] args)"
methodSignature
- the method signature to convertmethodName
- the name of the method to insert in the result, or
null
if no method name is to be includedparameterNames
- the parameter names to insert in the result, or
null
if no parameter names are to be included; if supplied,
the number of parameter names must match that of the method signaturefullyQualifyTypeNames
- true
if type names should be fully
qualified, and false
to use only simple namesincludeReturnType
- true
if the return type is to be
includedisVargArgs
- true
if the last argument should be displayed as a
variable argument, false
otherwise.IllegalArgumentException
- if the method signature is syntactically incorrectpublic static char[] toQualifiedName(char[][] segments)
For example:
toQualifiedName({{'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'O', 'b', 'j', 'e', 'c', 't'}}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}
toQualifiedName({{'O', 'b', 'j', 'e', 'c', 't'}}) -> {'O', 'b', 'j', 'e', 'c', 't'}
toQualifiedName({{}}) -> {}
segments
- the list of name segments, possibly emptypublic static String toQualifiedName(String[] segments)
For example:
toQualifiedName(new String[] {"java", "lang", "Object"}) -> "java.lang.Object"
toQualifiedName(new String[] {"Object"}) -> "Object"
toQualifiedName(new String[0]) -> ""
segments
- the list of name segments, possibly emptypublic static String toString(String signature) throws IllegalArgumentException
For example:
toString("[Ljava.lang.String;") -> "java.lang.String[]"
toString("I") -> "int"
toString("+QObject;") -> "? extends Object"
Note: This method assumes that a type signature containing a '$'
is an inner type signature. While this is correct in most cases, someone could
define a non-inner type name containing a '$'
. Handling this
correctly in all cases would have required resolving the signature, which
generally not feasible.
signature
- the type signatureIllegalArgumentException
- if the signature is not syntactically
correctpublic static String toString(String methodSignature, String methodName, String[] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType)
methodSignature
- the method signature to convertmethodName
- the name of the method to insert in the result, or
null
if no method name is to be includedparameterNames
- the parameter names to insert in the result, or
null
if no parameter names are to be included; if supplied,
the number of parameter names must match that of the method signaturefullyQualifyTypeNames
- true
if type names should be fully
qualified, and false
to use only simple namesincludeReturnType
- true
if the return type is to be
includedtoCharArray(char[], char[], char[][], boolean, boolean)
public static String toString(String methodSignature, String methodName, String[] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType, boolean isVarArgs)
methodSignature
- the method signature to convertmethodName
- the name of the method to insert in the result, or
null
if no method name is to be includedparameterNames
- the parameter names to insert in the result, or
null
if no parameter names are to be included; if supplied,
the number of parameter names must match that of the method signaturefullyQualifyTypeNames
- true
if type names should be fully
qualified, and false
to use only simple namesincludeReturnType
- true
if the return type is to be
includedisVarArgs
- true
if the last argument should be displayed as a
variable argument, false
otherwisetoCharArray(char[], char[], char[][], boolean, boolean)
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.