List of usage examples for java.lang.reflect Method getGenericParameterTypes
@Override
public Type[] getGenericParameterTypes()
From source file:cherry.foundation.testtool.invoker.InvokerImpl.java
@Override public String invoke(String beanName, Class<?> beanClass, Method method, List<String> args, List<String> argTypes) { try {/* w ww .ja va 2s. c o m*/ Object targetBean; if (StringUtils.isEmpty(beanName)) { targetBean = appCtx.getBean(beanClass); } else { targetBean = appCtx.getBean(beanName, beanClass); } Type[] paramType = method.getGenericParameterTypes(); Object[] param = new Object[paramType.length]; for (int i = 0; i < paramType.length; i++) { String arg = getOrNull(args, i); String argType = getOrNull(argTypes, i); JavaType javaType; if (StringUtils.isNotEmpty(argType)) { javaType = objectMapper.getTypeFactory().constructFromCanonical(argType); } else { javaType = objectMapper.getTypeFactory().constructType(paramType[i]); } param[i] = resolve(arg, javaType); } Object result = method.invoke(targetBean, param); return convert(result); } catch (InvocationTargetException | IllegalAccessException | IOException ex) { throw new IllegalStateException(ex); } }
From source file:com.qihang.winter.poi.excel.imports.CellValueServer.java
/** * ?cell//from w w w. ja va2 s. c o m * @param dataHanlder * @param object * @param entity * @param excelParams * @param titleString * @return */ public Object getValue(com.qihang.winter.poi.handler.inter.IExcelDataHandler dataHanlder, Object object, SaxReadCellEntity cellEntity, Map<String, ExcelImportEntity> excelParams, String titleString) { ExcelImportEntity entity = excelParams.get(titleString); Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod(); Type[] ts = setMethod.getGenericParameterTypes(); String xclass = ts[0].toString(); Object result = cellEntity.getValue(); result = hanlderSuffix(entity.getSuffix(), result); result = replaceValue(entity.getReplace(), result); result = hanlderValue(dataHanlder, object, result, titleString); return getValueByType(xclass, result, entity); }
From source file:org.xwiki.filter.internal.DefaultFilterDescriptorManager.java
/** * @param elementName the name of the element * @param descriptor the descriptor in which to add the element * @param method the method associated to the element */// w w w .j a v a2s . c om private void addElement(String elementName, FilterDescriptor descriptor, Method method) { String lowerElementName = elementName.toLowerCase(); FilterElementDescriptor element = descriptor.getElements().get(lowerElementName); Type[] methodTypes = method.getGenericParameterTypes(); // TODO: add support for multiple methods if (element == null || methodTypes.length > element.getParameters().length) { FilterElementParameterDescriptor<?>[] parameters = new FilterElementParameterDescriptor<?>[methodTypes.length]; for (int i = 0; i < methodTypes.length; ++i) { parameters[i] = createFilterElementParameter(method, i, methodTypes[i]); } element = new FilterElementDescriptor(elementName, parameters); descriptor.getElements().put(lowerElementName, element); } addMethod(element, method); }
From source file:org.openmrs.module.webservices.rest.web.ConversionUtilTest.java
/** * @verifies resolve TypeVariables to actual type * @see ConversionUtil#convert(Object, java.lang.reflect.Type) *//*from w w w . j a v a 2s . c om*/ @Test public void convert_shouldResolveTypeVariablesToActualType() throws Exception { ChildGenericType_Int i = new ChildGenericType_Int(); Method setter = PropertyUtils.getPropertyDescriptor(i, "value").getWriteMethod(); Object result = ConversionUtil.convert("25", setter.getGenericParameterTypes()[0], i); Assert.assertNotNull(result); Assert.assertEquals(25, result); }
From source file:org.jeecgframework.poi.excel.imports.CellValueServer.java
/** * ?cell/* ww w .j a va2 s . com*/ * * @param dataHanlder * @param object * @param entity * @param excelParams * @param titleString * @return */ public Object getValue(IExcelDataHandler dataHanlder, Object object, SaxReadCellEntity cellEntity, Map<String, ExcelImportEntity> excelParams, String titleString) { ExcelImportEntity entity = excelParams.get(titleString); Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod(); Type[] ts = setMethod.getGenericParameterTypes(); String xclass = ts[0].toString(); Object result = cellEntity.getValue(); result = hanlderSuffix(entity.getSuffix(), result); result = replaceValue(entity.getReplace(), result); result = hanlderValue(dataHanlder, object, result, titleString); return getValueByType(xclass, result, entity); }
From source file:com.qihang.winter.poi.excel.imports.CellValueServer.java
/** * ?cell/* ww w .j a v a 2 s .c om*/ * * @param object * @param excelParams * @param cell * @param titleString */ public Object getValue(com.qihang.winter.poi.handler.inter.IExcelDataHandler dataHanlder, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception { ExcelImportEntity entity = excelParams.get(titleString); String xclass = "class java.lang.Object"; if (!(object instanceof Map)) { Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod(); Type[] ts = setMethod.getGenericParameterTypes(); xclass = ts[0].toString(); } Object result = getCellValue(xclass, cell, entity); if (entity != null) { result = hanlderSuffix(entity.getSuffix(), result); result = replaceValue(entity.getReplace(), result); } result = hanlderValue(dataHanlder, object, result, titleString); return getValueByType(xclass, result, entity); }
From source file:org.apache.hadoop.yarn.webapp.hamlet.HamletGen.java
void genAttributeMethod(String className, Method method, int indent) { String methodName = method.getName(); String attrName = methodName.substring(1).replace('_', '-'); Type[] params = method.getGenericParameterTypes(); echo(indent, "\n", "@Override\n", "public ", className, topMode ? " " : "<T> ", methodName, "("); if (params.length == 0) { puts(0, ") {"); puts(indent, " addAttr(\"", attrName, "\", null);\n", " return this;\n", "}"); } else if (params.length == 1) { String typeName = getTypeName(params[0]); puts(0, typeName, " value) {"); if (typeName.equals("EnumSet<LinkType>")) { puts(indent, " addRelAttr(\"", attrName, "\", value);\n", " return this;\n", "}"); } else if (typeName.equals("EnumSet<Media>")) { puts(indent, " addMediaAttr(\"", attrName, "\", value);\n", " return this;\n", "}"); } else {/*from w ww.j a va 2s .com*/ puts(indent, " addAttr(\"", attrName, "\", value);\n", " return this;\n", "}"); } } else { throwUnhandled(className, method); } }
From source file:self.philbrown.javaQuery.AnimationOptions.java
/** * Constructor. Accepts a JSONObject that maps options to their values. * @param options the JSONObject that contains the options. * @throws JSONException if the JSONObject is malformed * @throws Throwable if another error occurs *///w ww . j av a2 s. c o m public AnimationOptions(JSONObject options) throws JSONException, Throwable { @SuppressWarnings("unchecked") Iterator<String> iterator = options.keys(); while (iterator.hasNext()) { String key = iterator.next(); try { Object value = options.get(key); for (Method m : methods) { if (m.getName().equalsIgnoreCase(key) && m.getGenericParameterTypes().length != 0) { m.invoke(this, value); break; } } } catch (JSONException e) { throw new JSONException("Invalid JSON String"); } catch (Throwable t) { if (key != null) Log.w("AnimationOptions", "Could not set value " + key); else throw new NullPointerException("Iterator reference is null."); } } }
From source file:org.jeecgframework.poi.excel.imports.CellValueServer.java
/** * ?cell// w w w . j a v a 2s . co m * * @param object * @param excelParams * @param cell * @param titleString */ public Object getValue(IExcelDataHandler dataHanlder, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception { ExcelImportEntity entity = excelParams.get(titleString); String xclass = "class java.lang.Object"; if (!(object instanceof Map)) { Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod(); Type[] ts = setMethod.getGenericParameterTypes(); xclass = ts[0].toString(); } Object result = null; try { result = getCellValue(xclass, cell, entity); } catch (Exception e) { // TODO: handle exception Exception f = new Exception("" + titleString); throw f; } if (entity != null) { result = hanlderSuffix(entity.getSuffix(), result); result = replaceValue(entity.getReplace(), result); } result = hanlderValue(dataHanlder, object, result, titleString); return getValueByType(xclass, result, entity); }
From source file:com.google.api.server.spi.config.jsonwriter.JacksonResourceSchemaProvider.java
@Nullable private TypeToken<?> getPropertyType(TypeToken<?> beanType, Method readMethod, Method writeMethod, AnnotatedField field, ApiConfig config) { if (readMethod != null) { // read method's return type is the property type return ApiAnnotationIntrospector.getSchemaType(beanType.resolveType(readMethod.getGenericReturnType()), config);/*from ww w . j ava 2s . c o m*/ } else if (writeMethod != null) { Type[] paramTypes = writeMethod.getGenericParameterTypes(); if (paramTypes.length == 1) { // write method's first parameter type is the property type return ApiAnnotationIntrospector.getSchemaType(beanType.resolveType(paramTypes[0]), config); } } else if (field != null) { return ApiAnnotationIntrospector.getSchemaType(beanType.resolveType(field.getGenericType()), config); } return null; }