List of usage examples for java.lang.reflect Method getGenericReturnType
public Type getGenericReturnType()
From source file:org.jiemamy.utils.reflect.ReflectionUtil.java
/** * ???????????????// w ww .j a va2 s. c o m * * @param method * @return ????????????? * @throws IllegalArgumentException ?{@code null}??? */ public static Class<?> getElementTypeOfSetFromReturnType(Method method) { Validate.notNull(method); return getElementTypeOfSet(method.getGenericReturnType()); }
From source file:org.jiemamy.utils.reflect.ReflectionUtil.java
/** * ???????????????// w ww.j ava 2 s . c o m * * @param method * @return ????????????? * @throws IllegalArgumentException ?{@code null}??? */ public static Class<?> getElementTypeOfListFromReturnType(Method method) { Validate.notNull(method); return getElementTypeOfList(method.getGenericReturnType()); }
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
private static Class detectSourceCollectionPayload(Method getter) { Class sourceArgClass = null;/*from w ww. j a v a 2 s .c o m*/ Type sourceArg = getter.getGenericReturnType(); if (sourceArg instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) sourceArg; Type[] typeArguments = type.getActualTypeArguments(); sourceArgClass = (Class) typeArguments[0]; } return sourceArgClass; }
From source file:org.jiemamy.utils.reflect.ReflectionUtil.java
/** * ???????????????//from w w w.j a v a 2 s .c o m * * @param method * @return ????????????? * @throws IllegalArgumentException ?{@code null}??? */ public static Class<?> getElementTypeOfCollectionFromReturnType(Method method) { Validate.notNull(method); return getElementTypeOfCollection(method.getGenericReturnType()); }
From source file:ch.digitalfondue.npjt.QueryType.java
@SuppressWarnings("unchecked") private static <T> AffectedRowCountAndKey<T> executeUpdateAndKeepKeys(String template, Method method, NamedParameterJdbcTemplate jdbc, SqlParameterSource parameters) { Class<T> keyClass = (Class<T>) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]; KeyHolder keyHolder = new GeneratedKeyHolder(); int result = jdbc.update(template, parameters, keyHolder); Map<String, Object> keys = keyHolder.getKeys(); Object key;// w w w. ja v a2 s . co m if (keys.size() > 1) { AutoGeneratedKey spec = Objects.requireNonNull(method.getDeclaredAnnotation(AutoGeneratedKey.class), "more than one key for query " + template + ": annotation @AutoGeneratedKey required"); key = Objects.requireNonNull(keys.get(spec.value()), "the key with name " + spec.value() + " has returned null for query " + template + ": required a non null key"); } else if (Number.class.isAssignableFrom(keyClass)) { Class<? extends Number> c = (Class<? extends Number>) keyClass; return new AffectedRowCountAndKey<>(result, (T) NumberUtils.convertNumberToTargetClass(keyHolder.getKey(), c)); } else { key = keys.values().iterator().next(); } return new AffectedRowCountAndKey<>(result, keyClass.cast(key)); }
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
private static Map<Integer, Class> detectSourceMapPayload(Method getter) { Map<Integer, Class> result = new HashMap(); Type sourceArg = getter.getGenericReturnType(); if (sourceArg instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) sourceArg; Type[] typeArguments = type.getActualTypeArguments(); if (typeArguments.length != 2) { System.err.println("Cannot determine payload type of source Map "); return null; }// w ww . j av a 2 s . co m result.put(0, (Class) typeArguments[0]); result.put(1, (Class) typeArguments[1]); } return result; }
From source file:org.bonitasoft.engine.commons.ClassReflector.java
public static Type getGetterReturnType(final Class<?> classConnector, final String getterName) throws SReflectException { Method m; try {/*www. j a va 2 s . com*/ m = getMethod(classConnector, getterName); } catch (final Exception e) { throw new SReflectException(e); } return m.getGenericReturnType(); }
From source file:com.wavemaker.json.type.reflect.ReflectTypeUtils.java
/** * Retrieves the field definition from that field's read method. This will recursively call get * //w w w. j a va 2s .co m * @param method * @return */ public static FieldDefinition getFieldDefinition(Method method, TypeState typeState, boolean strict, String name) { return getFieldDefinition(method.getGenericReturnType(), typeState, strict, name); }
From source file:api.wiki.WikiGenerator.java
private static String methodDisplayName(Method apiMethod) { String methodName = apiMethod.getName(); String parameterTypes = stream(apiMethod.getGenericParameterTypes()).map(WikiGenerator::typeDisplayName) .collect(joining(", ")); return typeDisplayName(apiMethod.getGenericReturnType()) + " " + methodName + "(" + parameterTypes + ")"; }
From source file:org.eclipse.wb.internal.swing.databinding.model.generic.GenericUtils.java
public static IGenericType getObjectType(TypeVariable<?> superTypeParameter, Type superTypeParameterClass, PropertyDescriptor descriptor) { Method readMethod = descriptor.getReadMethod(); Class<?> rawType = descriptor.getPropertyType(); if (readMethod == null) { return new ClassGenericType(rawType, null, null); }/*from ww w . j a v a2s .co m*/ Type type = readMethod.getGenericReturnType(); if (type instanceof Class<?> || type instanceof TypeVariable<?>) { return new ClassGenericType(rawType, null, null); } if (type instanceof ParameterizedType) { GenericTypeContainer genericType = new GenericTypeContainer(rawType); ParameterizedType parameterizedType = (ParameterizedType) type; // if (superTypeParameter != null && parameterizedType.getActualTypeArguments().length == 1 && superTypeParameter == parameterizedType.getActualTypeArguments()[0]) { genericType.getSubTypes().add(resolveType(superTypeParameterClass)); return genericType; } for (Type subType : parameterizedType.getActualTypeArguments()) { genericType.getSubTypes().add(resolveType(subType)); } return genericType; } if (type instanceof GenericArrayType) { int dimension = 0; Type elementType = null; GenericArrayType arrayType = (GenericArrayType) type; while (true) { dimension++; elementType = arrayType.getGenericComponentType(); if (elementType instanceof GenericArrayType) { arrayType = (GenericArrayType) elementType; continue; } break; } GenericTypeContainer genericType = new GenericTypeContainer(rawType, dimension); genericType.getSubTypes().add(resolveType(elementType)); return genericType; } Assert.fail(MessageFormat.format("Undefine type: {0} {1}", readMethod, rawType)); return null; }