List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:com.weibo.api.motan.protocol.yar.YarProtocolUtil.java
/** * add arguments//from w w w . j av a 2s.c o m * * @param interfaceClass * @param methodName * @param arguments * @return */ private static void addArguments(DefaultRequest request, Class<?> interfaceClass, String methodName, Object[] arguments) { Method targetMethod = null; Method[] methods = interfaceClass.getDeclaredMethods(); for (Method m : methods) { // FIXME parameters may be ambiguous in weak type language, temporarily by limiting the // size of parameters with same method name to avoid. if (m.getName().equalsIgnoreCase(methodName) && m.getParameterTypes().length == arguments.length) { targetMethod = m; break; } } if (targetMethod == null) { throw new MotanServiceException("cann't find request method. method name " + methodName); } request.setParamtersDesc(ReflectUtil.getMethodParamDesc(targetMethod)); if (arguments != null && arguments.length > 0) { Class<?>[] argumentClazz = targetMethod.getParameterTypes(); request.setArguments(adaptParams(targetMethod, arguments, argumentClazz)); } }
From source file:hydrograph.ui.expression.editor.buttons.ValidateExpressionToolButton.java
/** * Complies the given expression using engine's jar from ELT-Project's build path. * /*from www.ja va 2s . c o m*/ * @param expressionStyledText * @param fieldMap * @param componentName * @return DiagnosticCollector * complete diagnosis of given expression * @throws JavaModelException * @throws InvocationTargetException * @throws ClassNotFoundException * @throws MalformedURLException * @throws IllegalAccessException * @throws IllegalArgumentException */ @SuppressWarnings({ "unchecked" }) public static DiagnosticCollector<JavaFileObject> compileExpresion(String expressionStyledText, Map<String, Class<?>> fieldMap, String componentName) throws JavaModelException, InvocationTargetException, ClassNotFoundException, MalformedURLException, IllegalAccessException, IllegalArgumentException { LOGGER.debug("Compiling expression using Java-Compiler"); String expressiontext = getExpressionText(expressionStyledText); DiagnosticCollector<JavaFileObject> diagnostics = null; Object[] returObj = getBuildPathForMethodInvocation(); List<URL> urlList = (List<URL>) returObj[0]; String transfromJarPath = (String) returObj[1]; String propertyFilePath = (String) returObj[2]; URLClassLoader child = URLClassLoader.newInstance(urlList.toArray(new URL[urlList.size()])); Class<?> class1 = Class.forName(HYDROGRAPH_ENGINE_EXPRESSION_VALIDATION_API_CLASS, true, child); Thread.currentThread().setContextClassLoader(child); Method[] methods = class1.getDeclaredMethods(); for (Method method : methods) { if (method.getParameterTypes().length == 4 && StringUtils.equals(method.getName(), COMPILE_METHOD_OF_EXPRESSION_JAR_FOR_TRANSFORM_COMPONENTS) && !StringUtils.equalsIgnoreCase(componentName, hydrograph.ui.common.util.Constants.FILTER)) { method.getDeclaringClass().getClassLoader(); diagnostics = (DiagnosticCollector<JavaFileObject>) method.invoke(null, expressiontext, propertyFilePath, fieldMap, transfromJarPath); break; } else if (method.getParameterTypes().length == 4 && StringUtils.equals(method.getName(), COMPILE_METHOD_OF_EXPRESSION_JAR_FOR_FILTER_COMPONENT) && StringUtils.equalsIgnoreCase(componentName, hydrograph.ui.common.util.Constants.FILTER)) { method.getDeclaringClass().getClassLoader(); diagnostics = (DiagnosticCollector<JavaFileObject>) method.invoke(null, expressiontext, propertyFilePath, fieldMap, transfromJarPath); break; } } try { child.close(); } catch (IOException ioException) { LOGGER.error("Error occurred while closing classloader", ioException); } return diagnostics; }
From source file:com.haulmont.cuba.core.config.ConfigUtil.java
/** * Get the plain get method associated with a configuration interface * method. This is the unparameterized getter associated with the same * field as the specified configuration method. For example, * isDisabled() might be returned for the method * addDisabledListener().//from w w w .ja va 2 s . c om * * @param configInterface The configuration interface. * @param method The method. * @return The plain get method, or else null. */ public static Method getGetMethod(Class<?> configInterface, Method method) { Method getMethod = null; String methodName = method.getName(); Matcher matcher; if ((matcher = ACCESS_RE.matcher(methodName)).matches() || (matcher = LISTENER_RE.matcher(methodName)).matches()) { String prop = matcher.group(2); try { getMethod = configInterface.getMethod("get" + prop); } catch (NoSuchMethodException ex) { Class<?> methodType = getMethodType(method); try { getMethod = configInterface.getMethod("get" + prop, methodType); } catch (NoSuchMethodException ex2) { if (Boolean.TYPE.equals(methodType)) { try { getMethod = configInterface.getMethod("is" + prop); } catch (NoSuchMethodException ex3) { try { getMethod = configInterface.getMethod("is" + prop, methodType); } catch (NoSuchMethodException ex4) { // nothing } } } } } } return getMethod; }
From source file:com.google.gdt.eclipse.designer.ie.util.ReflectionUtils.java
/** * @return signature for given {@link Method}. This signature is not same signature as in JVM or JDT, just * some string that unique identifies method in its {@link Class}. *///from w w w. j a v a 2 s .c om public static String getMethodSignature(Method method) { Assert.isNotNull(method); return getMethodSignature(method.getName(), method.getParameterTypes()); }
From source file:net.sf.morph.reflect.support.MethodHolder.java
/** * Generate a String description of a Method. * @param method//from w w w.ja v a 2s . com * @return String */ protected static String methodToString(Method method) { StringBuffer buffer = new StringBuffer(); buffer.append("<"); buffer.append(method.getReturnType() == null ? "void" : method.getReturnType().getName()); buffer.append("> "); buffer.append(method.getName()); buffer.append("("); Class[] parameterTypes = method.getParameterTypes(); if (parameterTypes != null) { for (int i = 0; i < parameterTypes.length; i++) { buffer.append(parameterTypes[i].getName()); if (i != parameterTypes.length - 1) { buffer.append(","); } } } buffer.append(")"); return buffer.toString(); }
From source file:com.oembedler.moon.graphql.engine.dfs.ResolvableTypeAccessor.java
public static ResolvableTypeAccessor forMethodReturnType(Method method, Class<?> implClass) { ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, implClass); return new ResolvableTypeAccessor(method.getName(), resolvableType, Lists.newArrayList(method.getAnnotations()), implClass); }
From source file:com.facebook.stetho.inspector.MethodDispatcher.java
private static Map<String, MethodDispatchHelper> buildDispatchTable(ObjectMapper objectMapper, Iterable<ChromeDevtoolsDomain> domainHandlers) { Util.throwIfNull(objectMapper); HashMap<String, MethodDispatchHelper> methods = new HashMap<String, MethodDispatchHelper>(); for (ChromeDevtoolsDomain domainHandler : Util.throwIfNull(domainHandlers)) { Class<?> handlerClass = domainHandler.getClass(); String domainName = handlerClass.getSimpleName(); for (Method method : handlerClass.getDeclaredMethods()) { if (isDevtoolsMethod(method)) { MethodDispatchHelper dispatchHelper = new MethodDispatchHelper(objectMapper, domainHandler, method);/*from w w w . j av a 2 s. c om*/ methods.put(domainName + "." + method.getName(), dispatchHelper); } } } return Collections.unmodifiableMap(methods); }
From source file:mondrian.xmla.impl.Olap4jXmlaServlet.java
/** * Returns something that implements {@link OlapConnection} but still * behaves as the wrapper returned by the connection pool. * * <p>In other words we want the "close" method to play nice and do all the * pooling actions while we want all the olap methods to execute directly on * the un-wrapped OlapConnection object. *//*w w w. j a v a 2 s.c om*/ private static OlapConnection createDelegatingOlapConnection(final Connection connection, final OlapConnection olapConnection) { return (OlapConnection) Proxy.newProxyInstance(olapConnection.getClass().getClassLoader(), new Class[] { OlapConnection.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("unwrap".equals(method.getName()) || OlapConnection.class.isAssignableFrom(method.getDeclaringClass())) { return method.invoke(olapConnection, args); } else { return method.invoke(connection, args); } } }); }
From source file:com.linecorp.armeria.server.docs.FunctionInfo.java
static FunctionInfo of(Method method, Map<Class<?>, ? extends TBase<?, ?>> sampleRequests, @Nullable String namespace, Map<String, String> docStrings) throws ClassNotFoundException { requireNonNull(method, "method"); final String methodName = method.getName(); final Class<?> serviceClass = method.getDeclaringClass().getDeclaringClass(); final String serviceName = serviceClass.getName(); final ClassLoader classLoader = serviceClass.getClassLoader(); @SuppressWarnings("unchecked") Class<? extends TBase<?, ?>> argsClass = (Class<? extends TBase<?, ?>>) Class .forName(serviceName + '$' + methodName + "_args", false, classLoader); String sampleJsonRequest;//from w w w. j av a 2 s . co m TBase<?, ?> sampleRequest = sampleRequests.get(argsClass); if (sampleRequest == null) { sampleJsonRequest = ""; } else { TSerializer serializer = new TSerializer(ThriftProtocolFactories.TEXT); try { sampleJsonRequest = serializer.toString(sampleRequest, StandardCharsets.UTF_8.name()); } catch (TException e) { throw new IllegalArgumentException( "Failed to serialize to a memory buffer, this shouldn't ever happen.", e); } } @SuppressWarnings("unchecked") final FunctionInfo function = new FunctionInfo(namespace, methodName, argsClass, (Class<? extends TBase<?, ?>>) Class.forName(serviceName + '$' + methodName + "_result", false, classLoader), (Class<? extends TException>[]) method.getExceptionTypes(), sampleJsonRequest, docStrings); return function; }
From source file:cn.mypandora.util.MyExcelUtil.java
/** * Excel?sheet//from www.j a v a 2 s . c o m * * @param sheet sheet * @param objList ?? * @param objClass ??? * @param fieldNames ?objClassfield?? */ private static void createBody(Sheet sheet, List<?> objList, Class<?> objClass, String fieldNames) { String[] targetMethod = fieldNames.split(","); Method[] ms = objClass.getMethods(); Pattern pattern = Pattern.compile("^get.*"); // objList?sheet for (int objIndex = 0; objIndex < objList.size(); objIndex++) { Object obj = objList.get(objIndex); Row row = sheet.createRow(objIndex + 1); // strBody?sheet for (int strIndex = 0; strIndex < targetMethod.length; strIndex++) { String targetMethodName = targetMethod[strIndex]; // msstrBody for (int i = 0; i < ms.length; i++) { Method srcMethod = ms[i]; if (pattern.matcher(srcMethod.getName()).matches()) { int len = targetMethodName.indexOf(".") < 0 ? targetMethodName.length() : targetMethodName.indexOf("."); if (srcMethod.getName() .equals(("get" + String.valueOf(targetMethodName.substring(0, len).charAt(0)).toUpperCase() + targetMethodName.substring(1, len)))) { Cell cell = row.createCell(strIndex); cell.setCellType(CellType.STRING); try { // if (targetMethodName.contains(".")) { cell.setCellValue(referenceInvoke(targetMethodName, obj)); // } else { cell.setCellValue((srcMethod.invoke(obj)).toString()); } } catch (Exception e) { throw new RuntimeException(e); } } } } } } }