public static boolean hasStaticGenerator(Class<?> clazz) { for(Method m : ReflectionUtils.getMethods(clazz)) { if(Modifier.isStatic(m.getModifiers())) { if(clazz.isAssignableFrom(m.getReturnType())) { return true; } } } return false; }
public static Annotation[] getAnnotations(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getAnnotations(clazz)); }
public static Class<?>[] getClasses(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getClasses(clazz)); }
@EvoSuiteExclude public static boolean hasPostConstruct(Class<?> clazz) { if(!postConstructCache.containsKey(clazz)) { Method pc = null; outer : for(Method m : ReflectionUtils.getDeclaredMethods(clazz)) { for(Annotation annotation : ReflectionUtils.getDeclaredAnnotations(m)) { if(annotation instanceof PostConstruct){ pc = m; pc.setAccessible(true); break outer; } } } postConstructCache.put(clazz,pc); //note: it can be null } Method m = postConstructCache.get(clazz); return m != null; } }
public boolean hasField( Class<?> klass) throws IllegalArgumentException{ Inputs.checkNull(klass); String className = klass.getName(); if(!cache.containsKey(className)) { String fieldName = null; outer : for(Field field : ReflectionUtils.getDeclaredFields(klass)) { if(!fieldClass.isAssignableFrom(field.getType()) ) { continue; } for(Annotation annotation : ReflectionUtils.getDeclaredAnnotations(field)) { for(Class<? extends Annotation> valid : annotations) { if(valid.isAssignableFrom(annotation.getClass())) { fieldName = field.getName(); break outer; } } } } cache.put(className,fieldName); //can be null } String f = cache.get(className); return f != null; }
public static Annotation[] getDeclaredAnnotations(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredAnnotations(clazz)); }
public static Constructor<?>[] getDeclaredConstructors(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredConstructors(clazz)); }
public static Method[] getDeclaredMethods(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredMethods(clazz)); }
public static Field[] getDeclaredFields(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredFields(clazz)); }
public static Constructor<?>[] getConstructors(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getConstructors(clazz)); }
public static Class<?>[] getDeclaredClasses(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredClasses(clazz)); }
public Field getField(Class<?> klass) throws IllegalArgumentException { Inputs.checkNull(klass); if(!hasField(klass)) { return null; } // it should never return null Field field = ReflectionUtils.getDeclaredField(klass, cache.get(klass.getName())); assert field != null; return field; }
public static Annotation[] getDeclaredAnnotations(Field field) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getDeclaredAnnotations(field)); }
/** * Replace all the constructors of {@code target} with a constructor (with * same input parameters) of mock subclass {@code mockClass}. * * @param mockClass * @param target * @throws IllegalArgumentException */ private void replaceAllConstructors(Class<?> mockClass, Class<?> target) throws IllegalArgumentException { if (!target.isAssignableFrom(mockClass)) { throw new IllegalArgumentException("Constructor replacement can be done only for subclasses. Class " + mockClass + " is not an instance of " + target); } for (Constructor<?> constructor : ReflectionUtils.getDeclaredConstructors(mockClass)) { String desc = Type.getConstructorDescriptor(constructor); addSpecialReplacementCall(new MethodCallReplacement(target.getCanonicalName().replace('.', '/'), "<init>", desc, Opcodes.INVOKESPECIAL, mockClass.getCanonicalName().replace('.', '/'), "<init>", desc, false, false)); } }
public static Method[] getMethods(Class<?> clazz) throws SecurityException { return sortArrayInPlace(ReflectionUtils.getMethods(clazz)); }
for(Annotation ann : ReflectionUtils.getDeclaredAnnotations(field)){ Class<? extends Annotation> tag = ann.annotationType(); if(InjectionList.isValidForInjection(tag, tagsToCheck)){
for(Annotation annotation : ReflectionUtils.getAnnotations(klass)){ if(annotation.getClass().getName().equals(name)){ return;
for (Method m : ReflectionUtils.getMethods(target)) { if (Modifier.isStatic(m.getModifiers())) { continue;