Java Code Examples for org.springframework.util.ReflectionUtils#getDeclaredMethods()

The following examples show how to use org.springframework.util.ReflectionUtils#getDeclaredMethods() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public boolean hasAnnotatedMethods(String annotationName) {
	if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) {
		try {
			Method[] methods = ReflectionUtils.getDeclaredMethods(getIntrospectedClass());
			for (Method method : methods) {
				if (isAnnotatedMethod(method, annotationName)) {
					return true;
				}
			}
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
		}
	}
	return false;
}
 
Example 2
@Override
@SuppressWarnings("deprecation")
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
	Set<MethodMetadata> annotatedMethods = null;
	if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) {
		try {
			Method[] methods = ReflectionUtils.getDeclaredMethods(getIntrospectedClass());
			for (Method method : methods) {
				if (isAnnotatedMethod(method, annotationName)) {
					if (annotatedMethods == null) {
						annotatedMethods = new LinkedHashSet<>(4);
					}
					annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
				}
			}
		}
		catch (Throwable ex) {
			throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
		}
	}
	return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
}
 
Example 3
private static <T> boolean anyFinalMethods(T object, Class<T> iface) {
	try {
		for (Method method : ReflectionUtils.getDeclaredMethods(iface)) {
			Method m = ReflectionUtils.findMethod(object.getClass(), method.getName(),
					method.getParameterTypes());
			if (m != null && Modifier.isFinal(m.getModifiers())) {
				return true;
			}
		}
	}
	catch (IllegalAccessError er) {
		if (log.isDebugEnabled()) {
			log.debug("Error occurred while trying to access methods", er);
		}
		return false;
	}
	return false;
}
 
Example 4
private static <T> boolean anyFinalMethods(T object, Class<T> iface) {
    try {
        for (Method method : ReflectionUtils.getDeclaredMethods(iface)) {
            Method m = ReflectionUtils.findMethod(object.getClass(), method.getName(),
                    method.getParameterTypes());
            if (m != null && Modifier.isFinal(m.getModifiers())) {
                return true;
            }
        }
    } catch (IllegalAccessError er) {
        if (log.isDebugEnabled()) {
            log.debug("Error occurred while trying to access methods", er);
        }
        return false;
    }
    return false;
}
 
Example 5
private static <C> Method[] getBaseTypeMethods(
		C context, Class<?> baseType, @Nullable BiPredicate<C, Class<?>> classFilter) {

	if (baseType == Object.class || hasPlainJavaAnnotationsOnly(baseType) ||
			isFiltered(baseType, context, classFilter)) {
		return NO_METHODS;
	}

	Method[] methods = baseTypeMethodsCache.get(baseType);
	if (methods == null) {
		boolean isInterface = baseType.isInterface();
		methods = isInterface ? baseType.getMethods() : ReflectionUtils.getDeclaredMethods(baseType);
		int cleared = 0;
		for (int i = 0; i < methods.length; i++) {
			if ((!isInterface && Modifier.isPrivate(methods[i].getModifiers())) ||
					hasPlainJavaAnnotationsOnly(methods[i]) ||
					getDeclaredAnnotations(methods[i], false).length == 0) {
				methods[i] = null;
				cleared++;
			}
		}
		if (cleared == methods.length) {
			methods = NO_METHODS;
		}
		baseTypeMethodsCache.put(baseType, methods);
	}
	return methods;
}