Lines 294-299
Link Here
|
294 |
public static final char C_GENERIC_END = '>'; |
294 |
public static final char C_GENERIC_END = '>'; |
295 |
|
295 |
|
296 |
/** |
296 |
/** |
|
|
297 |
* Character constant indicating a capture of a wildcard type in a |
298 |
* signature.Value is <code>'!'</code>. |
299 |
* @since 3.1 |
300 |
*/ |
301 |
public static final char C_CAPTURE = '!'; |
302 |
|
303 |
/** |
297 |
* String constant for the signature of the primitive type boolean. |
304 |
* String constant for the signature of the primitive type boolean. |
298 |
* Value is <code>"Z"</code>. |
305 |
* Value is <code>"Z"</code>. |
299 |
*/ |
306 |
*/ |
Lines 382-387
Link Here
|
382 |
*/ |
389 |
*/ |
383 |
public static final int WILDCARD_TYPE_SIGNATURE = 5; |
390 |
public static final int WILDCARD_TYPE_SIGNATURE = 5; |
384 |
|
391 |
|
|
|
392 |
/** |
393 |
* Kind constant for the capture of a wildcard type signature. |
394 |
* @see #getTypeSignatureKind(String) |
395 |
* @since 3.1 |
396 |
*/ |
397 |
public static final int CAPTURE_TYPE_SIGNATURE = 6; |
398 |
|
385 |
private static final char[] BOOLEAN = "boolean".toCharArray(); //$NON-NLS-1$ |
399 |
private static final char[] BOOLEAN = "boolean".toCharArray(); //$NON-NLS-1$ |
386 |
private static final char[] BYTE = "byte".toCharArray(); //$NON-NLS-1$ |
400 |
private static final char[] BYTE = "byte".toCharArray(); //$NON-NLS-1$ |
387 |
private static final char[] CHAR = "char".toCharArray(); //$NON-NLS-1$ |
401 |
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$ |
407 |
private static final char[] VOID = "void".toCharArray(); //$NON-NLS-1$ |
394 |
private static final char[] EXTENDS = "extends".toCharArray(); //$NON-NLS-1$ |
408 |
private static final char[] EXTENDS = "extends".toCharArray(); //$NON-NLS-1$ |
395 |
private static final char[] SUPER = "super".toCharArray(); //$NON-NLS-1$ |
409 |
private static final char[] SUPER = "super".toCharArray(); //$NON-NLS-1$ |
|
|
410 |
private static final char[] CAPTURE = "capture-of".toCharArray(); //$NON-NLS-1$ |
396 |
|
411 |
|
397 |
private static final String EMPTY = new String(CharOperation.NO_CHAR); |
412 |
private static final String EMPTY = new String(CharOperation.NO_CHAR); |
398 |
|
413 |
|
Lines 720-733
Link Here
|
720 |
return pos; |
735 |
return pos; |
721 |
} |
736 |
} |
722 |
break; |
737 |
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': |
738 |
case 'd': |
732 |
checkPos = checkName(DOUBLE, typeName, pos, length); |
739 |
checkPos = checkName(DOUBLE, typeName, pos, length); |
733 |
if (checkPos > 0) { |
740 |
if (checkPos > 0) { |
Lines 776-781
Link Here
|
776 |
return pos; |
783 |
return pos; |
777 |
} |
784 |
} |
778 |
break; |
785 |
break; |
|
|
786 |
case 'c': |
787 |
checkPos = checkName(CHAR, typeName, pos, length); |
788 |
if (checkPos > 0) { |
789 |
pos = encodeArrayDimension(typeName, checkPos, length, buffer); |
790 |
buffer.append(C_CHAR); |
791 |
return pos; |
792 |
} else { |
793 |
checkPos = checkName(CAPTURE, typeName, pos, length); |
794 |
if (checkPos > 0) { |
795 |
pos = consumeWhitespace(typeName, checkPos, length); |
796 |
if (typeName[pos] != '?') { |
797 |
break; |
798 |
} |
799 |
} else { |
800 |
break; |
801 |
} |
802 |
} |
803 |
buffer.append(C_CAPTURE); |
804 |
// fall-thru for wildcard part of capture typecheckPos |
779 |
case '?': |
805 |
case '?': |
780 |
// wildcard |
806 |
// wildcard |
781 |
pos = consumeWhitespace(typeName, pos+1, length); |
807 |
pos = consumeWhitespace(typeName, pos+1, length); |
Lines 1007-1012
Link Here
|
1007 |
case C_SUPER : |
1033 |
case C_SUPER : |
1008 |
case C_EXTENDS : |
1034 |
case C_EXTENDS : |
1009 |
return WILDCARD_TYPE_SIGNATURE; |
1035 |
return WILDCARD_TYPE_SIGNATURE; |
|
|
1036 |
case C_CAPTURE : |
1037 |
return CAPTURE_TYPE_SIGNATURE; |
1010 |
default : |
1038 |
default : |
1011 |
throw new IllegalArgumentException(); |
1039 |
throw new IllegalArgumentException(); |
1012 |
} |
1040 |
} |
Lines 1050-1055
Link Here
|
1050 |
case C_SUPER : |
1078 |
case C_SUPER : |
1051 |
case C_EXTENDS : |
1079 |
case C_EXTENDS : |
1052 |
return WILDCARD_TYPE_SIGNATURE; |
1080 |
return WILDCARD_TYPE_SIGNATURE; |
|
|
1081 |
case C_CAPTURE : |
1082 |
return CAPTURE_TYPE_SIGNATURE; |
1053 |
default : |
1083 |
default : |
1054 |
throw new IllegalArgumentException(); |
1084 |
throw new IllegalArgumentException(); |
1055 |
} |
1085 |
} |
Lines 1944-1949
Link Here
|
1944 |
public static String[] getSimpleNames(String name) { |
1974 |
public static String[] getSimpleNames(String name) { |
1945 |
return CharOperation.toStrings(getSimpleNames(name.toCharArray())); |
1975 |
return CharOperation.toStrings(getSimpleNames(name.toCharArray())); |
1946 |
} |
1976 |
} |
|
|
1977 |
|
1978 |
|
1979 |
/** |
1980 |
* Returns new method signature without capture information or |
1981 |
* method signature itself if no specific capture information was present. |
1982 |
* <p> |
1983 |
* For example: |
1984 |
* <pre> |
1985 |
* <code> |
1986 |
* removeCaptureFromMethod({'L','T','e','s','t','<','!','+','L','j','a','v','a','.','l','a','n','g','.','T','h','r','o','w','a','b','l','e',';','>',';'}) |
1987 |
* will return: {'L','T','e','s','t','<','+','L','j','a','v','a','.','l','a','n','g','.','T','h','r','o','w','a','b','l','e',';','>',';'} |
1988 |
* </code> |
1989 |
* </pre> |
1990 |
* </p> |
1991 |
* |
1992 |
* @param captureSignature the signature which may have been captured |
1993 |
* @return new signature without capture information or siganture itself |
1994 |
* if no specific capture information was there |
1995 |
* @exception NullPointerException if name is null |
1996 |
* @since 3.1 |
1997 |
* TODO (frederic) Create remove(char[], char) method on CharOperation and call it from here |
1998 |
*/ |
1999 |
public static char[] removeCaptureFromMethod(char[] captureSignature) { |
2000 |
|
2001 |
char[] result = null; |
2002 |
int count = 0; |
2003 |
for (int i = 0, length = captureSignature.length; i < length; i++) { |
2004 |
char c = captureSignature[i]; |
2005 |
if (c == C_CAPTURE) { |
2006 |
if (result == null) { |
2007 |
result = new char[length]; |
2008 |
System.arraycopy(captureSignature, 0, result, 0, i); |
2009 |
count = i; |
2010 |
} |
2011 |
} else if (result != null) { |
2012 |
result[count++] = c; |
2013 |
} |
2014 |
} |
2015 |
if (result == null) return captureSignature; |
2016 |
System.arraycopy(result, 0, result = new char[count], 0, count); |
2017 |
return result; |
2018 |
} |
2019 |
|
2020 |
/** |
2021 |
* Returns new method signature without capture information or |
2022 |
* method signature itself if no specific capture information was present. |
2023 |
* <p> |
2024 |
* For example: |
2025 |
* <pre> |
2026 |
* <code> |
2027 |
* removeCaptureFromMethod("LTest<!+Ljava.lang.Throwable;>;") |
2028 |
* will return: "LTest<+Ljava.lang.Throwable;>;" |
2029 |
* </code> |
2030 |
* </pre> |
2031 |
* </p> |
2032 |
* |
2033 |
* @param captureSignature the signature which may have been captured |
2034 |
* @return new signature without capture information or siganture itself |
2035 |
* if no specific capture information was there |
2036 |
* @exception NullPointerException if name is null |
2037 |
* @since 3.1 |
2038 |
*/ |
2039 |
public static String removeCaptureFromMethod(String captureSignature) { |
2040 |
char[] array = captureSignature.toCharArray(); |
2041 |
char[] result = removeCaptureFromMethod(array); |
2042 |
if (array == result) return captureSignature; |
2043 |
return new String(result); |
2044 |
} |
2045 |
|
1947 |
/** |
2046 |
/** |
1948 |
* Converts the given method signature to a readable form. The method signature is expected to |
2047 |
* Converts the given method signature to a readable form. The method signature is expected to |
1949 |
* be dot-based. |
2048 |
* be dot-based. |
Lines 2145-2150
Link Here
|
2145 |
case C_STAR: |
2244 |
case C_STAR: |
2146 |
case C_EXTENDS: |
2245 |
case C_EXTENDS: |
2147 |
case C_SUPER: |
2246 |
case C_SUPER: |
|
|
2247 |
case C_CAPTURE: |
2148 |
default: |
2248 |
default: |
2149 |
throw new IllegalArgumentException(); // a var args is an array type |
2249 |
throw new IllegalArgumentException(); // a var args is an array type |
2150 |
} |
2250 |
} |
Lines 2186-2191
Link Here
|
2186 |
case C_VOID : |
2286 |
case C_VOID : |
2187 |
buffer.append(VOID); |
2287 |
buffer.append(VOID); |
2188 |
return start; |
2288 |
return start; |
|
|
2289 |
case C_CAPTURE : |
2290 |
return appendCaptureTypeSignature(string, start, fullyQualifyTypeNames, buffer); |
2189 |
case C_STAR: |
2291 |
case C_STAR: |
2190 |
case C_EXTENDS: |
2292 |
case C_EXTENDS: |
2191 |
case C_SUPER: |
2293 |
case C_SUPER: |
Lines 2220-2225
Link Here
|
2220 |
* @param start the 0-based character index of the first character |
2322 |
* @param start the 0-based character index of the first character |
2221 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2323 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2222 |
* qualified, and <code>false</code> to use only simple names |
2324 |
* qualified, and <code>false</code> to use only simple names |
|
|
2325 |
* @return the 0-based character index of the last character |
2326 |
* @exception IllegalArgumentException if this is not an array type signature |
2327 |
* @see Util#scanArrayTypeSignature(char[], int) |
2328 |
*/ |
2329 |
private static int appendCaptureTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) { |
2330 |
// need a minimum 2 char |
2331 |
if (start >= string.length - 1) { |
2332 |
throw new IllegalArgumentException(); |
2333 |
} |
2334 |
char c = string[start]; |
2335 |
if (c != C_CAPTURE) { //$NON-NLS-1$ |
2336 |
throw new IllegalArgumentException(); |
2337 |
} |
2338 |
buffer.append(CAPTURE).append(' '); |
2339 |
return appendTypeArgumentSignature(string, start + 1, fullyQualifyTypeNames, buffer); |
2340 |
} |
2341 |
|
2342 |
/** |
2343 |
* Scans the given string for an array type signature starting at the given |
2344 |
* index and appends it to the given buffer, and returns the index of the last |
2345 |
* character. |
2346 |
* |
2347 |
* @param string the signature string |
2348 |
* @param start the 0-based character index of the first character |
2349 |
* @param fullyQualifyTypeNames <code>true</code> if type names should be fully |
2350 |
* 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 |
2351 |
* @param isVarArgs <code>true</code> if the array type must be displayed as a |
2224 |
* variable argument, <code>false</code> otherwise |
2352 |
* variable argument, <code>false</code> otherwise |
2225 |
* @return the 0-based character index of the last character |
2353 |
* @return the 0-based character index of the last character |