List of usage examples for java.lang.reflect ParameterizedType getRawType
Type getRawType();
From source file:Main.java
public static void main(String args[]) throws Exception { Type type = StringList.class.getGenericSuperclass(); System.out.println(type);/*from ww w .ja va2 s . co m*/ ParameterizedType pt = (ParameterizedType) type; Type rawType = pt.getRawType(); System.out.println(rawType); }
From source file:Main.java
private static Type[] getActualTypeArguments(Class<?> type, Type t) { if (t != null && t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) t; if (pt.getRawType().equals(type)) return ((ParameterizedType) t).getActualTypeArguments(); }/*from w w w . j a v a 2s .co m*/ return null; }
From source file:GenericsUtil.java
public static boolean isTypeOf(final Type type, final Class<?> clazz) { if (Class.class.isInstance(type)) { final Class<?> typeAsClass = Class.class.cast(type); return clazz.isAssignableFrom(typeAsClass); }// w ww . j av a2 s. c o m if (ParameterizedType.class.isInstance(type)) { final ParameterizedType parameterizedType = ParameterizedType.class.cast(type); final Type rawType = parameterizedType.getRawType(); return isTypeOf(rawType, clazz); } return false; }
From source file:org.opendaylight.netvirt.federation.plugin.identifiers.FederationPluginIdentifierRegistry.java
@SuppressWarnings("unchecked") private static Class<? extends DataObject> getSubtreeClass( FederationPluginIdentifier<? extends DataObject, ? extends DataObject, ? extends DataObject> identifier) { for (Type type : identifier.getClass().getGenericInterfaces()) { ParameterizedType parameterizedType = (ParameterizedType) type; if (parameterizedType.getRawType().equals(FederationPluginIdentifier.class)) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (actualTypeArguments != null && actualTypeArguments.length > 1) { return (Class<? extends DataObject>) actualTypeArguments[2]; }// w w w . j a va 2 s .co m } } return null; }
From source file:Main.java
protected static boolean isTypeOf(Type type, Class<?> clazz) { if (Class.class.isInstance(type)) { return clazz.isAssignableFrom(Class.class.cast(type)); }/*from ww w. java 2s . c o m*/ if (ParameterizedType.class.isInstance(type)) { final ParameterizedType parameterizedType = ParameterizedType.class.cast(type); return isTypeOf(parameterizedType.getRawType(), clazz); } return false; }
From source file:com.sf.ddao.crud.param.CRUDParameterService.java
public static Class<?> getCRUDDaoBean(Context ctx, int idx) { final MethodCallCtx callCtx = CtxHelper.get(ctx, MethodCallCtx.class); final Method method = callCtx.getMethod(); if (idx != USE_GENERICS) { Type beanClass;/*from w w w . ja v a 2s .com*/ if (idx == DefaultParameter.RETURN_ARG_IDX) { beanClass = method.getGenericReturnType(); } else { beanClass = method.getGenericParameterTypes()[idx]; } if (beanClass instanceof Class) { return (Class) beanClass; } } Class<?> iFace = callCtx.getSubjClass(); for (Type type : iFace.getGenericInterfaces()) { final ParameterizedType parameterizedType = (ParameterizedType) type; if (parameterizedType.getRawType().equals(method.getDeclaringClass())) { final Type[] typeArguments = parameterizedType.getActualTypeArguments(); return (Class<?>) typeArguments[GENERICS_ARG_NUM]; } } throw new RuntimeException(iFace + " expected to extend " + CRUDDao.class); }
From source file:org.zkoss.ganttz.timetracker.OnColumnsRowRenderer.java
private static boolean isTypeForInterface(Type type, Class<?> interfaceBeingSearched) { if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; Type rawType = p.getRawType(); return rawType.equals(interfaceBeingSearched); }/*from www . j av a 2 s . c om*/ return type.equals(interfaceBeingSearched); }
From source file:Main.java
public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else//from w w w.j a va 2 s.c o m return getRawClass(expand(type, null)); }
From source file:com.wavemaker.tools.apidocs.tools.parser.util.TypeUtil.java
protected static TypeInformation getParameterizedTypeTypeInformation(ParameterizedType parameterizedType) { List<Class<?>> typeArguments = new LinkedList<>(); Class<?> actualType = (Class<?>) parameterizedType.getRawType(); for (Type type : parameterizedType.getActualTypeArguments()) { TypeInformation typeInfo = extractTypeInformation(type); typeArguments.add(typeInfo.getActualType()); }//from www . j a v a 2s . co m return new TypeInformation(actualType, typeArguments, false, parameterizedType); }
From source file:GenericUtils.java
/** * Get the Generic definitions from a class for given class without looking * super classes./* w ww. ja va 2 s .co m*/ * @param classFrom Implementing class * @param interfaceClz class with generic definition * @return null if not found */ @SuppressWarnings("unchecked") public static Type[] getGenericDefinitonsThis(Class classFrom, Class interfaceClz) { Type[] genericInterfaces = classFrom.getGenericInterfaces(); for (Type type : genericInterfaces) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; if (interfaceClz.isAssignableFrom((Class) pt.getRawType())) { return pt.getActualTypeArguments(); } } } // check if it if available on generic super class Type genericSuperclass = classFrom.getGenericSuperclass(); if (genericSuperclass instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) genericSuperclass; if (interfaceClz.equals(pt.getRawType())) { return pt.getActualTypeArguments(); } } return null; }