Package java.lang.reflect

Examples of java.lang.reflect.TypeVariable


                ParameterizedType pt = (ParameterizedType)t;
                Type[] args = pt.getActualTypeArguments();
                for (int i = 0; i < args.length; i++) {
                    Type arg = args[i];
                    if (arg instanceof TypeVariable) {
                        TypeVariable var = (TypeVariable)arg;
                        Type[] bounds = var.getBounds();
                        boolean isResolved = false;
                        for (int j = 0; j < bounds.length; j++) {
                            Class<?> cls = InjectionUtils.getRawType(bounds[j]);
                            if (cls != null && cls.isAssignableFrom(expectedType)) {
                                isResolved = true;
View Full Code Here


    {
        Asserts.assertNotNull(type, "type parameter can not be null");
       
        if (type instanceof TypeVariable)
        {
            TypeVariable wc = (TypeVariable)type;
            Type[] upper = wc.getBounds();           
           
           
            if(upper.length > 1)
            {
                return false;
View Full Code Here

            }

            int i = 0;
            for (Type type : typeArguments)
            {
                TypeVariable typeVariable = typeVariables[i];
                Type[] bounds = typeVariable.getBounds();

                Class<?> clazzBound = (Class<?>) bounds[0];

                if (!clazzBound.isAssignableFrom((Class<?>) type))
                {
View Full Code Here

     */
    public static GenericDeclaration findGenericDeclarationForTypeVariable(String typeVariableName, Object startPoint) {
        // XXX: redesign after debugging to join all the common places below:
        if (startPoint instanceof Field) {
            Class klass = ((Field)startPoint).getDeclaringClass();
            TypeVariable va[] = klass.getTypeParameters();
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(typeVariableName)){
                        return (GenericDeclaration) klass;
                    }
                }
            } else {
                while (klass != null) {
                    klass = klass.getDeclaringClass();
                    va = klass.getTypeParameters();
                    if (va != null) {
                        for(int i = 0; i < va.length; i++){
                            if(va[i].getName().equals(typeVariableName)) {
                                return (GenericDeclaration) klass;
                            }
                        }
                    }
                }
                return null;
            }
        } else if (startPoint instanceof Method || startPoint instanceof Constructor) {
            TypeVariable va[] = (startPoint instanceof Method ? (Method)startPoint : (Constructor)startPoint).getTypeParameters();
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(typeVariableName)){
                        return (GenericDeclaration) startPoint;
                    }
                }
            } else {
                Class klass = (startPoint instanceof Method) ? ((Method)startPoint).getDeclaringClass() : ((Constructor)startPoint).getDeclaringClass();
                va = klass.getTypeParameters();
                if (va != null) {
                    for(int i = 0; i < va.length; i++){
                        if(va[i].getName().equals(typeVariableName)){
                            return (GenericDeclaration) klass;
                        }
                    }
                } else {
                    while (klass != null) {
                        klass = klass.getDeclaringClass();
                        va = klass.getTypeParameters();
                        if (va != null) {
                            for(int i = 0; i < va.length; i++){
                                if(va[i].getName().equals(typeVariableName)){
                                    return (GenericDeclaration) klass;
                                }
                            }
                        }
                    }
                    return null;
                }
            }
        } else if (startPoint instanceof Class) {
            Class klass = (Class)startPoint;
            TypeVariable va[] = klass.getTypeParameters();
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(typeVariableName)){
                        return (GenericDeclaration) klass;
                    }
View Full Code Here

     */
    public static TypeVariable findTypeVariable(String typeVariableName, Object startPoint) {
        // XXX: redesign after debugging to join all the common places below:
        if (startPoint instanceof Field) {
            Class klass = ((Field)startPoint).getDeclaringClass();
            TypeVariable va[] = klass.getTypeParameters();
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(typeVariableName)){
                        /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, klass) == null) { // Yes, it may be very inefficient now (for example, klass.getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                        /**/                                                                                     // after all the TV-repository's functionality implementation
                        /**/                                                                                     // it will be time to improvement.
                        /**/    TypeVariableRepository.registerTypeVariable(va[i], typeVariableName, klass); // So, it was placed in repository just after an TV-instance creation but then
                        /**/                                                                                      // it was removed (since we did not find it into the invoking method of this method look there at line with
                        /**/                                                                                      // TypeVariableRepository.findTypeVariable(...) method invokation and also we did not find it in just above if-condition).
                        /**/                                                                                      // As a consequence, we should reregistry it again as long as it become so popular again
                        /**/}
                        return va[i];
                    }
                }
            }
                while (klass != null) {
                    klass = klass.getDeclaringClass();
                    /**/java.lang.reflect.TypeVariable variable = TypeVariableRepository.findTypeVariable(typeVariableName, klass);
                    /**/if (variable != null) {
                    /**/    return variable;
                    /**/}
                    va = klass.getTypeParameters();
                    if (va != null) {
                        for(int i = 0; i < va.length; i++){
                            if(va[i].getName().equals(typeVariableName)) {
                                /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, klass) == null) { // Yes, it may be very inefficient now (for example, klass.getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                                /**/                                                                                     // after all the TV-repository's functionality implementation
                                /**/                                                                                     // it will be time to improvement.
                                /**/    TypeVariableRepository.registerTypeVariable(va[i], typeVariableName, klass); // So, it was placed in repository just after an TV-instance creation but then
                                /**/                                                                                      // it was removed (since we did not find it into the invoking method of this method look there at line with
                                /**/                                                                                      // TypeVariableRepository.findTypeVariable(...) method invokation and also we did not find it in just above if-condition).
                                /**/                                                                                      // As a consequence, we should reregistry it again as long as it become so popular again
                                /**/}
                                return va[i];
                            }
                        }
                    }
                }
                return null;
        } else if (startPoint instanceof Method || startPoint instanceof Constructor) {
            TypeVariable va[];
            if (startPoint instanceof Method) {
                va = ((Method)startPoint).getTypeParameters();
            } else {
                va = ((Constructor)startPoint).getTypeParameters();
            }
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(transform(typeVariableName))){
                        /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, startPoint) == null) { // Yes, it may be very inefficient now (for example, ((Constructor/Method)startPoint).getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                        /**/                                                                                          // after all the TV-repository's functionality implementation
                        /**/                                                                                          // it will be time to improvement.
                        /**/    TypeVariableRepository.registerTypeVariable(va[i], typeVariableName, startPoint); // So, it was placed in repository just after an TV-instance creation but then
                        /**/                                                                                           // it was removed (since we did not find it into the invoking method of this method look there at line with
                        /**/                                                                                           // TypeVariableRepository.findTypeVariable(...) method invokation and also we did not find it in just above if-condition).
                        /**/                                                                                           // As a consequence, we should reregistry it again as long as it become so popular again
                        /**/}
                        return va[i];
                    }
                }
            }
                Class klass = (startPoint instanceof Method) ? ((Method)startPoint).getDeclaringClass() : ((Constructor)startPoint).getDeclaringClass();
                if (startPoint instanceof Method) {
                    klass = ((Method)startPoint).getDeclaringClass();
                } else {
                    klass = ((Constructor)startPoint).getDeclaringClass();
                }
                /**/java.lang.reflect.TypeVariable variable = TypeVariableRepository.findTypeVariable(typeVariableName, klass);
                /**/if (variable != null) {
                /**/    return variable;
                /**/}
                va = klass.getTypeParameters();
                if (va != null) {
                    for(int i = 0; i < va.length; i++){
                        if(va[i].getName().equals(transform(typeVariableName))){
                            /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, klass) == null) { // Yes, it may be very inefficient now (for example, klass.getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                            /**/                                                                                     // after all the TV-repository's functionality implementation
                            /**/                                                                                     // it will be time to improvement.
                            /**/    TypeVariableRepository.registerTypeVariable(va[i], typeVariableName, klass); // So, it was placed in repository just after an TV-instance creation but then
                            /**/                                                                                      // it was removed (since we did not find it into the invoking method of this method look there at line with
                            /**/                                                                                      // TypeVariableRepository.findTypeVariable(...) method invokation and also we did not find it in just above if-condition).
                            /**/                                                                                      // As a consequence, we should reregistry it again as long as it become so popular again
                            /**/}
                            return va[i];
                        }
                    }
                }
                    while (klass != null) {
                        klass = klass.getDeclaringClass();
                        /**/variable = TypeVariableRepository.findTypeVariable(typeVariableName, klass);
                        /**/if (variable != null) {
                        /**/    return variable;
                        /**/}
                        va = klass.getTypeParameters();
                        if (va != null) {
                            for(int i = 0; i < va.length; i++){
                                if(va[i].getName().equals(transform(typeVariableName))){
                                    /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, klass) == null) { // Yes, it may be very inefficient now (for example, klass.getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                                    /**/                                                                                     // after all the TV-repository's functionality implementation
                                    /**/                                                                                     // it will be time to improvement.
                                    /**/    TypeVariableRepository.registerTypeVariable(va[i], typeVariableName, klass); // So, it was placed in repository just after an TV-instance creation but then
                                    /**/                                                                                      // it was removed (since we did not find it into the invoking method of this method look there at line with
                                    /**/                                                                                      // TypeVariableRepository.findTypeVariable(...) method invokation and also we did not find it in just above if-condition).
                                    /**/                                                                                      // As a consequence, we should reregistry it again as long as it become so popular again
                                    /**/}
                                    return va[i];
                                }
                            }
                        }
                    }
                    return null;
        } else if (startPoint instanceof Class) {
            Class klass = (Class)startPoint;
            TypeVariable va[] = klass.getTypeParameters();
            if (va != null) {
                for(int i = 0; i < va.length; i++){
                    if(va[i].getName().equals(typeVariableName)){
                        /**/if (TypeVariableRepository.findTypeVariable(typeVariableName, klass) == null) { // Yes, it may be very inefficient now (for example, klass.getTypeParameters() invokation above can just registry a TV but we need to recheck it in this line) but
                        /**/                                                                                     // after all the TV-repository's functionality implementation
View Full Code Here

            GenericArrayType gt = (GenericArrayType)cls;
            Type componentType = gt.getGenericComponentType();
            if (componentType instanceof Class) {
                ct = (Class)componentType;
            } else {
                TypeVariable tv = (TypeVariable)componentType;
                Type[] bounds = tv.getBounds();
                if (bounds != null && bounds.length == 1) {
                    if (bounds[0] instanceof Class) {
                        ct = (Class)bounds[0];
                    } else {
                        throw new IllegalArgumentException("Unable to determine type for: " + tv);
View Full Code Here

        }
        if (type instanceof TypeVariable) {
            if (parameterizedTypes == null) {
                processParameterizedTypes();
            }
            TypeVariable var = (TypeVariable)type;
            Map<String, Class<?>> mp = parameterizedTypes.get(var.getGenericDeclaration());
            if (mp != null) {
                Class<?> c = parameterizedTypes.get(var.getGenericDeclaration()).get(var.getName());
                if (c != null) {
                    rawClass = c;
                    type = c;
                    part.getMessageInfo().setProperty("parameterized", Boolean.TRUE);
                }
View Full Code Here

            return getClassCode((Class)type);
        } else if (type instanceof GenericArrayType) {
            GenericArrayType at = (GenericArrayType)type;
            return "[" + getClassCode(at.getGenericComponentType());
        } else if (type instanceof TypeVariable) {
            TypeVariable tv = (TypeVariable)type;
            Type[] bounds = tv.getBounds();
            if (bounds != null && bounds.length == 1) {
                return getClassCode(bounds[0]);
            } else {
                throw new IllegalArgumentException("Unable to determine type for: " + tv);
            }
View Full Code Here

                if (Modifier.isVolatile(m2.getModifiers())) {
                    //bridge method, need to map the generics
                    Class params[] = method.getParameterTypes();
                    for (Type t : method.getGenericParameterTypes()) {
                        if (t instanceof TypeVariable) {
                            TypeVariable tv = (TypeVariable)t;
                            for (int x = 0; x < implInfo.getSEIClass().getTypeParameters().length; x++) {
                                TypeVariable t2 = implInfo.getSEIClass().getTypeParameters()[x];
                                if (t2.getName().equals(tv.getName())) {
                                    params[x] = (Class)implInfo.getSEIType().getActualTypeArguments()[x];
                                }
                            }
                        }
                    }
View Full Code Here

        }
        if (type instanceof TypeVariable) {
            if (parameterizedTypes == null) {
                processParameterizedTypes();
            }
            TypeVariable var = (TypeVariable)type;
            Map<String, Class<?>> mp = parameterizedTypes.get(var.getGenericDeclaration());
            if (mp != null) {
                Class<?> c = parameterizedTypes.get(var.getGenericDeclaration()).get(var.getName());
                if (c != null) {
                    rawClass = c;
                    type = c;
                    part.getMessageInfo().setProperty("parameterized", Boolean.TRUE);
                }
View Full Code Here

TOP

Related Classes of java.lang.reflect.TypeVariable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.