List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:com.beinformed.framework.osgi.osgitest.annotation.processor.TestAnnotationProcessor.java
/** * Creates a {@code TestSuiteImpl} instance for the given service parameter. * @param service/*from w w w.jav a2 s .c om*/ * the service to create a {@code TestSuite} for. * @return an initialized {@code TestSuiteImpl} instance. */ private TestSuiteImpl createTestSuite(Object service) { TestSuiteImpl testSuite = new TestSuiteImpl(); Class<?> c = service.getClass(); String label = c.getAnnotation(TestSuite.class).label(); testSuite.setLabel(label); Method[] declaredMethods = c.getDeclaredMethods(); for (Method m : declaredMethods) { Annotation[] methodAnnotations = m.getAnnotations(); for (Annotation a : methodAnnotations) { if (a instanceof TestCase) { TestCase testAnnotation = (TestCase) a; TestCaseImpl testCase = new TestCaseImpl(); boolean valid = true; testCase.setIdentifier(testAnnotation.identifier()); testCase.setLabel(testAnnotation.label()); testCase.setInstance(service); testCase.setMethod(m); if (valid) { testSuite.addTestCase(testCase); } } } } return testSuite; }
From source file:net.camelpe.extension.camel.typeconverter.CdiTypeConverterBuilder.java
private void buildTypeConvertersFromClassHierarchy(final Class<?> type, final Set<TypeConverterHolder> alreadyBuiltTypeConverters) { try {/* www. j a v a 2 s . com*/ final Method[] methods = type.getDeclaredMethods(); for (final Method method : methods) { // this may be prone to ClassLoader or packaging problems when // the same class is defined // in two different jars (as is the case sometimes with specs). if (ObjectHelper.hasAnnotation(method, Converter.class, true)) { alreadyBuiltTypeConverters.add(buildTypeConverterFromConverterAnnotatedClass(type, method)); } else if (ObjectHelper.hasAnnotation(method, FallbackConverter.class, true)) { alreadyBuiltTypeConverters .add(buildFallbackTypeConverterFromFallbackConverterAnnotatedClass(type, method)); } } final Class<?> superclass = type.getSuperclass(); if ((superclass != null) && !superclass.equals(Object.class)) { buildTypeConvertersFromClassHierarchy(superclass, alreadyBuiltTypeConverters); } } catch (final NoClassDefFoundError e) { throw new RuntimeException("Failed to load superclass of [" + type.getName() + "]: " + e.getMessage(), e); } }
From source file:org.openmrs.web.dwr.DeprecationCheckTest.java
/** * For the given class, checks if it contains any {@literal @}Deprecated annotation (at method/class level). * @param metadataReader/* w w w . j a v a2s . com*/ * @return true if it finds {@literal @}Deprecated annotation in the class or any of its methods. * @throws ClassNotFoundException */ private boolean doesClassContainDeprecatedAnnotation(MetadataReader metadataReader) throws ClassNotFoundException { try { Class dwrClass = Class.forName(metadataReader.getClassMetadata().getClassName()); if (dwrClass.isAnnotationPresent(Deprecated.class)) { return true; } Method[] methods = dwrClass.getDeclaredMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Deprecated.class)) return true; } } catch (Throwable e) { } return false; }
From source file:de.mpg.imeji.logic.vo.Item.java
/** * Copy all {@link Fields} of an {@link Item} (including {@link Metadata}) to the current * {@link Item}//from w w w. j a v a2 s .c o m * * @param copyFrom */ protected void copyInFields(Item copyFrom) { final Class<? extends Item> copyFromClass = copyFrom.getClass(); final Class<? extends Item> copyToClass = this.getClass(); for (final Method methodFrom : copyFromClass.getDeclaredMethods()) { String setMethodName = null; if (methodFrom.getName().startsWith("get")) { setMethodName = "set" + methodFrom.getName().substring(3, methodFrom.getName().length()); } else if (methodFrom.getName().startsWith("is")) { setMethodName = "set" + methodFrom.getName().substring(2, methodFrom.getName().length()); } if (setMethodName != null) { try { final Method methodTo = copyToClass.getMethod(setMethodName, methodFrom.getReturnType()); try { methodTo.invoke(this, methodFrom.invoke(copyFrom, (Object) null)); } catch (final Exception e) { // LOGGER.error("Could not copy field from method: " + // methodFrom.getName(), e); } } // No setter, do nothing. catch (final NoSuchMethodException e) { } } } }
From source file:ru.jts_dev.gameserver.handlers.HandlerManager.java
protected List<Method> getAnnotatedMethods(Class<? extends ICommandHandler<TCommandType>> handlerClass, Class<? extends Annotation> annotationClass) { ArrayList<Method> methods = new ArrayList<>(); for (Method method : handlerClass.getDeclaredMethods()) { if (method.isAnnotationPresent(annotationClass)) { methods.add(method);// ww w . j a va 2 s . c om } } methods.trimToSize(); return methods; }
From source file:hydrograph.ui.expression.editor.evaluate.EvaluateExpression.java
@SuppressWarnings({ "unchecked" }) String invokeEvaluateFunctionFromJar(String expression, String[] fieldNames, Object[] values) { LOGGER.debug("Evaluating expression from jar"); String output = null;// www . j a v a 2 s.c om Object[] returnObj; expression = ValidateExpressionToolButton.getExpressionText(expression); URLClassLoader child = null; try { returnObj = ValidateExpressionToolButton.getBuildPathForMethodInvocation(); List<URL> urlList = (List<URL>) returnObj[0]; String userFunctionsPropertyFileName = (String) returnObj[2]; child = URLClassLoader.newInstance(urlList.toArray(new URL[urlList.size()])); Thread.currentThread().setContextClassLoader(child); Class<?> class1 = Class.forName( ValidateExpressionToolButton.HYDROGRAPH_ENGINE_EXPRESSION_VALIDATION_API_CLASS, true, child); Method[] methods = class1.getDeclaredMethods(); for (Method method : methods) { if (method.getParameterTypes().length == 4 && StringUtils.equals(method.getName(), EVALUATE_METHOD_OF_EXPRESSION_JAR)) { method.getDeclaringClass().getClassLoader(); output = String.valueOf( method.invoke(null, expression, userFunctionsPropertyFileName, fieldNames, values)); break; } } } catch (JavaModelException | MalformedURLException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException exception) { evaluateDialog.showError(Messages.ERROR_OCCURRED_WHILE_EVALUATING_EXPRESSION); LOGGER.error(Messages.ERROR_OCCURRED_WHILE_EVALUATING_EXPRESSION, exception); } catch (InvocationTargetException | RuntimeException exception) { if (exception.getCause().getCause() != null) { if (StringUtils.equals(exception.getCause().getCause().getClass().getSimpleName(), TARGET_ERROR_EXCEPTION_CLASS)) { evaluateDialog.showError(getTargetException(exception.getCause().getCause().toString())); } else evaluateDialog.showError(exception.getCause().getCause().getMessage()); } else evaluateDialog.showError(exception.getCause().getMessage()); LOGGER.debug("Invalid Expression....", exception); } finally { if (child != null) { try { child.close(); } catch (IOException ioException) { LOGGER.error("Error occurred while closing classloader", ioException); } } } return output; }
From source file:io.cloudslang.lang.runtime.steps.ActionSteps.java
private Method getMethodByName(String className, String methodName) { Class actionClass = getActionClass(className); Method[] methods = actionClass.getDeclaredMethods(); Method actionMethod = null;/* www. j ava 2 s. c o m*/ for (Method m : methods) { if (m.getName().equals(methodName)) { actionMethod = m; } } return actionMethod; }
From source file:com.swtxml.util.reflector.MethodQuery.java
/** * Same as Class.getMethods() but with private methods included. Returns all * methods of <type> and its superclasses, overwritten superclass methods * are not included.//from w w w . j av a 2 s . c om */ private Collection<Method> getAllMethods(Class<?> type) { Map<String, Method> signatureToMethod = new HashMap<String, Method>(); while (type != null) { for (Method method : type.getDeclaredMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; } String signature = getSignature(method); if (!signatureToMethod.containsKey(signature)) { signatureToMethod.put(signature, method); } } type = type.getSuperclass(); } return signatureToMethod.values(); }
From source file:com.mystudy.source.spring.aop.JdkDynamicAopProxy.java
/** * Finds any {@link #equals} or {@link #hashCode} method that may be defined * on the supplied set of interfaces./*from ww w .j a v a 2s . c o m*/ * @param proxiedInterfaces the interfaces to introspect */ private void findDefinedEqualsAndHashCodeMethods(Class<?>[] proxiedInterfaces) { for (Class<?> proxiedInterface : proxiedInterfaces) { Method[] methods = proxiedInterface.getDeclaredMethods(); for (Method method : methods) { if (AopUtils.isEqualsMethod(method)) { this.equalsDefined = true; } if (AopUtils.isHashCodeMethod(method)) { this.hashCodeDefined = true; } if (this.equalsDefined && this.hashCodeDefined) { return; } } } }
From source file:com.googlecode.wicketelements.security.AnnotationSecurityCheck.java
private SecurityConstraint instantiateSecurityConstraint( Class<? extends SecurityConstraint> constraintClassParam) { try {/* ww w .jav a2 s . c o m*/ for (final Method m : constraintClassParam.getDeclaredMethods()) { if (m.isAnnotationPresent(Factory.class)) { try { return (SecurityConstraint) m.invoke(null); } catch (InvocationTargetException ex) { throw new IllegalStateException( "Cannot execute factory method for InstantiationSecurityConstraint: " + constraintClassParam.getName()); } } } return constraintClassParam.newInstance(); } catch (InstantiationException ex) { throw new IllegalStateException("Cannot instantiate security constraint class.", ex); } catch (IllegalAccessException ex) { throw new IllegalStateException("Cannot instantiate security constraint class.", ex); } }