/** * Describes a class by creating a new instance of {@link ClassDescriptor} * that examines all accessible methods and fields. */ protected ClassDescriptor describeClass(Class type) { return new ClassDescriptor(type, scanAccessible, enhancedProperties, includeFieldsAsProperties, propertyFieldPrefix); }
/** * {@inheritDoc} */ @Override public ClassDescriptor lookup(final Class type) { return cache.get(type, () -> new ClassDescriptor( type, scanAccessible, enhancedProperties, includeFieldsAsProperties, propertyFieldPrefix)); }
public DestroyMethodPoint[] resolve(final Class<?> type) { // lookup methods List<DestroyMethodPoint> list = new ArrayList<>(); ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null); MethodDescriptor[] allMethods = cd.getAllMethodDescriptors(); for (MethodDescriptor methodDescriptor : allMethods) { Method method = methodDescriptor.getMethod(); PetiteDestroyMethod petiteDestroyMethod = method.getAnnotation(PetiteDestroyMethod.class); if (petiteDestroyMethod == null) { continue; } if (method.getParameterTypes().length > 0) { throw new PetiteException("Arguments are not allowed for Petite destroy method: " + type.getName() + '#' + method.getName()); } list.add(new DestroyMethodPoint(method)); } DestroyMethodPoint[] methods; if (list.isEmpty()) { methods = DestroyMethodPoint.EMPTY; } else { methods = list.toArray(new DestroyMethodPoint[0]); } return methods; }
public InitMethodPoint[] resolve(final Class<?> type) { // lookup methods List<InitMethodPoint> list = new ArrayList<>(); ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null); MethodDescriptor[] allMethods = cd.getAllMethodDescriptors(); for (MethodDescriptor methodDescriptor : allMethods) { Method method = methodDescriptor.getMethod(); PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class); if (petiteInitMethod == null) { continue; } if (method.getParameterTypes().length > 0) { throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName()); } int order = petiteInitMethod.order(); list.add(new InitMethodPoint(method, order, petiteInitMethod.invoke())); } InitMethodPoint[] methods; if (list.isEmpty()) { methods = InitMethodPoint.EMPTY; } else { Collections.sort(list); methods = list.toArray(new InitMethodPoint[0]); } return methods; }
/** * {@inheritDoc} */ @Override public ClassDescriptor lookup(final Class type) { return cache.get(type, () -> new ClassDescriptor( type, scanAccessible, enhancedProperties, includeFieldsAsProperties, propertyFieldPrefix)); }
@SuppressWarnings("unchecked") public <T> List<Constructor<T>> listConstructors(Class<T> type) { ClassDescriptor classDescriptor = new ClassDescriptor(type, false, false, true, null); List<Constructor<T>> ctors = new ArrayList<>(); for (CtorDescriptor desc : classDescriptor.getAllCtorDescriptors()) { ctors.add(desc.getConstructor()); } Collections.sort(ctors, new ConstructorComparator()); return ctors; }
@SuppressWarnings("unchecked") public <T> List<Constructor<T>> listConstructors(Class<T> type) { ClassDescriptor classDescriptor = new ClassDescriptor(type, false, false, true, null); List<Constructor<T>> ctors = new ArrayList<>(); for (CtorDescriptor desc : classDescriptor.getAllCtorDescriptors()) { ctors.add(desc.getConstructor()); } Collections.sort(ctors, new ConstructorComparator()); return ctors; }
public DestroyMethodPoint[] resolve(final Class<?> type) { // lookup methods List<DestroyMethodPoint> list = new ArrayList<>(); ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null); MethodDescriptor[] allMethods = cd.getAllMethodDescriptors(); for (MethodDescriptor methodDescriptor : allMethods) { Method method = methodDescriptor.getMethod(); PetiteDestroyMethod petiteDestroyMethod = method.getAnnotation(PetiteDestroyMethod.class); if (petiteDestroyMethod == null) { continue; } if (method.getParameterTypes().length > 0) { throw new PetiteException("Arguments are not allowed for Petite destroy method: " + type.getName() + '#' + method.getName()); } list.add(new DestroyMethodPoint(method)); } DestroyMethodPoint[] methods; if (list.isEmpty()) { methods = DestroyMethodPoint.EMPTY; } else { methods = list.toArray(new DestroyMethodPoint[0]); } return methods; }
public InitMethodPoint[] resolve(Object bean) { Class<?> type = bean.getClass(); InitMethodPoint[] methods = initMethods.get(type); if (methods != null) { return methods; } // lookup methods List<InitMethodPoint> list = new ArrayList<InitMethodPoint>(); ClassDescriptor cd = new ClassDescriptor(type, false); Method[] allMethods = cd.getAllMethods(true); for (Method method : allMethods) { PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class); if (petiteInitMethod == null) { continue; } if (method.getParameterTypes().length > 0) { throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName() + "()."); } int order = petiteInitMethod.order(); list.add(new InitMethodPoint(method, order, petiteInitMethod.firstOff())); } if (list.isEmpty()) { methods = InitMethodPoint.EMPTY; } else { Collections.sort(list); methods = list.toArray(new InitMethodPoint[list.size()]); } initMethods.put(type, methods); return methods; }
public InitMethodPoint[] resolve(final Class<?> type) { // lookup methods List<InitMethodPoint> list = new ArrayList<>(); ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null); MethodDescriptor[] allMethods = cd.getAllMethodDescriptors(); for (MethodDescriptor methodDescriptor : allMethods) { Method method = methodDescriptor.getMethod(); PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class); if (petiteInitMethod == null) { continue; } if (method.getParameterTypes().length > 0) { throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName()); } int order = petiteInitMethod.order(); list.add(new InitMethodPoint(method, order, petiteInitMethod.invoke())); } InitMethodPoint[] methods; if (list.isEmpty()) { methods = InitMethodPoint.EMPTY; } else { Collections.sort(list); methods = list.toArray(new InitMethodPoint[0]); } return methods; }