From df675c8a18cca874123fc7be1e8ba2284c69cc67 Mon Sep 17 00:00:00 2001
From: Anton Leherbauer
- * Signatures obtained from parsing source (".java") files 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.
- * 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[]
- * | ResolvedClassTypeSignature
- * | UnresolvedClassTypeSignature
- *
- * ResolvedClassTypeSignature ::= // resolved named type (in compiled code)
- * "L" + Identifier + OptionalTypeArguments
- * ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";"
- *
- * UnresolvedClassTypeSignature ::= // unresolved named type (in source code)
- * "Q" + Identifier + OptionalTypeArguments
- * ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";"
- *
- * OptionalTypeArguments ::=
- * "<" + TypeArgument+ + ">"
- * |
- *
- * TypeArgument ::=
- * | TypeSignature
- * | "*" // wildcard ?
- * | "+" TypeSignature // wildcard ? extends X
- * | "-" TypeSignature // wildcard ? super X
- *
- *
- * 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- * The syntax for a method signature is: - *
- * MethodSignature ::= "(" + 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; it is not intended to be - * instantiated or subclassed by clients. - *
- */ -public final class Signature { - - /** - * Character constant indicating the primitive type boolean in a signature. - * Value is'Z'
.
- */
- public static final char C_BOOLEAN = 'Z';
-
- /**
- * Character constant indicating the primitive type byte in a signature.
- * Value is 'B'
.
- */
- public static final char C_BYTE = 'B';
-
- /**
- * Character constant indicating the primitive type char in a signature.
- * Value is 'C'
.
- */
- public static final char C_CHAR = 'C';
-
- /**
- * Character constant indicating the primitive type double in a signature.
- * Value is 'D'
.
- */
- public static final char C_DOUBLE = 'D';
-
- /**
- * Character constant indicating the primitive type float in a signature.
- * Value is 'F'
.
- */
- public static final char C_FLOAT = 'F';
-
- /**
- * Character constant indicating the primitive type int in a signature.
- * Value is 'I'
.
- */
- public static final char C_INT = 'I';
-
- /**
- * Character constant indicating the semicolon in a signature.
- * Value is ';'
.
- */
- public static final char C_SEMICOLON = ';';
-
- /**
- * Character constant indicating the colon in a signature.
- * Value is ':'
.
- * @since 3.0
- */
- public static final char C_COLON = ':';
-
- /**
- * Character constant indicating the primitive type long in a signature.
- * Value is 'J'
.
- */
- public static final char C_LONG = 'J';
-
- /**
- * Character constant indicating the primitive type short in a signature.
- * Value is 'S'
.
- */
- public static final char C_SHORT = 'S';
-
- /**
- * Character constant indicating result type void in a signature.
- * Value is 'V'
.
- */
- public static final char C_VOID = 'V';
-
- /**
- * Character constant indicating result const in a signature.
- * Value is 'K'
.
- */
- public static final char C_CONST = 'K';
-
- /**
- * Character constant indicating the start of a resolved type variable in a
- * signature. Value is 'T'
.
- * @since 3.0
- */
- public static final char C_TYPE_VARIABLE = 'T';
-
- /**
- * Character constant indicating a wildcard type argument
- * in a signature.
- * Value is '*'
.
- * @since 3.0
- */
- public static final char C_STAR = '*';
-
- /**
- * Character constant indicating the dot in a signature.
- * Value is '.'
.
- */
- public static final char C_DOT = '.';
-
- /**
- * Character constant indicating the dollar in a signature.
- * Value is '$'
.
- */
- public static final char C_DOLLAR = '$';
-
- /**
- * Character constant indicating an array type in a signature.
- * Value is '['
.
- */
- public static final char C_ARRAY = '[';
-
- /**
- * Character constant indicating the start of a resolved, named type in a
- * signature. Value is 'L'
.
- */
- public static final char C_RESOLVED = 'L';
-
- /**
- * Character constant indicating the start of an unresolved, named type in a
- * signature. Value is 'Q'
.
- */
- public static final char C_UNRESOLVED = 'Q';
-
- /**
- * Character constant indicating the end of a named type in a signature.
- * Value is ';'
.
- */
- public static final char C_NAME_END = ';';
-
- /**
- * Character constant indicating the start of a parameter type list in a
- * signature. Value is '('
.
- */
- public static final char C_PARAM_START = '(';
-
- /**
- * Character constant indicating the end of a parameter type list in a
- * signature. Value is ')'
.
- */
- public static final char C_PARAM_END = ')';
-
- /**
- * Character constant indicating the start of a formal type parameter
- * (or type argument) list in a signature. Value is '<'
.
- * @since 3.0
- */
- public static final char C_GENERIC_START = '<';
-
- /**
- * Character constant indicating the end of a generic type list in a
- * signature. Value is '%gt;'
.
- * @since 3.0
- */
- public static final char C_GENERIC_END = '>';
-
- /**
- * String constant for the signature of the primitive type boolean.
- * Value is "Z"
.
- */
- public static final String SIG_BOOLEAN = "Z"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type byte.
- * Value is "B"
.
- */
- public static final String SIG_BYTE = "B"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type char.
- * Value is "C"
.
- */
- public static final String SIG_CHAR = "C"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type double.
- * Value is "D"
.
- */
- public static final String SIG_DOUBLE = "D"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type float.
- * Value is "F"
.
- */
- public static final String SIG_FLOAT = "F"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type int.
- * Value is "I"
.
- */
- public static final String SIG_INT = "I"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type long.
- * Value is "J"
.
- */
- public static final String SIG_LONG = "J"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type short.
- * Value is "S"
.
- */
- public static final String SIG_SHORT = "S"; //$NON-NLS-1$
-
- /** String constant for the signature of result type void.
- * Value is "V"
.
- */
- public static final String SIG_VOID = "V"; //$NON-NLS-1$
-
-
- /**
- * Kind constant for a class type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int CLASS_TYPE_SIGNATURE = 1;
-
- /**
- * Kind constant for a base (primitive or void) type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int BASE_TYPE_SIGNATURE = 2;
-
- /**
- * Kind constant for a type variable signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int TYPE_VARIABLE_SIGNATURE = 3;
-
- /**
- * Kind constant for an array type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int ARRAY_TYPE_SIGNATURE = 4;
-
- private static final char[] BOOLEAN = {'b', 'o', 'o', 'l', 'e', 'a', 'n'};
- private static final char[] BYTE = {'b', 'y', 't', 'e'};
- private static final char[] CHAR = {'c', 'h', 'a', 'r'};
- private static final char[] DOUBLE = {'d', 'o', 'u', 'b', 'l', 'e'};
- private static final char[] FLOAT = {'f', 'l', 'o', 'a', 't'};
- private static final char[] INT = {'i', 'n', 't'};
- private static final char[] LONG = {'l', 'o', 'n', 'g'};
- private static final char[] SHORT = {'s', 'h', 'o', 'r', 't'};
- private static final char[] VOID = {'v', 'o', 'i', 'd'};
- private static final char[] CONST = {'c', 'o', 'n', 's', 't'};
-
- private static final String EMPTY = new String(CharOperation.NO_CHAR);
-
-private Signature() {
- // Not instantiable
-}
-
-private static boolean checkPrimitiveType(char[] primitiveTypeName, char[] typeName) {
- return CharOperation.fragmentEquals(primitiveTypeName, typeName, 0, true) &&
- (typeName.length == primitiveTypeName.length
- || Character.isWhitespace(typeName[primitiveTypeName.length])
- || typeName[primitiveTypeName.length] == C_ARRAY
- || typeName[primitiveTypeName.length] == C_DOT);
-}
-
-/**
- * Creates a new type signature with the given amount of array nesting added
- * to the given type signature.
- *
- * @param typeSignature the type signature
- * @param arrayCount the desired number of levels of array nesting
- * @return the encoded array type signature
- *
- * @since 2.0
- */
-public static char[] createArraySignature(char[] typeSignature, int arrayCount) {
- if (arrayCount == 0) return typeSignature;
- int sigLength = typeSignature.length;
- char[] result = new char[arrayCount + sigLength];
- for (int i = 0; i < arrayCount; i++) {
- result[i] = C_ARRAY;
- }
- System.arraycopy(typeSignature, 0, result, arrayCount, sigLength);
- return result;
-}
-/**
- * Creates a new type signature with the given amount of array nesting added
- * to the given type signature.
- *
- * @param typeSignature the type signature
- * @param arrayCount the desired number of levels of array nesting
- * @return the encoded array type signature
- */
-public static String createArraySignature(String typeSignature, int arrayCount) {
- return new String(createArraySignature(typeSignature.toCharArray(), arrayCount));
-}
-
-/**
- * Creates a method signature from the given parameter and return type
- * signatures. The encoded method signature is dot-based.
- *
- * @param parameterTypes the list of parameter type signatures
- * @param returnType the return type signature
- * @return the encoded method signature
- *
- * @since 2.0
- */
-public static char[] createMethodSignature(char[][] parameterTypes, char[] returnType) {
- int parameterTypesLength = parameterTypes.length;
- int parameterLength = 0;
- for (int i = 0; i < parameterTypesLength; i++) {
- parameterLength += parameterTypes[i].length;
-
- }
- int returnTypeLength = returnType.length;
- char[] result = new char[1 + parameterLength + 1 + returnTypeLength];
- result[0] = C_PARAM_START;
- int index = 1;
- for (int i = 0; i < parameterTypesLength; i++) {
- char[] parameterType = parameterTypes[i];
- int length = parameterType.length;
- System.arraycopy(parameterType, 0, result, index, length);
- index += length;
- }
- result[index] = C_PARAM_END;
- System.arraycopy(returnType, 0, result, index+1, returnTypeLength);
- return result;
-}
-
-/**
- * Creates a method signature from the given parameter and return type
- * signatures. The encoded method signature is dot-based. This method
- * is equivalent to
- * createMethodSignature(parameterTypes, returnType)
.
- *
- * @param parameterTypes the list of parameter type signatures
- * @param returnType the return type signature
- * @return the encoded method signature
- * @see Signature#createMethodSignature(char[][], char[])
- */
-public static String createMethodSignature(String[] parameterTypes, String returnType) {
- int parameterTypesLenth = parameterTypes.length;
- char[][] parameters = new char[parameterTypesLenth][];
- for (int i = 0; i < parameterTypesLenth; i++) {
- parameters[i] = parameterTypes[i].toCharArray();
- }
- return new String(createMethodSignature(parameters, returnType.toCharArray()));
-}
-
-/**
- * Creates a new type signature from the given type name encoded as a character
- * array. The type name may contain primitive types or array types. However,
- * parameterized types are not supported.
- * This method is equivalent to
- * 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.
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- * @see #createTypeSignature(java.lang.String,boolean)
- */
-public static String createTypeSignature(char[] typeName, boolean isResolved) {
- return new String(createCharArrayTypeSignature(typeName, isResolved));
-}
-/**
- * Creates a new type signature from the given type name encoded as a character
- * array. The type name may contain primitive types or array types. However,
- * parameterized types are not supported.
- * This method is equivalent to
- * 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.
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- * @see #createTypeSignature(java.lang.String,boolean)
- *
- * @since 2.0
- */
-public static char[] createCharArrayTypeSignature(char[] typeName, boolean isResolved) {
- if (typeName == null) throw new IllegalArgumentException("null"); //$NON-NLS-1$
- int length = typeName.length;
- if (length == 0) throw new IllegalArgumentException(new String(typeName));
-
- int arrayCount = CharOperation.occurencesOf('[', typeName);
- char[] sig;
-
- switch (typeName[0]) {
- // primitive type?
- case 'b' :
- if (checkPrimitiveType(BOOLEAN, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_BOOLEAN;
- break;
- } else if (checkPrimitiveType(BYTE, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_BYTE;
- break;
- }
- case 'c':
- if (checkPrimitiveType(CHAR, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_CHAR;
- break;
- }
- case 'd':
- if (checkPrimitiveType(DOUBLE, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_DOUBLE;
- break;
- }
- case 'f':
- if (checkPrimitiveType(FLOAT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_FLOAT;
- break;
- }
- case 'i':
- if (checkPrimitiveType(INT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_INT;
- break;
- }
- case 'l':
- if (checkPrimitiveType(LONG, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_LONG;
- break;
- }
- case 's':
- if (checkPrimitiveType(SHORT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_SHORT;
- break;
- }
- case 'v':
- if (checkPrimitiveType(VOID, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_VOID;
- break;
- }
- default:
- // non primitive type
- int sigLength = arrayCount + 1 + length + 1; // for example '[[[Ljava.lang.String;'
- sig = new char[sigLength];
- int sigIndex = arrayCount+1; // index in sig
- int startID = 0; // start of current ID in typeName
- int index = 0; // index in typeName
- while (index < length) {
- char currentChar = typeName[index];
- switch (currentChar) {
- case '.':
- if (startID == -1) throw new IllegalArgumentException(new String(typeName));
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- sig[sigIndex++] = C_DOT;
- index++;
- startID = index;
- break;
- case '[':
- if (startID != -1) {
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- startID = -1; // no more id after []
- }
- index++;
- break;
- default :
- if (startID != -1 && CharOperation.isWhitespace(currentChar)) {
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- startID = index+1;
- }
- index++;
- break;
- }
- }
- // last id
- if (startID != -1 && startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
-
- // add L (or Q) at the beigininig and ; at the end
- sig[arrayCount] = isResolved ? C_RESOLVED : C_UNRESOLVED;
- sig[sigIndex++] = C_NAME_END;
-
- // resize if needed
- if (sigLength > sigIndex) {
- System.arraycopy(sig, 0, sig = new char[sigIndex], 0, sigIndex);
- }
- }
-
- // add array info
- for (int i = 0; i < arrayCount; i++) {
- sig[i] = C_ARRAY;
- }
-
- return sig;
-}
-/**
- * Creates a new type signature from the given type name. If the type name is qualified,
- * then it is expected to be dot-based. The type name may contain primitive
- * types or array types. However, parameterized types are not supported.
- * - * 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"
- *
- *
- *
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- */
-public static String createTypeSignature(String typeName, boolean isResolved) {
- return createTypeSignature(typeName == null ? null : typeName.toCharArray(), isResolved);
-}
-
-/**
- * Returns the array count (array nesting depth) of the given type signature.
- *
- * @param typeSignature the type signature
- * @return the array nesting depth, or 0 if not an array
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- *
- * @since 2.0
- */
-public static int getArrayCount(char[] typeSignature) throws IllegalArgumentException {
- try {
- int count = 0;
- while (typeSignature[count] == C_ARRAY) {
- ++count;
- }
- return count;
- } catch (ArrayIndexOutOfBoundsException e) { // signature is syntactically incorrect if last character is C_ARRAY
- throw new IllegalArgumentException();
- }
-}
-/**
- * Returns the array count (array nesting depth) of the given type signature.
- *
- * @param typeSignature the type signature
- * @return the array nesting depth, or 0 if not an array
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- */
-public static int getArrayCount(String typeSignature) throws IllegalArgumentException {
- return getArrayCount(typeSignature.toCharArray());
-}
-/**
- * Returns the type signature without any array nesting.
- * - * For example: - *
- *
- * getElementType({'[', '[', 'I'}) --> {'I'}.
- *
- *
- *
- *
- * @param typeSignature the type signature
- * @return the type signature without arrays
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- *
- * @since 2.0
- */
-public static char[] getElementType(char[] typeSignature) throws IllegalArgumentException {
- int count = getArrayCount(typeSignature);
- if (count == 0) return typeSignature;
- int length = typeSignature.length;
- char[] result = new char[length-count];
- System.arraycopy(typeSignature, count, result, 0, length-count);
- return result;
-}
-/**
- * Returns the type signature without any array nesting.
- * - * For example: - *
- *
- * getElementType("[[I") --> "I".
- *
- *
- *
- *
- * @param typeSignature the type signature
- * @return the type signature without arrays
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- */
-public static String getElementType(String typeSignature) throws IllegalArgumentException {
- return new String(getElementType(typeSignature.toCharArray()));
-}
-/**
- * Returns the number of parameter types in the given method signature.
- *
- * @param methodSignature the method signature
- * @return the number of parameters
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- * @since 2.0
- */
-public static int getParameterCount(char[] methodSignature) throws IllegalArgumentException {
- try {
- int count = 0;
- int i = CharOperation.indexOf(C_PARAM_START, methodSignature);
- if (i < 0) {
- throw new IllegalArgumentException();
- }
- i++;
- for (;;) {
- if (methodSignature[i] == C_PARAM_END) {
- return count;
- }
- int e= scanTypeSignature(methodSignature, i);
- if (e < 0) {
- throw new IllegalArgumentException();
- }
- i = e + 1;
- count++;
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Returns the kind of type signature encoded by the given string.
- *
- * @param typeSignature the type signature string
- * @return the kind of type signature; one of the kind constants:
- * {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
- * {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE}
- * @exception IllegalArgumentException if this is not a type signature
- * @since 3.0
- */
-public static int getTypeSignatureKind(char[] typeSignature) {
- // need a minimum 1 char
- if (typeSignature.length < 1) {
- throw new IllegalArgumentException();
- }
- char c = typeSignature[0];
- switch (c) {
- case C_ARRAY :
- return ARRAY_TYPE_SIGNATURE;
- case C_RESOLVED :
- case C_UNRESOLVED :
- return CLASS_TYPE_SIGNATURE;
- case C_TYPE_VARIABLE :
- return TYPE_VARIABLE_SIGNATURE;
- case C_BOOLEAN :
- case C_BYTE :
- case C_CHAR :
- case C_DOUBLE :
- case C_FLOAT :
- case C_INT :
- case C_LONG :
- case C_SHORT :
- case C_VOID :
- return BASE_TYPE_SIGNATURE;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Returns the kind of type signature encoded by the given string.
- *
- * @param typeSignature the type signature string
- * @return the kind of type signature; one of the kind constants:
- * {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
- * {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE}
- * @exception IllegalArgumentException if this is not a type signature
- * @since 3.0
- */
-public static int getTypeSignatureKind(String typeSignature) {
- // need a minimum 1 char
- if (typeSignature.length() < 1) {
- throw new IllegalArgumentException();
- }
- char c = typeSignature.charAt(0);
- switch (c) {
- case C_ARRAY :
- return ARRAY_TYPE_SIGNATURE;
- case C_RESOLVED :
- case C_UNRESOLVED :
- return CLASS_TYPE_SIGNATURE;
- case C_TYPE_VARIABLE :
- return TYPE_VARIABLE_SIGNATURE;
- case C_BOOLEAN :
- case C_BYTE :
- case C_CHAR :
- case C_DOUBLE :
- case C_FLOAT :
- case C_INT :
- case C_LONG :
- case C_SHORT :
- case C_VOID :
- return BASE_TYPE_SIGNATURE;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Scans the given string for a type signature starting at the given index
- * and returns the index of the last character.
- * - * TypeSignature: - * | BaseTypeSignature - * | ArrayTypeSignature - * | ClassTypeSignature - * | TypeVariableSignature - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type signature - * @see #appendTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanTypeSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - switch (c) { - case C_ARRAY : - return scanArrayTypeSignature(string, start); - case C_RESOLVED : - case C_UNRESOLVED : - return scanClassTypeSignature(string, start); - case C_TYPE_VARIABLE : - return scanTypeVariableSignature(string, start); - case C_BOOLEAN : - case C_BYTE : - case C_CHAR : - case C_DOUBLE : - case C_FLOAT : - case C_INT : - case C_LONG : - case C_SHORT : - case C_VOID : - return scanBaseTypeSignature(string, start); - default : - throw new IllegalArgumentException(); - } -} - -/** - * Scans the given string for a base type signature starting at the given index - * and returns the index of the last character. - *
- * BaseTypeSignature: - * B | C | D | F | I - * | J | S | V | Z - *- * Note that although the base type "V" is only allowed in method return types, - * there is no syntactic ambiguity. This method will accept them anywhere - * without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a base type signature - */ -private static int scanBaseTypeSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if ("BCDFIJSVZ".indexOf(c) >= 0) { //$NON-NLS-1$ - return start; - } - throw new IllegalArgumentException(); -} - -/** - * Scans the given string for an array type signature starting at the given - * index and returns the index of the last character. - *
- * ArrayTypeSignature: - * [ TypeSignature - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not an array type signature - * @see #appendArrayTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanArrayTypeSignature(char[] string, int start) { - // need a minimum 2 char - if (start >= string.length - 1) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c != C_ARRAY) { //$NON-NLS-1$ - throw new IllegalArgumentException(); - } - return scanTypeSignature(string, start + 1); -} - -/** - * Scans the given string for a type variable signature starting at the given - * index and returns the index of the last character. - *
- * TypeVariableSignature: - * T Identifier ; - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type variable signature - */ -private static int scanTypeVariableSignature(char[] string, int start) { - // need a minimum 3 chars "Tx;" - if (start >= string.length - 2) { - throw new IllegalArgumentException(); - } - // must start in "T" - char c = string[start]; - if (c != C_TYPE_VARIABLE) { - throw new IllegalArgumentException(); - } - int id = scanIdentifier(string, start + 1); - c = string[id + 1]; - if (c == C_SEMICOLON) { - return id + 1; - } - throw new IllegalArgumentException(); -} - -/** - * Scans the given string for an identifier starting at the given - * index and returns the index of the last character. - * Stop characters are: ";", ":", "<", ">", "/", ".". - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not an identifier - */ -private static int scanIdentifier(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - int p = start; - while (true) { - char c = string[p]; - if (c == '<' || c == '>' || c == ':' || c == ';' || c == '.' || c == '/') { - return p - 1; - } - p++; - if (p == string.length) { - return p - 1; - } - } -} - -/** - * Scans the given string for a class type signature starting at the given - * index and returns the index of the last character. - *
- * ClassTypeSignature: - * { L | Q } Identifier - * { { / | . Identifier [ < TypeArgumentSignature* > ] } - * ; - *- * Note that although all "/"-identifiers most come before "."-identifiers, - * there is no syntactic ambiguity. This method will accept them without - * complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a class type signature - * @see #appendClassTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanClassTypeSignature(char[] string, int start) { - // need a minimum 3 chars "Lx;" - if (start >= string.length - 2) { - throw new IllegalArgumentException(); - } - // must start in "L" or "Q" - char c = string[start]; - if (c != C_RESOLVED && c != C_UNRESOLVED) { - return -1; - } - int p = start + 1; - while (true) { - if (p >= string.length) { - throw new IllegalArgumentException(); - } - c = string[p]; - if (c == C_SEMICOLON) { - // all done - return p; - } else if (c == C_GENERIC_START) { - int e = scanTypeArgumentSignatures(string, p); - p = e; - } else if (c == C_DOT || c == '/') { - int id = scanIdentifier(string, p + 1); - p = id; - } - p++; - } -} - -/** - * Scans the given string for a list of type argument signatures starting at - * the given index and returns the index of the last character. - *
- * TypeArgumentSignatures: - * < TypeArgumentSignature* > - *- * Note that although there is supposed to be at least one type argument, there - * is no syntactic ambiguity if there are none. This method will accept zero - * type argument signatures without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a list of type arguments - * signatures - * @see #appendTypeArgumentSignatures(char[], int, boolean, StringBuffer) - */ -private static int scanTypeArgumentSignatures(char[] string, int start) { - // need a minimum 2 char "<>" - if (start >= string.length - 1) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c != C_GENERIC_START) { - throw new IllegalArgumentException(); - } - int p = start + 1; - while (true) { - if (p >= string.length) { - throw new IllegalArgumentException(); - } - c = string[p]; - if (c == C_GENERIC_END) { - return p; - } - int e = scanTypeArgumentSignature(string, p); - p = e + 1; - } -} - -/** - * Scans the given string for a type argument signature starting at the given - * index and returns the index of the last character. - *
- * TypeArgumentSignature: - * * - * | + TypeSignature - * | - TypeSignature - * | TypeSignature - *- * Note that although base types are not allowed in type arguments, there is - * no syntactic ambiguity. This method will accept them without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type argument signature - * @see #appendTypeArgumentSignature(char[], int, boolean, StringBuffer) - */ -private static int scanTypeArgumentSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c == C_STAR) { - return start; - } - if (c == '+' || c == '-') { - return scanTypeSignature(string, start + 1); - } - return scanTypeSignature(string, start); -} - -/** - * Returns the number of parameter types in the given method signature. - * - * @param methodSignature the method signature - * @return the number of parameters - * @exception IllegalArgumentException if the signature is not syntactically - * correct - */ -public static int getParameterCount(String methodSignature) throws IllegalArgumentException { - return getParameterCount(methodSignature.toCharArray()); -} -/** - * Extracts the parameter type signatures from the given method signature. - * The method signature is expected to be dot-based. - * - * @param methodSignature the method signature - * @return the list of parameter type signatures - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * - * @since 2.0 - */ -public static char[][] getParameterTypes(char[] methodSignature) throws IllegalArgumentException { - try { - int count = getParameterCount(methodSignature); - char[][] result = new char[count][]; - if (count == 0) { - return result; - } - int i = CharOperation.indexOf(C_PARAM_START, methodSignature); - if (i < 0) { - throw new IllegalArgumentException(); - } - i++; - int t = 0; - for (;;) { - if (methodSignature[i] == C_PARAM_END) { - return result; - } - int e = scanTypeSignature(methodSignature, i); - if (e < 0) { - throw new IllegalArgumentException(); - } - result[t] = CharOperation.subarray(methodSignature, i, e + 1); - t++; - i = e + 1; - } - } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalArgumentException(); - } -} -/** - * Extracts the parameter type signatures from the given method signature. - * The method signature is expected to be dot-based. - * - * @param methodSignature the method signature - * @return the list of parameter type signatures - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - */ -public static String[] getParameterTypes(String methodSignature) throws IllegalArgumentException { - char[][] parameterTypes = getParameterTypes(methodSignature.toCharArray()); - int length = parameterTypes.length; - String[] result = new String[length]; - for (int i = 0; i < length; i++) { - result[i] = new String(parameterTypes[i]); - } - return result; -} - -/** - * Extracts the type variable name from the given formal type parameter - * signature. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the name of the type variable - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static String getTypeVariable(String formalTypeParameterSignature) throws IllegalArgumentException { - return new String(getTypeVariable(formalTypeParameterSignature.toCharArray())); -} - -/** - * Extracts the type variable name from the given formal type parameter - * signature. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the name of the type variable - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static char[] getTypeVariable(char[] formalTypeParameterSignature) throws IllegalArgumentException { - int p = CharOperation.indexOf(C_COLON, formalTypeParameterSignature); - if (p < 0) { - // no ":" means can't be a formal type parameter signature - throw new IllegalArgumentException(); - } - return CharOperation.subarray(formalTypeParameterSignature, 0, p); -} - -/** - * Extracts the class and interface bounds from the given formal type - * parameter signature. The class bound, if present, is listed before - * the interface bounds. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the (possibly empty) list of type signatures for the bounds - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static char[][] getTypeParameterBounds(char[] formalTypeParameterSignature) throws IllegalArgumentException { - int p1 = CharOperation.indexOf(C_COLON, formalTypeParameterSignature); - if (p1 < 0) { - // no ":" means can't be a formal type parameter signature - throw new IllegalArgumentException(); - } - if (p1 == formalTypeParameterSignature.length - 1) { - // no class or interface bounds - return CharOperation.NO_CHAR_CHAR; - } - int p2 = CharOperation.indexOf(C_COLON, formalTypeParameterSignature, p1 + 1); - char[] classBound; - if (p2 < 0) { - // no interface bounds - classBound = CharOperation.subarray(formalTypeParameterSignature, p1 + 1, formalTypeParameterSignature.length); - return new char[][] {classBound}; - } - if (p2 == p1 + 1) { - // no class bound, but 1 or more interface bounds - classBound = null; - } else { - classBound = CharOperation.subarray(formalTypeParameterSignature, p1 + 1, p2); - } - char[][] interfaceBounds = CharOperation.splitOn(C_COLON, formalTypeParameterSignature, p2 + 1, formalTypeParameterSignature.length); - if (classBound == null) { - return interfaceBounds; - } - int resultLength = interfaceBounds.length + 1; - char[][] result = new char[resultLength][]; - result[0] = classBound; - System.arraycopy(interfaceBounds, 0, result, 1, interfaceBounds.length); - return result; -} - -/** - * Extracts the class and interface bounds from the given formal type - * parameter signature. The class bound, if present, is listed before - * the interface bounds. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the (possibly empty) list of type signatures for the bounds - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static String[] getTypeParameterBounds(String formalTypeParameterSignature) throws IllegalArgumentException { - char[][] bounds = getTypeParameterBounds(formalTypeParameterSignature.toCharArray()); - int length = bounds.length; - String[] result = new String[length]; - for (int i = 0; i < length; i++) { - result[i] = new String(bounds[i]); - } - return result; -} - -/** - * Returns a char array containing all but the last segment of the given - * dot-separated qualified name. Returns the empty char array if it is not qualified. - *
- * 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'}
- *
- *
- *
- *
- * @param name the name
- * @return the qualifier prefix, or the empty char array if the name contains no
- * dots
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[] getQualifier(char[] name) {
- int lastDot = CharOperation.lastIndexOf(C_DOT, name);
- if (lastDot == -1) {
- return CharOperation.NO_CHAR;
- }
- return CharOperation.subarray(name, 0, lastDot);
-}
-/**
- * Returns a string containing all but the last segment of the given
- * dot-separated qualified name. Returns the empty string if it is not qualified.
- * - * For example: - *
- *
- * getQualifier("java.lang.Object") -> "java.lang"
- * getQualifier("Outer.Inner") -> "Outer"
- *
- *
- *
- *
- * @param name the name
- * @return the qualifier prefix, or the empty string if the name contains no
- * dots
- * @exception NullPointerException if name is null
- */
-public static String getQualifier(String name) {
- int lastDot = name.lastIndexOf(C_DOT);
- if (lastDot == -1) {
- return EMPTY;
- }
- return name.substring(0, lastDot);
-}
-/**
- * Extracts the return type from the given method signature. The method signature is
- * expected to be dot-based.
- *
- * @param methodSignature the method signature
- * @return the type signature of the return type
- * @exception IllegalArgumentException if the signature is syntactically
- * incorrect
- *
- * @since 2.0
- */
-public static char[] getReturnType(char[] methodSignature) throws IllegalArgumentException {
- // skip type parameters
- int i = CharOperation.lastIndexOf(C_PARAM_END, methodSignature);
- if (i == -1) {
- throw new IllegalArgumentException();
- }
- // ignore any thrown exceptions
- int j = CharOperation.indexOf('^', methodSignature);
- int last = (j == -1 ? methodSignature.length : j);
- return CharOperation.subarray(methodSignature, i + 1, last);
-}
-/**
- * Extracts the return type from the given method signature. The method signature is
- * expected to be dot-based.
- *
- * @param methodSignature the method signature
- * @return the type signature of the return type
- * @exception IllegalArgumentException if the signature is syntactically
- * incorrect
- */
-public static String getReturnType(String methodSignature) throws IllegalArgumentException {
- return new String(getReturnType(methodSignature.toCharArray()));
-}
-/**
- * Returns the last segment of the given dot-separated qualified name.
- * Returns the given name if it is not qualified.
- * - * For example: - *
- *
- * getSimpleName({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'O', 'b', 'j', 'e', 'c', 't'}
- *
- *
- *
- *
- * @param name the name
- * @return the last segment of the qualified name
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[] getSimpleName(char[] name) {
- int lastDot = CharOperation.lastIndexOf(C_DOT, name);
- if (lastDot == -1) {
- return name;
- }
- return CharOperation.subarray(name, lastDot + 1, name.length);
-}
-/**
- * Returns the last segment of the given dot-separated qualified name.
- * Returns the given name if it is not qualified.
- * - * For example: - *
- *
- * getSimpleName("java.lang.Object") -> "Object"
- *
- *
- *
- *
- * @param name the name
- * @return the last segment of the qualified name
- * @exception NullPointerException if name is null
- */
-public static String getSimpleName(String name) {
- int lastDot = name.lastIndexOf(C_DOT);
- if (lastDot == -1) {
- return name;
- }
- return name.substring(lastDot + 1, name.length());
-}
-/**
- * Returns all segments of the given dot-separated qualified name.
- * Returns an array with only the given name if it is not qualified.
- * Returns an empty array if the name is empty.
- * - * 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("") -> {}
- *
- *
- *
- * @param name the name
- * @return the list of simple names, possibly empty
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[][] getSimpleNames(char[] name) {
- if (name.length == 0) {
- return CharOperation.NO_CHAR_CHAR;
- }
- int dot = CharOperation.indexOf(C_DOT, name);
- if (dot == -1) {
- return new char[][] {name};
- }
- int n = 1;
- while ((dot = CharOperation.indexOf(C_DOT, name, dot + 1)) != -1) {
- ++n;
- }
- char[][] result = new char[n + 1][];
- int segStart = 0;
- for (int i = 0; i < n; ++i) {
- dot = CharOperation.indexOf(C_DOT, name, segStart);
- result[i] = CharOperation.subarray(name, segStart, dot);
- segStart = dot + 1;
- }
- result[n] = CharOperation.subarray(name, segStart, name.length);
- return result;
-}
-/**
- * Returns all segments of the given dot-separated qualified name.
- * Returns an array with only the given name if it is not qualified.
- * Returns an empty array if the name is empty.
- * - * For example: - *
- *
- * getSimpleNames("java.lang.Object") -> {"java", "lang", "Object"}
- * getSimpleNames("Object") -> {"Object"}
- * getSimpleNames("") -> {}
- *
- *
- *
- * @param name the name
- * @return the list of simple names, possibly empty
- * @exception NullPointerException if name is null
- */
-public static String[] getSimpleNames(String name) {
- char[][] simpleNames = getSimpleNames(name.toCharArray());
- int length = simpleNames.length;
- String[] result = new String[length];
- for (int i = 0; i < length; i++) {
- result[i] = new String(simpleNames[i]);
- }
- return result;
-}
-/**
- * Converts the given method signature to a readable form. The method signature is expected to
- * be dot-based.
- * - * For example: - *
- *
- * toString("([Ljava.lang.String;)V", "main", new String[] {"args"}, false, true) -> "void main(String[] args)"
- *
- *
- *
- *
- * @param methodSignature the method signature to convert
- * @param methodName the name of the method to insert in the result, or
- * null
if no method name is to be included
- * @param parameterNames 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 signature
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param includeReturnType true
if the return type is to be
- * included
- * @return the char array representation of the method signature
- *
- * @since 2.0
- */
-public static char[] toCharArray(char[] methodSignature, char[] methodName, char[][] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType) {
- int firstParen = CharOperation.indexOf(C_PARAM_START, methodSignature);
- if (firstParen == -1) {
- throw new IllegalArgumentException();
- }
-
- StringBuffer buffer = new StringBuffer(methodSignature.length + 10);
-
- // return type
- if (includeReturnType) {
- char[] rts = getReturnType(methodSignature);
- appendTypeSignature(rts, 0 , fullyQualifyTypeNames, buffer);
- buffer.append(' ');
- }
-
- // selector
- if (methodName != null) {
- buffer.append(methodName);
- }
-
- // parameters
- buffer.append('(');
- char[][] pts = getParameterTypes(methodSignature);
- for (int i = 0; i < pts.length; i++) {
- appendTypeSignature(pts[i], 0 , fullyQualifyTypeNames, buffer);
- if (parameterNames != null) {
- buffer.append(' ');
- buffer.append(parameterNames[i]);
- }
- if (i != pts.length - 1) {
- buffer.append(',');
- buffer.append(' ');
- }
- }
- buffer.append(')');
- char[] result = new char[buffer.length()];
- buffer.getChars(0, buffer.length(), result, 0);
- return result;
-}
-
-/**
- * Converts the given type signature to a readable string. The signature is expected to
- * be dot-based.
- *
- * - * 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'}
- *
- *
- *
- *
- * 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.
- *
true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a type signature
- * @see #scanTypeSignature(char[], int)
- */
-private static int appendTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 1 char
- if (start >= string.length) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- switch (c) {
- case C_ARRAY :
- return appendArrayTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- case C_RESOLVED :
- case C_UNRESOLVED :
- return appendClassTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- case C_TYPE_VARIABLE :
- int e = scanTypeVariableSignature(string, start);
- buffer.append(CharOperation.subarray(string, start + 1, e));
- return e;
- case C_BOOLEAN :
- buffer.append(BOOLEAN);
- return start;
- case C_BYTE :
- buffer.append(BYTE);
- return start;
- case C_CHAR :
- buffer.append(CHAR);
- return start;
- case C_DOUBLE :
- buffer.append(DOUBLE);
- return start;
- case C_FLOAT :
- buffer.append(FLOAT);
- return start;
- case C_INT :
- buffer.append(INT);
- return start;
- case C_LONG :
- buffer.append(LONG);
- return start;
- case C_SHORT :
- buffer.append(SHORT);
- return start;
- case C_VOID :
- buffer.append(VOID);
- return start;
- case C_CONST :
- buffer.append(CONST);
- return start;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Scans the given string for an array type signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not an array type signature
- * @see #scanArrayTypeSignature(char[], int)
- */
-private static int appendArrayTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 2 char
- if (start >= string.length - 1) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- if (c != C_ARRAY) { //$NON-NLS-1$
- throw new IllegalArgumentException();
- }
- int e = appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- buffer.append('[');
- buffer.append(']');
- return e;
-}
-
-/**
- * Scans the given string for a class type signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a class type signature
- * @see #scanClassTypeSignature(char[], int)
- */
-private static int appendClassTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 3 chars "Lx;"
- if (start >= string.length - 2) {
- throw new IllegalArgumentException();
- }
- // must start in "L" or "Q"
- char c = string[start];
- if (c != C_RESOLVED && c != C_UNRESOLVED) {
- throw new IllegalArgumentException();
- }
- boolean resolved = (c == C_RESOLVED);
- boolean removePackageQualifiers = !fullyQualifyTypeNames;
- if (!resolved) {
- // keep everything in an unresolved name
- removePackageQualifiers = false;
- }
- int p = start + 1;
- int checkpoint = buffer.length();
- while (true) {
- if (p >= string.length) {
- throw new IllegalArgumentException();
- }
- c = string[p];
- switch(c) {
- case C_SEMICOLON :
- // all done
- return p;
- case C_GENERIC_START :
- int e = appendTypeArgumentSignatures(string, p, fullyQualifyTypeNames, buffer);
- // once we hit type arguments there are no more package prefixes
- removePackageQualifiers = false;
- p = e;
- break;
- case C_DOT :
- if (removePackageQualifiers) {
- // erase package prefix
- buffer.setLength(checkpoint);
- } else {
- buffer.append('.');
- }
- break;
- case '/' :
- if (removePackageQualifiers) {
- // erase package prefix
- buffer.setLength(checkpoint);
- } else {
- buffer.append('/');
- }
- break;
- case C_DOLLAR :
- if (resolved) {
- // once we hit "$" there are no more package prefixes
- removePackageQualifiers = false;
- /**
- * Convert '$' in resolved type signatures into '.'.
- * NOTE: This assumes that the type signature is an inner type
- * signature. This is true in most cases, but someone can define a
- * non-inner type name containing a '$'.
- */
- buffer.append('.');
- }
- break;
- default :
- buffer.append(c);
- }
- p++;
- }
-}
-
-/**
- * Scans the given string for a list of type arguments signature starting at the
- * given index and appends it to the given buffer, and returns the index of the
- * last character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a list of type argument
- * signatures
- * @see #scanTypeArgumentSignatures(char[], int)
- */
-private static int appendTypeArgumentSignatures(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 2 char "<>"
- if (start >= string.length - 1) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- if (c != C_GENERIC_START) {
- throw new IllegalArgumentException();
- }
- buffer.append('<');
- int p = start + 1;
- int count = 0;
- while (true) {
- if (p >= string.length) {
- throw new IllegalArgumentException();
- }
- c = string[p];
- if (c == C_GENERIC_END) {
- buffer.append('>');
- return p;
- }
- if (count != 0) {
- buffer.append(',');
- }
- int e = appendTypeArgumentSignature(string, p, fullyQualifyTypeNames, buffer);
- count++;
- p = e + 1;
- }
-}
-
-/**
- * Scans the given string for a type argument signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a type argument signature
- * @see #scanTypeArgumentSignature(char[], int)
- */
-private static int appendTypeArgumentSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 1 char
- if (start >= string.length) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- switch(c) {
- case C_STAR :
- buffer.append('?');
- return start;
- case '+' :
- buffer.append("? extends "); //$NON-NLS-1$
- return appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- case '-' :
- buffer.append("? super "); //$NON-NLS-1$
- return appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- default :
- return appendTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- }
-}
-
-/**
- * Converts the given array of qualified name segments to a qualified name.
- * - * 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({{}}) -> {}
- *
- *
- *
- *
- * @param segments the list of name segments, possibly empty
- * @return the dot-separated qualified name, or the empty string
- *
- * @since 2.0
- */
-public static char[] toQualifiedName(char[][] segments) {
- int length = segments.length;
- if (length == 0) return CharOperation.NO_CHAR;
- if (length == 1) return segments[0];
-
- int resultLength = 0;
- for (int i = 0; i < length; i++) {
- resultLength += segments[i].length+1;
- }
- resultLength--;
- char[] result = new char[resultLength];
- int index = 0;
- for (int i = 0; i < length; i++) {
- char[] segment = segments[i];
- int segmentLength = segment.length;
- System.arraycopy(segment, 0, result, index, segmentLength);
- index += segmentLength;
- if (i != length-1) {
- result[index++] = C_DOT;
- }
- }
- return result;
-}
-/**
- * Converts the given array of qualified name segments to a qualified name.
- * - * For example: - *
- *
- * toQualifiedName(new String[] {"java", "lang", "Object"}) -> "java.lang.Object"
- * toQualifiedName(new String[] {"Object"}) -> "Object"
- * toQualifiedName(new String[0]) -> ""
- *
- *
- *
- *
- * @param segments the list of name segments, possibly empty
- * @return the dot-separated qualified name, or the empty string
- */
-public static String toQualifiedName(String[] segments) {
- int length = segments.length;
- char[][] charArrays = new char[length][];
- for (int i = 0; i < length; i++) {
- charArrays[i] = segments[i].toCharArray();
- }
- return new String(toQualifiedName(charArrays));
-}
-/**
- * Converts the given type signature to a readable string. The signature is expected to
- * be dot-based.
- *
- * - * For example: - *
- *
- * toString("[Ljava.lang.String;") -> "java.lang.String[]"
- * toString("I") -> "int"
- *
- *
- *
- *
- * 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.
- *
null
if no method name is to be included
- * @param parameterNames 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 signature
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param includeReturnType true
if the return type is to be
- * included
- * @see #toCharArray(char[], char[], char[][], boolean, boolean)
- * @return the string representation of the method signature
- */
-public static String toString(String methodSignature, String methodName, String[] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType) {
- char[][] params;
- if (parameterNames == null) {
- params = null;
- } else {
- int paramLength = parameterNames.length;
- params = new char[paramLength][];
- for (int i = 0; i < paramLength; i++) {
- params[i] = parameterNames[i].toCharArray();
- }
- }
- return new String(toCharArray(methodSignature.toCharArray(), methodName == null ? null : methodName.toCharArray(), params, fullyQualifyTypeNames, includeReturnType));
-}
-
-}
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeUtil.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeUtil.java
index b38b979280a..a1286b946bc 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeUtil.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
+ * Copyright (c) 2004, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -111,13 +111,13 @@ public class TypeUtil {
* exception occurs while accessing its corresponding resource
*/
public static ICElement[] getTypes(ITranslationUnit tu) throws CModelException {
- List typeList = new ArrayList();
+ ListFor example, a source method declared as void foo(string text, int length)
* would return the array {"string","int"}
.
- *
- * @see Signature
*/
String[] getParameterTypes();
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/IQualifiedTypeName.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/IQualifiedTypeName.java
deleted file mode 100644
index fa08847d9ab..00000000000
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/IQualifiedTypeName.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * QNX Software Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.core.model.util;
-
-public interface IQualifiedTypeName extends Comparable {
-
- public final static String QUALIFIER = "::"; //$NON-NLS-1$
-
- public String getName();
-
- public String getFullyQualifiedName();
- public IQualifiedTypeName getEnclosingTypeName();
- public String[] getEnclosingNames();
-
- public boolean isQualified();
- public boolean isEmpty();
- public boolean isGlobal();
-
- public IQualifiedTypeName append(String qualifiedName);
- public IQualifiedTypeName append(String[] names);
- public IQualifiedTypeName append(IQualifiedTypeName typeName);
-
- public String[] segments();
- public String segment(int index);
- public int segmentCount();
- public String lastSegment();
- public int matchingFirstSegments(IQualifiedTypeName typeName);
- public IQualifiedTypeName removeFirstSegments(int count);
- public IQualifiedTypeName removeLastSegments(int count);
- public boolean isPrefixOf(IQualifiedTypeName typeName);
-
- public boolean isLowLevel();
- public boolean isValidSegment(String segment);
- public boolean isValid();
-
- public boolean equals(IQualifiedTypeName typeName);
- public boolean equalsIgnoreCase(IQualifiedTypeName typeName);
- public int compareTo(IQualifiedTypeName typeName);
- public int compareToIgnoreCase(IQualifiedTypeName typeName);
-}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/QualifiedTypeName.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/QualifiedTypeName.java
deleted file mode 100644
index bb1cf5dfa44..00000000000
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/QualifiedTypeName.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * QNX Software Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.core.model.util;
-
-import org.eclipse.cdt.core.CConventions;
-import org.eclipse.core.runtime.IStatus;
-
-public class QualifiedTypeName implements IQualifiedTypeName {
-
- private static final String[] NO_SEGMENTS = new String[0];
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- private static final int INITIAL_SEGMENT_LENGTH = 12;
- private static final int HASH_INIT = 17;
- private static final int HASH_MULTIPLIER = 37;
-
- private String[] fSegments = NO_SEGMENTS;
- private int fHashCode = 0;
-
- public static final QualifiedTypeName EMPTY = new QualifiedTypeName();
-
- public QualifiedTypeName(IQualifiedTypeName typeName) {
- fSegments = typeName.segments();
- }
-
- public QualifiedTypeName(String qualifiedName) {
- fSegments = createSegments(qualifiedName);
- }
-
- public QualifiedTypeName(String[] names) {
- fSegments = createSegments(names);
- }
-
- public QualifiedTypeName(String name, String[] enclosingNames) {
- if (enclosingNames == null)
- fSegments = createSegments(name);
- else
- fSegments = createSegments(name, enclosingNames);
- }
-
- private QualifiedTypeName() {
- }
-
- private String[] createSegments(String qualifiedName) {
- String[] segments;
- int qualifierIndex = qualifiedName.indexOf(QUALIFIER, 0);
- if (qualifierIndex == -1) {
- segments = new String[] { qualifiedName };
- } else {
- int maxSegments = 1;
- int lastIndex = 0;
- while (qualifierIndex >= 0) {
- lastIndex = qualifierIndex + QUALIFIER.length();
- ++maxSegments;
- qualifierIndex = qualifiedName.indexOf(QUALIFIER, lastIndex);
- }
- segments = new String[maxSegments];
- int segmentCount = 0;
- lastIndex = 0;
- qualifierIndex = qualifiedName.indexOf(QUALIFIER, 0);
- while (qualifierIndex >= 0) {
- // note: we allocate a new string rather than use the returned substring,
- // otherwise we're holding a reference to the entire original string
- segments[segmentCount] = new String(qualifiedName.substring(lastIndex, qualifierIndex));
- ++segmentCount;
- lastIndex = qualifierIndex + QUALIFIER.length();
- qualifierIndex = qualifiedName.indexOf(QUALIFIER, lastIndex);
- }
- // note: we allocate a new string rather than use the returned substring,
- // otherwise we're holding a reference to the entire original string
- segments[segmentCount] = new String(qualifiedName.substring(lastIndex));
- }
- return segments;
- }
-
- private String[] createSegments(String[] names) {
- String[] segments = new String[names.length];
- System.arraycopy(names, 0, segments, 0, names.length);
- return segments;
- }
-
- private String[] createSegments(String name, String[] enclosingNames) {
- String[] segments = new String[enclosingNames.length + 1];
- System.arraycopy(enclosingNames, 0, segments, 0, enclosingNames.length);
- segments[segments.length - 1] = name;
- return segments;
- }
-
- public String getName() {
- if (fSegments.length > 0) {
- return fSegments[fSegments.length - 1];
- }
- return EMPTY_STRING;
- }
-
- public String[] getEnclosingNames() {
- if (fSegments.length > 1) {
- String[] enclosingNames = new String[fSegments.length - 1];
- System.arraycopy(fSegments, 0, enclosingNames, 0, fSegments.length - 1);
- return enclosingNames;
- }
- return NO_SEGMENTS;
- }
-
- public String getFullyQualifiedName() {
- if (fSegments.length > 0) {
- StringBuffer buf = new StringBuffer(fSegments.length * INITIAL_SEGMENT_LENGTH);
- for (int i = 0; i < fSegments.length; ++i) {
- if (i > 0) {
- buf.append(QUALIFIER);
- }
- buf.append(fSegments[i]);
- }
- return buf.toString();
- }
- return EMPTY_STRING;
- }
-
- public IQualifiedTypeName getEnclosingTypeName() {
- String[] enclosingNames = getEnclosingNames();
- if (enclosingNames.length > 0) {
- QualifiedTypeName enclosingTypeName = new QualifiedTypeName();
- enclosingTypeName.fSegments = enclosingNames;
- return enclosingTypeName;
- }
- return null;
- }
-
- public boolean isQualified() {
- return (fSegments.length > 1);
- }
-
- public boolean isEmpty() {
- return (fSegments.length == 0);
- }
-
- public boolean isGlobal() {
- return (fSegments.length <= 1 || fSegments[0].length() == 0);
- }
-
- public int segmentCount() {
- return fSegments.length;
- }
-
- public String[] segments() {
- String[] segmentCopy = new String[fSegments.length];
- System.arraycopy(fSegments, 0, segmentCopy, 0, fSegments.length);
- return segmentCopy;
- }
-
- public String segment(int index) {
- if (index >= fSegments.length) {
- return null;
- }
- return fSegments[index];
- }
-
- public String lastSegment() {
- if (fSegments.length > 0) {
- return fSegments[fSegments.length - 1];
- }
- return null;
- }
-
- public int matchingFirstSegments(IQualifiedTypeName typeName) {
- int max = Math.min(fSegments.length, typeName.segmentCount());
- int count = 0;
- for (int i = 0; i < max; ++i) {
- if (!fSegments[i].equals(typeName.segment(i))) {
- return count;
- }
- ++count;
- }
- return count;
- }
-
- public boolean isPrefixOf(IQualifiedTypeName typeName) {
- if (fSegments.length == 0)
- return true;
-
- if (fSegments.length > typeName.segmentCount()) {
- return false;
- }
-
- for (int i = 0; i < fSegments.length; ++i) {
- if (!fSegments[i].equals(typeName.segment(i))) {
- return false;
- }
- }
- return true;
- }
-
- public IQualifiedTypeName append(String[] names) {
- int length = fSegments.length;
- int typeNameLength = names.length;
- String[] newSegments = new String[length + typeNameLength];
- System.arraycopy(fSegments, 0, newSegments, 0, length);
- System.arraycopy(names, 0, newSegments, length, typeNameLength);
- QualifiedTypeName newTypeName = new QualifiedTypeName();
- newTypeName.fSegments = newSegments;
- return newTypeName;
- }
-
- public IQualifiedTypeName append(IQualifiedTypeName typeName) {
- int length = fSegments.length;
- int typeNameLength = typeName.segmentCount();
- String[] newSegments = new String[length + typeNameLength];
- System.arraycopy(fSegments, 0, newSegments, 0, length);
- for (int i = 0; i < typeNameLength; ++i) {
- newSegments[i + length] = typeName.segment(i);
- }
- QualifiedTypeName newTypeName = new QualifiedTypeName();
- newTypeName.fSegments = newSegments;
- return newTypeName;
- }
-
- public IQualifiedTypeName append(String qualifiedName) {
- return append(createSegments(qualifiedName));
- }
-
- public IQualifiedTypeName removeFirstSegments(int count) {
- if (count == 0) {
- return this;
- } else if (count >= fSegments.length || count < 0) {
- return EMPTY;
- } else {
- int newSize = fSegments.length - count;
- String[] newSegments = new String[newSize];
- System.arraycopy(fSegments, count, newSegments, 0, newSize);
- QualifiedTypeName newTypeName = new QualifiedTypeName();
- newTypeName.fSegments = newSegments;
- return newTypeName;
- }
- }
-
- public IQualifiedTypeName removeLastSegments(int count) {
- if (count == 0) {
- return this;
- } else if (count >= fSegments.length || count < 0) {
- return EMPTY;
- } else {
- int newSize = fSegments.length - count;
- String[] newSegments = new String[newSize];
- System.arraycopy(fSegments, 0, newSegments, 0, newSize);
- QualifiedTypeName newTypeName = new QualifiedTypeName();
- newTypeName.fSegments = newSegments;
- return newTypeName;
- }
- }
-
- public boolean isLowLevel() {
- for (int i = 0; i < fSegments.length; ++i) {
- if (fSegments[i].startsWith("_")) { //$NON-NLS-1$
- return true;
- }
- }
- return false;
- }
-
- public boolean isValid() {
- for (int i = 0; i < fSegments.length; ++i) {
- String segment = fSegments[i];
- // type name must follow C conventions
- IStatus val = CConventions.validateIdentifier(segment);
- if (val.getSeverity() == IStatus.ERROR)
- return false;
- }
- return true;
- }
-
- public boolean isValidSegment(String segment) {
- if (segment.indexOf(QUALIFIER) != -1)
- return false;
- // type name must follow C conventions
- IStatus val = CConventions.validateIdentifier(segment);
- return (val.getSeverity() != IStatus.ERROR);
- }
-
- public int hashCode() {
- if (fHashCode == 0) {
- fHashCode = HASH_INIT;
- for (int i = 0; i < fSegments.length; ++i) {
- fHashCode = fHashCode * HASH_MULTIPLIER + fSegments[i].hashCode();
- }
- }
- return fHashCode;
- }
-
- public String toString() {
- return getFullyQualifiedName();
- }
-
- public int compareTo(Object obj) {
- if (obj == this) {
- return 0;
- }
- if (!(obj instanceof IQualifiedTypeName)) {
- throw new ClassCastException();
- }
- return compareTo((IQualifiedTypeName)obj);
- }
-
- public int compareTo(IQualifiedTypeName typeName) {
- if (typeName == this)
- return 0;
- if (typeName == null)
- return 1;
-
- int length = fSegments.length;
- int typeNameLength = typeName.segmentCount();
- int len = Math.min(length, typeNameLength);
- int result = 0;
- for (int i = 0; result == 0 && i < len; ++i) {
- result = fSegments[i].compareTo(typeName.segment(i));
- }
- if (result == 0 && length != typeNameLength) {
- result = (length < typeNameLength) ? -1 : 1;
- }
- return result;
- }
-
- public int compareToIgnoreCase(IQualifiedTypeName typeName) {
- if (typeName == this)
- return 0;
- if (typeName == null)
- return 1;
-
- int length = fSegments.length;
- int typeNameLength = typeName.segmentCount();
- int len = Math.min(length, typeNameLength);
- int result = 0;
- for (int i = 0; result == 0 && i < len; ++i) {
- result = fSegments[i].compareToIgnoreCase(typeName.segment(i));
- }
- if (result == 0 && length != typeNameLength) {
- result = (length < typeNameLength) ? -1 : 1;
- }
- return result;
- }
-
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof IQualifiedTypeName)) {
- return false;
- }
- return equals((IQualifiedTypeName)obj);
- }
-
- public boolean equals(IQualifiedTypeName typeName) {
- if (typeName == this)
- return true;
- if (typeName == null)
- return false;
-
- int length = fSegments.length;
- int typeNameLength = typeName.segmentCount();
- if (length != typeNameLength)
- return false;
- for (int i = 0; i < length; ++i) {
- if (!fSegments[i].equals(typeName.segment(i)))
- return false;
- }
- return true;
- }
-
- public boolean equalsIgnoreCase(IQualifiedTypeName typeName) {
- if (typeName == this)
- return true;
- if (typeName == null)
- return false;
-
- int length = fSegments.length;
- int typeNameLength = typeName.segmentCount();
- if (length != typeNameLength)
- return false;
- for (int i = 0; i < length; ++i) {
- if (!fSegments[i].equalsIgnoreCase(typeName.segment(i)))
- return false;
- }
- return true;
- }
-}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/Signature.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/Signature.java
deleted file mode 100644
index 7cfe88ed243..00000000000
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/Signature.java
+++ /dev/null
@@ -1,1991 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * IBM Corporation - added J2SE 1.5 support
- *******************************************************************************/
-package org.eclipse.cdt.core.model.util;
-
-import org.eclipse.cdt.internal.core.CharOperation;
-
-//TODO move this class to CoreModel?
-
-/**
- * Provides methods for encoding and decoding type and method signature strings.
- *
- * Signatures obtained from parsing source (".java") files 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.
- * 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[] - * | ResolvedClassTypeSignature - * | UnresolvedClassTypeSignature - * - * ResolvedClassTypeSignature ::= // resolved named type (in compiled code) - * "L" + Identifier + OptionalTypeArguments - * ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";" - * - * UnresolvedClassTypeSignature ::= // unresolved named type (in source code) - * "Q" + Identifier + OptionalTypeArguments - * ( ( "." | "/" ) + Identifier + OptionalTypeArguments )* + ";" - * - * OptionalTypeArguments ::= - * "<" + TypeArgument+ + ">" - * | - * - * TypeArgument ::= - * | TypeSignature - * | "*" // wildcard ? - * | "+" TypeSignature // wildcard ? extends X - * | "-" TypeSignature // wildcard ? super X - *- * - *
- * 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- * The syntax for a method signature is: - *
- * MethodSignature ::= "(" + 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; it is not intended to be - * instantiated or subclassed by clients. - *
- */ -public final class Signature { - - /** - * Character constant indicating the primitive type boolean in a signature. - * Value is'Z'
.
- */
- public static final char C_BOOLEAN = 'Z';
-
- /**
- * Character constant indicating the primitive type byte in a signature.
- * Value is 'B'
.
- */
- public static final char C_BYTE = 'B';
-
- /**
- * Character constant indicating the primitive type char in a signature.
- * Value is 'C'
.
- */
- public static final char C_CHAR = 'C';
-
- /**
- * Character constant indicating the primitive type double in a signature.
- * Value is 'D'
.
- */
- public static final char C_DOUBLE = 'D';
-
- /**
- * Character constant indicating the primitive type float in a signature.
- * Value is 'F'
.
- */
- public static final char C_FLOAT = 'F';
-
- /**
- * Character constant indicating the primitive type int in a signature.
- * Value is 'I'
.
- */
- public static final char C_INT = 'I';
-
- /**
- * Character constant indicating the semicolon in a signature.
- * Value is ';'
.
- */
- public static final char C_SEMICOLON = ';';
-
- /**
- * Character constant indicating the colon in a signature.
- * Value is ':'
.
- * @since 3.0
- */
- public static final char C_COLON = ':';
-
- /**
- * Character constant indicating the primitive type long in a signature.
- * Value is 'J'
.
- */
- public static final char C_LONG = 'J';
-
- /**
- * Character constant indicating the primitive type short in a signature.
- * Value is 'S'
.
- */
- public static final char C_SHORT = 'S';
-
- /**
- * Character constant indicating result type void in a signature.
- * Value is 'V'
.
- */
- public static final char C_VOID = 'V';
-
- /**
- * Character constant indicating result const in a signature.
- * Value is 'K'
.
- */
- public static final char C_CONST = 'K';
-
- /**
- * Character constant indicating the start of a resolved type variable in a
- * signature. Value is 'T'
.
- * @since 3.0
- */
- public static final char C_TYPE_VARIABLE = 'T';
-
- /**
- * Character constant indicating a wildcard type argument
- * in a signature.
- * Value is '*'
.
- * @since 3.0
- */
- public static final char C_STAR = '*';
-
- /**
- * Character constant indicating the dot in a signature.
- * Value is '.'
.
- */
- public static final char C_DOT = '.';
-
- /**
- * Character constant indicating the dollar in a signature.
- * Value is '$'
.
- */
- public static final char C_DOLLAR = '$';
-
- /**
- * Character constant indicating an array type in a signature.
- * Value is '['
.
- */
- public static final char C_ARRAY = '[';
-
- /**
- * Character constant indicating the start of a resolved, named type in a
- * signature. Value is 'L'
.
- */
- public static final char C_RESOLVED = 'L';
-
- /**
- * Character constant indicating the start of an unresolved, named type in a
- * signature. Value is 'Q'
.
- */
- public static final char C_UNRESOLVED = 'Q';
-
- /**
- * Character constant indicating the end of a named type in a signature.
- * Value is ';'
.
- */
- public static final char C_NAME_END = ';';
-
- /**
- * Character constant indicating the start of a parameter type list in a
- * signature. Value is '('
.
- */
- public static final char C_PARAM_START = '(';
-
- /**
- * Character constant indicating the end of a parameter type list in a
- * signature. Value is ')'
.
- */
- public static final char C_PARAM_END = ')';
-
- /**
- * Character constant indicating the start of a formal type parameter
- * (or type argument) list in a signature. Value is '<'
.
- * @since 3.0
- */
- public static final char C_GENERIC_START = '<';
-
- /**
- * Character constant indicating the end of a generic type list in a
- * signature. Value is '%gt;'
.
- * @since 3.0
- */
- public static final char C_GENERIC_END = '>';
-
- /**
- * String constant for the signature of the primitive type boolean.
- * Value is "Z"
.
- */
- public static final String SIG_BOOLEAN = "Z"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type byte.
- * Value is "B"
.
- */
- public static final String SIG_BYTE = "B"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type char.
- * Value is "C"
.
- */
- public static final String SIG_CHAR = "C"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type double.
- * Value is "D"
.
- */
- public static final String SIG_DOUBLE = "D"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type float.
- * Value is "F"
.
- */
- public static final String SIG_FLOAT = "F"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type int.
- * Value is "I"
.
- */
- public static final String SIG_INT = "I"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type long.
- * Value is "J"
.
- */
- public static final String SIG_LONG = "J"; //$NON-NLS-1$
-
- /**
- * String constant for the signature of the primitive type short.
- * Value is "S"
.
- */
- public static final String SIG_SHORT = "S"; //$NON-NLS-1$
-
- /** String constant for the signature of result type void.
- * Value is "V"
.
- */
- public static final String SIG_VOID = "V"; //$NON-NLS-1$
-
-
- /**
- * Kind constant for a class type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int CLASS_TYPE_SIGNATURE = 1;
-
- /**
- * Kind constant for a base (primitive or void) type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int BASE_TYPE_SIGNATURE = 2;
-
- /**
- * Kind constant for a type variable signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int TYPE_VARIABLE_SIGNATURE = 3;
-
- /**
- * Kind constant for an array type signature.
- * @see #getTypeSignatureKind(String)
- * @since 3.0
- */
- public static int ARRAY_TYPE_SIGNATURE = 4;
-
- private static final char[] BOOLEAN = {'b', 'o', 'o', 'l', 'e', 'a', 'n'};
- private static final char[] BYTE = {'b', 'y', 't', 'e'};
- private static final char[] CHAR = {'c', 'h', 'a', 'r'};
- private static final char[] DOUBLE = {'d', 'o', 'u', 'b', 'l', 'e'};
- private static final char[] FLOAT = {'f', 'l', 'o', 'a', 't'};
- private static final char[] INT = {'i', 'n', 't'};
- private static final char[] LONG = {'l', 'o', 'n', 'g'};
- private static final char[] SHORT = {'s', 'h', 'o', 'r', 't'};
- private static final char[] VOID = {'v', 'o', 'i', 'd'};
- private static final char[] CONST = {'c', 'o', 'n', 's', 't'};
-
- private static final String EMPTY = new String(CharOperation.NO_CHAR);
-
-private Signature() {
- // Not instantiable
-}
-
-private static boolean checkPrimitiveType(char[] primitiveTypeName, char[] typeName) {
- return CharOperation.fragmentEquals(primitiveTypeName, typeName, 0, true) &&
- (typeName.length == primitiveTypeName.length
- || Character.isWhitespace(typeName[primitiveTypeName.length])
- || typeName[primitiveTypeName.length] == C_ARRAY
- || typeName[primitiveTypeName.length] == C_DOT);
-}
-
-/**
- * Creates a new type signature with the given amount of array nesting added
- * to the given type signature.
- *
- * @param typeSignature the type signature
- * @param arrayCount the desired number of levels of array nesting
- * @return the encoded array type signature
- *
- * @since 2.0
- */
-public static char[] createArraySignature(char[] typeSignature, int arrayCount) {
- if (arrayCount == 0) return typeSignature;
- int sigLength = typeSignature.length;
- char[] result = new char[arrayCount + sigLength];
- for (int i = 0; i < arrayCount; i++) {
- result[i] = C_ARRAY;
- }
- System.arraycopy(typeSignature, 0, result, arrayCount, sigLength);
- return result;
-}
-/**
- * Creates a new type signature with the given amount of array nesting added
- * to the given type signature.
- *
- * @param typeSignature the type signature
- * @param arrayCount the desired number of levels of array nesting
- * @return the encoded array type signature
- */
-public static String createArraySignature(String typeSignature, int arrayCount) {
- return new String(createArraySignature(typeSignature.toCharArray(), arrayCount));
-}
-
-/**
- * Creates a method signature from the given parameter and return type
- * signatures. The encoded method signature is dot-based.
- *
- * @param parameterTypes the list of parameter type signatures
- * @param returnType the return type signature
- * @return the encoded method signature
- *
- * @since 2.0
- */
-public static char[] createMethodSignature(char[][] parameterTypes, char[] returnType) {
- int parameterTypesLength = parameterTypes.length;
- int parameterLength = 0;
- for (int i = 0; i < parameterTypesLength; i++) {
- parameterLength += parameterTypes[i].length;
-
- }
- int returnTypeLength = returnType.length;
- char[] result = new char[1 + parameterLength + 1 + returnTypeLength];
- result[0] = C_PARAM_START;
- int index = 1;
- for (int i = 0; i < parameterTypesLength; i++) {
- char[] parameterType = parameterTypes[i];
- int length = parameterType.length;
- System.arraycopy(parameterType, 0, result, index, length);
- index += length;
- }
- result[index] = C_PARAM_END;
- System.arraycopy(returnType, 0, result, index+1, returnTypeLength);
- return result;
-}
-
-/**
- * Creates a method signature from the given parameter and return type
- * signatures. The encoded method signature is dot-based. This method
- * is equivalent to
- * createMethodSignature(parameterTypes, returnType)
.
- *
- * @param parameterTypes the list of parameter type signatures
- * @param returnType the return type signature
- * @return the encoded method signature
- * @see Signature#createMethodSignature(char[][], char[])
- */
-public static String createMethodSignature(String[] parameterTypes, String returnType) {
- int parameterTypesLenth = parameterTypes.length;
- char[][] parameters = new char[parameterTypesLenth][];
- for (int i = 0; i < parameterTypesLenth; i++) {
- parameters[i] = parameterTypes[i].toCharArray();
- }
- return new String(createMethodSignature(parameters, returnType.toCharArray()));
-}
-
-/**
- * Creates a new type signature from the given type name encoded as a character
- * array. The type name may contain primitive types or array types. However,
- * parameterized types are not supported.
- * This method is equivalent to
- * 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.
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- * @see #createTypeSignature(java.lang.String,boolean)
- */
-public static String createTypeSignature(char[] typeName, boolean isResolved) {
- return new String(createCharArrayTypeSignature(typeName, isResolved));
-}
-/**
- * Creates a new type signature from the given type name encoded as a character
- * array. The type name may contain primitive types or array types. However,
- * parameterized types are not supported.
- * This method is equivalent to
- * 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.
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- * @see #createTypeSignature(java.lang.String,boolean)
- *
- * @since 2.0
- */
-public static char[] createCharArrayTypeSignature(char[] typeName, boolean isResolved) {
- if (typeName == null) throw new IllegalArgumentException("null"); //$NON-NLS-1$
- int length = typeName.length;
- if (length == 0) throw new IllegalArgumentException(new String(typeName));
-
- int arrayCount = CharOperation.occurencesOf('[', typeName);
- char[] sig;
-
- switch (typeName[0]) {
- // primitive type?
- case 'b' :
- if (checkPrimitiveType(BOOLEAN, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_BOOLEAN;
- break;
- } else if (checkPrimitiveType(BYTE, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_BYTE;
- break;
- }
- case 'c':
- if (checkPrimitiveType(CHAR, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_CHAR;
- break;
- }
- case 'd':
- if (checkPrimitiveType(DOUBLE, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_DOUBLE;
- break;
- }
- case 'f':
- if (checkPrimitiveType(FLOAT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_FLOAT;
- break;
- }
- case 'i':
- if (checkPrimitiveType(INT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_INT;
- break;
- }
- case 'l':
- if (checkPrimitiveType(LONG, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_LONG;
- break;
- }
- case 's':
- if (checkPrimitiveType(SHORT, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_SHORT;
- break;
- }
- case 'v':
- if (checkPrimitiveType(VOID, typeName)) {
- sig = new char[arrayCount+1];
- sig[arrayCount] = C_VOID;
- break;
- }
- default:
- // non primitive type
- int sigLength = arrayCount + 1 + length + 1; // for example '[[[Ljava.lang.String;'
- sig = new char[sigLength];
- int sigIndex = arrayCount+1; // index in sig
- int startID = 0; // start of current ID in typeName
- int index = 0; // index in typeName
- while (index < length) {
- char currentChar = typeName[index];
- switch (currentChar) {
- case '.':
- if (startID == -1) throw new IllegalArgumentException(new String(typeName));
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- sig[sigIndex++] = C_DOT;
- index++;
- startID = index;
- break;
- case '[':
- if (startID != -1) {
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- startID = -1; // no more id after []
- }
- index++;
- break;
- default :
- if (startID != -1 && CharOperation.isWhitespace(currentChar)) {
- if (startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
- startID = index+1;
- }
- index++;
- break;
- }
- }
- // last id
- if (startID != -1 && startID < index) {
- sig = CharOperation.append(sig, sigIndex, typeName, startID, index);
- sigIndex += index-startID;
- }
-
- // add L (or Q) at the beigininig and ; at the end
- sig[arrayCount] = isResolved ? C_RESOLVED : C_UNRESOLVED;
- sig[sigIndex++] = C_NAME_END;
-
- // resize if needed
- if (sigLength > sigIndex) {
- System.arraycopy(sig, 0, sig = new char[sigIndex], 0, sigIndex);
- }
- }
-
- // add array info
- for (int i = 0; i < arrayCount; i++) {
- sig[i] = C_ARRAY;
- }
-
- return sig;
-}
-/**
- * Creates a new type signature from the given type name. If the type name is qualified,
- * then it is expected to be dot-based. The type name may contain primitive
- * types or array types. However, parameterized types are not supported.
- * - * 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"
- *
- *
- *
- *
- * @param typeName the possibly qualified type name
- * @param isResolved 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)
- * @return the encoded type signature
- */
-public static String createTypeSignature(String typeName, boolean isResolved) {
- return createTypeSignature(typeName == null ? null : typeName.toCharArray(), isResolved);
-}
-
-/**
- * Returns the array count (array nesting depth) of the given type signature.
- *
- * @param typeSignature the type signature
- * @return the array nesting depth, or 0 if not an array
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- *
- * @since 2.0
- */
-public static int getArrayCount(char[] typeSignature) throws IllegalArgumentException {
- try {
- int count = 0;
- while (typeSignature[count] == C_ARRAY) {
- ++count;
- }
- return count;
- } catch (ArrayIndexOutOfBoundsException e) { // signature is syntactically incorrect if last character is C_ARRAY
- throw new IllegalArgumentException();
- }
-}
-/**
- * Returns the array count (array nesting depth) of the given type signature.
- *
- * @param typeSignature the type signature
- * @return the array nesting depth, or 0 if not an array
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- */
-public static int getArrayCount(String typeSignature) throws IllegalArgumentException {
- return getArrayCount(typeSignature.toCharArray());
-}
-/**
- * Returns the type signature without any array nesting.
- * - * For example: - *
- *
- * getElementType({'[', '[', 'I'}) --> {'I'}.
- *
- *
- *
- *
- * @param typeSignature the type signature
- * @return the type signature without arrays
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- *
- * @since 2.0
- */
-public static char[] getElementType(char[] typeSignature) throws IllegalArgumentException {
- int count = getArrayCount(typeSignature);
- if (count == 0) return typeSignature;
- int length = typeSignature.length;
- char[] result = new char[length-count];
- System.arraycopy(typeSignature, count, result, 0, length-count);
- return result;
-}
-/**
- * Returns the type signature without any array nesting.
- * - * For example: - *
- *
- * getElementType("[[I") --> "I".
- *
- *
- *
- *
- * @param typeSignature the type signature
- * @return the type signature without arrays
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- */
-public static String getElementType(String typeSignature) throws IllegalArgumentException {
- return new String(getElementType(typeSignature.toCharArray()));
-}
-/**
- * Returns the number of parameter types in the given method signature.
- *
- * @param methodSignature the method signature
- * @return the number of parameters
- * @exception IllegalArgumentException if the signature is not syntactically
- * correct
- * @since 2.0
- */
-public static int getParameterCount(char[] methodSignature) throws IllegalArgumentException {
- try {
- int count = 0;
- int i = CharOperation.indexOf(C_PARAM_START, methodSignature);
- if (i < 0) {
- throw new IllegalArgumentException();
- }
- i++;
- for (;;) {
- if (methodSignature[i] == C_PARAM_END) {
- return count;
- }
- int e= scanTypeSignature(methodSignature, i);
- if (e < 0) {
- throw new IllegalArgumentException();
- }
- i = e + 1;
- count++;
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Returns the kind of type signature encoded by the given string.
- *
- * @param typeSignature the type signature string
- * @return the kind of type signature; one of the kind constants:
- * {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
- * {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE}
- * @exception IllegalArgumentException if this is not a type signature
- * @since 3.0
- */
-public static int getTypeSignatureKind(char[] typeSignature) {
- // need a minimum 1 char
- if (typeSignature.length < 1) {
- throw new IllegalArgumentException();
- }
- char c = typeSignature[0];
- switch (c) {
- case C_ARRAY :
- return ARRAY_TYPE_SIGNATURE;
- case C_RESOLVED :
- case C_UNRESOLVED :
- return CLASS_TYPE_SIGNATURE;
- case C_TYPE_VARIABLE :
- return TYPE_VARIABLE_SIGNATURE;
- case C_BOOLEAN :
- case C_BYTE :
- case C_CHAR :
- case C_DOUBLE :
- case C_FLOAT :
- case C_INT :
- case C_LONG :
- case C_SHORT :
- case C_VOID :
- return BASE_TYPE_SIGNATURE;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Returns the kind of type signature encoded by the given string.
- *
- * @param typeSignature the type signature string
- * @return the kind of type signature; one of the kind constants:
- * {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
- * {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE}
- * @exception IllegalArgumentException if this is not a type signature
- * @since 3.0
- */
-public static int getTypeSignatureKind(String typeSignature) {
- // need a minimum 1 char
- if (typeSignature.length() < 1) {
- throw new IllegalArgumentException();
- }
- char c = typeSignature.charAt(0);
- switch (c) {
- case C_ARRAY :
- return ARRAY_TYPE_SIGNATURE;
- case C_RESOLVED :
- case C_UNRESOLVED :
- return CLASS_TYPE_SIGNATURE;
- case C_TYPE_VARIABLE :
- return TYPE_VARIABLE_SIGNATURE;
- case C_BOOLEAN :
- case C_BYTE :
- case C_CHAR :
- case C_DOUBLE :
- case C_FLOAT :
- case C_INT :
- case C_LONG :
- case C_SHORT :
- case C_VOID :
- return BASE_TYPE_SIGNATURE;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Scans the given string for a type signature starting at the given index
- * and returns the index of the last character.
- * - * TypeSignature: - * | BaseTypeSignature - * | ArrayTypeSignature - * | ClassTypeSignature - * | TypeVariableSignature - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type signature - * @see #appendTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanTypeSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - switch (c) { - case C_ARRAY : - return scanArrayTypeSignature(string, start); - case C_RESOLVED : - case C_UNRESOLVED : - return scanClassTypeSignature(string, start); - case C_TYPE_VARIABLE : - return scanTypeVariableSignature(string, start); - case C_BOOLEAN : - case C_BYTE : - case C_CHAR : - case C_DOUBLE : - case C_FLOAT : - case C_INT : - case C_LONG : - case C_SHORT : - case C_VOID : - return scanBaseTypeSignature(string, start); - default : - throw new IllegalArgumentException(); - } -} - -/** - * Scans the given string for a base type signature starting at the given index - * and returns the index of the last character. - *
- * BaseTypeSignature: - * B | C | D | F | I - * | J | S | V | Z - *- * Note that although the base type "V" is only allowed in method return types, - * there is no syntactic ambiguity. This method will accept them anywhere - * without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a base type signature - */ -private static int scanBaseTypeSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if ("BCDFIJSVZ".indexOf(c) >= 0) { //$NON-NLS-1$ - return start; - } - throw new IllegalArgumentException(); -} - -/** - * Scans the given string for an array type signature starting at the given - * index and returns the index of the last character. - *
- * ArrayTypeSignature: - * [ TypeSignature - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not an array type signature - * @see #appendArrayTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanArrayTypeSignature(char[] string, int start) { - // need a minimum 2 char - if (start >= string.length - 1) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c != C_ARRAY) { - throw new IllegalArgumentException(); - } - return scanTypeSignature(string, start + 1); -} - -/** - * Scans the given string for a type variable signature starting at the given - * index and returns the index of the last character. - *
- * TypeVariableSignature: - * T Identifier ; - *- * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type variable signature - */ -private static int scanTypeVariableSignature(char[] string, int start) { - // need a minimum 3 chars "Tx;" - if (start >= string.length - 2) { - throw new IllegalArgumentException(); - } - // must start in "T" - char c = string[start]; - if (c != C_TYPE_VARIABLE) { - throw new IllegalArgumentException(); - } - int id = scanIdentifier(string, start + 1); - c = string[id + 1]; - if (c == C_SEMICOLON) { - return id + 1; - } - throw new IllegalArgumentException(); -} - -/** - * Scans the given string for an identifier starting at the given - * index and returns the index of the last character. - * Stop characters are: ";", ":", "<", ">", "/", ".". - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not an identifier - */ -private static int scanIdentifier(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - int p = start; - while (true) { - char c = string[p]; - if (c == '<' || c == '>' || c == ':' || c == ';' || c == '.' || c == '/') { - return p - 1; - } - p++; - if (p == string.length) { - return p - 1; - } - } -} - -/** - * Scans the given string for a class type signature starting at the given - * index and returns the index of the last character. - *
- * ClassTypeSignature: - * { L | Q } Identifier - * { { / | . Identifier [ < TypeArgumentSignature* > ] } - * ; - *- * Note that although all "/"-identifiers most come before "."-identifiers, - * there is no syntactic ambiguity. This method will accept them without - * complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a class type signature - * @see #appendClassTypeSignature(char[], int, boolean, StringBuffer) - */ -private static int scanClassTypeSignature(char[] string, int start) { - // need a minimum 3 chars "Lx;" - if (start >= string.length - 2) { - throw new IllegalArgumentException(); - } - // must start in "L" or "Q" - char c = string[start]; - if (c != C_RESOLVED && c != C_UNRESOLVED) { - return -1; - } - int p = start + 1; - while (true) { - if (p >= string.length) { - throw new IllegalArgumentException(); - } - c = string[p]; - if (c == C_SEMICOLON) { - // all done - return p; - } else if (c == C_GENERIC_START) { - int e = scanTypeArgumentSignatures(string, p); - p = e; - } else if (c == C_DOT || c == '/') { - int id = scanIdentifier(string, p + 1); - p = id; - } - p++; - } -} - -/** - * Scans the given string for a list of type argument signatures starting at - * the given index and returns the index of the last character. - *
- * TypeArgumentSignatures: - * < TypeArgumentSignature* > - *- * Note that although there is supposed to be at least one type argument, there - * is no syntactic ambiguity if there are none. This method will accept zero - * type argument signatures without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a list of type arguments - * signatures - * @see #appendTypeArgumentSignatures(char[], int, boolean, StringBuffer) - */ -private static int scanTypeArgumentSignatures(char[] string, int start) { - // need a minimum 2 char "<>" - if (start >= string.length - 1) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c != C_GENERIC_START) { - throw new IllegalArgumentException(); - } - int p = start + 1; - while (true) { - if (p >= string.length) { - throw new IllegalArgumentException(); - } - c = string[p]; - if (c == C_GENERIC_END) { - return p; - } - int e = scanTypeArgumentSignature(string, p); - p = e + 1; - } -} - -/** - * Scans the given string for a type argument signature starting at the given - * index and returns the index of the last character. - *
- * TypeArgumentSignature: - * * - * | + TypeSignature - * | - TypeSignature - * | TypeSignature - *- * Note that although base types are not allowed in type arguments, there is - * no syntactic ambiguity. This method will accept them without complaint. - * - * @param string the signature string - * @param start the 0-based character index of the first character - * @return the 0-based character index of the last character - * @exception IllegalArgumentException if this is not a type argument signature - * @see #appendTypeArgumentSignature(char[], int, boolean, StringBuffer) - */ -private static int scanTypeArgumentSignature(char[] string, int start) { - // need a minimum 1 char - if (start >= string.length) { - throw new IllegalArgumentException(); - } - char c = string[start]; - if (c == C_STAR) { - return start; - } - if (c == '+' || c == '-') { - return scanTypeSignature(string, start + 1); - } - return scanTypeSignature(string, start); -} - -/** - * Returns the number of parameter types in the given method signature. - * - * @param methodSignature the method signature - * @return the number of parameters - * @exception IllegalArgumentException if the signature is not syntactically - * correct - */ -public static int getParameterCount(String methodSignature) throws IllegalArgumentException { - return getParameterCount(methodSignature.toCharArray()); -} -/** - * Extracts the parameter type signatures from the given method signature. - * The method signature is expected to be dot-based. - * - * @param methodSignature the method signature - * @return the list of parameter type signatures - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * - * @since 2.0 - */ -public static char[][] getParameterTypes(char[] methodSignature) throws IllegalArgumentException { - try { - int count = getParameterCount(methodSignature); - char[][] result = new char[count][]; - if (count == 0) { - return result; - } - int i = CharOperation.indexOf(C_PARAM_START, methodSignature); - if (i < 0) { - throw new IllegalArgumentException(); - } - i++; - int t = 0; - for (;;) { - if (methodSignature[i] == C_PARAM_END) { - return result; - } - int e = scanTypeSignature(methodSignature, i); - if (e < 0) { - throw new IllegalArgumentException(); - } - result[t] = CharOperation.subarray(methodSignature, i, e + 1); - t++; - i = e + 1; - } - } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalArgumentException(); - } -} -/** - * Extracts the parameter type signatures from the given method signature. - * The method signature is expected to be dot-based. - * - * @param methodSignature the method signature - * @return the list of parameter type signatures - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - */ -public static String[] getParameterTypes(String methodSignature) throws IllegalArgumentException { - char[][] parameterTypes = getParameterTypes(methodSignature.toCharArray()); - int length = parameterTypes.length; - String[] result = new String[length]; - for (int i = 0; i < length; i++) { - result[i] = new String(parameterTypes[i]); - } - return result; -} - -/** - * Extracts the type variable name from the given formal type parameter - * signature. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the name of the type variable - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static String getTypeVariable(String formalTypeParameterSignature) throws IllegalArgumentException { - return new String(getTypeVariable(formalTypeParameterSignature.toCharArray())); -} - -/** - * Extracts the type variable name from the given formal type parameter - * signature. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the name of the type variable - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static char[] getTypeVariable(char[] formalTypeParameterSignature) throws IllegalArgumentException { - int p = CharOperation.indexOf(C_COLON, formalTypeParameterSignature); - if (p < 0) { - // no ":" means can't be a formal type parameter signature - throw new IllegalArgumentException(); - } - return CharOperation.subarray(formalTypeParameterSignature, 0, p); -} - -/** - * Extracts the class and interface bounds from the given formal type - * parameter signature. The class bound, if present, is listed before - * the interface bounds. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the (possibly empty) list of type signatures for the bounds - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static char[][] getTypeParameterBounds(char[] formalTypeParameterSignature) throws IllegalArgumentException { - int p1 = CharOperation.indexOf(C_COLON, formalTypeParameterSignature); - if (p1 < 0) { - // no ":" means can't be a formal type parameter signature - throw new IllegalArgumentException(); - } - if (p1 == formalTypeParameterSignature.length - 1) { - // no class or interface bounds - return CharOperation.NO_CHAR_CHAR; - } - int p2 = CharOperation.indexOf(C_COLON, formalTypeParameterSignature, p1 + 1); - char[] classBound; - if (p2 < 0) { - // no interface bounds - classBound = CharOperation.subarray(formalTypeParameterSignature, p1 + 1, formalTypeParameterSignature.length); - return new char[][] {classBound}; - } - if (p2 == p1 + 1) { - // no class bound, but 1 or more interface bounds - classBound = null; - } else { - classBound = CharOperation.subarray(formalTypeParameterSignature, p1 + 1, p2); - } - char[][] interfaceBounds = CharOperation.splitOn(C_COLON, formalTypeParameterSignature, p2 + 1, formalTypeParameterSignature.length); - if (classBound == null) { - return interfaceBounds; - } - int resultLength = interfaceBounds.length + 1; - char[][] result = new char[resultLength][]; - result[0] = classBound; - System.arraycopy(interfaceBounds, 0, result, 1, interfaceBounds.length); - return result; -} - -/** - * Extracts the class and interface bounds from the given formal type - * parameter signature. The class bound, if present, is listed before - * the interface bounds. The signature is expected to be dot-based. - * - * @param formalTypeParameterSignature the formal type parameter signature - * @return the (possibly empty) list of type signatures for the bounds - * @exception IllegalArgumentException if the signature is syntactically - * incorrect - * @since 3.0 - */ -public static String[] getTypeParameterBounds(String formalTypeParameterSignature) throws IllegalArgumentException { - char[][] bounds = getTypeParameterBounds(formalTypeParameterSignature.toCharArray()); - int length = bounds.length; - String[] result = new String[length]; - for (int i = 0; i < length; i++) { - result[i] = new String(bounds[i]); - } - return result; -} - -/** - * Returns a char array containing all but the last segment of the given - * dot-separated qualified name. Returns the empty char array if it is not qualified. - *
- * 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'}
- *
- *
- *
- *
- * @param name the name
- * @return the qualifier prefix, or the empty char array if the name contains no
- * dots
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[] getQualifier(char[] name) {
- int lastDot = CharOperation.lastIndexOf(C_DOT, name);
- if (lastDot == -1) {
- return CharOperation.NO_CHAR;
- }
- return CharOperation.subarray(name, 0, lastDot);
-}
-/**
- * Returns a string containing all but the last segment of the given
- * dot-separated qualified name. Returns the empty string if it is not qualified.
- * - * For example: - *
- *
- * getQualifier("java.lang.Object") -> "java.lang"
- * getQualifier("Outer.Inner") -> "Outer"
- *
- *
- *
- *
- * @param name the name
- * @return the qualifier prefix, or the empty string if the name contains no
- * dots
- * @exception NullPointerException if name is null
- */
-public static String getQualifier(String name) {
- int lastDot = name.lastIndexOf(C_DOT);
- if (lastDot == -1) {
- return EMPTY;
- }
- return name.substring(0, lastDot);
-}
-/**
- * Extracts the return type from the given method signature. The method signature is
- * expected to be dot-based.
- *
- * @param methodSignature the method signature
- * @return the type signature of the return type
- * @exception IllegalArgumentException if the signature is syntactically
- * incorrect
- *
- * @since 2.0
- */
-public static char[] getReturnType(char[] methodSignature) throws IllegalArgumentException {
- // skip type parameters
- int i = CharOperation.lastIndexOf(C_PARAM_END, methodSignature);
- if (i == -1) {
- throw new IllegalArgumentException();
- }
- // ignore any thrown exceptions
- int j = CharOperation.indexOf('^', methodSignature);
- int last = (j == -1 ? methodSignature.length : j);
- return CharOperation.subarray(methodSignature, i + 1, last);
-}
-/**
- * Extracts the return type from the given method signature. The method signature is
- * expected to be dot-based.
- *
- * @param methodSignature the method signature
- * @return the type signature of the return type
- * @exception IllegalArgumentException if the signature is syntactically
- * incorrect
- */
-public static String getReturnType(String methodSignature) throws IllegalArgumentException {
- return new String(getReturnType(methodSignature.toCharArray()));
-}
-/**
- * Returns the last segment of the given dot-separated qualified name.
- * Returns the given name if it is not qualified.
- * - * For example: - *
- *
- * getSimpleName({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'O', 'b', 'j', 'e', 'c', 't'}
- *
- *
- *
- *
- * @param name the name
- * @return the last segment of the qualified name
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[] getSimpleName(char[] name) {
- int lastDot = CharOperation.lastIndexOf(C_DOT, name);
- if (lastDot == -1) {
- return name;
- }
- return CharOperation.subarray(name, lastDot + 1, name.length);
-}
-/**
- * Returns the last segment of the given dot-separated qualified name.
- * Returns the given name if it is not qualified.
- * - * For example: - *
- *
- * getSimpleName("java.lang.Object") -> "Object"
- *
- *
- *
- *
- * @param name the name
- * @return the last segment of the qualified name
- * @exception NullPointerException if name is null
- */
-public static String getSimpleName(String name) {
- int lastDot = name.lastIndexOf(C_DOT);
- if (lastDot == -1) {
- return name;
- }
- return name.substring(lastDot + 1, name.length());
-}
-/**
- * Returns all segments of the given dot-separated qualified name.
- * Returns an array with only the given name if it is not qualified.
- * Returns an empty array if the name is empty.
- * - * 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("") -> {}
- *
- *
- *
- * @param name the name
- * @return the list of simple names, possibly empty
- * @exception NullPointerException if name is null
- * @since 2.0
- */
-public static char[][] getSimpleNames(char[] name) {
- if (name.length == 0) {
- return CharOperation.NO_CHAR_CHAR;
- }
- int dot = CharOperation.indexOf(C_DOT, name);
- if (dot == -1) {
- return new char[][] {name};
- }
- int n = 1;
- while ((dot = CharOperation.indexOf(C_DOT, name, dot + 1)) != -1) {
- ++n;
- }
- char[][] result = new char[n + 1][];
- int segStart = 0;
- for (int i = 0; i < n; ++i) {
- dot = CharOperation.indexOf(C_DOT, name, segStart);
- result[i] = CharOperation.subarray(name, segStart, dot);
- segStart = dot + 1;
- }
- result[n] = CharOperation.subarray(name, segStart, name.length);
- return result;
-}
-/**
- * Returns all segments of the given dot-separated qualified name.
- * Returns an array with only the given name if it is not qualified.
- * Returns an empty array if the name is empty.
- * - * For example: - *
- *
- * getSimpleNames("java.lang.Object") -> {"java", "lang", "Object"}
- * getSimpleNames("Object") -> {"Object"}
- * getSimpleNames("") -> {}
- *
- *
- *
- * @param name the name
- * @return the list of simple names, possibly empty
- * @exception NullPointerException if name is null
- */
-public static String[] getSimpleNames(String name) {
- char[][] simpleNames = getSimpleNames(name.toCharArray());
- int length = simpleNames.length;
- String[] result = new String[length];
- for (int i = 0; i < length; i++) {
- result[i] = new String(simpleNames[i]);
- }
- return result;
-}
-/**
- * Converts the given method signature to a readable form. The method signature is expected to
- * be dot-based.
- * - * For example: - *
- *
- * toString("([Ljava.lang.String;)V", "main", new String[] {"args"}, false, true) -> "void main(String[] args)"
- *
- *
- *
- *
- * @param methodSignature the method signature to convert
- * @param methodName the name of the method to insert in the result, or
- * null
if no method name is to be included
- * @param parameterNames 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 signature
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param includeReturnType true
if the return type is to be
- * included
- * @return the char array representation of the method signature
- *
- * @since 2.0
- */
-public static char[] toCharArray(char[] methodSignature, char[] methodName, char[][] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType) {
- int firstParen = CharOperation.indexOf(C_PARAM_START, methodSignature);
- if (firstParen == -1) {
- throw new IllegalArgumentException();
- }
-
- StringBuffer buffer = new StringBuffer(methodSignature.length + 10);
-
- // return type
- if (includeReturnType) {
- char[] rts = getReturnType(methodSignature);
- appendTypeSignature(rts, 0 , fullyQualifyTypeNames, buffer);
- buffer.append(' ');
- }
-
- // selector
- if (methodName != null) {
- buffer.append(methodName);
- }
-
- // parameters
- buffer.append('(');
- char[][] pts = getParameterTypes(methodSignature);
- for (int i = 0; i < pts.length; i++) {
- appendTypeSignature(pts[i], 0 , fullyQualifyTypeNames, buffer);
- if (parameterNames != null) {
- buffer.append(' ');
- buffer.append(parameterNames[i]);
- }
- if (i != pts.length - 1) {
- buffer.append(',');
- buffer.append(' ');
- }
- }
- buffer.append(')');
- char[] result = new char[buffer.length()];
- buffer.getChars(0, buffer.length(), result, 0);
- return result;
-}
-
-/**
- * Converts the given type signature to a readable string. The signature is expected to
- * be dot-based.
- *
- * - * 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'}
- *
- *
- *
- *
- * 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.
- *
true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a type signature
- * @see #scanTypeSignature(char[], int)
- */
-private static int appendTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 1 char
- if (start >= string.length) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- switch (c) {
- case C_ARRAY :
- return appendArrayTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- case C_RESOLVED :
- case C_UNRESOLVED :
- return appendClassTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- case C_TYPE_VARIABLE :
- int e = scanTypeVariableSignature(string, start);
- buffer.append(CharOperation.subarray(string, start + 1, e));
- return e;
- case C_BOOLEAN :
- buffer.append(BOOLEAN);
- return start;
- case C_BYTE :
- buffer.append(BYTE);
- return start;
- case C_CHAR :
- buffer.append(CHAR);
- return start;
- case C_DOUBLE :
- buffer.append(DOUBLE);
- return start;
- case C_FLOAT :
- buffer.append(FLOAT);
- return start;
- case C_INT :
- buffer.append(INT);
- return start;
- case C_LONG :
- buffer.append(LONG);
- return start;
- case C_SHORT :
- buffer.append(SHORT);
- return start;
- case C_VOID :
- buffer.append(VOID);
- return start;
- case C_CONST :
- buffer.append(CONST);
- return start;
- default :
- throw new IllegalArgumentException();
- }
-}
-
-/**
- * Scans the given string for an array type signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not an array type signature
- * @see #scanArrayTypeSignature(char[], int)
- */
-private static int appendArrayTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 2 char
- if (start >= string.length - 1) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- if (c != C_ARRAY) {
- throw new IllegalArgumentException();
- }
- int e = appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- buffer.append('[');
- buffer.append(']');
- return e;
-}
-
-/**
- * Scans the given string for a class type signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a class type signature
- * @see #scanClassTypeSignature(char[], int)
- */
-private static int appendClassTypeSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 3 chars "Lx;"
- if (start >= string.length - 2) {
- throw new IllegalArgumentException();
- }
- // must start in "L" or "Q"
- char c = string[start];
- if (c != C_RESOLVED && c != C_UNRESOLVED) {
- throw new IllegalArgumentException();
- }
- boolean resolved = (c == C_RESOLVED);
- boolean removePackageQualifiers = !fullyQualifyTypeNames;
- if (!resolved) {
- // keep everything in an unresolved name
- removePackageQualifiers = false;
- }
- int p = start + 1;
- int checkpoint = buffer.length();
- while (true) {
- if (p >= string.length) {
- throw new IllegalArgumentException();
- }
- c = string[p];
- switch(c) {
- case C_SEMICOLON :
- // all done
- return p;
- case C_GENERIC_START :
- int e = appendTypeArgumentSignatures(string, p, fullyQualifyTypeNames, buffer);
- // once we hit type arguments there are no more package prefixes
- removePackageQualifiers = false;
- p = e;
- break;
- case C_DOT :
- if (removePackageQualifiers) {
- // erase package prefix
- buffer.setLength(checkpoint);
- } else {
- buffer.append('.');
- }
- break;
- case '/' :
- if (removePackageQualifiers) {
- // erase package prefix
- buffer.setLength(checkpoint);
- } else {
- buffer.append('/');
- }
- break;
- case C_DOLLAR :
- if (resolved) {
- // once we hit "$" there are no more package prefixes
- removePackageQualifiers = false;
- /**
- * Convert '$' in resolved type signatures into '.'.
- * NOTE: This assumes that the type signature is an inner type
- * signature. This is true in most cases, but someone can define a
- * non-inner type name containing a '$'.
- */
- buffer.append('.');
- }
- break;
- default :
- buffer.append(c);
- }
- p++;
- }
-}
-
-/**
- * Scans the given string for a list of type arguments signature starting at the
- * given index and appends it to the given buffer, and returns the index of the
- * last character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a list of type argument
- * signatures
- * @see #scanTypeArgumentSignatures(char[], int)
- */
-private static int appendTypeArgumentSignatures(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 2 char "<>"
- if (start >= string.length - 1) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- if (c != C_GENERIC_START) {
- throw new IllegalArgumentException();
- }
- buffer.append('<');
- int p = start + 1;
- int count = 0;
- while (true) {
- if (p >= string.length) {
- throw new IllegalArgumentException();
- }
- c = string[p];
- if (c == C_GENERIC_END) {
- buffer.append('>');
- return p;
- }
- if (count != 0) {
- buffer.append(',');
- }
- int e = appendTypeArgumentSignature(string, p, fullyQualifyTypeNames, buffer);
- count++;
- p = e + 1;
- }
-}
-
-/**
- * Scans the given string for a type argument signature starting at the given
- * index and appends it to the given buffer, and returns the index of the last
- * character.
- *
- * @param string the signature string
- * @param start the 0-based character index of the first character
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param buffer the string buffer to append to
- * @return the 0-based character index of the last character
- * @exception IllegalArgumentException if this is not a type argument signature
- * @see #scanTypeArgumentSignature(char[], int)
- */
-private static int appendTypeArgumentSignature(char[] string, int start, boolean fullyQualifyTypeNames, StringBuffer buffer) {
- // need a minimum 1 char
- if (start >= string.length) {
- throw new IllegalArgumentException();
- }
- char c = string[start];
- switch(c) {
- case C_STAR :
- buffer.append('?');
- return start;
- case '+' :
- buffer.append("? extends "); //$NON-NLS-1$
- return appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- case '-' :
- buffer.append("? super "); //$NON-NLS-1$
- return appendTypeSignature(string, start + 1, fullyQualifyTypeNames, buffer);
- default :
- return appendTypeSignature(string, start, fullyQualifyTypeNames, buffer);
- }
-}
-
-/**
- * Converts the given array of qualified name segments to a qualified name.
- * - * 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({{}}) -> {}
- *
- *
- *
- *
- * @param segments the list of name segments, possibly empty
- * @return the dot-separated qualified name, or the empty string
- *
- * @since 2.0
- */
-public static char[] toQualifiedName(char[][] segments) {
- int length = segments.length;
- if (length == 0) return CharOperation.NO_CHAR;
- if (length == 1) return segments[0];
-
- int resultLength = 0;
- for (int i = 0; i < length; i++) {
- resultLength += segments[i].length+1;
- }
- resultLength--;
- char[] result = new char[resultLength];
- int index = 0;
- for (int i = 0; i < length; i++) {
- char[] segment = segments[i];
- int segmentLength = segment.length;
- System.arraycopy(segment, 0, result, index, segmentLength);
- index += segmentLength;
- if (i != length-1) {
- result[index++] = C_DOT;
- }
- }
- return result;
-}
-/**
- * Converts the given array of qualified name segments to a qualified name.
- * - * For example: - *
- *
- * toQualifiedName(new String[] {"java", "lang", "Object"}) -> "java.lang.Object"
- * toQualifiedName(new String[] {"Object"}) -> "Object"
- * toQualifiedName(new String[0]) -> ""
- *
- *
- *
- *
- * @param segments the list of name segments, possibly empty
- * @return the dot-separated qualified name, or the empty string
- */
-public static String toQualifiedName(String[] segments) {
- int length = segments.length;
- char[][] charArrays = new char[length][];
- for (int i = 0; i < length; i++) {
- charArrays[i] = segments[i].toCharArray();
- }
- return new String(toQualifiedName(charArrays));
-}
-/**
- * Converts the given type signature to a readable string. The signature is expected to
- * be dot-based.
- *
- * - * For example: - *
- *
- * toString("[Ljava.lang.String;") -> "java.lang.String[]"
- * toString("I") -> "int"
- *
- *
- *
- *
- * 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.
- *
null
if no method name is to be included
- * @param parameterNames 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 signature
- * @param fullyQualifyTypeNames true
if type names should be fully
- * qualified, and false
to use only simple names
- * @param includeReturnType true
if the return type is to be
- * included
- * @see #toCharArray(char[], char[], char[][], boolean, boolean)
- * @return the string representation of the method signature
- */
-public static String toString(String methodSignature, String methodName, String[] parameterNames, boolean fullyQualifyTypeNames, boolean includeReturnType) {
- char[][] params;
- if (parameterNames == null) {
- params = null;
- } else {
- int paramLength = parameterNames.length;
- params = new char[paramLength][];
- for (int i = 0; i < paramLength; i++) {
- params[i] = parameterNames[i].toCharArray();
- }
- }
- return new String(toCharArray(methodSignature.toCharArray(), methodName == null ? null : methodName.toCharArray(), params, fullyQualifyTypeNames, includeReturnType));
-}
-
-}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/TypeUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/TypeUtil.java
deleted file mode 100644
index f046dfd7222..00000000000
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/TypeUtil.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * QNX Software Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.core.model.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IMember;
-import org.eclipse.cdt.core.model.IMethodDeclaration;
-import org.eclipse.cdt.core.model.IParent;
-import org.eclipse.cdt.core.model.IStructure;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-
-public class TypeUtil {
-
- public static boolean isDeclaringType(ICElement elem) {
- int type = elem.getElementType();
- return (type == ICElement.C_CLASS
- || type == ICElement.C_STRUCT
- || type == ICElement.C_ENUMERATION
- || type == ICElement.C_UNION
- || type == ICElement.C_TYPEDEF
- || type == ICElement.C_NAMESPACE);
- }
-
- public static boolean isMemberType(ICElement elem) {
- int type = elem.getElementType();
- if (type == ICElement.C_CLASS
- || type == ICElement.C_STRUCT
- || type == ICElement.C_ENUMERATION
- || type == ICElement.C_UNION
- || type == ICElement.C_TYPEDEF
- || type == ICElement.C_NAMESPACE)
- return true;
- return elem instanceof IMember;
- }
-
- /**
- * Returns the type in which this member is declared, or null
- * if this member is not declared in a type (for example, a top-level type).
- * This is a handle-only method.
- *
- * @return the type in which this member is declared, or null
- * if this member is not declared in a type (for example, a top-level type)
- */
- public static ICElement getDeclaringType(ICElement elem) {
- if (!isMemberType(elem))
- return null;
- ICElement parent = elem.getParent();
- while (parent != null && !(parent instanceof ITranslationUnit)) {
- if (isDeclaringType(parent))
- return parent;
- parent = parent.getParent();
- }
- return null;
- }
-
- public static ICElement getDeclaringClass(ICElement type) {
- ICElement parentElement = type.getParent();
- if (parentElement != null && isClassOrStruct(parentElement)) {
- return parentElement;
- }
-
- if (isClassOrStruct(type)) {
- while (parentElement != null) {
- if (isClassOrStruct(parentElement)) {
- return parentElement;
- } else if (parentElement instanceof IMember) {
- parentElement = parentElement.getParent();
- } else {
- return null;
- }
- }
- }
-
- return null;
- }
-
- public static boolean isClassOrStruct(ICElement type) {
- int kind = type.getElementType();
- // case ICElement.C_TEMPLATE_CLASS:
- // case ICElement.C_TEMPLATE_STRUCT:
- return (kind == ICElement.C_CLASS || kind == ICElement.C_STRUCT);
- }
-
- public static boolean isClass(ICElement type) {
- return (type.getElementType() == ICElement.C_CLASS);
- }
-
- public static boolean isNamespace(ICElement type) {
- return (type.getElementType() == ICElement.C_NAMESPACE);
- }
-
- /**
- * Returns the top-level types declared in the given translation unit
- * in the order in which they appear in the source.
- *
- * @param tu the translation unit
- * @return the top-level types declared in the given translation unit
- * @throws CModelException if this element does not exist or if an
- * exception occurs while accessing its corresponding resource
- */
- public static ICElement[] getTypes(ITranslationUnit tu) throws CModelException {
- List typeList = new ArrayList();
- ICElement[] children = tu.getChildren();
- for (int i = 0; i < children.length; ++i) {
- if (isDeclaringType(children[i]))
- typeList.add(children[i]);
- }
- return (ICElement[])typeList.toArray(new ICElement[typeList.size()]);
- }
-
- /**
- * Returns all types declared in the given translation unit in the order
- * in which they appear in the source.
- * This includes all top-level types and nested member types.
- * It does NOT include local types (types defined in methods).
- *
- * @return the array of top-level and member types defined in the given translation unit, in declaration order.
- * @throws CModelException if this element does not exist or if an
- * exception occurs while accessing its corresponding resource
- */
- public static ICElement[] getAllTypes(ITranslationUnit tu) throws CModelException {
- ICElement[] types = getTypes(tu);
- ArrayList allTypes = new ArrayList(types.length);
- ArrayList typesToTraverse = new ArrayList(types.length);
- for (int i = 0; i < types.length; i++) {
- typesToTraverse.add(types[i]);
- }
- while (!typesToTraverse.isEmpty()) {
- ICElement type = (ICElement) typesToTraverse.get(0);
- typesToTraverse.remove(type);
- allTypes.add(type);
- types = getTypes(type);
- for (int i = 0; i < types.length; i++) {
- typesToTraverse.add(types[i]);
- }
- }
- return (ICElement[])allTypes.toArray(new ICElement[allTypes.size()]);
- }
-
-
- /**
- * Returns the immediate member types declared by the given element.
- * The results are listed in the order in which they appear in the source file.
- *
- * @param elem the element
- * @exception CModelException if this element does not exist or if an
- * exception occurs while accessing its corresponding resource.
- * @return the immediate member types declared by this type
- */
- public static ICElement[] getTypes(ICElement elem) throws CModelException {
- List typeList = new ArrayList();
- if (isDeclaringType(elem) && elem instanceof IParent) {
- ICElement[] children = ((IParent)elem).getChildren();
- for (int i = 0; i < children.length; ++i) {
- if (isDeclaringType(children[i]))
- typeList.add(children[i]);
- }
- }
- return (ICElement[])typeList.toArray(new ICElement[typeList.size()]);
- }
-
- public static ITranslationUnit getTranslationUnit(ICElement elem) {
- while (elem != null) {
- if (elem instanceof ITranslationUnit)
- return (ITranslationUnit)elem;
- elem = elem.getParent();
- }
- return null;
- }
-
-// TODO move method to CModelUtil
- public static IQualifiedTypeName getFullyQualifiedName(ICElement type) {
- String name = type.getElementName();
- IQualifiedTypeName qualifiedName = new QualifiedTypeName(name);
- ICElement parent = type.getParent();
- while (parent != null && (isNamespace(parent) || isClass(parent))) {
- qualifiedName = new QualifiedTypeName(parent.getElementName()).append(qualifiedName);
- parent = parent.getParent();
- }
- return qualifiedName;
- }
-
- public static IMethodDeclaration[] getMethods(ICElement elem) {
- if (elem instanceof IStructure) {
- try {
- List list = ((IParent)elem).getChildrenOfType(ICElement.C_METHOD_DECLARATION);
- if (list != null && !list.isEmpty()) {
- return (IMethodDeclaration[]) list.toArray(new IMethodDeclaration[list.size()]);
- }
- } catch (CModelException e) {
- }
- }
- return null;
- }
-
- public static ICElement[] getFields(ICElement elem) {
- if (elem instanceof IStructure) {
- try {
- List list = ((IParent)elem).getChildrenOfType(ICElement.C_FIELD);
- if (list != null && !list.isEmpty()) {
- return (ICElement[]) list.toArray(new ICElement[list.size()]);
- }
- } catch (CModelException e) {
- }
- }
- return null;
- }
-
-
- /**
- * Finds a method by name.
- * This searches for a method with a name and signature. Parameter types are only
- * compared by the simple name, no resolving for the fully qualified type name is done.
- * Constructors are only compared by parameters, not the name.
- * @param name The name of the method to find
- * @param paramTypes The type signatures of the parameters e.g. {"QString;","I"}
- * @param isConstructor If the method is a constructor
- * @param methods The methods to search in
- * @return The found method or null
, if nothing found
- */
-// TODO move methods to CModelUtil
- public static IMethodDeclaration findMethod(String name, String[] paramTypes, boolean isConstructor, boolean isDestructor, IMethodDeclaration[] methods) throws CModelException {
- for (int i= methods.length - 1; i >= 0; i--) {
- if (isSameMethodSignature(name, paramTypes, isConstructor, isDestructor, methods[i])) {
- return methods[i];
- }
- }
- return null;
- }
-
- /**
- * Tests if a method equals to the given signature.
- * Parameter types are only compared by the simple name, no resolving for
- * the fully qualified type name is done. Constructors are only compared by
- * parameters, not the name.
- * @param name Name of the method
- * @param paramTypes The type signatures of the parameters e.g. {"QString;","I"}
- * @param isConstructor Specifies if the method is a constructor
- * @return Returns true
if the method has the given name and parameter types and constructor state.
- */
-//TODO move methods to CModelUtil
- public static boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, boolean isDestructor, IMethodDeclaration curr) throws CModelException {
- if (isConstructor || isDestructor || name.equals(curr.getElementName())) {
- if ((isConstructor == curr.isConstructor()) && (isDestructor == curr.isDestructor())) {
- String[] currParamTypes= curr.getParameterTypes();
- if (paramTypes.length == currParamTypes.length) {
- for (int i= 0; i < paramTypes.length; i++) {
- String t1= Signature.getSimpleName(Signature.toString(paramTypes[i]));
- String t2= Signature.getSimpleName(Signature.toString(currParamTypes[i]));
- if (!t1.equals(t2)) {
- return false;
- }
- }
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Finds a method in a type.
- * This searches for a method with the same name and signature. Parameter types are only
- * compared by the simple name, no resolving for the fully qualified type name is done.
- * Constructors are only compared by parameters, not the name.
- * @param name The name of the method to find
- * @param paramTypes The type signatures of the parameters e.g. {"QString;","I"}
- * @param isConstructor If the method is a constructor
- * @return The first found method or null
, if nothing found
- */
-// TODO move methods to CModelUtil
- public static IMethodDeclaration findMethod(String name, String[] paramTypes, boolean isConstructor, boolean isDestructor, ICElement type) throws CModelException {
- return findMethod(name, paramTypes, isConstructor, isDestructor, getMethods(type));
- }
-
- /**
- * Finds a method declararion in a type's hierarchy. The search is top down, so this
- * returns the first declaration of the method in the hierarchy.
- * This searches for a method with a name and signature. Parameter types are only
- * compared by the simple name, no resolving for the fully qualified type name is done.
- * Constructors are only compared by parameters, not the name.
- * @param type Searches in this type's supertypes.
- * @param name The name of the method to find
- * @param paramTypes The type signatures of the parameters e.g. {"QString;","I"}
- * @param isConstructor If the method is a constructor
- * @return The first method found or null, if nothing found
- */
-// TODO move methods to CModelUtil
-// public static IMethodDeclaration findMethodDeclarationInHierarchy(ITypeHierarchy hierarchy, ICElement type, String name, String[] paramTypes, boolean isConstructor, boolean isDestructor) throws CModelException {
-// ICElement[] superTypes= hierarchy.getAllSupertypes(type);
-// for (int i= superTypes.length - 1; i >= 0; i--) {
-// IMethodDeclaration first= findMethod(name, paramTypes, isConstructor, isDestructor, superTypes[i]);
-// if (first != null && first.getVisibility() != ASTAccessVisibility.PRIVATE) {
-// // the order getAllSupertypes does make assumptions of the order of inner elements -> search recursivly
-// IMethodDeclaration res= findMethodDeclarationInHierarchy(hierarchy, TypeUtil.getDeclaringClass(first), name, paramTypes, isConstructor, isDestructor);
-// if (res != null) {
-// return res;
-// }
-// return first;
-// }
-// }
-// return null;
-// }
-
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleDocument.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleDocument.java
deleted file mode 100644
index 87c218b7bc9..00000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/SimpleDocument.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.ui.text;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.IDocumentPartitioningListener;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Position;
-
-/**
- * Minimal implementation of IDocument to apply text edit onto a string.
- */
-public class SimpleDocument implements IDocument {
-
- private StringBuffer buffer;
-
- public SimpleDocument(String source) {
- buffer = new StringBuffer(source);
- }
-
- public SimpleDocument(char[] source) {
- buffer = new StringBuffer(source.length);
- buffer.append(source);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getChar(int)
- */
- public char getChar(int offset) {
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLength()
- */
- public int getLength() {
- return this.buffer.length();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#get()
- */
- public String get() {
- return this.buffer.toString();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#get(int, int)
- */
- public String get(int offset, int length) {
- return this.buffer.substring(offset, offset + length);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#set(java.lang.String)
- */
- public void set(String text) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String)
- */
- public void replace(int offset, int length, String text) {
-
- this.buffer.replace(offset, offset + length, text);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addDocumentListener(org.eclipse.jface.text.IDocumentListener)
- */
- public void addDocumentListener(IDocumentListener listener) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removeDocumentListener(org.eclipse.jface.text.IDocumentListener)
- */
- public void removeDocumentListener(IDocumentListener listener) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addPrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
- */
- public void addPrenotifiedDocumentListener(IDocumentListener documentAdapter) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removePrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
- */
- public void removePrenotifiedDocumentListener(IDocumentListener documentAdapter) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String)
- */
- public void addPositionCategory(String category) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String)
- */
- public void removePositionCategory(String category) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getPositionCategories()
- */
- public String[] getPositionCategories() {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String)
- */
- public boolean containsPositionCategory(String category) {
- // defining interface method
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position)
- */
- public void addPosition(Position position) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removePosition(org.eclipse.jface.text.Position)
- */
- public void removePosition(Position position) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
- */
- public void addPosition(String category, Position position) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
- */
- public void removePosition(String category, Position position) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String)
- */
- public Position[] getPositions(String category) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#containsPosition(java.lang.String, int, int)
- */
- public boolean containsPosition(String category, int offset, int length) {
- // defining interface method
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#computeIndexInCategory(java.lang.String, int)
- */
- public int computeIndexInCategory(String category, int offset) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater)
- */
- public void addPositionUpdater(IPositionUpdater updater) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater)
- */
- public void removePositionUpdater(IPositionUpdater updater) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater, int)
- */
- public void insertPositionUpdater(IPositionUpdater updater, int index) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getPositionUpdaters()
- */
- public IPositionUpdater[] getPositionUpdaters() {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLegalContentTypes()
- */
- public String[] getLegalContentTypes() {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getContentType(int)
- */
- public String getContentType(int offset) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getPartition(int)
- */
- public ITypedRegion getPartition(int offset) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#computePartitioning(int, int)
- */
- public ITypedRegion[] computePartitioning(int offset, int length) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#addDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
- */
- public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#removeDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
- */
- public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#setDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)
- */
- public void setDocumentPartitioner(IDocumentPartitioner partitioner) {
- // defining interface method
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getDocumentPartitioner()
- */
- public IDocumentPartitioner getDocumentPartitioner() {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineLength(int)
- */
- public int getLineLength(int line) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineOfOffset(int)
- */
- public int getLineOfOffset(int offset) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineOffset(int)
- */
- public int getLineOffset(int line) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineInformation(int)
- */
- public IRegion getLineInformation(int line) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineInformationOfOffset(int)
- */
- public IRegion getLineInformationOfOffset(int offset) {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getNumberOfLines()
- */
- public int getNumberOfLines() {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getNumberOfLines(int, int)
- */
- public int getNumberOfLines(int offset, int length) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#computeNumberOfLines(java.lang.String)
- */
- public int computeNumberOfLines(String text) {
- // defining interface method
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters()
- */
- public String[] getLegalLineDelimiters() {
- // defining interface method
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int)
- */
- public String getLineDelimiter(int line) {
- // defining interface method
- return null;
- }
-
- /**
- * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String, boolean, boolean, boolean)
- * @deprecated
- */
- public int search(
- int startOffset,
- String findString,
- boolean forwardSearch,
- boolean caseSensitive,
- boolean wholeWord) {
- // defining interface method
- return 0;
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java
index ccfc5ade328..ce0eca18a2a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 QNX Software Systems and others.
+ * Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -76,7 +76,7 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme
protected Object fInput;
/** Remember what refreshes we already have pending so we don't post them again. */
- protected HashSet pendingRefreshes = new HashSet();
+ protected HashSet