public final class Signature
extends java.lang.Object
This class provides static methods and constants only; it is not intended to be instantiated or subclassed by clients.
Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.Modifier and Type | Field and Description |
---|---|
static char[] |
ANY |
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_ANY
Character constant indicating any type in a signature.
|
static char |
C_ARRAY
Character constant indicating an array type in a signature.
|
static char |
C_COLON
Character constant indicating the colon in a signature.
|
static char |
C_COMPILATION_UNIT
Character constant indicating a compilation unit.
|
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_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_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 |
CLASS_TYPE_SIGNATURE
Kind constant for a class type signature.
|
static java.lang.String |
SIG_ANY |
static java.lang.String |
SIG_COMPILATION_UNIT |
static java.lang.String |
SIG_VOID
String constant for the signature of result type void.
|
static char[] |
VOID |
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 java.lang.String |
createArraySignature(java.lang.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 char[] |
createMethodSignature(char[][] parameterTypes,
char[] returnType)
Creates a method signature from the given parameter and return type
signatures.
|
static java.lang.String |
createMethodSignature(java.lang.String[] parameterTypes,
java.lang.String returnType)
Creates a method signature from the given parameter and return type
signatures.
|
static java.lang.String |
createTypeSignature(char[] typeName,
boolean isResolved)
Creates a new type signature from the given type name encoded as a character
array.
|
static java.lang.String |
createTypeSignature(java.lang.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(java.lang.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 java.lang.String |
getElementType(java.lang.String typeSignature)
Returns the type signature without any array nesting.
|
static int |
getParameterCount(char[] methodSignature)
Returns the number of parameter types in the given method signature.
|
static int |
getParameterCount(java.lang.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 java.lang.String[] |
getParameterTypes(java.lang.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 java.lang.String |
getQualifier(java.lang.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 java.lang.String |
getReturnType(java.lang.String methodSignature)
Extracts the return type from the given method signature.
|
static char[] |
getSignatureQualifier(char[] typeSignature)
Returns package fragment of a type signature.
|
static java.lang.String |
getSignatureQualifier(java.lang.String typeSignature)
Returns package fragment of a type signature.
|
static char[] |
getSignatureSimpleName(char[] typeSignature)
Returns type fragment of a type signature.
|
static java.lang.String |
getSignatureSimpleName(java.lang.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 java.lang.String |
getSimpleName(java.lang.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 java.lang.String[] |
getSimpleNames(java.lang.String name)
Returns all segments of the given dot-separated qualified name.
|
static int |
getTypeSignatureKind(char[] typeSignature)
Returns the kind of type signature encoded by the given string.
|
static int |
getTypeSignatureKind(java.lang.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 java.lang.String |
getTypeVariable(java.lang.String formalTypeParameterSignature)
Extracts the type variable name from the given formal type parameter
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 java.lang.String |
toQualifiedName(java.lang.String[] segments)
Converts the given array of qualified name segments to a qualified name.
|
static java.lang.String |
toString(java.lang.String signature)
Converts the given type signature to a readable string.
|
static java.lang.String |
toString(java.lang.String methodSignature,
java.lang.String methodName,
java.lang.String[] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType)
Converts the given method signature to a readable string.
|
static java.lang.String |
toString(java.lang.String methodSignature,
java.lang.String methodName,
java.lang.String[] parameterNames,
boolean fullyQualifyTypeNames,
boolean includeReturnType,
boolean isVarArgs)
Converts the given method signature to a readable string.
|
public static final char C_SEMICOLON
';'
.public static final char C_COLON
':'
.
3.0public static final char C_VOID
'V'
.public static final char C_ANY
'A'
.public static final char C_DOT
'.'
.public static final char C_DOLLAR
'$'
.public static final char C_ARRAY
'['
.public static final char C_RESOLVED
'L'
.public static final char C_COMPILATION_UNIT
'X'
.public static final char C_UNRESOLVED
'Q'
.public static final char C_NAME_END
';'
.public static final char C_PARAM_START
'('
.public static final char C_PARAM_END
')'
.public static final java.lang.String SIG_VOID
"V"
.public static final java.lang.String SIG_ANY
public static final java.lang.String SIG_COMPILATION_UNIT
public static final int CLASS_TYPE_SIGNATURE
public static final int BASE_TYPE_SIGNATURE
public static final int ARRAY_TYPE_SIGNATURE
public static final char[] VOID
public static final char[] ANY
public static char[] createArraySignature(char[] typeSignature, int arrayCount)
typeSignature
- the type signaturearrayCount
- the desired number of levels of array nestingpublic static java.lang.String createArraySignature(java.lang.String typeSignature, int arrayCount)
typeSignature
- the type signaturearrayCount
- the desired number of levels of array nestingpublic static char[] createMethodSignature(char[][] parameterTypes, char[] returnType)
parameterTypes
- the list of parameter type signaturesreturnType
- the return type signaturepublic static java.lang.String createMethodSignature(java.lang.String[] parameterTypes, java.lang.String returnType)
createMethodSignature(parameterTypes, returnType)
.parameterTypes
- the list of parameter type signaturesreturnType
- the return type signaturecreateMethodSignature(char[][], char[])
public static java.lang.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 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 java.lang.String createTypeSignature(java.lang.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 java.lang.IllegalArgumentException
typeSignature
- the type signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static int getArrayCount(java.lang.String typeSignature) throws java.lang.IllegalArgumentException
typeSignature
- the type signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static char[] getElementType(char[] typeSignature) throws java.lang.IllegalArgumentException
For example:
getElementType({'[', '[', 'I'}) --> {'I'}.
typeSignature
- the type signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static java.lang.String getElementType(java.lang.String typeSignature) throws java.lang.IllegalArgumentException
For example:
getElementType("[[I") --> "I".
typeSignature
- the type signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static int getParameterCount(char[] methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static int getTypeSignatureKind(char[] typeSignature)
typeSignature
- the type signature stringARRAY_TYPE_SIGNATURE
, CLASS_TYPE_SIGNATURE
,
BASE_TYPE_SIGNATURE
, or #TYPE_VARIABLE_SIGNATURE
,
or #CAPTURE_TYPE_SIGNATURE
java.lang.IllegalArgumentException
- if this is not a type signaturepublic static int getTypeSignatureKind(java.lang.String typeSignature)
typeSignature
- the type signature stringARRAY_TYPE_SIGNATURE
, CLASS_TYPE_SIGNATURE
,
BASE_TYPE_SIGNATURE
, or #TYPE_VARIABLE_SIGNATURE
,
or #CAPTURE_TYPE_SIGNATURE
java.lang.IllegalArgumentException
- if this is not a type signaturepublic static int getParameterCount(java.lang.String methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static char[][] getParameterTypes(char[] methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- if the signature is syntactically
incorrectpublic static java.lang.String[] getParameterTypes(java.lang.String methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- if the signature is syntactically
incorrectpublic static java.lang.String getTypeVariable(java.lang.String formalTypeParameterSignature) throws java.lang.IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signaturejava.lang.IllegalArgumentException
- if the signature is syntactically
incorrectpublic static char[] getTypeVariable(char[] formalTypeParameterSignature) throws java.lang.IllegalArgumentException
formalTypeParameterSignature
- the formal type parameter signaturejava.lang.IllegalArgumentException
- 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 namejava.lang.NullPointerException
- if name is nullpublic static java.lang.String getQualifier(java.lang.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 namejava.lang.NullPointerException
- if name is nullpublic static char[] getReturnType(char[] methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- if the signature is syntactically
incorrectpublic static java.lang.String getReturnType(java.lang.String methodSignature) throws java.lang.IllegalArgumentException
methodSignature
- the method signaturejava.lang.IllegalArgumentException
- 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 java.lang.String getSignatureQualifier(java.lang.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 java.lang.String getSignatureSimpleName(java.lang.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 namejava.lang.NullPointerException
- if name is nullpublic static java.lang.String getSimpleName(java.lang.String name)
For example:
getSimpleName("java.lang.Object") -> "Object"
getSimpleName("java.util.Map<java.lang.String, java.lang.Object>") -> "Map<String,Object>"
name
- the namejava.lang.NullPointerException
- 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 namejava.lang.NullPointerException
- if name is nullpublic static java.lang.String[] getSimpleNames(java.lang.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 namejava.lang.NullPointerException
- if name is nullpublic 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
includedpublic 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.public static char[] toCharArray(char[] signature) throws java.lang.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 signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic 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 java.lang.String toQualifiedName(java.lang.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 java.lang.String toString(java.lang.String signature) throws java.lang.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 signaturejava.lang.IllegalArgumentException
- if the signature is not syntactically
correctpublic static java.lang.String toString(java.lang.String methodSignature, java.lang.String methodName, java.lang.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 java.lang.String toString(java.lang.String methodSignature, java.lang.String methodName, java.lang.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) IBM Corp. and others 2000, 2010. All Rights Reserved.