org.apache.commons.lang3.reflect.MethodUtils Java Examples
The following examples show how to use
org.apache.commons.lang3.reflect.MethodUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeViewWrapper.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
private void initialiseTreeViewReflection() { // we can't use wrapped.getSkin() because it may be null. // we don't care about the specific instance, we just want the class @SuppressWarnings("PMD.UselessOverridingMethod") Skin<?> dftSkin = new TreeView<Object>() { @Override protected Skin<?> createDefaultSkin() { return super.createDefaultSkin(); } }.createDefaultSkin(); Object flow = getVirtualFlow(dftSkin); if (flow == null) { return; } treeViewFirstVisibleMethod = MethodUtils.getMatchingMethod(flow.getClass(), "getFirstVisibleCell"); treeViewLastVisibleMethod = MethodUtils.getMatchingMethod(flow.getClass(), "getLastVisibleCell"); }
Example #2
Source File: JQueryExtractor.java From htmlunit with Apache License 2.0 | 6 votes |
/** * Main method. * @param args program arguments * @throws Exception s */ public static void main(final String[] args) throws Exception { // final Class<? extends WebDriverTestCase> testClass = JQuery1x8x2Test.class; // final Class<? extends WebDriverTestCase> testClass = JQuery1x11x3Test.class; final Class<? extends WebDriverTestCase> testClass = JQuery3x3x1Test.class; final String version = (String) MethodUtils.invokeExactMethod(testClass.newInstance(), "getVersion"); final File baseDir = new File("src/test/resources/libraries/jQuery/" + version + "/expectations"); for (String browser : new String[] {"CHROME", "FF", "FF68", "FF60", "IE"}) { final File out = new File(baseDir, browser + ".out"); final File results = new File(baseDir, "results." + browser + ".txt"); extractExpectations(out, results); } generateTestCases(testClass, baseDir); }
Example #3
Source File: AppletClassLoader.java From htmlunit with Apache License 2.0 | 6 votes |
/** * The constructor. * @param window the window containing this applet * @param parent the parent class loader for delegation */ public AppletClassLoader(final Window window, final ClassLoader parent) { super(new URL[0], parent); if (window.getWebWindow().getWebClient().getOptions().isUseInsecureSSL()) { if (LOG.isWarnEnabled()) { LOG.warn("AppletClassLoader: your WebClient accepts ssl connections without certificate checking." + " If you like to load applet archives from a SSL/HTTPS connection you have to configure" + " your jvm to accept untrusted certificate for SSL/HTTPS connections also."); } } try { loadOurNetscapeStuff("netscape.javascript.JSException"); final Class<?> jsObjectClass = loadOurNetscapeStuff("netscape.javascript.JSObject"); MethodUtils.invokeExactStaticMethod(jsObjectClass, "setWindow", window); } catch (final Exception e) { LOG.error(e.getMessage(), e); } }
Example #4
Source File: DebugGeneratorsTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void mustNotCrashOnMarker() throws Exception { // Augment signature methodNode.desc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { }); // Initialize variable table VariableTable varTable = new VariableTable(classNode, methodNode); methodNode.instructions = merge( // test marker of each type debugMarker(MarkerType.NONE, "marker1"), debugMarker(MarkerType.CONSTANT, "marker2"), debugMarker(MarkerType.STDOUT, "marker3"), returnVoid() ); // Write to JAR file + load up in classloader -- then execute tests try (URLClassLoader cl = createJarAndLoad(classNode)) { Object obj = cl.loadClass(STUB_CLASSNAME).newInstance(); MethodUtils.invokeMethod(obj, STUB_METHOD_NAME); } }
Example #5
Source File: DebugGeneratorsTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void mustNotCrashOnDebugPrint() throws Exception { // Augment signature methodNode.desc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { }); // Initialize variable table VariableTable varTable = new VariableTable(classNode, methodNode); methodNode.instructions = merge( // test marker of each type debugPrint(loadStringConst("marker1")), returnVoid() ); // Write to JAR file + load up in classloader -- then execute tests try (URLClassLoader cl = createJarAndLoad(classNode)) { Object obj = cl.loadClass(STUB_CLASSNAME).newInstance(); MethodUtils.invokeMethod(obj, STUB_METHOD_NAME); } }
Example #6
Source File: DubboConsumerInvocationProcessor.java From jvm-sandbox-repeater with Apache License 2.0 | 6 votes |
@Override public Object[] assembleRequest(BeforeEvent event) { Object invocation; if (ON_RESPONSE.equals(event.javaMethodName)) { // for record parameter assemble // onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {} invocation = event.argumentArray[2]; } else { // for repeater parameter assemble // invoke(Invoker<?> invoker, Invocation invocation) invocation = event.argumentArray[1]; } try { return (Object[]) MethodUtils.invokeMethod(invocation, "getArguments"); } catch (Exception e) { // ignore LogUtil.error("error occurred when assemble dubbo request", e); } return null; }
Example #7
Source File: AbstractObjectToStringConverter.java From yarg with Apache License 2.0 | 6 votes |
protected Object convertFromStringUnresolved(Class<?> parameterClass, String paramValueStr) { try { Constructor constructor = ConstructorUtils.getAccessibleConstructor(parameterClass, String.class); if (constructor != null) { return constructor.newInstance(paramValueStr); } else { Method valueOf = MethodUtils.getAccessibleMethod(parameterClass, "valueOf", String.class); if (valueOf != null) { return valueOf.invoke(null, paramValueStr); } } } catch (ReflectiveOperationException e) { throw new ReportingException( String.format("Could not instantiate object with class [%s] from [%s] string.", parameterClass.getCanonicalName(), paramValueStr)); } return paramValueStr; }
Example #8
Source File: Javassis.java From TakinRPC with Apache License 2.0 | 6 votes |
/** * * 快捷调用公共方法(性能较差) * * @param host * 宿主对象 * @param name * 方法名 * @param args * 方法参数 * @return 执行结果 * @throws NoSuchMethodException * 如果没有相应的方法 */ public static Object invokePublic(Object host, String name, Object... args) throws NoSuchMethodException { final Class<?> clazz = host instanceof Class ? (Class<?>) host : host.getClass(); args = args == null ? new Object[] { null } : args; Class<?>[] paramTypes = new Class[args.length]; for (int i = 0; i < paramTypes.length; i++) { paramTypes[i] = args[i] == null ? null : args[i].getClass(); } int[] keys = new int[3]; keys[0] = clazz.hashCode(); keys[1] = name.hashCode(); keys[2] = Arrays.hashCode(paramTypes); int key = Arrays.hashCode(keys); Invoker invoker = PUBLIC_INVOKER_MAP.get(key); if (invoker == null) { Method method = MethodUtils.getMatchingAccessibleMethod(clazz, name, paramTypes); if (method == null) { throw new NoSuchMethodException(clazz.getName() + "." + name + argumentTypesToString(paramTypes)); } invoker = newInvoker(method); PUBLIC_INVOKER_MAP.put(key, invoker); } return invoker.invoke(host, args); }
Example #9
Source File: SpliceDefaultCompactor.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * * This only overwrites favored nodes when there are none supplied. I believe in later versions the favoredNodes are * populated for region groups. When this happens, we will pass those favored nodes along. Until then, we attempt to put the local * node in the favored nodes since sometimes Spark Tasks will run compactions remotely. * * @return * @throws IOException */ protected InetSocketAddress[] getFavoredNodes() throws IOException { try { RegionServerServices rsServices = (RegionServerServices) FieldUtils.readField(((HStore) store).getHRegion(), "rsServices", true); InetSocketAddress[] returnAddresses = (InetSocketAddress[]) MethodUtils.invokeMethod(rsServices,"getFavoredNodesForRegion",store.getRegionInfo().getEncodedName()); if ( (returnAddresses == null || returnAddresses.length == 0) && store.getFileSystem() instanceof HFileSystem && ((HFileSystem)store.getFileSystem()).getBackingFs() instanceof DistributedFileSystem) { String[] txvr = conf.get("dfs.datanode.address").split(":"); // hack if (txvr.length == 2) { returnAddresses = new InetSocketAddress[1]; returnAddresses[0] = new InetSocketAddress(hostName, Integer.parseInt(txvr[1])); } else { SpliceLogUtils.warn(LOG,"dfs.datanode.address is expected to have form hostname:port but is %s",txvr); } } return returnAddresses; } catch (Exception e) { SpliceLogUtils.error(LOG,e); throw new IOException(e); } }
Example #10
Source File: ApiBuilder.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private List<Class<?>> scanJaxrsClass() throws Exception { try (ScanResult scanResult = new ClassGraph().disableJarScanning().enableAnnotationInfo().scan()) { SetUniqueList<Class<?>> classes = SetUniqueList.setUniqueList(new ArrayList<Class<?>>()); for (ClassInfo info : scanResult.getClassesWithAnnotation(ApplicationPath.class.getName())) { Class<?> applicationPathClass = ClassUtils.getClass(info.getName()); for (Class<?> o : (Set<Class<?>>) MethodUtils.invokeMethod(applicationPathClass.newInstance(), "getClasses")) { Path path = o.getAnnotation(Path.class); JaxrsDescribe jaxrsDescribe = o.getAnnotation(JaxrsDescribe.class); if (null != path && null != jaxrsDescribe) { classes.add(o); } } } return classes; } }
Example #11
Source File: SearchUtilsTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void mustFindLocalVariableNodeForInstruction() { MethodNode methodNode = findMethodsWithName(classNode.methods, "localVariablesTest").get(0); List<AbstractInsnNode> insns = findInvocationsOf(methodNode.instructions, MethodUtils.getAccessibleMethod(PrintStream.class, "println", String.class)); AbstractInsnNode insnNode = insns.get(0); LocalVariableNode lvn0 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 0); LocalVariableNode lvn1 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 1); LocalVariableNode lvn2 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 2); assertEquals(lvn0.name, "this"); assertEquals(lvn1.name, "val1"); assertEquals(lvn2.name, "val2"); }
Example #12
Source File: MethodUtil.java From feilong-core with Apache License 2.0 | 6 votes |
/** * Do with no such method exception. * * @param <T> * the generic type * @param klass * the klass * @param staticMethodName * the static method name * @param args * the args * @param parameterTypes * the parameter types * @return the t * @throws ReflectException * the reflect exception * @since 1.11.5 */ @SuppressWarnings("unchecked") private static <T> T doWithNoSuchMethodException(Class<?> klass,String staticMethodName,Object[] args,Class<?>[] parameterTypes){ try{ Method matchingMethod = MethodUtils.getMatchingMethod(klass, staticMethodName, parameterTypes); if (null == matchingMethod){ throw new NoSuchMethodException("No such method:[" + staticMethodName + "()] on class: " + klass.getName()); } //--------------------------------------------------------------- if (LOGGER.isDebugEnabled()){ LOGGER.debug("bingo,from class:[{}],find name [{}] method", klass.getSimpleName(), staticMethodName); } //--------------------------------------------------------------- matchingMethod.setAccessible(true); return (T) matchingMethod.invoke(null, args); }catch (Exception e){ throw new ReflectException(buildMessage(klass, staticMethodName, args, parameterTypes), e); } }
Example #13
Source File: AeroRemoteApiController.java From webanno with Apache License 2.0 | 6 votes |
private static void forceOverwriteSofa(CAS aCas, String aValue) { try { Sofa sofa = (Sofa) aCas.getSofa(); MethodHandle _FH_sofaString = (MethodHandle) FieldUtils.readField(sofa, "_FH_sofaString", true); Method method = MethodUtils.getMatchingMethod(Sofa.class, "wrapGetIntCatchException", MethodHandle.class); int adjOffset; try { method.setAccessible(true); adjOffset = (int) method.invoke(null, _FH_sofaString); } finally { method.setAccessible(false); } sofa._setStringValueNcWj(adjOffset, aValue); } catch (Exception e) { throw new IllegalStateException("Cannot force-update SofA string", e); } }
Example #14
Source File: DeclarativeColumnGenerator.java From cuba with Apache License 2.0 | 6 votes |
@Nullable protected Method findGeneratorMethod(Class cls, String methodName) { Method exactMethod = MethodUtils.getAccessibleMethod(cls, methodName, Entity.class); if (exactMethod != null) { return exactMethod; } // search through all methods Method[] methods = cls.getMethods(); for (Method availableMethod : methods) { if (availableMethod.getName().equals(methodName)) { if (availableMethod.getParameterCount() == 1 && Component.class.isAssignableFrom(availableMethod.getReturnType())) { if (Entity.class.isAssignableFrom(availableMethod.getParameterTypes()[0])) { // get accessible version of method return MethodUtils.getAccessibleMethod(availableMethod); } } } } return null; }
Example #15
Source File: LinkCellClickListener.java From cuba with Apache License 2.0 | 6 votes |
protected Method findLinkInvokeMethod(Class cls, String methodName) { Method exactMethod = MethodUtils.getAccessibleMethod(cls, methodName, Entity.class, String.class); if (exactMethod != null) { return exactMethod; } // search through all methods Method[] methods = cls.getMethods(); for (Method availableMethod : methods) { if (availableMethod.getName().equals(methodName)) { if (availableMethod.getParameterCount() == 2 && Void.TYPE.equals(availableMethod.getReturnType())) { if (Entity.class.isAssignableFrom(availableMethod.getParameterTypes()[0]) && String.class == availableMethod.getParameterTypes()[1]) { // get accessible version of method return MethodUtils.getAccessibleMethod(availableMethod); } } } } return null; }
Example #16
Source File: PrebidServerAdapterTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
private JSONObject getPostDataHelper(AdType adType, @Nullable Map<String, Set<String>> contextDataDictionary, @Nullable Set<String> contextKeywordsSet, @Nullable AdSize minSizePerc, @Nullable VideoBaseAdUnit.Parameters parameters) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { PrebidMobile.setApplicationContext(activity.getApplicationContext()); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid())); DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class); PrebidServerAdapter adapter = new PrebidServerAdapter(); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("67890", adType, sizes, contextDataDictionary, contextKeywordsSet, minSizePerc, parameters); String uuid = UUID.randomUUID().toString(); adapter.requestDemand(requestParams, mockListener, uuid); @SuppressWarnings("unchecked") ArrayList<PrebidServerAdapter.ServerConnector> connectors = (ArrayList<PrebidServerAdapter.ServerConnector>) FieldUtils.readDeclaredField(adapter, "serverConnectors", true); PrebidServerAdapter.ServerConnector connector = connectors.get(0); JSONObject postData = (JSONObject) MethodUtils.invokeMethod(connector, true, "getPostData"); return postData; }
Example #17
Source File: CommonsExample.java From pragmatic-java-engineer with GNU General Public License v3.0 | 6 votes |
public static void lang() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { String[] strs = new String[]{"1", "4", "2"}; ArrayUtils.addAll(strs, "3"); RandomUtils.nextInt(0, 10); RandomStringUtils.random(3); StopWatch stopWatch = new StopWatch(); stopWatch.start(); stopWatch.split(); stopWatch.getSplitTime(); stopWatch.suspend(); stopWatch.resume(); stopWatch.stop(); stopWatch.getTime(); long max = NumberUtils.max(new long[]{1, 5, 10}); //计算数组最大值 MethodUtils.invokeStaticMethod(StringUtils.class, "isNotBlank", "test"); //调用静态方法 MethodUtils.invokeMethod(StringUtils.class, "isNotBlank", "test"); //调用静态方法 DateUtils.truncate(new Date(), Calendar.HOUR); DateFormatUtils.format(new Date(), "yyyyMMdd"); }
Example #18
Source File: ModelPersistorImpl.java From sling-whiteboard with Apache License 2.0 | 6 votes |
private static String getJcrPath(Object obj) { String path = (String) getAnnotatedValue(obj, Path.class); if (path != null) { return path; } try { Method pathGetter = MethodUtils.getMatchingMethod(obj.getClass(), "getPath"); if (pathGetter != null) { return (String) MethodUtils.invokeMethod(obj, "getPath"); } Field pathField = FieldUtils.getDeclaredField(obj.getClass(), "path"); if (pathField != null) { return (String) FieldUtils.readField(pathField, obj, true); } } catch (IllegalArgumentException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { LOGGER.warn("exception caught", ex); } LOGGER.warn("Object of type {} does NOT contain a Path attribute or a path property - multiple instances may conflict", obj.getClass()); return null; }
Example #19
Source File: Describe.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private List<Class<?>> scanJaxrsClass(String name) throws Exception { // String pack = "com." + name.replaceAll("_", "."); String pack = ""; if (StringUtils.startsWith(name, "o2_")) { pack = name.replaceAll("_", "."); } else { pack = "com." + name.replaceAll("_", "."); } try (ScanResult scanResult = new ClassGraph().whitelistPackages(pack).enableAllInfo().scan()) { SetUniqueList<Class<?>> classes = SetUniqueList.setUniqueList(new ArrayList<Class<?>>()); for (ClassInfo info : scanResult.getClassesWithAnnotation(ApplicationPath.class.getName())) { Class<?> applicationPathClass = ClassUtils.getClass(info.getName()); for (Class<?> o : (Set<Class<?>>) MethodUtils.invokeMethod(applicationPathClass.newInstance(), "getClasses")) { Path path = o.getAnnotation(Path.class); JaxrsDescribe jaxrsDescribe = o.getAnnotation(JaxrsDescribe.class); if (null != path && null != jaxrsDescribe) { classes.add(o); } } } return classes; } }
Example #20
Source File: DescribeBuilder.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private List<Class<?>> scanJaxrsClass() throws Exception { try (ScanResult scanResult = new ClassGraph().disableJarScanning().enableAnnotationInfo().scan()) { SetUniqueList<Class<?>> classes = SetUniqueList.setUniqueList(new ArrayList<Class<?>>()); for (ClassInfo info : scanResult.getClassesWithAnnotation(ApplicationPath.class.getName())) { Class<?> applicationPathClass = ClassUtils.getClass(info.getName()); for (Class<?> o : (Set<Class<?>>) MethodUtils.invokeMethod(applicationPathClass.newInstance(), "getClasses")) { Path path = o.getAnnotation(Path.class); JaxrsDescribe jaxrsDescribe = o.getAnnotation(JaxrsDescribe.class); if (null != path && null != jaxrsDescribe) { classes.add(o); } } } return classes; } }
Example #21
Source File: EnumUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
public static <E extends Enum<E>> String getStr(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ { try { return (String) MethodUtils.invokeExactMethod(type, "getStr", new Object[]{}); } catch (Exception e) { return null; } }
Example #22
Source File: MenuItemCommands.java From cuba with Apache License 2.0 | 5 votes |
@Override public void run() { userActionsLog.trace("Menu item {} triggered", item.getId()); StopWatch sw = createStopWatch(item); Object beanInstance = beanLocator.get(bean); try { Method methodWithParams = MethodUtils.getAccessibleMethod(beanInstance.getClass(), beanMethod, Map.class); if (methodWithParams != null) { methodWithParams.invoke(beanInstance, params); return; } Method methodWithScreen = MethodUtils.getAccessibleMethod(beanInstance.getClass(), beanMethod, FrameOwner.class); if (methodWithScreen != null) { methodWithScreen.invoke(beanInstance, origin); return; } MethodUtils.invokeMethod(beanInstance, beanMethod, (Object[]) null); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Unable to execute bean method", e); } sw.stop(); }
Example #23
Source File: EnumUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
/** Calls the value() method of the given enum. */ public static <E extends Enum<E>> String value(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ { try { return (String) MethodUtils.invokeExactMethod(type, "value", new Object[]{}); } catch (Exception e) { return null; } }
Example #24
Source File: WekaUtil.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
public static Classifier cloneClassifier(final Classifier c) throws Exception { Method cloneMethod = MethodUtils.getAccessibleMethod(c.getClass(), "clone"); if (cloneMethod != null) { return (Classifier) cloneMethod.invoke(c); } return AbstractClassifier.makeCopy(c); }
Example #25
Source File: EventUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } else { return MethodUtils.invokeMethod(target, methodName); } } return null; }
Example #26
Source File: EnumUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
/** Calls the fromValue(String v) method of the given enum. If the value was not found, null is returned instead of an IllegalArgumentException. */ @SuppressWarnings("unchecked") public static <E extends Enum<E>> E fromValue(Class<E> enumClass, String value) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ { try { return (E) MethodUtils.invokeExactStaticMethod(enumClass, "fromValue", new Object[]{value}); } catch (Exception e) { return null; // // if illegal argument given -> return null! // if (e.getCause() instanceof IllegalArgumentException) { // return null; // } else // throw e; } }
Example #27
Source File: EnumUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
/** Calls the fromString(String v) method of the given enum. If the value was not found, null is returned instead of an IllegalArgumentException. */ @SuppressWarnings("unchecked") public static <E extends Enum<E>> E fromString(Class<E> enumClass, String value) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ { try { return (E) MethodUtils.invokeExactStaticMethod(enumClass, "fromString", new Object[]{value}); } catch (Exception e) { return null; } }
Example #28
Source File: ReflectionUtil.java From glitr with MIT License | 5 votes |
/** * Returns {@code Optional} instance by reflect and query method or field for the specified {@code Annotation}. * This method support {@code Annotation} declared in superclass/interfaces * * @param declaringClass - the {@link Class} to reflect * @param method - the {@link Method} to query * @param aClass - the {@link Annotation} class to check * @param <A> - annotation type * @return - {@code Optional} contains annotation, or empty if not found */ public static <A extends Annotation> Optional<A> getAnnotationOfMethodOrField(Class declaringClass, Method method, Class<A> aClass) { A annotation = MethodUtils.getAnnotation(method, aClass, true, true); if (annotation == null) { String fieldName = ReflectionUtil.sanitizeMethodName(method.getName()); Field field = FieldUtils.getField(declaringClass, fieldName, true); if (field != null) { annotation = field.getAnnotation(aClass); } } return Optional.ofNullable(annotation); }
Example #29
Source File: EumnUtil.java From HA-DB with BSD 3-Clause "New" or "Revised" License | 5 votes |
static <T> String getInvokeValue(T t, String methodName) { try { Method method = MethodUtils.getAccessibleMethod(t.getClass(), methodName); String text = TransformUtils.toString(method.invoke(t)); return text; } catch (Exception e) { return null; } }
Example #30
Source File: EventUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } else { return MethodUtils.invokeMethod(target, methodName); } } return null; }