List of usage examples for java.lang.reflect Method getReturnType
public Class<?> getReturnType()
From source file:com.mnxfst.testing.plan.ctx.TSPlanExecutionContext.java
/** * Extracts the {@link Method method representations} for the given path of getter methods * @param varType// w w w.j av a 2 s.c o m * @param getterMethodNames * @param result * @throws TSVariableEvaluationFailedException */ protected void extractGetterMethods(Class<?> varType, String[] getterMethodNames, List<Method> result) throws TSVariableEvaluationFailedException { if (varType != null && getterMethodNames != null && getterMethodNames.length > 0) { String nextGetter = getterMethodNames[0]; try { Method getterMethod = varType.getMethod(nextGetter, null); result.add(getterMethod); extractGetterMethods(getterMethod.getReturnType(), (String[]) ArrayUtils.subarray(getterMethodNames, 1, getterMethodNames.length), result); } catch (NoSuchMethodException e) { throw new TSVariableEvaluationFailedException( "No such getter '" + nextGetter + "' for class " + varType.getName()); } } }
From source file:com.weibo.api.motan.config.AbstractConfig.java
private boolean isConfigMethod(Method method) { boolean checkMethod = (method.getName().startsWith("get") || method.getName().startsWith("is")) && !"isDefault".equals(method.getName()) && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0 && isPrimitive(method.getReturnType()); if (checkMethod) { ConfigDesc configDesc = method.getAnnotation(ConfigDesc.class); if (configDesc != null && configDesc.excluded()) { return false; }/*from w w w .j ava2s . co m*/ } return checkMethod; }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
@SuppressWarnings("unchecked") private <A extends Annotation> void scanMethod(Map<Class<?>, A> result, Method method, Class<A> annotationClass) { final A methodAnnotation = method.getAnnotation(annotationClass); if (methodAnnotation != null) { result.put(resolveClass(method.getReturnType()), methodAnnotation); }//from w w w . j av a 2s . c o m Class<?>[] paramTypes = method.getParameterTypes(); Annotation[][] paramsAnnotations = method.getParameterAnnotations(); for (int i = 0; i < paramTypes.length; i++) { Annotation[] paramAnnotations = paramsAnnotations[i]; A paramAnnotation = methodAnnotation; for (Annotation annotation : paramAnnotations) { if (annotation.annotationType().equals(annotationClass)) { paramAnnotation = (A) annotation; break; } } if (paramAnnotation != null) { result.put(resolveClass(paramTypes[i]), paramAnnotation); } } }
From source file:dk.netdesign.common.osgi.config.Attribute.java
private void checkCardinality(Method method) throws InvalidMethodException { if (cardinalityDef.equals(cardinalityDef.List)) { if (!List.class.isAssignableFrom(method.getReturnType())) { throw new InvalidMethodException("Could not create handler for method " + method.getName() + ". Methods with list cardinality must return a list"); }//from w ww .j ava 2 s .c om if (Collection.class.isAssignableFrom(inputType)) { throw new InvalidMethodException("Could not create handler for method " + method.getName() + ". Methods with list must define a property type"); } } }
From source file:gov.nih.nci.system.webservice.WSQuery.java
private Object copyValue(Object newObject, Object obj, Class objKlass) { try {/*w w w . jav a2s . c om*/ Field[] newObjFields = objKlass.getDeclaredFields(); for (int i = 0; i < newObjFields.length; i++) { Field field = newObjFields[i]; field.setAccessible(true); String fieldName = field.getName(); if (fieldName.equals("serialVersionUID")) continue; // if (field.getType().getName().indexOf("gov.nih.nci") > -1) continue; if (field.getType().isPrimitive() || field.getType().getName().startsWith("java.")) { String getterMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); String setterMethodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); log.debug("WSQuery.copyValue: methodName = " + getterMethodName); Method getterMethod = objKlass.getMethod(getterMethodName); Object value = getterMethod.invoke(obj); Method setterMethod = newObject.getClass().getMethod(setterMethodName, new Class[] { getterMethod.getReturnType() }); setterMethod.invoke(newObject, new Object[] { value }); } } // the superclass objKlass = objKlass.getSuperclass(); while (objKlass != null && !objKlass.equals(Object.class) && !objKlass.isInterface()) { copyValue(newObject, obj, objKlass); objKlass = objKlass.getSuperclass(); } } catch (Exception e) { e.printStackTrace(); log.error("WSQuery.copyValue: WS Error" + e.getMessage()); //System.out.println("WSQuery.copyValue: WS Error"+ e); return null; } return newObject; }
From source file:net.sf.jasperreports.export.PropertiesNoDefaultsConfigurationFactory.java
/** * //from w ww . j a v a2 s . c o m */ protected Object getPropertyValue(Method method, JRPropertiesHolder propertiesHolder) { Object value = null; ExporterProperty exporterProperty = method.getAnnotation(ExporterProperty.class); if (exporterProperty != null) { value = getPropertyValue(jasperReportsContext, propertiesHolder, exporterProperty, method.getReturnType()); } return value; }
From source file:gov.nih.nci.system.web.struts.action.CreateAction.java
private void setParameterValue(Class klass, Object instance, String name, String value) throws NumberFormatException, Exception { if (value != null && value.trim().length() == 0) value = null;// ww w . j a va2s. c o m try { String paramName = name.substring(0, 1).toUpperCase() + name.substring(1); Method[] allMethods = klass.getMethods(); for (Method m : allMethods) { String mname = m.getName(); if (mname.equals("get" + paramName)) { Class type = m.getReturnType(); Class[] argTypes = new Class[] { type }; Method method = null; while (klass != Object.class) { try { Method setMethod = klass.getDeclaredMethod("set" + paramName, argTypes); setMethod.setAccessible(true); Object converted = convertValue(type, value); if (converted != null) setMethod.invoke(instance, converted); break; } catch (NumberFormatException e) { throw e; } catch (NoSuchMethodException ex) { klass = klass.getSuperclass(); } catch (Exception e) { throw e; } } } } } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:com.vityuk.ginger.DefaultLocalization.java
private Callback createCallback(Method method) { String key = createKeyFromMethodName(method.getName()); Class<?> type = method.getReturnType(); if (isConstantMethod(method)) { return getConstantCallback(method, type, key); } else {/*from w w w .ja v a 2 s . c o m*/ return getMessageCallback(method, type, key); } }
From source file:net.firejack.platform.core.validation.GreaterThanProcessor.java
@Override public List<ValidationMessage> validate(Method readMethod, String property, Object value, ValidationMode mode) throws RuleValidationException { GreaterThan greaterThanAnnotation = readMethod.getAnnotation(GreaterThan.class); List<ValidationMessage> messages = null; if (greaterThanAnnotation != null) { messages = new ArrayList<ValidationMessage>(); Class<?> returnType = readMethod.getReturnType(); String parameterName = StringUtils.isBlank(greaterThanAnnotation.parameterName()) ? property : greaterThanAnnotation.parameterName(); if (value != null) { if (returnType.getSuperclass() == Number.class || returnType.isPrimitive()) { boolean checkEquality = greaterThanAnnotation.checkEquality(); Number val = null; if (returnType == Float.class || returnType == float.class) { Float f = (Float) value; if (checkEquality && f < greaterThanAnnotation.floatVal() || !checkEquality && f <= greaterThanAnnotation.floatVal()) { val = greaterThanAnnotation.floatVal(); }/*from ww w.j a va2 s .c om*/ } else if (returnType == Double.class || returnType == double.class) { Double d = (Double) value; if (checkEquality && d < greaterThanAnnotation.doubleVal() || !checkEquality && d <= greaterThanAnnotation.doubleVal()) { val = greaterThanAnnotation.doubleVal(); } } else { Long longValue = ((Number) value).longValue(); Long rangeValue = ((Integer) greaterThanAnnotation.intVal()).longValue(); if (checkEquality && longValue < rangeValue || !checkEquality && longValue <= rangeValue) { val = greaterThanAnnotation.intVal(); } } if (val != null) { messages.add(new ValidationMessage(property, checkEquality ? greaterThanAnnotation.equalityMsgKey() : greaterThanAnnotation.msgKey(), parameterName, val)); } } } } return messages; }
From source file:com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.java
private Class getDatatype(Method method, Field fieldAnno) { Class datatype;/*from www . ja va 2 s .c o m*/ if (followsBeanStandard(method)) { datatype = method.getReturnType(); } else { throw new FixedFormatException(format( "Cannot annotate method %s, with %s annotation. %s annotations must be placed on methods starting with 'get' or 'is'", method.getName(), fieldAnno.getClass().getName(), fieldAnno.getClass().getName())); } return datatype; }