Java Code Examples for java.lang.reflect.Type.getClass()

The following are Jave code examples for showing how to use getClass() of the java.lang.reflect.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ProjectAres   File: Types.java   View Source Code Vote up 7 votes
public static boolean isFullySpecified(Type type) {
    checkNotNull(type);
    if(type instanceof Class) {
        return true;
    } else if(type instanceof TypeVariable) {
        return false;
    } else if(type instanceof GenericArrayType) {
        return isFullySpecified(((GenericArrayType) type).getGenericComponentType());
    } else if(type instanceof WildcardType) {
        final WildcardType wildcard = (WildcardType) type;
        return Stream.of(wildcard.getLowerBounds()).allMatch(Types::isFullySpecified) &&
               Stream.of(wildcard.getUpperBounds()).allMatch(Types::isFullySpecified);
    } else if(type instanceof ParameterizedType) {
        final ParameterizedType parameterized = (ParameterizedType) type;
        return isFullySpecified(parameterized.getRawType()) &&
               (parameterized.getOwnerType() == null || isFullySpecified(parameterized.getOwnerType())) &&
               Stream.of(parameterized.getActualTypeArguments()).allMatch(Types::isFullySpecified);
    } else {
        throw new IllegalArgumentException("Unhandled metatype " + type.getClass());
    }
}
 
Example 2
Project: GitHub   File: TypeUtils.java   View Source Code Vote up 6 votes
public static Class<?> getClass(Type type){
    if(type.getClass() == Class.class){
        return (Class<?>) type;
    }

    if(type instanceof ParameterizedType){
        return getClass(((ParameterizedType) type).getRawType());
    }

    if(type instanceof TypeVariable){
        Type boundType = ((TypeVariable<?>) type).getBounds()[0];
        return (Class<?>) boundType;
    }

    if(type instanceof WildcardType){
        Type[] upperBounds = ((WildcardType) type).getUpperBounds();
        if (upperBounds.length == 1) {
            return getClass(upperBounds[0]);
        }
    }

    return Object.class;
}
 
Example 3
Project: jsouplib   File: TypeLiteral.java   View Source Code Vote up 6 votes
private static String formatTypeWithoutSpecialCharacter(Type type) {
    if (type instanceof Class) {
        Class clazz = (Class) type;
        return clazz.getCanonicalName();
    }
    if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType) type;
        String typeName = formatTypeWithoutSpecialCharacter(pType.getRawType());
        for (Type typeArg : pType.getActualTypeArguments()) {
            typeName += "_";
            typeName += formatTypeWithoutSpecialCharacter(typeArg);
        }
        return typeName;
    }
    if (type instanceof GenericArrayType) {
        GenericArrayType gaType = (GenericArrayType) type;
        return formatTypeWithoutSpecialCharacter(gaType.getGenericComponentType()) + "_array";
    }
    throw new AJsoupReaderException("unsupported type: " + type + ", of class " + type.getClass());
}
 
Example 4
Project: minijax   File: ReflectionUtils.java   View Source Code Vote up 5 votes
public static Class<?> getRawType(final AnnotatedType annotatedType) {
    final Type containerType = annotatedType.getType();
    if (containerType instanceof Class) {
        return (Class<?>) containerType;
    } else if (containerType instanceof ParameterizedType) {
        return (Class<?>) ((ParameterizedType) containerType).getRawType();
    } else {
        throw new ValidationException("Unknown type: " + containerType.getClass());
    }
}
 
Example 5
Project: boohee_v5.6   File: TypeUtils.java   View Source Code Vote up 5 votes
public static Class<?> getClass(Type type) {
    if (type.getClass() == Class.class) {
        return (Class) type;
    }
    if (type instanceof ParameterizedType) {
        return getClass(((ParameterizedType) type).getRawType());
    }
    return Object.class;
}
 
Example 6
Project: uavstack   File: TypeUtils.java   View Source Code Vote up 5 votes
public static Class<?> getClass(Type type) {
    if (type.getClass() == Class.class) {
        return (Class<?>) type;
    }

    if (type instanceof ParameterizedType) {
        return getClass(((ParameterizedType) type).getRawType());
    }

    return Object.class;
}
 
Example 7
Project: gemini.blueprint   File: TypeFactory.java   View Source Code Vote up 4 votes
private static ReifiedType getReifiedType(Type targetType, Collection<Type> variableTypes) {
	if (targetType instanceof Class) {
		if (Object.class.equals(targetType)) {
			return OBJECT;
		}
		return new GenericsReifiedType((Class<?>) targetType);
	}
	if (targetType instanceof ParameterizedType) {
		Type ata = ((ParameterizedType) targetType).getActualTypeArguments()[0];
		return getReifiedType(ata, variableTypes);
	}
	if (targetType instanceof WildcardType) {
		WildcardType wt = (WildcardType) targetType;
		Type[] lowerBounds = wt.getLowerBounds();
		if (ObjectUtils.isEmpty(lowerBounds)) {
			// there's always an upper bound (Object)
			Type upperBound = wt.getUpperBounds()[0];
			return getReifiedType(upperBound, variableTypes);
		}

		return getReifiedType(lowerBounds[0], variableTypes);
	}

	if (targetType instanceof TypeVariable) {
		TypeVariable<?> typeVariable = (TypeVariable<?>) targetType;
		if (variableTypes.contains(targetType)) {
			//Looped around on itself via a recursive Generics definition
			return OBJECT;
		}
		variableTypes.add(targetType);
		Type[] bounds = typeVariable.getBounds();
		
		return getReifiedType(bounds[0], variableTypes);
	}

	if (targetType instanceof GenericArrayType) {
		return getReifiedType(((GenericArrayType) targetType).getGenericComponentType(), variableTypes);
	}

	throw new IllegalArgumentException("Unknown type " + targetType.getClass());
}
 
Example 8
Project: Atomic   File: AtomRequest.java   View Source Code Vote up 4 votes
AtomRequest(A a, Type t) {
    this.a = a;
    this.aClass = t.getClass();

    a.createClient();
}