/** * Return all public declared and inherited setter methods and fields * associated with an annotation whose type name is one of those contained * in <code>annotClassNames</code>. * * @param cl the class * @param annotClassNames the annotation class names */ public static AccessibleObject[] getAnnotatedSettersAndFields( Class<?> cl, String... annotClassNames ) { // Setter methods Method[] methods = cl.getMethods(); Method[] ms0 = Filters.filter(methods,new SetterMethodFilter()); Predicate<AnnotatedElement> filter = new AnnotatedElementFilter(annotClassNames); Method[] ms1 = Filters.filter(ms0,filter); // Fields Field[] fields = cl.getFields(); Field[] fs0 = Filters.filter(fields,filter); // Result AccessibleObject[] aos = new AccessibleObject[ ms1.length + fs0.length ]; System.arraycopy(ms1,0,aos,0,ms1.length); System.arraycopy(fs0,0,aos,ms1.length,fs0.length); return aos; }
/** * Return all unannotated methods, declared ones whatever their access * modifier is and inherited public ones, in the specified class. * * @param cl the class * @return the corresponding map of methods indexed by property names * (the property set by the method) */ public static Map<String,Method> getAllUnAnnotatedSetterMethods( Class<?> cl ) { Method[] methods = getAllMethods(cl); Method[] ms0 = Filters.filter(methods,new SetterMethodFilter()); Predicate<AnnotatedElement> filter = new UnAnnotatedElementFilter(); Method[] ms1 = Filters.filter(ms0,filter); // Create the resulting map Map<String,Method> result = new HashMap<>(); for (Method setter : ms1) { String propName = MethodHelper.getSetterPropertyName(setter); result.put(propName,setter); } return result; }
java.lang.reflect.Method[] methods = org.objectweb.fractal.juliac.commons.lang.ClassHelper.getAllMethods(cl); java.util.function.Predicate<java.lang.reflect.AnnotatedElement> filter = new org.objectweb.fractal.juliac.commons.lang.reflect.AnnotatedElementFilter(annotcl.getName()); java.lang.reflect.Method[] ms = org.objectweb.fractal.juliac.commons.util.function.Filters.filter(methods, filter); for (java.lang.reflect.Method method : ms) { T annot = method.getAnnotation(annotcl);
Predicate<AnnotatedElement> filter = new AnnotatedElementFilter(annotcl.getName()); Method[] ms = Filters.filter(methods,filter);
org.oasisopen.sca.annotation.Constructor.class.getName(), "org.osoa.sca.annotations.Constructor"); Constructor<?>[] ctors = Filters.filter(constructors,filter); if( ctors.length > 1 ) { final String msg = Method[] provides = Filters.filter(methods,filter); provides = MethodHelper.removeOverridden(provides); providesMethod = "org.osoa.sca.annotations.Init"), new LifecycleAnnotatedElementFilter(Step.CREATE) ); Method[] inits = Filters.filter(methods,filter); inits = MethodHelper.removeOverridden(inits); initMethod = "org.osoa.sca.annotations.Destroy"), new LifecycleAnnotatedElementFilter(Step.DESTROY) ); Method[] destroys = Filters.filter(methods,filter); destroys = MethodHelper.removeOverridden(destroys); destroyMethod = Method[] starts = Filters.filter(methods,filter); starts = MethodHelper.removeOverridden(starts); startMethod = Method[] stops = Filters.filter(methods,filter); stops = MethodHelper.removeOverridden(stops); stopMethod =