public static Set<Field> getOwnFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(); final Set<Field> inheritedFields = getInheritedFields(clazz); final Set<Field> overriddenFields = getHiddenFields(clazz); for (final Field declaredField : declaredFieldSet) { if (!containField(inheritedFields, declaredField) && !containField(overriddenFields, declaredField)) { ret.add(declaredField); } } return ret; }
public static Set<Method> getOwnMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<>(); final Set<Method> inheritedMethods = getInheritedMethods(clazz); final Set<Method> overriddenMethods = getOverriddenMethods(clazz); for (final Method declaredMethod : declaredMethodSet) { if (!containMethod(inheritedMethods, declaredMethod) && !containMethod(overriddenMethods, declaredMethod)) { ret.add(declaredMethod); } } return ret; }
/** * Gets stereo types of the specified class. * * @param clazz the specified class * @return stereo types of the specified class */ public static Set<Class<? extends Annotation>> getStereotypes(final Class<?> clazz) { final Set<Class<? extends Annotation>> ret = new HashSet<>(); final Set<Annotation> annotations = getAnnotations(clazz.getAnnotations(), Stereotype.class); if (annotations.isEmpty()) { return ret; } for (final Annotation annotation : annotations) { ret.add(annotation.annotationType()); } return ret; }
/** * Builds the annotated fields of this annotated type. */ private void initAnnotatedFields() { final Set<Field> hiddenFields = Reflections.getHiddenFields(beanClass); inject(hiddenFields); final Set<Field> inheritedFields = Reflections.getInheritedFields(beanClass); inject(inheritedFields); final Set<Field> ownFields = Reflections.getOwnFields(beanClass); inject(ownFields); }
public <T> Bean<T> createBean(final Class<T> beanClass) { try { return beanManager.getBean(beanClass); } catch (final Exception e) { LOGGER.log(Level.TRACE, "Not found bean [beanClass={0}], so to create it", beanClass); } if (Reflections.isAbstract(beanClass) || Reflections.isInterface(beanClass)) { throw new IllegalStateException("Can't create bean for class [" + beanClass.getName() + "] caused by it is an interface or an abstract class, or it dose not implement any interface"); } final String className = beanClass.getName(); final String name = className.substring(0, 1).toLowerCase() + className.substring(1); final Set<Type> beanTypes = Reflections.getBeanTypes(beanClass); final Set<Class<? extends Annotation>> stereotypes = Reflections.getStereotypes(beanClass); LOGGER.log(Level.DEBUG, "Adding a bean [name={0}, class={1}] to the bean manager", name, beanClass.getName()); final Bean<T> ret = new Bean<T>(beanManager, name, beanClass, beanTypes, stereotypes); beanManager.addBean(ret); for (final Type beanType : beanTypes) { addTypeClassBinding(beanType, beanClass); } return ret; }
private static <T> Set<Type> getInterfaces(final Class<T> interfaceClass) { final Set<Type> ret = new HashSet<>(); final Class<?>[] interfaces = interfaceClass.getInterfaces(); if (0 == interfaces.length) { return ret; } for (final Class<?> i : interfaces) { ret.add(i); ret.addAll(getInterfaces(i)); } return ret; }
public static Set<Field> getHiddenFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Field[] superFields = currentClass.getDeclaredFields(); for (Field superField : superFields) { final Field match = getMatch(declaredFieldSet, superField); if (!Modifier.isPrivate(superField.getModifiers()) && !Modifier.isStatic(superField.getModifiers()) && match != null) { ret.add(match); } } currentClass = currentClass.getSuperclass(); } return ret; }
public static Set<Field> getInheritedFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(declaredFieldSet); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Field[] superFields = currentClass.getDeclaredFields(); for (Field superField : superFields) { if (!Modifier.isPrivate(superField.getModifiers()) && !Modifier.isStatic(superField.getModifiers()) && !containField(ret, superField)) { ret.add(superField); } } currentClass = currentClass.getSuperclass(); } ret.removeAll(declaredFieldSet); return ret; }
public static Set<Method> getInheritedMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<Method>(declaredMethodSet); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Method[] superMethods = currentClass.getDeclaredMethods(); for (Method superMethod : superMethods) { if (!Modifier.isPrivate(superMethod.getModifiers()) && !Modifier.isStatic(superMethod.getModifiers()) && !containMethod(ret, superMethod)) { ret.add(superMethod); } } currentClass = currentClass.getSuperclass(); } ret.removeAll(declaredMethodSet); return ret; }
public <T> Bean<T> createBean(final Class<T> beanClass) { try { return beanManager.getBean(beanClass); } catch (final Exception e) { LOGGER.log(Level.TRACE, "Not found bean [beanClass={0}], so to create it", beanClass); } if (Reflections.isAbstract(beanClass) || Reflections.isInterface(beanClass)) { throw new IllegalStateException("Can't create bean for class [" + beanClass.getName() + "] caused by it is an interface or an abstract class, or it dose not implement any interface"); } final String className = beanClass.getName(); final String name = className.substring(0, 1).toLowerCase() + className.substring(1); final Set<Type> beanTypes = Reflections.getBeanTypes(beanClass); final Set<Class<? extends Annotation>> stereotypes = Reflections.getStereotypes(beanClass); LOGGER.log(Level.DEBUG, "Adding a bean [name={0}, class={1}] to the bean manager", name, beanClass.getName()); final Bean<T> ret = new Bean<T>(beanManager, name, beanClass, beanTypes, stereotypes); beanManager.addBean(ret); for (final Type beanType : beanTypes) { addTypeClassBinding(beanType, beanClass); } return ret; }
/** * Builds the annotated fields of this annotated type. */ private void initAnnotatedFields() { final Set<Field> hiddenFields = Reflections.getHiddenFields(beanClass); inject(hiddenFields); final Set<Field> inheritedFields = Reflections.getInheritedFields(beanClass); inject(inheritedFields); final Set<Field> ownFields = Reflections.getOwnFields(beanClass); inject(ownFields); }
public static <T> Set<Type> getBeanTypes(final Class<T> beanClass) { final Set<Type> ret = new HashSet<>(); ret.add(beanClass); Type genericSuperclass = beanClass; while (genericSuperclass != Object.class) { Type[] genericInterfaces = null; if (genericSuperclass instanceof Class<?>) { genericInterfaces = ((Class<?>) genericSuperclass).getGenericInterfaces(); genericSuperclass = ((Class<?>) genericSuperclass).getGenericSuperclass(); } else if (genericSuperclass instanceof ParameterizedType) { final Type rawType = ((ParameterizedType) genericSuperclass).getRawType(); genericInterfaces = ((Class<?>) rawType).getGenericInterfaces(); genericSuperclass = ((Class<?>) rawType).getGenericSuperclass(); } if (genericSuperclass != Object.class) { ret.add(genericSuperclass); } if (null != genericInterfaces && 0 != genericInterfaces.length) { for (final Type genericInterface : genericInterfaces) { ret.add(genericInterface); ret.addAll(getInterfaces((Class<? super T>) genericInterface)); } } } return ret; }
public static Set<Method> getOverriddenMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<>(); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Method[] superclassMethods = currentClass.getDeclaredMethods(); for (Method superclassMethod : superclassMethods) { final Method match = getMatch(declaredMethodSet, superclassMethod, true); if (match != null) { ret.add(match); } } currentClass = currentClass.getSuperclass(); } return ret; }
public static Set<Field> getInheritedFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(declaredFieldSet); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Field[] superFields = currentClass.getDeclaredFields(); for (Field superField : superFields) { if (!Modifier.isPrivate(superField.getModifiers()) && !Modifier.isStatic(superField.getModifiers()) && !containField(ret, superField)) { ret.add(superField); } } currentClass = currentClass.getSuperclass(); } ret.removeAll(declaredFieldSet); return ret; }
public static Set<Method> getInheritedMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<Method>(declaredMethodSet); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Method[] superMethods = currentClass.getDeclaredMethods(); for (Method superMethod : superMethods) { if (!Modifier.isPrivate(superMethod.getModifiers()) && !Modifier.isStatic(superMethod.getModifiers()) && !containMethod(ret, superMethod)) { ret.add(superMethod); } } currentClass = currentClass.getSuperclass(); } ret.removeAll(declaredMethodSet); return ret; }
public static Set<Field> getOwnFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(); final Set<Field> inheritedFields = getInheritedFields(clazz); final Set<Field> overriddenFields = getHiddenFields(clazz); for (final Field declaredField : declaredFieldSet) { if (!containField(inheritedFields, declaredField) && !containField(overriddenFields, declaredField)) { ret.add(declaredField); } } return ret; }
public static Set<Method> getOwnMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<>(); final Set<Method> inheritedMethods = getInheritedMethods(clazz); final Set<Method> overriddenMethods = getOverriddenMethods(clazz); for (final Method declaredMethod : declaredMethodSet) { if (!containMethod(inheritedMethods, declaredMethod) && !containMethod(overriddenMethods, declaredMethod)) { ret.add(declaredMethod); } } return ret; }
private static <T> Set<Type> getInterfaces(final Class<T> interfaceClass) { final Set<Type> ret = new HashSet<>(); final Class<?>[] interfaces = interfaceClass.getInterfaces(); if (0 == interfaces.length) { return ret; } for (final Class<?> i : interfaces) { ret.add(i); ret.addAll(getInterfaces(i)); } return ret; }
public static Set<Method> getOverriddenMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<>(); Class<?> currentClass = clazz.getSuperclass(); while (currentClass != null) { final Method[] superclassMethods = currentClass.getDeclaredMethods(); for (Method superclassMethod : superclassMethods) { final Method match = getMatch(declaredMethodSet, superclassMethod, true); if (match != null) { ret.add(match); } } currentClass = currentClass.getSuperclass(); } return ret; }
/** * Gets stereo types of the specified class. * * @param clazz the specified class * @return stereo types of the specified class */ public static Set<Class<? extends Annotation>> getStereotypes(final Class<?> clazz) { final Set<Class<? extends Annotation>> ret = new HashSet<>(); final Set<Annotation> annotations = getAnnotations(clazz.getAnnotations(), Stereotype.class); if (annotations.isEmpty()) { return ret; } for (final Annotation annotation : annotations) { ret.add(annotation.annotationType()); } return ret; }