Lines 36-41
Link Here
|
36 |
* with J2SE 1.4 or earlier, involved only <it>simple</it> signatures. |
36 |
* with J2SE 1.4 or earlier, involved only <it>simple</it> signatures. |
37 |
* </p> |
37 |
* </p> |
38 |
* <p> |
38 |
* <p> |
|
|
39 |
* Note that the "Q" and "!" formats are specific to Eclipse; the remainder |
40 |
* are specified in the JVM spec. |
41 |
* </p> |
42 |
* <p> |
39 |
* The syntax for a type signature is: |
43 |
* The syntax for a type signature is: |
40 |
* <pre> |
44 |
* <pre> |
41 |
* TypeSignature ::= |
45 |
* TypeSignature ::= |
Lines 50-55
Link Here
|
50 |
* | "Z" // boolean |
54 |
* | "Z" // boolean |
51 |
* | "T" + Identifier + ";" // type variable |
55 |
* | "T" + Identifier + ";" // type variable |
52 |
* | "[" + TypeSignature // array X[] |
56 |
* | "[" + TypeSignature // array X[] |
|
|
57 |
* | "!" + TypeSignature // capture-of ? |
53 |
* | ResolvedClassTypeSignature |
58 |
* | ResolvedClassTypeSignature |
54 |
* | UnresolvedClassTypeSignature |
59 |
* | UnresolvedClassTypeSignature |
55 |
* |
60 |
* |
Lines 294-299
Link Here
|
294 |
public static final char C_GENERIC_END = '>'; |
299 |
public static final char C_GENERIC_END = '>'; |
295 |
|
300 |
|
296 |
/** |
301 |
/** |
|
|
302 |
* Character constant indicating a capture of a wildcard type in a |
303 |
* signature.Value is <code>'!'</code>. |
304 |
* @since 3.1 |
305 |
*/ |
306 |
public static final char C_CAPTURE = '!'; |
307 |
|
308 |
/** |
297 |
* String constant for the signature of the primitive type boolean. |
309 |
* String constant for the signature of the primitive type boolean. |
298 |
* Value is <code>"Z"</code>. |
310 |
* Value is <code>"Z"</code>. |
299 |
*/ |
311 |
*/ |
Lines 382-387
Link Here
|
382 |
*/ |
394 |
*/ |
383 |
public static final int WILDCARD_TYPE_SIGNATURE = 5; |
395 |
public static final int WILDCARD_TYPE_SIGNATURE = 5; |
384 |
|
396 |
|
|
|
397 |
/** |
398 |
* Kind constant for the capture of a wildcard type signature. |
399 |
* @see #getTypeSignatureKind(String) |
400 |
* @since 3.1 |
401 |
*/ |
402 |
public static final int CAPTURE_TYPE_SIGNATURE = 6; |
403 |
|
385 |
private static final char[] BOOLEAN = "boolean".toCharArray(); //$NON-NLS-1$ |
404 |
private static final char[] BOOLEAN = "boolean".toCharArray(); //$NON-NLS-1$ |
386 |
private static final char[] BYTE = "byte".toCharArray(); //$NON-NLS-1$ |
405 |
private static final char[] BYTE = "byte".toCharArray(); //$NON-NLS-1$ |
387 |
private static final char[] CHAR = "char".toCharArray(); //$NON-NLS-1$ |
406 |
private static final char[] CHAR = "char".toCharArray(); //$NON-NLS-1$ |
Lines 393-398
Link Here
|
393 |
private static final char[] VOID = "void".toCharArray(); //$NON-NLS-1$ |
412 |
private static final char[] VOID = "void".toCharArray(); //$NON-NLS-1$ |
394 |
private static final char[] EXTENDS = "extends".toCharArray(); //$NON-NLS-1$ |
413 |
private static final char[] EXTENDS = "extends".toCharArray(); //$NON-NLS-1$ |
395 |
private static final char[] SUPER = "super".toCharArray(); //$NON-NLS-1$ |
414 |
private static final char[] SUPER = "super".toCharArray(); //$NON-NLS-1$ |
|
|
415 |
private static final char[] CAPTURE = "capture-of".toCharArray(); //$NON-NLS-1$ |
396 |
|
416 |
|
397 |
private static final String EMPTY = new String(CharOperation.NO_CHAR); |
417 |
private static final String EMPTY = new String(CharOperation.NO_CHAR); |
398 |
|
418 |
|
Lines 720-733
Link Here
|
720 |
return pos; |
740 |
return pos; |
721 |
} |
741 |
} |
722 |
break; |
742 |
break; |
723 |
case 'c': |
|
|
724 |
checkPos = checkName(CHAR, typeName, pos, length); |
725 |
if (checkPos > 0) { |
726 |
pos = encodeArrayDimension(typeName, checkPos, length, buffer); |
727 |
buffer.append(C_CHAR); |
728 |
return pos; |
729 |
} |
730 |
break; |
731 |
case 'd': |
743 |
case 'd': |
732 |
checkPos = checkName(DOUBLE, typeName, pos, length); |
744 |
checkPos = checkName(DOUBLE, typeName, pos, length); |
733 |
if (checkPos > 0) { |
745 |
if (checkPos > 0) { |
Lines 776-781
Link Here
|
776 |
return pos; |
788 |
return pos; |
777 |
} |
789 |
} |
778 |
break; |
790 |
break; |
|
|
791 |
case 'c': |
792 |
checkPos = checkName(CHAR, typeName, pos, length); |
793 |
if (checkPos > 0) { |
794 |
pos = encodeArrayDimension(typeName, checkPos, length, buffer); |
795 |
buffer.append(C_CHAR); |
796 |
return pos; |
797 |
} else { |
798 |
checkPos = checkName(CAPTURE, typeName, pos, length); |
799 |
if (checkPos > 0) { |
800 |
pos = consumeWhitespace(typeName, checkPos, length); |
801 |
if (typeName[pos] != '?') { |
802 |
break; |
803 |
} |
804 |
} else { |
805 |
break; |
806 |
} |
807 |
} |
808 |
buffer.append(C_CAPTURE); |
809 |
// fall-thru for wildcard part of capture typecheckPos |
779 |
case '?': |
810 |
case '?': |
780 |
// wildcard |
811 |
// wildcard |
781 |
pos = consumeWhitespace(typeName, pos+1, length); |
812 |
pos = consumeWhitespace(typeName, pos+1, length); |
Lines 1007-1012
Link Here
|
1007 |
case C_SUPER : |
1038 |
case C_SUPER : |
1008 |
case C_EXTENDS : |
1039 |
case C_EXTENDS : |
1009 |
return WILDCARD_TYPE_SIGNATURE; |
1040 |
return WILDCARD_TYPE_SIGNATURE; |
|
|
1041 |
case C_CAPTURE : |
1042 |
return CAPTURE_TYPE_SIGNATURE; |
1010 |
default : |
1043 |
default : |
1011 |
throw new IllegalArgumentException(); |
1044 |
throw new IllegalArgumentException(); |
1012 |
} |
1045 |
} |
Lines 1050-1055
Link Here
|
1050 |
case C_SUPER : |
1083 |
case C_SUPER : |
1051 |
case C_EXTENDS : |
1084 |
case C_EXTENDS : |
1052 |
return WILDCARD_TYPE_SIGNATURE; |
1085 |
return WILDCARD_TYPE_SIGNATURE; |
|
|
1086 |
case C_CAPTURE : |
1087 |
return CAPTURE_TYPE_SIGNATURE; |
1053 |
default : |
1088 |
default : |
1054 |
throw new IllegalArgumentException(); |
1089 |
throw new IllegalArgumentException(); |
1055 |
} |
1090 |
} |
Lines 1944-1949
Link Here
|
1944 |
public static String[] getSimpleNames(String name) { |
1979 |
public static String[] getSimpleNames(String name) { |
1945 |
return CharOperation.toStrings(getSimpleNames(name.toCharArray())); |
1980 |
return CharOperation.toStrings(getSimpleNames(name.toCharArray())); |
1946 |
} |
1981 |
} |
|
|
1982 |
|
1983 |
|
1984 |
/** |
1985 |
* Returns a method signature with any capture information removed. |
1986 |
* Returns the method signature itself if no capture information is |
1987 |
* present. |
1988 |
* <p> |
1989 |
* For example (using equivalent string-based method): |
1990 |
* <pre> |
1991 |
* <code> |
1992 |
* removeCaptureFromMethod("LTest<!+Ljava.lang.Throwable;>;") |
1993 |
* will return: "LTest<+Ljava.lang.Throwable;>;" |
1994 |
* </code> |
1995 |
* </pre> |
1996 |
* </p> |
1997 |
* |
1998 |
* @param captureSignature the signature which may have been captured |
1999 |
* @return new signature without capture information or siganture itself |
2000 |
* if no specific capture information was there |
2001 |
* @exception NullPointerException if <code>captureSignature</code> is null |
2002 |
* @since 3.1 |
2003 |
* TODO (frederic) Create remove(char[], char) method on CharOperation and call it from here |
2004 |
*/ |
2005 |
public static char[] removeCaptureFromMethod(char[] captureSignature) { |
2006 |
|
2007 |
char[] result = null; |
2008 |
int count = 0; |
2009 |
for (int i = 0, length = captureSignature.length; i < length; i++) { |
2010 |
char c = captureSignature[i]; |
2011 |
if (c == C_CAPTURE) { |
2012 |
if (result == null) { |
2013 |
result = new char[length]; |
2014 |
System.arraycopy(captureSignature, 0, result, 0, i); |
2015 |
count = i; |
2016 |
} |
2017 |
} else if (result != null) { |
2018 |
result[count++] = c; |
2019 |
} |
2020 |
} |
2021 |
if (result == null) return captureSignature; |
2022 |
System.arraycopy(result, 0, result = new char[count], 0, count); |
2023 |
return result; |
2024 |
} |
2025 |
|
2026 |
/** |
2027 |
* Returns a method signature with any capture information removed. |
2028 |
* Returns the method signature itself if no capture information is |
2029 |
* present. |
2030 |
* <p> |
2031 |
* For example: |
2032 |
* <pre> |
2033 |
* <code> |
2034 |
* removeCaptureFromMethod("LTest<!+Ljava.lang.Throwable;>;") |
2035 |
* will return: "LTest<+Ljava.lang.Throwable;>;" |
2036 |
* </code> |
2037 |
* </pre> |
2038 |
* </p> |
2039 |
* |
2040 |
* @param captureSignature the signature which may have been captured |
2041 |
* @return new signature without capture information or siganture itself |
2042 |
* if no specific capture information was there |
2043 |
* @exception NullPointerException if <code>captureSignature</code> is null |
2044 |
* @since 3.1 |
2045 |
*/ |
2046 |
public static String removeCaptureFromMethod(String captureSignature) { |
2047 |
char[] array = captureSignature.toCharArray(); |
2048 |
char[] result = removeCaptureFromMethod(array); |
2049 |
if (array == result) return captureSignature; |
2050 |
return new String(result); |
2051 |
} |
2052 |
|
1947 |
/** |
2053 |
/** |
1948 |
* Converts the given method signature to a readable form. The method signature is expected to |
2054 |
* Converts the given method signature to a readable form. The method signature is expected to |
1949 |
* be dot-based. |
2055 |
* be dot-based. |
Lines 2145-2150
Link Here
|
2145 |
case C_STAR: |
2251 |
case C_STAR: |
2146 |
case C_EXTENDS: |
2252 |
case C_EXTENDS: |
2147 |
case C_SUPER: |
2253 |
case C_SUPER: |
|
|
2254 |
case C_CAPTURE: |
2148 |
default: |
2255 |
default: |
2149 |
throw new IllegalArgumentException(); // a var args is an array type |
2256 |
throw new IllegalArgumentException(); // a var args is an array type |
2150 |
} |
2257 |
} |
Lines 2186-2191
Link Here
|
2186 |
case C_VOID : |
2293 |
case C_VOID : |
2187 |
buffer.append(VOID); |
2294 |
buffer.append(VOID); |
2188 |
return start; |
2295 |
return start; |
|
|
2296 |
case C_CAPTURE : |
2297 |
return appendCaptureTypeSignature(string, start, fullyQualifyTypeNames, buffer); |
2189 |
case C_STAR: |
2298 |
case C_STAR: |
2190 |
case C_EXTENDS: |
2299 |
case C_EXTENDS: |
2191 |
case C_SUPER: |
2300 |
case C_SUPER: |
Lines 2220-2225
Link Here
|
2220 |
* @param start the 0-based character index of the first character |
2329 |
* @param start the 0-based character index of the first character |
2221 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2330 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2222 |
* qualified, and <code>false</code> to use only simple names |
2331 |
* qualified, and <code>false</code> to use only simple names |
|
|
2332 |
* @return the 0-based character index of the last character |
2333 |
* @exception IllegalArgumentException if this is not an array type signature |
2334 |
* @see Util#scanArrayTypeSignature(char[], int) |
2335 |
*/ |
2336 |
private static int appendCaptureTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) { |
2337 |
// need a minimum 2 char |
2338 |
if (start >= string.length - 1) { |
2339 |
throw new IllegalArgumentException(); |
2340 |
} |
2341 |
char c = string[start]; |
2342 |
if (c != C_CAPTURE) { //$NON-NLS-1$ |
2343 |
throw new IllegalArgumentException(); |
2344 |
} |
2345 |
buffer.append(CAPTURE).append(' '); |
2346 |
return appendTypeArgumentSignature(string, start + 1, fullyQualifyTypeNames, buffer); |
2347 |
} |
2348 |
|
2349 |
/** |
2350 |
* Scans the given string for an array type signature starting at the given |
2351 |
* index and appends it to the given buffer, and returns the index of the last |
2352 |
* character. |
2353 |
* |
2354 |
* @param string the signature string |
2355 |
* @param start the 0-based character index of the first character |
2356 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2357 |
* qualified, and <code>false</code> to use only simple names |
2223 |
* @param isVarArgs <code>true</code> if the array type must be displayed as a |
2358 |
* @param isVarArgs <code>true</code> if the array type must be displayed as a |
2224 |
* variable argument, <code>false</code> otherwise |
2359 |
* variable argument, <code>false</code> otherwise |
2225 |
* @return the 0-based character index of the last character |
2360 |
* @return the 0-based character index of the last character |