List of usage examples for java.lang.reflect ParameterizedType getActualTypeArguments
Type[] getActualTypeArguments();
From source file:eu.stratosphere.api.java.typeutils.TypeExtractor.java
private static Type getParameterType(Class<?> baseClass, ArrayList<Type> typeHierarchy, Class<?> clazz, int pos) { Type t = clazz.getGenericSuperclass(); // check if type is child of the base class if (!(t instanceof Class<?> && baseClass.isAssignableFrom((Class<?>) t)) && !(t instanceof ParameterizedType && baseClass.isAssignableFrom((Class<?>) ((ParameterizedType) t).getRawType()))) { throw new IllegalArgumentException("A generic function base class must be a super class."); }//w w w . j av a2 s .c o m if (typeHierarchy != null) { typeHierarchy.add(t); } Type curT = t; // go up the hierarchy until we reach the base class (with or without generics) // collect the types while moving up for a later top-down while (!(curT instanceof ParameterizedType && ((Class<?>) ((ParameterizedType) curT).getRawType()).equals(baseClass)) && !(curT instanceof Class<?> && ((Class<?>) curT).equals(baseClass))) { if (typeHierarchy != null) { typeHierarchy.add(curT); } // parameterized type if (curT instanceof ParameterizedType) { curT = ((Class<?>) ((ParameterizedType) curT).getRawType()).getGenericSuperclass(); } // class else { curT = ((Class<?>) curT).getGenericSuperclass(); } } // check if immediate child of base class has generics if (curT instanceof Class<?>) { throw new InvalidTypesException("Function needs to be parameterized by using generics."); } if (typeHierarchy != null) { typeHierarchy.add(curT); } ParameterizedType baseClassChild = (ParameterizedType) curT; return baseClassChild.getActualTypeArguments()[pos]; }
From source file:org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.java
private static TypeInfo getExtendedTypeInfoFromJavaType(Type t, Method m) { if (t == Object.class) { return TypeInfoFactory.unknownTypeInfo; }/*from w w w. j a v a 2s.c o m*/ if (t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) t; if (List.class == (Class<?>) pt.getRawType() || ArrayList.class == (Class<?>) pt.getRawType()) { return TypeInfoFactory .getListTypeInfo(getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[0], m)); } if (Map.class == (Class<?>) pt.getRawType() || HashMap.class == (Class<?>) pt.getRawType()) { return TypeInfoFactory.getMapTypeInfo( getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[0], m), getExtendedTypeInfoFromJavaType(pt.getActualTypeArguments()[1], m)); } t = pt.getRawType(); } if (!(t instanceof Class)) { throw new RuntimeException("Hive does not understand type " + t + " from " + m); } Class<?> c = (Class<?>) t; if (PrimitiveObjectInspectorUtils.isPrimitiveJavaType(c)) { return TypeInfoUtils .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveJavaType(c).primitiveCategory)); } if (PrimitiveObjectInspectorUtils.isPrimitiveJavaClass(c)) { return TypeInfoUtils .getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveJavaClass(c).primitiveCategory)); } if (PrimitiveObjectInspectorUtils.isPrimitiveWritableClass(c)) { return TypeInfoUtils.getTypeInfoFromObjectInspector(PrimitiveObjectInspectorFactory .getPrimitiveWritableObjectInspector(PrimitiveObjectInspectorUtils .getTypeEntryFromPrimitiveWritableClass(c).primitiveCategory)); } Field[] fields = ObjectInspectorUtils.getDeclaredNonStaticFields(c); ArrayList<String> fieldNames = new ArrayList<String>(fields.length); ArrayList<TypeInfo> fieldTypeInfos = new ArrayList<TypeInfo>(fields.length); for (int i = 0; i < fields.length; i++) { fieldNames.add(fields[i].getName()); fieldTypeInfos.add(getExtendedTypeInfoFromJavaType(fields[i].getGenericType(), m)); } return TypeInfoFactory.getStructTypeInfo(fieldNames, fieldTypeInfos); }
From source file:org.apache.olingo.ext.proxy.utils.CoreUtils.java
@SuppressWarnings({ "unchecked" }) private static void populate(final EdmEnabledODataClient client, final EntityInvocationHandler typeHandler, final Object bean, final Class<?> typeRef, final Class<? extends Annotation> getterAnn, final Iterator<? extends ClientProperty> propItor) { if (bean != null) { while (propItor.hasNext()) { final ClientProperty property = propItor.next(); final Method getter = ClassUtils.findGetterByAnnotatedName(typeRef, getterAnn, property.getName()); if (getter == null) { LOG.warn("Could not find any property annotated as {} in {}", property.getName(), bean.getClass().getName()); } else { try { if (property.hasNullValue()) { setPropertyValue(bean, getter, null); } else if (property.hasPrimitiveValue()) { setPropertyValue(bean, getter, primitiveValueToObject(property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName()))); } else if (property.hasComplexValue()) { final Object complex = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class<?>[] { getter.getReturnType() }, ComplexInvocationHandler.getInstance(typeHandler, getter.getReturnType())); populate(client, typeHandler, complex, Property.class, property.getValue().asComplex().iterator()); setPropertyValue(bean, getter, complex); } else if (property.hasCollectionValue()) { final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType(); final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0]; Collection<Object> collection = (Collection<Object>) getter.invoke(bean); if (collection == null) { collection = new ArrayList<Object>(); setPropertyValue(bean, getter, collection); }/*from w w w . j a v a 2 s . co m*/ final Iterator<ClientValue> collPropItor = property.getValue().asCollection() .iterator(); while (collPropItor.hasNext()) { final ClientValue value = collPropItor.next(); if (value.isPrimitive()) { collection.add(primitiveValueToObject(value.asPrimitive(), getPropertyClass(typeRef, property.getName()))); } else if (value.isComplex()) { final Object collItem = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class<?>[] { collItemClass }, ComplexInvocationHandler.getInstance(typeHandler, collItemClass)); populate(client, typeHandler, collItem, Property.class, value.asComplex().iterator()); collection.add(collItem); } } } } catch (Exception e) { LOG.error("Could not set property {} on {}", getter, bean, e); } } } } }
From source file:com.jaspersoft.jasperserver.war.helper.GenericParametersHelper.java
private static ParameterizedType findParametrizedType(Class<?> classToParse, Class<?> genericClassToFind, Map<String, Class<?>> inputParameterValues) { ParameterizedType type = null; if (genericClassToFind.isInterface()) { final Type[] genericInterfaces = classToParse.getGenericInterfaces(); if (genericInterfaces != null && genericInterfaces.length > 0) { for (Type genericInterface : genericInterfaces) { if (genericInterface == genericClassToFind) { throw new IllegalArgumentException(classToParse.getName() + " is raw implementation of " + genericClassToFind.getName()); }/*from w w w . j a v a 2s.c o m*/ if (genericInterface instanceof ParameterizedType) { ParameterizedType currentParametrizedType = (ParameterizedType) genericInterface; Map<String, Class<?>> currentParameterValues = new HashMap<String, Class<?>>( inputParameterValues); if (currentParametrizedType.getRawType() == genericClassToFind) { type = (ParameterizedType) genericInterface; } else { currentParameterValues = getCurrentParameterValues( ((Class<?>) currentParametrizedType.getRawType()).getTypeParameters(), currentParametrizedType.getActualTypeArguments(), new HashMap<String, Class<?>>(inputParameterValues)); type = findParametrizedType((Class<?>) currentParametrizedType.getRawType(), genericClassToFind, currentParameterValues); } if (type != null) { inputParameterValues.clear(); inputParameterValues.putAll(currentParameterValues); break; } } } } } else { final Type genericSuperclass = classToParse.getGenericSuperclass(); if (genericSuperclass == genericClassToFind) { log.debug(classToParse.getName() + " is raw subclass of " + genericClassToFind.getName()); } else if (genericSuperclass instanceof ParameterizedType && ((ParameterizedType) genericSuperclass).getRawType() == genericClassToFind) { type = (ParameterizedType) genericSuperclass; } } return type; }
From source file:org.soybeanMilk.SbmUtils.java
/** * ???//from w w w . j av a 2s .c o m * <pre> * class A<T>{} * class B extends A<Integer>{} * </pre> * <code>extractTypeVariablesInType(B.class, map)</code><code>map</code> * <pre> * T -------> Integer * </pre> * @param source * @param container * @date 2012-5-14 */ private static void extractTypeVariablesInType(Type source, Map<TypeVariable<?>, Type> variableTypesMap) { if (source == null) return; else if (source instanceof Class<?>) { Class<?> clazz = (Class<?>) source; //? Type[] genericInterfaces = clazz.getGenericInterfaces(); if (genericInterfaces != null) { for (Type t : genericInterfaces) extractTypeVariablesInType(t, variableTypesMap); } // Type genericSuperType = clazz.getGenericSuperclass(); Class<?> superClass = clazz.getSuperclass(); while (superClass != null && !Object.class.equals(superClass)) { extractTypeVariablesInType(genericSuperType, variableTypesMap); genericSuperType = superClass.getGenericSuperclass(); superClass = superClass.getSuperclass(); } // Class<?> outerClass = clazz; while (outerClass.isMemberClass()) { Type genericOuterType = outerClass.getGenericSuperclass(); extractTypeVariablesInType(genericOuterType, variableTypesMap); outerClass = outerClass.getEnclosingClass(); } } else if (source instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) source; if (isClassType(pt.getRawType())) { Type[] actualArgTypes = pt.getActualTypeArguments(); TypeVariable<?>[] typeVariables = narrowToClass(pt.getRawType()).getTypeParameters(); for (int i = 0; i < actualArgTypes.length; i++) { TypeVariable<?> var = typeVariables[i]; Type value = actualArgTypes[i]; //???? if (value instanceof TypeVariable<?>) { Type actual = variableTypesMap.get(value); if (actual != null) value = actual; } variableTypesMap.put(var, value); } } //?? extractTypeVariablesInType(pt.getRawType(), variableTypesMap); } }
From source file:eu.stratosphere.api.java.typeutils.TypeExtractor.java
private static <IN1, IN2> TypeInformation<?> createTypeInfoWithImmediateBaseChildInput( ParameterizedType baseChild, TypeVariable<?> typeVar, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type) { Type[] baseChildArgs = baseChild.getActualTypeArguments(); TypeInformation<?> info = null; if (in1Type != null) { info = findCorrespondingInfo(typeVar, baseChildArgs[0], in1Type); }/*from ww w. j av a 2 s . co m*/ if (info == null && in2Type != null) { info = findCorrespondingInfo(typeVar, baseChildArgs[1], in2Type); } if (info != null) { return info; } return null; }
From source file:com.jk.util.JKObjectUtil.java
/** * Gets the generic paramter./*from w w w.j av a 2 s . co m*/ * * @param <T> * the generic type * @param handler * the handler * @return the generic paramter */ public static <T> Class<? extends T> getGenericParamter(String handler) { ParameterizedType parameterizedType = (ParameterizedType) JKObjectUtil.getClass(handler) .getGenericInterfaces()[0]; Class<? extends T> clas = (Class<? extends T>) (parameterizedType.getActualTypeArguments()[0]); return clas; }
From source file:com.yahoo.egads.data.JsonEncoder.java
public static void fromJson(Object object, JSONObject json_obj) throws Exception { // for each json key-value, that has a corresponding variable in object ... for (Iterator k = json_obj.keys(); k.hasNext();) { String key = (String) k.next(); Object value = json_obj.get(key); // try to access object variable Field field = null;/*from ww w .ja v a 2 s .co m*/ try { field = object.getClass().getField(key); } catch (Exception e) { continue; } if (Modifier.isStatic(field.getModifiers())) { continue; } if (Modifier.isPrivate(field.getModifiers())) { continue; } Object member = field.get(object); if (json_obj.isNull(key)) { field.set(object, null); continue; // if variable is container... recurse } else if (member instanceof JsonAble) { ((JsonAble) member).fromJson((JSONObject) value); // if variable is an array... recurse on sub-objects } else if (member instanceof ArrayList) { // Depends on existance of ArrayList<T> template parameter, and T constructor with no arguments. // May be better to use custom fromJson() in member class. ArrayList memberArray = (ArrayList) member; JSONArray jsonArray = (JSONArray) value; // find array element constructor ParameterizedType arrayType = null; if (field.getGenericType() instanceof ParameterizedType) { arrayType = (ParameterizedType) field.getGenericType(); } for (Class c = member.getClass(); arrayType == null && c != null; c = c.getSuperclass()) { if (c.getGenericSuperclass() instanceof ParameterizedType) { arrayType = (ParameterizedType) c.getGenericSuperclass(); } } if (arrayType == null) { throw new Exception("could not find ArrayList element type for field 'key'"); } Class elementClass = (Class) (arrayType.getActualTypeArguments()[0]); Constructor elementConstructor = elementClass.getConstructor(); // for each element in JSON array ... append element to member array, recursively decode element for (int i = 0; i < jsonArray.length(); ++i) { Object element = elementConstructor.newInstance(); fromJson(element, jsonArray.getJSONObject(i)); memberArray.add(element); } // if variable is simple value... set } else if (field.getType() == float.class) { field.set(object, (float) json_obj.getDouble(key)); } else { field.set(object, value); } } }
From source file:com.android.camera2.its.ItsSerializer.java
@SuppressWarnings("unchecked") public static CaptureRequest.Builder deserialize(CaptureRequest.Builder mdDefault, JSONObject jsonReq) throws ItsException { try {/*from w ww .j av a 2 s. c o m*/ Logt.i(TAG, "Parsing JSON capture request ..."); // Iterate over the CaptureRequest reflected fields. CaptureRequest.Builder md = mdDefault; Field[] allFields = CaptureRequest.class.getDeclaredFields(); for (Field field : allFields) { if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && field.getType() == CaptureRequest.Key.class && field.getGenericType() instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) field.getGenericType(); Type[] argTypes = paramType.getActualTypeArguments(); if (argTypes.length > 0) { CaptureRequest.Key key = (CaptureRequest.Key) field.get(md); String keyName = key.getName(); Type keyType = argTypes[0]; // For each reflected CaptureRequest entry, look inside the JSON object // to see if it is being set. If it is found, remove the key from the // JSON object. After this process, there should be no keys left in the // JSON (otherwise an invalid key was specified). if (jsonReq.has(keyName) && !jsonReq.isNull(keyName)) { if (keyType instanceof GenericArrayType) { Type elmtType = ((GenericArrayType) keyType).getGenericComponentType(); JSONArray ja = jsonReq.getJSONArray(keyName); Object val[] = new Object[ja.length()]; for (int i = 0; i < ja.length(); i++) { if (elmtType == int.class) { Array.set(val, i, ja.getInt(i)); } else if (elmtType == byte.class) { Array.set(val, i, (byte) ja.getInt(i)); } else if (elmtType == float.class) { Array.set(val, i, (float) ja.getDouble(i)); } else if (elmtType == long.class) { Array.set(val, i, ja.getLong(i)); } else if (elmtType == double.class) { Array.set(val, i, ja.getDouble(i)); } else if (elmtType == boolean.class) { Array.set(val, i, ja.getBoolean(i)); } else if (elmtType == String.class) { Array.set(val, i, ja.getString(i)); } else if (elmtType == Size.class) { JSONObject obj = ja.getJSONObject(i); Array.set(val, i, new Size(obj.getInt("width"), obj.getInt("height"))); } else if (elmtType == Rect.class) { JSONObject obj = ja.getJSONObject(i); Array.set(val, i, new Rect(obj.getInt("left"), obj.getInt("top"), obj.getInt("bottom"), obj.getInt("right"))); } else if (elmtType == Rational.class) { JSONObject obj = ja.getJSONObject(i); Array.set(val, i, new Rational(obj.getInt("numerator"), obj.getInt("denominator"))); } else if (elmtType == RggbChannelVector.class) { JSONArray arr = ja.getJSONArray(i); Array.set(val, i, new RggbChannelVector((float) arr.getDouble(0), (float) arr.getDouble(1), (float) arr.getDouble(2), (float) arr.getDouble(3))); } else if (elmtType == ColorSpaceTransform.class) { JSONArray arr = ja.getJSONArray(i); Rational xform[] = new Rational[9]; for (int j = 0; j < 9; j++) { xform[j] = new Rational(arr.getJSONObject(j).getInt("numerator"), arr.getJSONObject(j).getInt("denominator")); } Array.set(val, i, new ColorSpaceTransform(xform)); } else if (elmtType == MeteringRectangle.class) { JSONObject obj = ja.getJSONObject(i); Array.set(val, i, new MeteringRectangle(obj.getInt("x"), obj.getInt("y"), obj.getInt("width"), obj.getInt("height"), obj.getInt("weight"))); } else { throw new ItsException("Failed to parse key from JSON: " + keyName); } } if (val != null) { Logt.i(TAG, "Set: " + keyName + " -> " + Arrays.toString(val)); md.set(key, val); jsonReq.remove(keyName); } } else { Object val = null; if (keyType == Integer.class) { val = jsonReq.getInt(keyName); } else if (keyType == Byte.class) { val = (byte) jsonReq.getInt(keyName); } else if (keyType == Double.class) { val = jsonReq.getDouble(keyName); } else if (keyType == Long.class) { val = jsonReq.getLong(keyName); } else if (keyType == Float.class) { val = (float) jsonReq.getDouble(keyName); } else if (keyType == Boolean.class) { val = jsonReq.getBoolean(keyName); } else if (keyType == String.class) { val = jsonReq.getString(keyName); } else if (keyType == Size.class) { JSONObject obj = jsonReq.getJSONObject(keyName); val = new Size(obj.getInt("width"), obj.getInt("height")); } else if (keyType == Rect.class) { JSONObject obj = jsonReq.getJSONObject(keyName); val = new Rect(obj.getInt("left"), obj.getInt("top"), obj.getInt("right"), obj.getInt("bottom")); } else if (keyType == Rational.class) { JSONObject obj = jsonReq.getJSONObject(keyName); val = new Rational(obj.getInt("numerator"), obj.getInt("denominator")); } else if (keyType == RggbChannelVector.class) { JSONObject obj = jsonReq.optJSONObject(keyName); JSONArray arr = jsonReq.optJSONArray(keyName); if (arr != null) { val = new RggbChannelVector((float) arr.getDouble(0), (float) arr.getDouble(1), (float) arr.getDouble(2), (float) arr.getDouble(3)); } else if (obj != null) { val = new RggbChannelVector((float) obj.getDouble("red"), (float) obj.getDouble("greenEven"), (float) obj.getDouble("greenOdd"), (float) obj.getDouble("blue")); } else { throw new ItsException("Invalid RggbChannelVector object"); } } else if (keyType == ColorSpaceTransform.class) { JSONArray arr = jsonReq.getJSONArray(keyName); Rational a[] = new Rational[9]; for (int i = 0; i < 9; i++) { a[i] = new Rational(arr.getJSONObject(i).getInt("numerator"), arr.getJSONObject(i).getInt("denominator")); } val = new ColorSpaceTransform(a); } else if (keyType instanceof ParameterizedType && ((ParameterizedType) keyType).getRawType() == Range.class && ((ParameterizedType) keyType).getActualTypeArguments().length == 1 && ((ParameterizedType) keyType) .getActualTypeArguments()[0] == Integer.class) { JSONArray arr = jsonReq.getJSONArray(keyName); val = new Range<Integer>(arr.getInt(0), arr.getInt(1)); } else { throw new ItsException( "Failed to parse key from JSON: " + keyName + ", " + keyType); } if (val != null) { Logt.i(TAG, "Set: " + keyName + " -> " + val); md.set(key, val); jsonReq.remove(keyName); } } } } } } // Ensure that there were no invalid keys in the JSON request object. if (jsonReq.length() != 0) { throw new ItsException("Invalid JSON key(s): " + jsonReq.toString()); } Logt.i(TAG, "Parsing JSON capture request completed"); return md; } catch (java.lang.IllegalAccessException e) { throw new ItsException("Access error: ", e); } catch (org.json.JSONException e) { throw new ItsException("JSON error: ", e); } }
From source file:eu.stratosphere.api.java.typeutils.TypeExtractor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <IN1, IN2, OUT> TypeInformation<OUT> createTypeInfoWithTypeHierarchy( ArrayList<Type> typeHierarchy, Type t, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type) { // check if type is a subclass of tuple if ((t instanceof Class<?> && Tuple.class.isAssignableFrom((Class<?>) t)) || (t instanceof ParameterizedType && Tuple.class.isAssignableFrom((Class<?>) ((ParameterizedType) t).getRawType()))) { Type curT = t;//from w w w.ja va 2 s . c o m // do not allow usage of Tuple as type if (curT instanceof Class<?> && ((Class<?>) curT).equals(Tuple.class)) { throw new InvalidTypesException( "Usage of class Tuple as a type is not allowed. Use a concrete subclass (e.g. Tuple1, Tuple2, etc.) instead."); } // go up the hierarchy until we reach immediate child of Tuple (with or without generics) // collect the types while moving up for a later top-down while (!(curT instanceof ParameterizedType && ((Class<?>) ((ParameterizedType) curT).getRawType()).getSuperclass().equals(Tuple.class)) && !(curT instanceof Class<?> && ((Class<?>) curT).getSuperclass().equals(Tuple.class))) { typeHierarchy.add(curT); // parameterized type if (curT instanceof ParameterizedType) { curT = ((Class<?>) ((ParameterizedType) curT).getRawType()).getGenericSuperclass(); } // class else { curT = ((Class<?>) curT).getGenericSuperclass(); } } // check if immediate child of Tuple has generics if (curT instanceof Class<?>) { throw new InvalidTypesException("Tuple needs to be parameterized by using generics."); } ParameterizedType tupleChild = (ParameterizedType) curT; Type[] subtypes = new Type[tupleChild.getActualTypeArguments().length]; // materialize possible type variables for (int i = 0; i < subtypes.length; i++) { // materialize immediate TypeVariables if (tupleChild.getActualTypeArguments()[i] instanceof TypeVariable<?>) { Type varContent = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) tupleChild.getActualTypeArguments()[i]); // variable could not be materialized if (varContent == null) { // add the TypeVariable as subtype for step in next section subtypes[i] = tupleChild.getActualTypeArguments()[i]; } else { // add class or parameterized type subtypes[i] = varContent; } } // class or parameterized type else { subtypes[i] = tupleChild.getActualTypeArguments()[i]; } } TypeInformation<?>[] tupleSubTypes = new TypeInformation<?>[subtypes.length]; for (int i = 0; i < subtypes.length; i++) { // sub type could not be determined with materializing // try to derive the type info of the TypeVariable from the immediate base child input as a last attempt if (subtypes[i] instanceof TypeVariable<?>) { ParameterizedType immediateBaseChild = (ParameterizedType) typeHierarchy .get(typeHierarchy.size() - 1); tupleSubTypes[i] = createTypeInfoWithImmediateBaseChildInput(immediateBaseChild, (TypeVariable<?>) subtypes[i], in1Type, in2Type); // variable could not be determined if (tupleSubTypes[i] == null) { throw new InvalidTypesException("Type of TypeVariable '" + ((TypeVariable<?>) subtypes[i]).getName() + "' in '" + ((TypeVariable<?>) subtypes[i]).getGenericDeclaration() + "' could not be determined. This is most likely a type erasure problem. " + "The type extraction currently supports types with generic variables only in cases where " + "all variables in the return type can be deduced from the input type(s)."); } } else { tupleSubTypes[i] = createTypeInfoWithTypeHierarchy(new ArrayList<Type>(typeHierarchy), subtypes[i], in1Type, in2Type); } } // TODO: Check that type that extends Tuple does not have additional fields. // Right now, these fields are not be serialized by the TupleSerializer. // We might want to add an ExtendedTupleSerializer for that. if (t instanceof Class<?>) { return new TupleTypeInfo(((Class<? extends Tuple>) t), tupleSubTypes); } else if (t instanceof ParameterizedType) { return new TupleTypeInfo(((Class<? extends Tuple>) ((ParameterizedType) t).getRawType()), tupleSubTypes); } } // type depends on another type // e.g. class MyMapper<E> extends MapFunction<String, E> else if (t instanceof TypeVariable) { Type typeVar = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) t); if (typeVar != null) { return createTypeInfoWithTypeHierarchy(typeHierarchy, typeVar, in1Type, in2Type); } // try to derive the type info of the TypeVariable from the immediate base child input as a last attempt else { ParameterizedType immediateBaseChild = (ParameterizedType) typeHierarchy .get(typeHierarchy.size() - 1); TypeInformation<OUT> typeInfo = (TypeInformation<OUT>) createTypeInfoWithImmediateBaseChildInput( immediateBaseChild, (TypeVariable<?>) t, in1Type, in2Type); if (typeInfo != null) { return typeInfo; } else { throw new InvalidTypesException("Type of TypeVariable '" + ((TypeVariable<?>) t).getName() + "' in '" + ((TypeVariable<?>) t).getGenericDeclaration() + "' could not be determined. This is most likely a type erasure problem. " + "The type extraction currently supports types with generic variables only in cases where " + "all variables in the return type can be deduced from the input type(s)."); } } } // arrays with generics // (due to a Java 6 bug, it is possible that BasicArrayTypes also get classified as ObjectArrayTypes // since the JVM classifies e.g. String[] as GenericArrayType instead of Class) else if (t instanceof GenericArrayType) { GenericArrayType genericArray = (GenericArrayType) t; TypeInformation<?> componentInfo = createTypeInfoWithTypeHierarchy(typeHierarchy, genericArray.getGenericComponentType(), in1Type, in2Type); return ObjectArrayTypeInfo.getInfoFor(t, componentInfo); } // objects with generics are treated as raw type else if (t instanceof ParameterizedType) { return getForClass((Class<OUT>) ((ParameterizedType) t).getRawType()); } // no tuple, no TypeVariable, no generic type else if (t instanceof Class) { return getForClass((Class<OUT>) t); } throw new InvalidTypesException("Type Information could not be created."); }