FileDocCategorySizeDatePackage
ImplForVariable.javaAPI DocAndroid 1.5 API4727Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.lang.reflect

ImplForVariable

public final class ImplForVariable extends Object implements TypeVariable

Fields Summary
private ImplForVariable
formalVar
private final GenericDeclaration
declOfVarUser
private final String
name
private D
genericDeclaration
private ListOfTypes
bounds
Constructors Summary
ImplForVariable(D genericDecl, String name, ListOfTypes bounds)

param
genericDecl declaration where a type variable is declared
param
name type variable name
param
bounds class and interface bounds
api2vm

        this.genericDeclaration = genericDecl;
        this.name = name;
        this.bounds = bounds;
        this.formalVar = this;
        this.declOfVarUser = null;
    
ImplForVariable(D genericDecl, String name)

param
genericDecl declaration where a type variable is used
param
name type variable name
api2vm

        this.name = name;
        this.declOfVarUser = genericDecl;
    
Methods Summary
public booleanequals(java.lang.Object o)

        if(!(o instanceof TypeVariable)) {
            return false;
        }
        TypeVariable<?> that = (TypeVariable<?>) o;
        return getName().equals(that.getName()) && 
                getGenericDeclaration().equals(that.getGenericDeclaration()); 
    
static java.lang.reflect.TypeVariablefindFormalVar(java.lang.reflect.GenericDeclaration layer, java.lang.String name)

        TypeVariable[] formalVars = layer.getTypeParameters();
        for (TypeVariable var : formalVars) {
            if (name.equals(var.getName())) {
                return var;
            }
        }
        // resolve() looks up the next level only, if null is returned
        return null;
    
public java.lang.reflect.Type[]getBounds()

        resolve();
        return bounds.getResolvedTypes().clone();
    
public DgetGenericDeclaration()

        resolve();
        return genericDeclaration;
    
public java.lang.StringgetName()

        return name;
    
public inthashCode()

        return 31 * getName().hashCode() + getGenericDeclaration().hashCode();
    
static java.lang.reflect.GenericDeclarationnextLayer(java.lang.reflect.GenericDeclaration decl)

            if (decl instanceof Class) {
                // FIXME: Is the following hierarchy correct?:
                Class cl = (Class)decl;
                decl = cl.getEnclosingMethod(); 
                if (decl != null) {
                    return decl;
                }
                decl = cl.getEnclosingConstructor(); 
                if (decl != null) {
                    return decl;
                }
                return cl.getEnclosingClass();
            } else if (decl instanceof Method) {
                return ((Method)decl).getDeclaringClass();
            } else if (decl instanceof Constructor) {
                return ((Constructor)decl).getDeclaringClass();
            }
            throw new RuntimeException("unknown GenericDeclaration2: " 
                    + decl.toString());
    
voidresolve()

        if (formalVar == null) {
            GenericDeclaration curLayer = declOfVarUser;
            TypeVariable var = null;
            do {
                var = findFormalVar(curLayer, name);
                if (var != null) break;
                else {
                    curLayer = nextLayer(curLayer);
                    if (curLayer == null) break; // FIXME: SHOULD NEVER HAPPEN! 
                                                 // throw exception: illegal 
                                                 // type variable reference.
                }
            } while (true);
            formalVar = (ImplForVariable<D>)var;
            this.genericDeclaration = formalVar.genericDeclaration;
            this.bounds = formalVar.bounds;
        }
    
public java.lang.StringtoString()

        return name;