Package java.lang.reflect

Examples of java.lang.reflect.Type


      param = " resultMap=\"" + resultMap + "\"";
    } else if (resultClazz == Null.class) {
      returnType = method.getReturnType();
      if (!returnType.getName().equals("void")) {
        resultClazz = returnType;
        final Type genericType = method.getGenericReturnType();
        if (genericType instanceof ParameterizedTypeImpl) {
          ParameterizedTypeImpl pgType = (ParameterizedTypeImpl) genericType;
          Type[] actualTypeArguments = pgType
              .getActualTypeArguments();
          resultClazz = (Class<?>) actualTypeArguments[0];
View Full Code Here


    Class<? super T> rawType = key.getTypeLiteral().getRawType();

    // Handle cases where T is a Provider<?>.
    if (rawType.equals(Provider.class)) {
      Type providerType = key.getTypeLiteral().getType();
      if (!(providerType instanceof ParameterizedType)) {
        // Raw Provider.
        return null;
      }
      Type entryType = ((ParameterizedType) providerType)
          .getActualTypeArguments()[0];

      try {
        final Provider<?> provider = getProvider(key.ofType(entryType));
        return new InternalFactory<T>() {
View Full Code Here

     * @return any
     */
    public static Class<?> getGenericType(Field field) {
        Class<?> clazz = null;
        if (field != null) {
            Type t = field.getGenericType();
            if (t instanceof ParameterizedType) {
                ParameterizedType type = (ParameterizedType) t;
                if ((type != null) && (type.getActualTypeArguments() != null) && (type.getActualTypeArguments().length > 0)) clazz = (Class<?>) type.getActualTypeArguments()[0];
            } else if (t instanceof Class) clazz = (Class<?>) t;
        }
View Full Code Here

    private final Type[] types;
    private volatile Constructor<?> constructor;

    protected TypeReference() {
        final Type superclass = getClass().getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new IllegalArgumentException("Class should be anonymous or extended from a generic class");
        }
        this.types = ((ParameterizedType) superclass).getActualTypeArguments();
    }
View Full Code Here

    /**
     * Gets the referenced Class of the n-th generic parameter
     */
    public Class<?> getGenericParameterClass(final int n) {
        QL.require(n < types.length , "Missing parameter"); // QA:[RG]::verified // TODO: message
        final Type type = types[n];
        final Class<?> clazz = (type instanceof Class<?>) ? (Class<?>) type : (Class<?>) ((ParameterizedType) type).getRawType();
        QL.require(((clazz.getModifiers() & Modifier.ABSTRACT) == 0) , "generic parameter must be a concrete class"); // QA:[RG]::verified // TODO: message
        return clazz;
    }
View Full Code Here

    /**
     * Instantiates a new instance of {@code T} using the n-th generic parameter
     */
    @SuppressWarnings("unchecked")
    public T newGenericInstance(final int n, final Object ... objects) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        final Type type = types[n];
        final Class<?> rawType = type instanceof Class<?> ? (Class<?>) type : (Class<?>) ((ParameterizedType) type).getRawType();

        final Class<?>[] types = new Class[objects.length];
        for (int i=0; i<objects.length; i++) {
            types[i] = objects[i].getClass();
View Full Code Here

    //
    // private methods
    //

    private TypeNode retrieve(final Class<?> klass) {
        final Type superclass = klass.getGenericSuperclass();
        QL.require(!(superclass instanceof Class) , ReflectConstants.SHOULD_BE_ANONYMOUS_OR_EXTENDED); // QA:[RG]::verified
        final TypeNode node = new TypeNode(klass);
        for (final Type t : ((ParameterizedType) superclass).getActualTypeArguments() ) {
            node.add(retrieve(t));
        }
View Full Code Here

    private TypeNode retrieve(final Type type) {
        final TypeNode node;
        if (type instanceof Class<?>) {
            node = new TypeNode((Class<?>)type);
        } else if (type instanceof ParameterizedType) {
            final Type rawType = ((ParameterizedType) type).getRawType();
            node = retrieve(rawType);
            for (final Type arg : ((ParameterizedType) type).getActualTypeArguments()) {
                node.add(retrieve(arg));
                //
                //TODO: code review
View Full Code Here

    static public Type getType(final Class<?> klass) {
        return getType(klass, 0);
    }

    static public Type getType(final Class<?> klass, final int pos) {
        final Type superclass = klass.getGenericSuperclass();
        QL.require(!(superclass instanceof Class) , ReflectConstants.SHOULD_BE_ANONYMOUS_OR_EXTENDED); // QA:[RG]::verified
        final Type[] types = ((ParameterizedType) superclass).getActualTypeArguments();
        QL.require(pos < types.length , ReflectConstants.MISSING_GENERIC_PARAMETER_TYPE); // QA:[RG]::verified
        return types[pos];
    }
View Full Code Here

    static public Class<?> getClazz(final Class<?> klass) {
        return getClazz(klass, 0);
    }

    static public Class<?> getClazz(final Class<?> klass, final int pos) {
        final Type type = getType(klass, pos);
        final Class<?> clazz = (type instanceof Class<?>) ? (Class<?>) type : (Class<?>) ((ParameterizedType) type).getRawType();
        QL.require(((clazz.getModifiers() & Modifier.ABSTRACT) == 0) , ReflectConstants.GENERIC_PARAMETER_MUST_BE_CONCRETE_CLASS); // QA:[RG]::verified
        return clazz;
    }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Type

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.