Example usage for java.lang.reflect Type toString

List of usage examples for java.lang.reflect Type toString

Introduction

In this page you can find the example usage for java.lang.reflect Type toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:ca.appvelopers.mcgillmobile.model.retrofit.CourseResultConverter.java

@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
        Retrofit retrofit) {/*from   w ww  .  j av a 2  s .  c o m*/
    if (!type.toString().equals(this.type.toString())) {
        //This can only convert a list of course results
        return null;
    }
    return new CourseResultConverter();
}

From source file:org.jgentleframework.utils.ReflectUtils.java

/**
 * Returns the all {@link Type Types} representing the interfaces
 * implemented by the class or interface represented by given object class.
 * /*from  w w  w.  jav a 2s  . co m*/
 * @param clazz
 *            the given object class
 * @param superClass
 *            if <b>true</b>, the result will includes all types of super
 *            classes and super interfaces of given object class.
 * @return an {@link ArrayList} containing returned types if they exist,
 *         otherwise, returns an empty {@link ArrayList}.
 */
public static List<Type> getAllGenericInterfaces(Class<?> clazz, boolean superClass) {

    Assertor.notNull(clazz);
    List<Type> result = new ArrayList<Type>();
    for (Type type : clazz.getGenericInterfaces()) {
        if (!result.contains(type)) {
            int i = 0;
            for (Type resultType : result) {
                if (resultType.toString().equals(type.toString())) {
                    i++;
                }
            }
            if (i == 0) {
                result.add(type);
            }
        }
    }
    // Tm trn tt c cc interfaces ca clazz hin hnh
    Set<Class<?>> listInterfaces = ReflectUtils.getAllInterfaces(clazz, superClass);
    for (Class<?> interfaze : listInterfaces) {
        for (Type type : interfaze.getGenericInterfaces()) {
            if (!result.contains(type)) {
                int i = 0;
                for (Type resultType : result) {
                    if (resultType.toString().equals(type.toString())) {
                        i++;
                    }
                }
                if (i == 0) {
                    result.add(type);
                }
            }
        }
    }
    // Tm trn tt c cc superClass ca clazz hin hnh
    List<Class<?>> listClass = ReflectUtils.getAllSuperClass(clazz, false);
    for (Class<?> current : listClass) {
        for (Type type : current.getGenericInterfaces()) {
            if (!result.contains(type)) {
                int i = 0;
                for (Type resultType : result) {
                    if (resultType.toString().equals(type.toString())) {
                        i++;
                    }
                }
                if (i == 0) {
                    result.add(type);
                }
            }
        }
    }
    return result;
}

From source file:fm.audiobox.core.models.Playlists.java

/**
 * Returns first {@link Playlist} associated with the given {@code name} and {@code type}
 * @param name the Playlist name//from w ww  .j a va 2s  . com
 * @param type the Playlist type
 * @return the {@link Playlist} associated with the given {@code name} and {@code type}
 */
public Playlist getPlaylistByNameAndType(String name, Type type) {
    for (Iterator<Playlist> it = this.iterator(); it.hasNext();) {
        Playlist pl = it.next();
        if (pl.getName().equalsIgnoreCase(name) && type.toString().equals(pl.getType())) {
            return pl;
        }
    }
    return null;
}

From source file:io.cloudslang.lang.compiler.modeller.TransformersHandler.java

private Class getTransformerFromType(Transformer transformer) {
    // Always take the first interface Transformer<F, T> in case of many interfaces
    // Always take the first parameter F of the Transformer interface
    Type interfaceType = transformer.getClass().getGenericInterfaces()[0];
    Type typeF = ((ParameterizedType) interfaceType).getActualTypeArguments()[0];
    if (typeF instanceof ParameterizedType) {
        return (Class) ((ParameterizedType) typeF).getRawType();
    } else if (typeF instanceof Class) {
        return (Class) typeF;
    } else {/* www .j a v a 2 s. com*/
        String fullName = typeF.toString();
        try {
            return fullName.startsWith(CLASS) ? Class.forName(fullName.substring(CLASS.length()))
                    : Class.forName(fullName);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }
}

From source file:de.escalon.hypermedia.spring.AffordanceBuilderFactory.java

private boolean containsCollection(Type genericReturnType) {
    final boolean ret;
    if (genericReturnType instanceof ParameterizedType) {
        ParameterizedType t = (ParameterizedType) genericReturnType;
        Type rawType = t.getRawType();
        Assert.state(rawType instanceof Class<?>, "raw type is not a Class: " + rawType.toString());
        Class<?> cls = (Class<?>) rawType;
        if (HttpEntity.class.isAssignableFrom(cls)) {
            Type[] typeArguments = t.getActualTypeArguments();
            ret = containsCollection(typeArguments[0]);
        } else if (Resources.class.isAssignableFrom(cls) || Collection.class.isAssignableFrom(cls)) {
            ret = true;/*from  w  ww.j a v  a  2s.c o m*/
        } else {
            ret = false;
        }
    } else if (genericReturnType instanceof GenericArrayType) {
        ret = true;
    } else if (genericReturnType instanceof WildcardType) {
        WildcardType t = (WildcardType) genericReturnType;
        ret = containsCollection(getBound(t.getLowerBounds()))
                || containsCollection(getBound(t.getUpperBounds()));
    } else if (genericReturnType instanceof TypeVariable) {
        ret = false;
    } else if (genericReturnType instanceof Class) {
        Class<?> cls = (Class<?>) genericReturnType;
        ret = Resources.class.isAssignableFrom(cls) || Collection.class.isAssignableFrom(cls);
    } else {
        ret = false;
    }
    return ret;
}

From source file:org.xwiki.properties.internal.DefaultConverterManager.java

/**
 * Get class name without generics./*from  www .j a v a2 s.  c  om*/
 *
 * @param type the type
 * @return type name without generics
 */
private String getTypeName(Type type) {
    String name;
    if (type instanceof Class) {
        name = ((Class<?>) type).getName();
    } else if (type instanceof ParameterizedType) {
        name = ((Class<?>) ((ParameterizedType) type).getRawType()).getName();
    } else {
        name = type.toString();
    }

    return name;
}

From source file:br.gov.frameworkdemoiselle.internal.interceptor.AuditableInterceptor.java

private Class<?> getFirstInterfaceTypeParameter(Class<?> internalAuditorClass) throws Exception {
    Type genericInterface = internalAuditorClass.getGenericInterfaces()[0];
    if (genericInterface != null) {
        String gStr = genericInterface.toString();
        String strType = StringUtils.EMPTY;
        if (gStr.indexOf('<') != -1) {
            strType = gStr.substring(gStr.indexOf('<') + 1, gStr.indexOf('>'));
        }//from w  w  w.  java  2 s . c  om
        if (StringUtils.isNotEmpty(strType)) {
            return Class.forName(strType);
        }
    }
    return null;
}

From source file:therian.operation.Convert.java

private Convert(Position.Readable<SOURCE> sourcePosition, final Type targetType) {
    this(sourcePosition, new Position.Writable<TARGET>() {
        {/*from w ww . ja v  a  2  s . c o m*/
            Validate.notNull(targetType, "targetType");
        }

        public Type getType() {
            return targetType;
        }

        public void setValue(TARGET value) {
        }

        @Override
        public String toString() {
            return targetType.toString();
        }
    });
}

From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java

private static Class<?> toClass(Type type) {
    if (type instanceof Class<?>) {
        return (Class<?>) type;
    } else {//w  ww .ja v a  2  s.  co  m
        try {
            if (type instanceof ParameterizedType) {
                return (Class<?>) ((ParameterizedType) type).getRawType();
            } else if (type instanceof ParameterizedCollectionType) {
                return ((ParameterizedCollectionType) type).getCollectionType();
            }
        } catch (ClassCastException e) {
            // do nothing
        }
        String message = resourceManager.getString("dorado.common/unsupportedArgType", type.toString());
        throw new IllegalArgumentException(message);
    }
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

@SuppressWarnings("rawtypes")
protected Class getClassAtDepth(Type type, int depth) throws Exception {
    if (depth <= 0) {
        String className = type.toString();
        if (className.length() >= 6 && className.substring(0, 6).equalsIgnoreCase("class ")) {
            className = className.substring(6);
        }/*ww  w  .j a va 2 s.  co m*/
        if (className.indexOf("<") >= 0) {
            className = className.substring(0, className.indexOf("<"));
        }
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException ex) {
            // ugly fix for primitive data types
            if (className.equalsIgnoreCase("byte"))
                return Byte.class;
            if (className.equalsIgnoreCase("short"))
                return Short.class;
            if (className.equalsIgnoreCase("int"))
                return Integer.class;
            if (className.equalsIgnoreCase("long"))
                return Long.class;
            if (className.equalsIgnoreCase("float"))
                return Float.class;
            if (className.equalsIgnoreCase("double"))
                return Double.class;
            if (className.equalsIgnoreCase("char"))
                return Character.class;
            if (className.equalsIgnoreCase("boolean"))
                return Boolean.class;
            throw ex;
        }
    }
    depth--;
    ParameterizedType pType = (ParameterizedType) type;
    Type[] typeArgs = pType.getActualTypeArguments();
    return getClassAtDepth(typeArgs[typeArgs.length - 1], depth);
}