List of usage examples for java.lang.reflect Method getReturnType
public Class<?> getReturnType()
From source file:net.paoding.rose.jade.statement.UpdateQuerier.java
public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) { this.dataAccessProvider = dataAccessProvider; Method method = metaData.getMethod(); // ?/*w ww . jav a 2 s . c om*/ Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; if (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class))) { returnGeneratedKeys = true; } else { returnGeneratedKeys = false; } }
From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java
@Test public void checkHandleGetter() { try {/*from w w w.j a v a 2s . c o m*/ Method method = eventImpl.getMethod("getHandle"); checkSpongeEvent(eventImpl, method.getReturnType()); } catch (NoSuchMethodException ignored) { fail(eventImpl.getSimpleName() + ": missing getHandle() method (handle getter)"); } }
From source file:net.nelz.simplesm.aop.CacheBase.java
protected void verifyReturnTypeIsList(final Method method, final Class annotationClass) { if (verifyTypeIsList(method.getReturnType())) { return;// w ww . j a v a2 s . c om } throw new InvalidAnnotationException(String.format( "The annotation [%s] is only valid on a method that returns a [%s]. " + "[%s] does not fulfill this requirement.", ReadThroughMultiCache.class.getName(), List.class.getName(), method.toString())); }
From source file:com.proteanplatform.protean.entity.EntityTableCellMetadata.java
/** * <p>The representative of the an object cell must be a string or a number. We let the * admin annotation argument "cellMethod" determine which method should return a * legal represenation. If this is itself an object, we repeat the procedure. </p> * //from w w w . j a v a2 s .co m * @param cell * @param method * @throws NoSuchMethodException */ private void calculateObjectCell(Method method) throws NoSuchMethodException { methods.add(method); Class<?> rtype = method.getReturnType(); while (Object.class.isAssignableFrom(rtype)) { if (rtype.isAnnotationPresent(Protean.class)) { Protean adm = rtype.getAnnotation(Protean.class); // we must insist that the method supplied must exist and must take no arguments try { method = rtype.getMethod(adm.cellMethod(), new Class[0]); } catch (Exception e) { method = null; } if (method == null) { method = rtype.getMethod("toString", new Class[0]); } } else { method = rtype.getMethod("toString", new Class[0]); } rtype = method.getReturnType(); methods.add(method); if (String.class.isAssignableFrom(rtype)) { break; // Otherwise, the loop might never end. } } }
From source file:net.paslavsky.springrest.SpringAnnotationPreprocessor.java
private Class<?> getResponseType0(Method method) { if (method.isAnnotationPresent(ResponseBody.class)) { return method.getReturnType(); } else {// w w w .j a va 2 s. co m if (method.getReturnType() == ResponseEntity.class) { Type methodGenericReturnType = method.getGenericReturnType(); if (methodGenericReturnType instanceof ParameterizedTypeImpl) { ParameterizedTypeImpl parameterizedType = (ParameterizedTypeImpl) methodGenericReturnType; Type type = parameterizedType.getActualTypeArguments()[0]; return typeToClass(type); } else { // TODO Message to the log: recommendation to use ResponseEntity with generic parameter return byte[].class; } } return Void.class; } }
From source file:ninja.eivind.hotsreplayuploader.ClientTest.java
@Test public void testClientIsMainClass() throws Exception { String className = parse.select("project > properties > mainClass").text(); LOG.info("Loading class " + className); Class<?> mainClass = Class.forName(className); Method main = mainClass.getDeclaredMethod("main", String[].class); int modifiers = main.getModifiers(); Class<?> returnType = main.getReturnType(); assertEquals("Client is mainClass", Client.class, mainClass); assertSame("Main method returns void", returnType, Void.TYPE); assertTrue("Main method is static", Modifier.isStatic(modifiers)); assertTrue("Main method is public", Modifier.isPublic(modifiers)); }
From source file:cn.aposoft.util.spring.ReflectionUtils.java
/** * Get the unique set of declared methods on the leaf class and all * superclasses. Leaf class methods are included first and while traversing * the superclass hierarchy any methods found with signatures matching a * method already included are filtered out. * /*from w w w. j ava2 s . c o m*/ * @param leafClass * the class to introspect */ public static Method[] getUniqueDeclaredMethods(Class<?> leafClass) { final List<Method> methods = new ArrayList<Method>(32); doWithMethods(leafClass, new MethodCallback() { @Override public void doWith(Method method) { boolean knownSignature = false; Method methodBeingOverriddenWithCovariantReturnType = null; for (Method existingMethod : methods) { if (method.getName().equals(existingMethod.getName()) && Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) { // Is this a covariant return type situation? if (existingMethod.getReturnType() != method.getReturnType() && existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) { methodBeingOverriddenWithCovariantReturnType = existingMethod; } else { knownSignature = true; } break; } } if (methodBeingOverriddenWithCovariantReturnType != null) { methods.remove(methodBeingOverriddenWithCovariantReturnType); } if (!knownSignature && !isCglibRenamedMethod(method)) { methods.add(method); } } }); return methods.toArray(new Method[methods.size()]); }
From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResolver.java
/** * Fallback used to load the methods from classloader * * @param clazzname//from w w w . j ava 2 s. c o m * @param variable * @return set with all methods, can be empty */ private Set<MemberLookupResult> getMethodsFromClassLoader(String clazzname, String variable) { final Set<MemberLookupResult> ret = new LinkedHashSet<>(); try { Class clazz = classPath.getClassLoader(true).loadClass(clazzname); for (Method method : clazz.getMethods()) { if (method.getReturnType() != Void.TYPE && GETTER_PATTERN.matcher(method.getName()).matches()) { ret.add(new MemberLookupResult(variable, method.getName(), method.getReturnType().getName())); } } for (Field field : clazz.getFields()) { ret.add(new MemberLookupResult(variable, field.getName(), field.getType().getName())); } } catch (ClassNotFoundException cnfe) { LOGGER.log(Level.FINE, "Could not resolve class " + clazzname + "defined for variable " + variable, cnfe); } return ret; }
From source file:com.socialize.SocializeActionProxy.java
protected boolean isVoidMethod(Method method) { Class<?> returnType = method.getReturnType(); return (returnType == null || returnType.equals(Void.TYPE)); }
From source file:com.sinosoft.one.data.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {/*from w w w . j av a 2 s . c o m*/ this.metaData = statementMetaData; this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (returnType != void.class && returnType != int[].class && returnType != Integer[].class && returnType != Integer.class) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } else { this.batchUpdate = false; if (returnType != void.class && returnType != Boolean.class && !Number.class.isAssignableFrom(returnType)) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } } else { this.batchUpdate = false; } }