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); }
void parseClassSignature() { // ClassSignature ::= // OptFormalTypeParameters SuperclassSignature {SuperinterfaceSignature}. parseOptFormalTypeParameters(); // SuperclassSignature ::= ClassTypeSignature. this.superclassType = parseClassTypeSignature(); interfaceTypes = new ListOfTypes(16); while (symbol > 0) { // SuperinterfaceSignature ::= ClassTypeSignature. interfaceTypes.add(parseClassTypeSignature()); } }
Type getResolvedType() { if (args.getResolvedTypes().length == 0) { return getRawType(); } else { return this; } }
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); }
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(); }
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 parseTypeArgument() { // TypeArgument ::= (["+" | "-"] FieldTypeSignature) | "*". ListOfTypes extendsBound = new ListOfTypes(1); ListOfTypes superBound = new ListOfTypes(1); if (symbol == '*') { scanSymbol(); extendsBound.add(Object.class); return new WildcardTypeImpl(extendsBound, superBound); } else if (symbol == '+') { scanSymbol(); extendsBound.add(parseFieldTypeSignature()); return new WildcardTypeImpl(extendsBound, superBound); } else if (symbol == '-') { scanSymbol(); superBound.add(parseFieldTypeSignature()); extendsBound.add(Object.class); return new WildcardTypeImpl(extendsBound, superBound); } else { return parseFieldTypeSignature(); } }
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(); } }
/** * 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); }
/** * Returns the {@link Type}s of the interfaces that this {@code Class} directly * implements. If the {@code Class} represents a primitive type or {@code * void} then an empty array is returned. */ public Type[] getGenericInterfaces() { GenericSignatureParser parser = new GenericSignatureParser(getClassLoader()); parser.parseForClass(this, getSignatureAttribute()); return Types.getTypeArray(parser.interfaceTypes, true); }
Type parseReturnType() { // ReturnType ::= TypeSignature | "V". if (symbol != 'V') { return parseTypeSignature(); } else { scanSymbol(); return void.class; } }
/** * 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(); } }
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(); } }
public Type[] getBounds() { resolve(); return bounds.getResolvedTypes().clone(); }
public Type getGenericComponentType() { try { return ((ParameterizedTypeImpl)componentType).getResolvedType(); } catch (ClassCastException e) { return componentType; } }
/** * Returns a hash code composed as a sum of hash codes of member elements, * including elements with default values. * @see AnnotationMember#hashCode() */ public int hashCode() { int hash = 0; for (AnnotationMember element : elements) { hash += element.hashCode(); } return hash; }
public Type[] getResolvedTypes() { Type[] result = resolvedTypes; if (result == null) { result = resolveTypes(types); resolvedTypes = result; } return result; }
public D getGenericDeclaration() { resolve(); return genericDeclaration; }
void setInput(GenericDeclaration genericDecl, String input) { if (input != null) { this.genericDecl = genericDecl; this.buffer = input.toCharArray(); this.eof = false; scanSymbol(); } else { this.eof = true; } }
public static Type getType(Type type) { if (type instanceof ParameterizedTypeImpl) { return ((ParameterizedTypeImpl)type).getResolvedType(); } return type; }