List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:com.trigonic.utils.spring.cmdline.CommandLineMetaData.java
private void populateOptionMethods(Class<?> beanClass) { Class<?> superClass = beanClass.getSuperclass(); if (!superClass.equals(Object.class)) { populateOptionMethods(superClass); }//from w w w . j a va 2 s . co m for (Method method : beanClass.getDeclaredMethods()) { Option option = method.getAnnotation(Option.class); if (option != null) { options.put(option, new OptionPropertyHandler(option, getPropertyForMethod("@Option", option, method), beanClass)); } } }
From source file:com.trigonic.utils.spring.cmdline.CommandLineMetaData.java
private void populateOperandMethods(Class<?> beanClass) { Class<?> superClass = beanClass.getSuperclass(); if (!superClass.equals(Object.class)) { populateOperandMethods(superClass); }// w ww . ja v a2 s.com for (Method method : beanClass.getDeclaredMethods()) { Operand operand = method.getAnnotation(Operand.class); if (operand != null) { operands.put(operand, new OperandPropertyHandler(operand, getPropertyForMethod("@Operand", operand, method), beanClass)); } } }
From source file:net.java.javabuild.ExecuteMojo.java
private void processClass(String className) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, IOException { Class<?> theClass = classLoader.loadClass(className); if (theClass.isAnnotationPresent(Builder.class)) { Object instance = theClass.newInstance(); Method[] methods = theClass.getDeclaredMethods(); for (int j = 0; j < methods.length; j++) { Method method = methods[j]; Execute execute = method.getAnnotation(Execute.class); if (execute != null) { buildPlan.addMethodExecution(execute.phase(), instance, method); }// w ww .ja v a2 s . c om } } }
From source file:org.vaadin.spring.events.internal.ScopedEventBus.java
private void subscribe(final Object listener, final String topic, final boolean includingPropagatingEvents, final boolean weakReference) { logger.trace(// ww w. j a v a2s . c o m "Subscribing listener [{}] to event bus [{}], includingPropagatingEvents = {}, weakReference = {}", listener, this, includingPropagatingEvents, weakReference); final int[] foundMethods = new int[1]; ClassUtils.visitClassHierarchy(new ClassUtils.ClassVisitor() { @Override public void visit(Class<?> clazz) { for (Method m : clazz.getDeclaredMethods()) { if (m.isAnnotationPresent(EventBusListenerMethod.class)) { if (m.getParameterTypes().length == 1) { logger.trace("Found listener method [{}] in listener [{}]", m.getName(), listener); MethodListenerWrapper l = new MethodListenerWrapper(ScopedEventBus.this, listener, topic, includingPropagatingEvents, m); if (weakReference) { listeners.addWithWeakReference(l); } else { listeners.add(l); } foundMethods[0]++; } else { throw new IllegalArgumentException( "Listener method " + m.getName() + " does not have the required signature"); } } } } }, listener.getClass()); if (foundMethods[0] == 0) { logger.warn("Listener [{}] did not contain a single listener method!", listener); } }
From source file:net.erdfelt.android.sdkfido.configer.Configer.java
private void findRawArgsMethod(Class<?> clazz) { for (Method method : clazz.getDeclaredMethods()) { ConfigArguments arg = method.getAnnotation(ConfigArguments.class); if (arg == null) { continue; // skip, not tagged }//from w w w. j a va 2 s . co m int mods = method.getModifiers(); if (!Modifier.isPublic(mods)) { continue; // skip, not public } if (Modifier.isStatic(mods)) { continue; // skip, dont support static } Class<?>[] params = method.getParameterTypes(); if (params == null) { continue; // skip, needs params } if (params.length != 1) { continue; // skip, needs 1 param } if (!(params[0].equals(String.class))) { continue; // skip, param must be String } if (this.rawArgAdder != null) { StringBuilder err = new StringBuilder(); err.append("Not allowed to have multiple @ConfigArguments defined: "); err.append("\n Duplicate found at ").append(clazz.getName()).append("#").append(method.getName()); err.append("\n Original found at ").append(rawArgAdder.getDeclaringClass().getName()).append("#") .append(rawArgAdder.getName()); throw new IllegalStateException(err.toString()); } this.rawArgAdder = method; } }
From source file:com.xpn.xwiki.plugin.XWikiPluginManager.java
public void initPlugin(Object plugin, Class<XWikiPluginInterface> pluginClass, XWikiContext context) throws XWikiException { for (Method method : pluginClass.getDeclaredMethods()) { String name = method.getName(); if (this.functionList.containsKey(name)) { this.functionList.get(name).add((XWikiPluginInterface) plugin); }/*from ww w . j av a 2 s. c om*/ } ((XWikiPluginInterface) plugin).init(context); }
From source file:org.echocat.redprecursor.annotations.utils.AccessAlsoProtectedMembersReflectivePropertyAccessor.java
@Override protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) { Method result = null;/*ww w .j ava 2 s . c o m*/ final PropertyDescriptor propertyDescriptor = findPropertyDescriptorFor(clazz, propertyName); if (propertyDescriptor != null) { result = propertyDescriptor.getWriteMethod(); } if (result == null) { Class<?> current = clazz; final String setterName = "set" + StringUtils.capitalize(propertyName); while (result == null && !Object.class.equals(current)) { final Method[] potentialMethods = current.getDeclaredMethods(); for (Method potentialMethod : potentialMethods) { if (setterName.equals(potentialMethod.getName())) { if (potentialMethod.getParameterTypes().length == 1) { if (!mustBeStatic || Modifier.isStatic(potentialMethod.getModifiers())) { if (!potentialMethod.isAccessible()) { potentialMethod.setAccessible(true); } result = potentialMethod; } } } } current = current.getSuperclass(); } } return result; }
From source file:Main.java
public static void print_class(Class c) { if (c.isInterface()) { System.out.print(Modifier.toString(c.getModifiers()) + " " + typename(c)); } else if (c.getSuperclass() != null) { System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c) + " extends " + typename(c.getSuperclass())); } else {/*from w w w .j a v a 2s. com*/ System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c)); } Class[] interfaces = c.getInterfaces(); if ((interfaces != null) && (interfaces.length > 0)) { if (c.isInterface()) System.out.print(" extends "); else System.out.print(" implements "); for (int i = 0; i < interfaces.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(interfaces[i])); } } System.out.println(" {"); Constructor[] constructors = c.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) print_method_or_constructor(constructors[i]); Field[] fields = c.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { print_field(fields[i]); } Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) print_method_or_constructor(methods[i]); System.out.println("}"); }
From source file:com.github.steveash.typedconfig.resolver.ProxyValueResolver.java
private <T> T tryToMake(Class<T> interfaze, HierarchicalConfiguration configuration) throws NoSuchMethodException { Builder<Method, ValueResolver> builder = ImmutableMap.builder(); for (Method method : interfaze.getDeclaredMethods()) { builder.put(method, makeResolverForMethod(interfaze, method, configuration)); }//from w ww . j a va 2 s. c o m return makeProxyForResolvers(interfaze, builder.build()); }
From source file:com.googlecode.wicketelements.security.AnnotationSecurityCheck.java
private InstantiationSecurityConstraint instantiateInstantiationSecurityConstraint( Class<? extends InstantiationSecurityConstraint> constraintClassParam) { try {/*from ww w.j a v a 2 s . com*/ for (final Method m : constraintClassParam.getDeclaredMethods()) { if (m.isAnnotationPresent(Factory.class)) { try { return (InstantiationSecurityConstraint) 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); } }