/** * Returns the {@code Type} that represents the superclass of this {@code * class}. */ public Type getGenericSuperclass() { GenericSignatureParser parser = new GenericSignatureParser(getClassLoader()); parser.parseForClass(this, getSignatureAttribute()); return Types.getType(parser.superclassType); }
parseOptFormalTypeParameters(); expect('('); while (symbol != ')' && (symbol > 0)) { parameterTypes.add(parseTypeSignature()); expect(')'); returnType = parseReturnType(); scanSymbol(); exceptionTypes.add(parseTypeVariableSignature()); } else { exceptionTypes.add(parseClassTypeSignature());
void scanIdentifier() { if (!eof) { StringBuilder identBuf = new StringBuilder(32); if (!isStopSymbol(symbol)) { identBuf.append(symbol); do { char ch = buffer[pos]; if ((ch >= 'a') && (ch <= 'z') || (ch >= 'A') && (ch <= 'Z') || !isStopSymbol(ch)) { identBuf.append(ch); pos++; } else { identifier = identBuf.toString(); scanSymbol(); return;
Type parseTypeSignature() { switch (symbol) { case 'B': scanSymbol(); return byte.class; case 'C': scanSymbol(); return char.class; case 'D': scanSymbol(); return double.class; case 'F': scanSymbol(); return float.class; case 'I': scanSymbol(); return int.class; case 'J': scanSymbol(); return long.class; case 'S': scanSymbol(); return short.class; case 'Z': scanSymbol(); return boolean.class; default: // Not an elementary type, but a FieldTypeSignature. return parseFieldTypeSignature(); } }
/** * Parses the generic signature of a field and creates the data structure * representing the signature. * * @param genericDecl the GenericDeclaration calling this method * @param signature the generic signature of the class */ public void parseForField(GenericDeclaration genericDecl, String signature) { setInput(genericDecl, signature); if (!eof) { this.fieldType = parseFieldTypeSignature(); } }
TypeVariableImpl<GenericDeclaration> parseTypeVariableSignature() { // TypeVariableSignature ::= "T" Ident ";". expect('T'); scanIdentifier(); expect(';'); // Reference to type variable: // Note: we don't know the declaring GenericDeclaration yet. return new TypeVariableImpl<GenericDeclaration>(genericDecl, identifier); }
Type parseFieldTypeSignature() { // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature // | TypeVariableSignature. switch (symbol) { case 'L': return parseClassTypeSignature(); case '[': // ArrayTypeSignature ::= "[" TypSignature. scanSymbol(); return new GenericArrayTypeImpl(parseTypeSignature()); case 'T': return parseTypeVariableSignature(); default: throw new GenericSignatureFormatError(); } }
TypeVariableImpl<GenericDeclaration> parseFormalTypeParameter() { // FormalTypeParameter ::= Ident ClassBound {InterfaceBound}. scanIdentifier(); String name = identifier.intern(); // FIXME: is this o.k.? ListOfTypes bounds = new ListOfTypes(8); // ClassBound ::= ":" [FieldTypeSignature]. expect(':'); if (symbol == 'L' || symbol == '[' || symbol == 'T') { bounds.add(parseFieldTypeSignature()); } while (symbol == ':') { // InterfaceBound ::= ":" FieldTypeSignature. scanSymbol(); bounds.add(parseFieldTypeSignature()); } return new TypeVariableImpl<GenericDeclaration>(genericDecl, name, bounds); }
ListOfTypes parseOptTypeArguments() { // OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">". ListOfTypes typeArgs = new ListOfTypes(8); if (symbol == '<') { scanSymbol(); typeArgs.add(parseTypeArgument()); while ((symbol != '>') && (symbol > 0)) { typeArgs.add(parseTypeArgument()); } expect('>'); } return typeArgs; }
Type parseClassTypeSignature() { // ClassTypeSignature ::= "L" {Ident "/"} Ident // OptTypeArguments {"." Ident OptTypeArguments} ";". expect('L'); StringBuilder qualIdent = new StringBuilder(); scanIdentifier(); while (symbol == '/') { scanSymbol(); qualIdent.append(identifier).append("."); scanIdentifier(); } qualIdent.append(this.identifier); ListOfTypes typeArgs = parseOptTypeArguments(); ParameterizedTypeImpl parentType = new ParameterizedTypeImpl(null, qualIdent.toString(), typeArgs, loader); ParameterizedTypeImpl type = parentType; while (symbol == '.') { // Deal with Member Classes: scanSymbol(); scanIdentifier(); qualIdent.append("$").append(identifier); // FIXME: is "$" correct? typeArgs = parseOptTypeArguments(); type = new ParameterizedTypeImpl(parentType, qualIdent.toString(), typeArgs, loader); } expect(';'); return type; }
void parseClassSignature() { // ClassSignature ::= // OptFormalTypeParameters SuperclassSignature {SuperinterfaceSignature}. parseOptFormalTypeParameters(); // SuperclassSignature ::= ClassTypeSignature. this.superclassType = parseClassTypeSignature(); interfaceTypes = new ListOfTypes(16); while (symbol > 0) { // SuperinterfaceSignature ::= ClassTypeSignature. interfaceTypes.add(parseClassTypeSignature()); } }
private synchronized void initGenericType() { if (!genericTypesAreInitialized) { String signatureAttribute = getSignatureAttribute(); GenericSignatureParser parser = new GenericSignatureParser( getDeclaringClass().getClassLoader()); parser.parseForField(this.getDeclaringClass(), signatureAttribute); genericType = parser.fieldType; if (genericType == null) { genericType = getType(); } genericTypesAreInitialized = true; } }
@SuppressWarnings("unchecked") private synchronized void initGenericTypes() { if (!genericTypesAreInitialized) { String signatureAttribute = getSignatureAttribute(); GenericSignatureParser parser = new GenericSignatureParser( getDeclaringClass().getClassLoader()); parser.parseForConstructor(this, signatureAttribute, getExceptionTypes()); formalTypeParameters = parser.formalTypeParameters; genericParameterTypes = parser.parameterTypes; genericExceptionTypes = parser.exceptionTypes; genericTypesAreInitialized = true; } }
@SuppressWarnings("unchecked") private synchronized void initGenericTypes() { if (!genericTypesAreInitialized) { String signatureAttribute = getSignatureAttribute(); GenericSignatureParser parser = new GenericSignatureParser( getDeclaringClass().getClassLoader()); parser.parseForMethod(this, signatureAttribute, getExceptionTypes()); formalTypeParameters = parser.formalTypeParameters; genericParameterTypes = parser.parameterTypes; genericExceptionTypes = parser.exceptionTypes; genericReturnType = parser.returnType; genericTypesAreInitialized = true; } }
/** * Parses the generic signature of a class and creates the data structure * representing the signature. * * @param genericDecl the GenericDeclaration calling this method * @param signature the generic signature of the class */ public void parseForClass(GenericDeclaration genericDecl, String signature) { setInput(genericDecl, signature); if (!eof) { parseClassSignature(); } else { if(genericDecl instanceof Class) { Class c = (Class) genericDecl; this.formalTypeParameters = EmptyArray.TYPE_VARIABLE; this.superclassType = c.getSuperclass(); Class<?>[] interfaces = c.getInterfaces(); if (interfaces.length == 0) { this.interfaceTypes = ListOfTypes.EMPTY; } else { this.interfaceTypes = new ListOfTypes(interfaces); } } else { this.formalTypeParameters = EmptyArray.TYPE_VARIABLE; this.superclassType = Object.class; this.interfaceTypes = ListOfTypes.EMPTY; } } }
void parseOptFormalTypeParameters() { // OptFormalTypeParameters ::= // ["<" FormalTypeParameter {FormalTypeParameter} ">"]. ListOfVariables typeParams = new ListOfVariables(); if (symbol == '<') { scanSymbol(); typeParams.add(parseFormalTypeParameter()); while ((symbol != '>') && (symbol > 0)) { typeParams.add(parseFormalTypeParameter()); } expect('>'); } this.formalTypeParameters = typeParams.getArray(); }
Type parseFieldTypeSignature() { // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature // | TypeVariableSignature. switch (symbol) { case 'L': return parseClassTypeSignature(); case '[': // ArrayTypeSignature ::= "[" TypSignature. scanSymbol(); return new GenericArrayTypeImpl(parseTypeSignature()); case 'T': return parseTypeVariableSignature(); default: throw new GenericSignatureFormatError(); } }
TypeVariableImpl<GenericDeclaration> parseFormalTypeParameter() { // FormalTypeParameter ::= Ident ClassBound {InterfaceBound}. scanIdentifier(); String name = identifier.intern(); // FIXME: is this o.k.? ListOfTypes bounds = new ListOfTypes(8); // ClassBound ::= ":" [FieldTypeSignature]. expect(':'); if (symbol == 'L' || symbol == '[' || symbol == 'T') { bounds.add(parseFieldTypeSignature()); } while (symbol == ':') { // InterfaceBound ::= ":" FieldTypeSignature. scanSymbol(); bounds.add(parseFieldTypeSignature()); } return new TypeVariableImpl<GenericDeclaration>(genericDecl, name, bounds); }
ListOfTypes parseOptTypeArguments() { // OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">". ListOfTypes typeArgs = new ListOfTypes(8); if (symbol == '<') { scanSymbol(); typeArgs.add(parseTypeArgument()); while ((symbol != '>') && (symbol > 0)) { typeArgs.add(parseTypeArgument()); } expect('>'); } return typeArgs; }
TypeVariableImpl<GenericDeclaration> parseTypeVariableSignature() { // TypeVariableSignature ::= "T" Ident ";". expect('T'); scanIdentifier(); expect(';'); // Reference to type variable: // Note: we don't know the declaring GenericDeclaration yet. return new TypeVariableImpl<GenericDeclaration>(genericDecl, identifier); }