List of usage examples for java.lang Class getMethods
@CallerSensitive public Method[] getMethods() throws SecurityException
From source file:com.facebook.GraphObjectWrapper.java
private static <T extends GraphObject> void verifyCanProxyClass(Class<T> graphObjectClass) { if (hasClassBeenVerified(graphObjectClass)) { return;// w w w . ja v a2 s .c om } if (!graphObjectClass.isInterface()) { throw new FacebookGraphObjectException( "GraphObjectWrapper can only wrap interfaces, not class: " + graphObjectClass.getName()); } Method[] methods = graphObjectClass.getMethods(); for (Method method : methods) { String methodName = method.getName(); int parameterCount = method.getParameterTypes().length; Class<?> returnType = method.getReturnType(); boolean hasPropertyNameOverride = method.isAnnotationPresent(PropertyName.class); if (method.getDeclaringClass().isAssignableFrom(GraphObject.class)) { // Don't worry about any methods from GraphObject or one of its base classes. continue; } else if (parameterCount == 1 && returnType == Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("set") && methodName.length() > 3) { // Looks like a valid setter continue; } } else if (parameterCount == 0 && returnType != Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("get") && methodName.length() > 3) { // Looks like a valid getter continue; } } throw new FacebookGraphObjectException("GraphObjectWrapper can't proxy method: " + method.toString()); } recordClassHasBeenVerified(graphObjectClass); }
From source file:cn.aposoft.util.spring.ReflectionUtils.java
/** * Attempt to find a {@link Method} on the supplied class with the supplied * name and parameter types. Searches all superclasses up to {@code Object}. * <p>//from ww w . j a va 2 s. c o m * Returns {@code null} if no {@link Method} can be found. * * @param clazz * the class to introspect * @param name * the name of the method * @param paramTypes * the parameter types of the method (may be {@code null} to * indicate any signature) * @return the Method object, or {@code null} if none found */ public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(name, "Method name must not be null"); Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType)); for (Method method : methods) { if (name.equals(method.getName()) && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { return method; } } searchType = searchType.getSuperclass(); } return null; }
From source file:Reflect1.java
public void run(String classes[]) { for (int i = 0; i < classes.length; i++) try {/* w ww.j a v a 2s . c o m*/ Class c = Class.forName(classes[i]); Method methods[] = c.getMethods(); for (int m = 0; m < methods.length; m++) System.out.println(methods[m].toString()); } catch (ClassNotFoundException e) { System.err.println("Error: Class " + classes[i] + " not found!"); } catch (Exception e) { System.err.println(e); } }
From source file:org.psnively.scala.beans.ScalaBeanInfoFactory.java
private boolean supports(Class<?> beanClass) { for (Method method : beanClass.getMethods()) { if (ScalaBeanInfo.isScalaSetter(method)) { return true; }/*from w ww. j ava2 s. com*/ } return false; }
From source file:com.google.code.siren4j.util.ReflectionUtils.java
/** * Retrieve all fields deemed as Exposed, i.e. they are public or have a public accessor method or are marked by an * annotation to be exposed.//from ww w . j a v a2 s.co m * * @param clazz cannot be <code>null</code>. * @return */ public static List<ReflectedInfo> getExposedFieldInfo(final Class<?> clazz) { List<ReflectedInfo> results = null; try { results = fieldInfoCache.get(clazz, new Callable<List<ReflectedInfo>>() { /** * This method is called if the value is not found in the cache. This * is where the real reflection work is done. */ public List<ReflectedInfo> call() throws Exception { List<ReflectedInfo> exposed = new ArrayList<ReflectedInfo>(); for (Method m : clazz.getMethods()) { if (ReflectionUtils.isGetter(m) && !isIgnored(m)) { Field f = getGetterField(m); if (f != null && !isIgnored(f)) { f.setAccessible(true); Siren4JProperty propAnno = f.getAnnotation(Siren4JProperty.class); String effectiveName = propAnno != null ? StringUtils.defaultIfEmpty(propAnno.name(), f.getName()) : f.getName(); Siren4JSubEntity subAnno = f.getAnnotation(Siren4JSubEntity.class); if (subAnno != null && !ArrayUtils.isEmpty(subAnno.rel())) { effectiveName = subAnno.rel().length == 1 ? subAnno.rel()[0] : ArrayUtils.toString(subAnno.rel()); } exposed.add(new ReflectedInfo(f, m, ReflectionUtils.getSetter(clazz, f), effectiveName)); } } } return exposed; } }); } catch (ExecutionException e) { throw new Siren4JRuntimeException(e); } return results; }
From source file:com.haulmont.chile.core.model.utils.MethodsCache.java
public MethodsCache(Class clazz) { final Method[] methods = clazz.getMethods(); for (Method method : methods) { String name = method.getName(); if (name.startsWith("get") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true);//from ww w.j a v a 2 s . c om getters.put(name, method); } if (name.startsWith("is") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(2)); method.setAccessible(true); getters.put(name, method); } else if (name.startsWith("set") && method.getParameterTypes().length == 1) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true); setters.put(name, method); } } }
From source file:org.LexGrid.LexBIG.caCore.applicationservice.resource.RemoteResourceManager.java
private boolean doMethodsContainClientSideSafeAnnotation(Class<?> clazz) { for (Method method : clazz.getMethods()) { if (method.isAnnotationPresent(LgClientSideSafe.class)) { LgClientSideSafe css = method.getAnnotation(LgClientSideSafe.class); if (css.force()) { return true; }/*from w w w . ja v a 2s .co m*/ } } return false; }
From source file:lucee.runtime.reflection.storage.SoftMethodStorage.java
/** * store a class with his methods/*from w ww.j av a 2 s . c om*/ * @param clazz * @return returns stored struct */ private Map<Key, Array> store(Class clazz) { Method[] methods = clazz.getMethods(); Map<Key, Array> methodsMap = new ConcurrentHashMap<Key, Array>(); for (int i = 0; i < methods.length; i++) { storeMethod(methods[i], methodsMap); } map.put(clazz, methodsMap); return methodsMap; }
From source file:io.stallion.reflection.PropertyUtils.java
private static boolean containsSetterForGetter(Class clazz, Method method) { String methodName = method.getName(); String setterName;// ww w. j a v a 2s . com if (methodName.startsWith("get")) setterName = "set" + methodName.substring(3); else if (methodName.startsWith("is")) setterName = "set" + methodName.substring(2); else throw new PropertyException( "method '" + methodName + "' is not a getter, thereof no setter can be found"); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { Method method1 = methods[i]; if (method1.getName().equals(setterName)) return true; } return false; }
From source file:pl.com.bottega.ecommerce.system.saga.impl.SpringSagaRegistry.java
private void registerSagaLoader(Class<?> loaderClass, String beanName) { for (Method method : loaderClass.getMethods()) { if (method.getAnnotation(SagaAction.class) != null || method.getAnnotation(LoadSaga.class) != null) { Class<?>[] params = method.getParameterTypes(); if (params.length == 1) { loadersInterestedIn.put(params[0], beanName); } else { throw new RuntimeException("incorred event hadndler: " + method); }/*w ww .j a v a 2 s. c om*/ } } }