List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:com.google.gdt.eclipse.designer.ie.util.ReflectionUtils.java
/** * Returns the {@link Method} defined in {@link Class} (exactly). * /*from ww w. j a v a2 s . c o m*/ * @see #getMethodBySignature(Class, String). */ private static Method getMethodBySignature0(Class<?> clazz, String signatureName, String signature) { for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(signatureName) && getMethodSignature(method).equals(signature)) { method.setAccessible(true); return method; } } // not found return null; }
From source file:org.apache.niolex.commons.reflect.MethodUtil.java
/** * Retrieve all the methods including static methods of this class and it's super classes and * all of it's interfaces.//w w w . java 2 s. c om * * @param clazz the class to be used * @return the list contains all the methods * @throws SecurityException if a security manager is present and the reflection is rejected * @see #getAllMethods(Class) */ public static final List<Method> getAllMethodsIncludeInterfaces(Class<?> clazz) { List<Method> outList = new ArrayList<Method>(); for (Class<?> type : getAllTypes(clazz)) { CollectionUtil.addAll(outList, type.getDeclaredMethods()); } return outList; }
From source file:com.buaa.cfs.utils.ReflectionUtils.java
/** * Gets all the declared methods of a class including methods declared in superclasses. *///from www .j a v a2 s .co m public static List<Method> getDeclaredMethodsIncludingInherited(Class<?> clazz) { List<Method> methods = new ArrayList<Method>(); while (clazz != null) { for (Method method : clazz.getDeclaredMethods()) { methods.add(method); } clazz = clazz.getSuperclass(); } return methods; }
From source file:fi.foyt.foursquare.api.JSONFieldParser.java
/** * Returns list of all methods in a class * /*from w ww . j a va 2 s . co m*/ * @param entityClass class * @return list of all methods in a class */ private static List<Method> getMethods(Class<?> entityClass) { List<Method> result = new ArrayList<Method>(Arrays.asList(entityClass.getDeclaredMethods())); if (!entityClass.getSuperclass().equals(Object.class)) { result.addAll(getMethods(entityClass.getSuperclass())); } return result; }
From source file:com.palantir.ptoss.util.Reflections.java
private static List<ObjectFieldMethod> getParameterlessMethods(Object tupleObject, Class<?> klass) { List<ObjectFieldMethod> methods = Lists.newArrayList(); for (Method method : klass.getDeclaredMethods()) { if (method.getParameterTypes().length == 0) { methods.add(new ObjectFieldMethod(tupleObject, null, method)); }// www.ja v a 2s.c o m } return methods; }
From source file:io.coala.json.JsonUtil.java
public static <T> Class<T> checkRegisteredMembers(final ObjectMapper om, final Class<T> type, final Properties... imports) { for (Method method : type.getDeclaredMethods()) if (method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE && method.getReturnType() != type) { // LOG.trace( // "Checking {}#{}(..) return type: {} @JsonProperty={}", // type.getSimpleName(), method.getName(), // method.getReturnType().getSimpleName(), // method.getAnnotation( JsonProperty.class ) ); checkRegistered(om, method.getReturnType(), imports); }// w w w . j a v a2 s .c om return type; }
From source file:org.apache.axis2.jaxws.server.endpoint.injection.impl.WebServiceContextInjectorImpl.java
/** * Gets all of the fields in this class and the super classes * * @param beanClass/* www .j a v a2s.com*/ * @return */ static private List<Method> getMethods(final Class beanClass) { // This class must remain private due to Java 2 Security concerns List<Method> methods; methods = (List<Method>) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { List<Method> methods = new ArrayList<Method>(); Class cls = beanClass; while (cls != null) { Method[] methodArray = cls.getDeclaredMethods(); for (Method method : methodArray) { methods.add(method); } cls = cls.getSuperclass(); } return methods; } }); return methods; }
From source file:jenkins.plugins.git.MethodUtils.java
/** * <p>Retrieves a method whether or not it's accessible. If no such method * can be found, return {@code null}.</p> * * @param cls The class that will be subjected to the method search * @param methodName The method that we wish to call * @param parameterTypes Argument class types * @return The method//from w w w. ja va2s. c om */ static Method getMethodImpl(final Class<?> cls, final String methodName, final Class<?>... parameterTypes) { Validate.notNull(cls, "Null class not allowed."); Validate.notEmpty(methodName, "Null or blank methodName not allowed."); // fast path, check if directly declared on the class itself for (final Method method : cls.getDeclaredMethods()) { if (methodName.equals(method.getName()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { return method; } } if (!cls.isInterface()) { // ok, now check if directly implemented on a superclass // Java 8: note that super-interface implementations trump default methods for (Class<?> klass = cls.getSuperclass(); klass != null; klass = klass.getSuperclass()) { for (final Method method : klass.getDeclaredMethods()) { if (methodName.equals(method.getName()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { return method; } } } } // ok, now we are looking for an interface method... the most specific one // in the event that we have two unrelated interfaces both declaring a method of the same name // we will give up and say we could not find the method (the logic here is that we are primarily // checking for overrides, in the event of a Java 8 default method, that default only // applies if there is no conflict from an unrelated interface... thus if there are // default methods and they are unrelated then they don't exist... if there are multiple unrelated // abstract methods... well they won't count as a non-abstract implementation Method res = null; for (final Class<?> klass : (List<Class<?>>) ClassUtils.getAllInterfaces(cls)) { for (final Method method : klass.getDeclaredMethods()) { if (methodName.equals(method.getName()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { if (res == null) { res = method; } else { Class<?> c = res.getDeclaringClass(); if (c == klass) { // match, ignore } else if (c.isAssignableFrom(klass)) { // this is a more specific match res = method; } else if (!klass.isAssignableFrom(c)) { // multiple overlapping interfaces declare this method and there is no common ancestor return null; } } } } } return res; }
From source file:es.logongas.ix3.util.ReflectionUtil.java
static public Method getDeclaredMethod(Class clazz, String methodName) { Method[] methods = clazz.getDeclaredMethods(); return findUniqueMethodByName(methods, methodName); }
From source file:com.eucalyptus.upgrade.TestHarness.java
@SuppressWarnings("unchecked") private static Multimap<Class, Method> getTestMethods() throws Exception { final Multimap<Class, Method> testMethods = ArrayListMultimap.create(); List<Class> classList = Lists.newArrayList(); for (File f : new File(System.getProperty("euca.home") + "/usr/share/eucalyptus").listFiles()) { if (f.getName().startsWith("eucalyptus") && f.getName().endsWith(".jar") && !f.getName().matches(".*-ext-.*")) { try { JarFile jar = new JarFile(f); Enumeration<JarEntry> jarList = jar.entries(); for (JarEntry j : Collections.list(jar.entries())) { if (j.getName().matches(".*\\.class.{0,1}")) { String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", ""); try { Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess); for (final Method m : candidate.getDeclaredMethods()) { if (Iterables.any(testAnnotations, new Predicate<Class<? extends Annotation>>() { public boolean apply(Class<? extends Annotation> arg0) { return m.getAnnotation(arg0) != null; } })) { System.out.println("Added test class: " + candidate.getCanonicalName()); testMethods.put(candidate, m); }/* w w w . j av a 2 s.c o m*/ } } catch (ClassNotFoundException e) { } } } jar.close(); } catch (Exception e) { System.out.println(e.getMessage()); continue; } } } return testMethods; }