Package java.lang.reflect

Examples of java.lang.reflect.TypeVariable


            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


            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

  Class[] computeFieldGenerics (Type fieldGenericType, Field field, Class[] fieldClass) {
    Class[] fieldGenerics = null;
    if (fieldGenericType != null) {
      if (fieldGenericType instanceof TypeVariable && serializer.getGenericsScope() != null) {
        TypeVariable typeVar = (TypeVariable)fieldGenericType;
        // Obtain information about a concrete type of a given variable from the environment
        Class concreteClass = serializer.getGenericsScope().getConcreteClass(typeVar.getName());
        if (concreteClass != null) {
          fieldClass[0] = concreteClass;
          fieldGenerics = new Class[] {fieldClass[0]};
          if (TRACE)
            trace("kryo", "Determined concrete class of '" + field.getName() + "' to be " + fieldClass[0].getName());
View Full Code Here

    // Build a generics scope for this field
    Generics scope = buildGenericsScope(fieldClass[0], cachedFieldGenerics);

    // Is it a field of a generic parameter type, i.e. "T field"?
    if (fieldClass[0] == Object.class && fieldGenericType instanceof TypeVariable && serializer.getGenericsScope() != null) {
      TypeVariable typeVar = (TypeVariable)fieldGenericType;
      // Obtain information about a concrete type of a given variable from the environment
      Class concreteClass = serializer.getGenericsScope().getConcreteClass(typeVar.getName());
      if (concreteClass != null) {
        scope = new Generics();
        scope.add(typeVar.getName(), concreteClass);
      }
    }

    if (TRACE) {
      trace("kryo", "Generics scope of field '" + field.getName() + "' of class " + fieldGenericType + " is " + scope);
View Full Code Here

    public void givenTypeVariableWhenResolveThenResolved()
    {
        for( Method method : Type1.class.getMethods() )
        {
            Type type = method.getGenericReturnType();
            TypeVariable typeVariable = (TypeVariable) type;
            Type resolvedType = Classes.resolveTypeVariable( typeVariable, method.getDeclaringClass(), Type1.class );
            System.out.println( type + "=" + resolvedType );
        }
    }
View Full Code Here

            {
                ParameterizedType pt = (ParameterizedType) type;
                Type collectionType = pt.getActualTypeArguments()[ 0 ];
                if( collectionType instanceof TypeVariable )
                {
                    TypeVariable collectionTypeVariable = (TypeVariable) collectionType;
                    collectionType = Classes.resolveTypeVariable( collectionTypeVariable, declaringClass, compositeType );
                }
                ValueType collectedType = newValueType( collectionType, declaringClass, compositeType, layer, module );
                valueType = new CollectionType( Classes.RAW_CLASS.map(type) , collectedType );
            }
            else
            {
                valueType = new CollectionType( Classes.RAW_CLASS.map(type) , newValueType( Object.class, declaringClass, compositeType, layer, module ) );
            }
        }
        else if( MapType.isMap( type ) )
        {
            if( type instanceof ParameterizedType )
            {
                ParameterizedType pt = (ParameterizedType) type;
                Type keyType = pt.getActualTypeArguments()[ 0 ];
                if( keyType instanceof TypeVariable )
                {
                    TypeVariable keyTypeVariable = (TypeVariable) keyType;
                    keyType = Classes.resolveTypeVariable( keyTypeVariable, declaringClass, compositeType );
                }
                ValueType keyedType = newValueType( keyType, declaringClass, compositeType, layer, module );

                Type valType = pt.getActualTypeArguments()[ 1 ];
                if( valType instanceof TypeVariable )
                {
                    TypeVariable valueTypeVariable = (TypeVariable) valType;
                    valType = Classes.resolveTypeVariable( valueTypeVariable, declaringClass, compositeType );
                }
                ValueType valuedType = newValueType( valType, declaringClass, compositeType, layer, module );

                valueType = new MapType( Classes.RAW_CLASS.map(type) , keyedType, valuedType );
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

                    Type[] actualTypeArguments = ((ParameterizedType) genericParent).getActualTypeArguments();
                    TypeVariable[] typeVariables = ((Class) ((ParameterizedType) genericParent).getRawType()).getTypeParameters();
                   
                    for (int i = 0; i < actualTypeArguments.length; i++) {
                        Type actualTypeArgument = actualTypeArguments[i];
                        TypeVariable variable = typeVariables[i];
                       
                        // We are building bottom up and need to link up
                        // any TypeVariables with the actual class from the
                        // originating entity.
                        if (actualTypeArgument instanceof TypeVariable) {
                            getDescriptor().addGenericType(variable.getName(), getDescriptor().getGenericType(((TypeVariable) actualTypeArgument).getName()));
                        } else {
                            getDescriptor().addGenericType(variable.getName(), actualTypeArgument);
                        }
                    }
                }
               
                MappedSuperclassAccessor accessor = getProject().getMappedSuperclass(parent);
View Full Code Here

    private static Class<?> resolveReturnType(Method method, Class<? extends Decoder> decoder) {
        Type genericReturnType = method.getGenericReturnType();
        if (genericReturnType instanceof Class) {
            return (Class<?>) genericReturnType;
        } else if (genericReturnType instanceof TypeVariable) {
            TypeVariable type = ((TypeVariable) genericReturnType);
            List<Class> classes = new ArrayList<>();
            Class c = decoder;
            while (c != method.getDeclaringClass() && c != null) {
                classes.add(c);
                c = c.getSuperclass();
            }
            Collections.reverse(classes);

            String currentName = type.getName();
            int currentPos = -1;
            for (Class clz : classes) {
                for (int i = 0; i < clz.getSuperclass().getTypeParameters().length; ++i) {
                    TypeVariable<? extends Class<?>> param = clz.getSuperclass().getTypeParameters()[i];
                    if (param.getName().equals(currentName)) {
                        currentPos = i;
                        break;
                    }
                }
                Type gs = clz.getGenericSuperclass();
                if (gs instanceof ParameterizedType) {
                    ParameterizedType pt = (ParameterizedType) gs;
                    Type at = pt.getActualTypeArguments()[currentPos];
                    if (at instanceof Class) {
                        return (Class<?>) at;
                    } else if (at instanceof TypeVariable) {
                        TypeVariable tv = (TypeVariable) at;
                        currentName = tv.getName();
                    }
                }
            }
            //todo: should we throw an exception here? It should never actually be reached
            return method.getReturnType();
View Full Code Here

            Type genericType = field.getGenericType();
            if (genericType instanceof Class) {
               return fieldClass.getComponentType();
            }
            GenericArrayType genericArrayType = (GenericArrayType) genericType;
            TypeVariable genericComponentType = (TypeVariable) genericArrayType.getGenericComponentType();
            return (Class) genericComponentType.getBounds()[0];
         } else if (Collection.class.isAssignableFrom(fieldClass)) {
            return determineCollectionElementTypeParam(field.getGenericType());
         } else if (Map.class.isAssignableFrom(fieldClass)) {
            return determineMapValueTypeParam(field.getGenericType());
         }
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.