List of usage examples for java.lang.reflect Method getGenericReturnType
public Type getGenericReturnType()
From source file:com.iorga.iraj.json.MethodTemplate.java
@Override protected Type getPropertyType(final Method targetMethod) { return targetMethod.getGenericReturnType(); }
From source file:com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.java
private Type getFirstParametrizedType(Method m) { Type gtype = m.getGenericReturnType(); if (gtype instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) gtype; return pType.getActualTypeArguments()[0]; }/* w w w .j a v a 2 s. c o m*/ return null; }
From source file:com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.java
private List<Type> getParametrizedTypes(Method m) { return getAllParameterizedTypes(m.getGenericReturnType()); }
From source file:com.wavemaker.tools.apidocs.tools.parser.impl.ReflectionModelParser.java
protected Map<String, Property> parsePropertiesUsingGetters(Class<?> classToScan) { Map<String, Property> properties = new LinkedHashMap<>(); Collection<Method> methods = MethodUtils.findGetterMethods(classToScan); for (final Method method : methods) { PropertyParser propertyParser = new PropertyParserImpl(method.getGenericReturnType()); properties.put(MethodUtils.getPropertyName(method.getName()), propertyParser.parse()); }//from w w w . j a va 2 s .co m return properties; }
From source file:pl.bristleback.server.bristle.conf.resolver.action.ResponseResolver.java
@SuppressWarnings("unchecked") private void resolveResponseSerialization(Method action, ActionResponseInformation responseInformation) { SerializationResolver serializationResolver = serializationEngine.getSerializationResolver(); Object payloadSerialization = serializationResolver.resolveSerialization(action.getGenericReturnType(), action.getAnnotations());//w w w. j a va2s .c o m responseInformation.setSerialization(payloadSerialization); }
From source file:com.autentia.common.util.ClassWithList.java
@Ignore("No es un test, son pruebas con reflection") @Test/* w w w .j av a2 s .c om*/ public void testGetGenericFromList() throws SecurityException, NoSuchMethodException { final ClassWithList<String> stringList = new ClassWithList<String>(); for (TypeVariable<?> v : stringList.getClass().getTypeParameters()) { print(v); } final Method method = stringList.getClass().getMethod("getElements"); Type returnType = method.getGenericReturnType(); if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; Type[] typeArguments = type.getActualTypeArguments(); for (Type typeArgument : typeArguments) { System.out.println(typeArgument); print(typeArgument); TypeVariable<?> typeVariable = (TypeVariable<?>) typeArgument; Class typeArgClass = (Class) typeArgument; System.out.println("typeArgClass = " + typeArgClass); } } }
From source file:com.googlecode.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test public void additionalPropertiesOfStringTypeOnly() throws SecurityException, NoSuchMethodException, ClassNotFoundException { ClassLoader resultsClassLoader = generateAndCompile( "/schema/additionalProperties/additionalPropertiesString.json", "com.example"); Class<?> classWithNoAdditionalProperties = resultsClassLoader .loadClass("com.example.AdditionalPropertiesString"); Method getter = classWithNoAdditionalProperties.getMethod("getAdditionalProperties"); assertThat(((ParameterizedType) getter.getGenericReturnType()).getActualTypeArguments()[1], is(equalTo((Type) String.class))); // setter with these types should exist: classWithNoAdditionalProperties.getMethod("setAdditionalProperties", String.class, String.class); }
From source file:com.googlecode.jsonschema2pojo.integration.AdditionalPropertiesIT.java
public void additionalPropertiesOfObjectTypeCreatesNewClassForPropertyValues() throws SecurityException, NoSuchMethodException, ClassNotFoundException { ClassLoader resultsClassLoader = generateAndCompile( "/schema/additionalProperties/additionalPropertiesObject.json", "com.example"); Class<?> classWithNoAdditionalProperties = resultsClassLoader .loadClass("com.example.AdditionalPropertiesObject"); Class<?> propertyValueType = resultsClassLoader.loadClass("com.example.AdditionalPropertiesObjectProperty"); Method getter = classWithNoAdditionalProperties.getMethod("getAdditionalProperties"); assertThat(((ParameterizedType) getter.getGenericReturnType()).getActualTypeArguments()[1], is(equalTo((Type) propertyValueType))); // setter with these types should exist: classWithNoAdditionalProperties.getMethod("setAdditionalProperties", String.class, propertyValueType); }
From source file:com.googlecode.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test public void additionalPropertiesOfBooleanTypeOnly() throws SecurityException, NoSuchMethodException, ClassNotFoundException { ClassLoader resultsClassLoader = generateAndCompile( "/schema/additionalProperties/additionalPropertiesPrimitiveBoolean.json", "com.example", config("usePrimitives", true)); Class<?> classWithNoAdditionalProperties = resultsClassLoader .loadClass("com.example.AdditionalPropertiesPrimitiveBoolean"); Method getter = classWithNoAdditionalProperties.getMethod("getAdditionalProperties"); assertThat(((ParameterizedType) getter.getGenericReturnType()).getActualTypeArguments()[1], is(equalTo((Type) Boolean.class))); // setter with these types should exist: classWithNoAdditionalProperties.getMethod("setAdditionalProperties", String.class, boolean.class); }
From source file:net.easysmarthouse.service.scripting.ScriptDecoratorPointcut.java
@Override public boolean matches(Method method, Class<?> type) { Class<?> returnType = method.getReturnType(); if (returnType == Device.class) { return true; }/*from w w w . ja va 2 s . com*/ if (Collection.class.isAssignableFrom(returnType)) { Type genericReturnType = method.getGenericReturnType(); if (genericReturnType instanceof ParameterizedType) { ParameterizedType listType = (ParameterizedType) genericReturnType; Type[] actualTypeArgs = listType.getActualTypeArguments(); if (actualTypeArgs != null && actualTypeArgs.length != 0) { Class<?> listClass = (Class<?>) actualTypeArgs[0]; if (listClass == Device.class) { return true; } } } } return false; }