Java Code Examples for org.springframework.util.ClassUtils#getAllInterfacesForClassAsSet()

The following examples show how to use org.springframework.util.ClassUtils#getAllInterfacesForClassAsSet() . 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
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
	Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
	if (targetMethod.getDeclaringClass().isInterface()) {
		// Try to build the most specific interface possible for inherited methods to be
		// considered for sub-interface matches as well, in particular for proxy classes.
		// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
		Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
		if (ifcs.size() > 1) {
			try {
				Class<?> compositeInterface = ClassUtils.createCompositeInterface(
						ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
				targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
			}
			catch (IllegalArgumentException ex) {
				// Implemented interfaces probably expose conflicting method signatures...
				// Proceed with original target method.
			}
		}
	}
	return getShadowMatch(targetMethod, method);
}
 
Example 2
Source File: Projection.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Class<?> determineCommonType(@Nullable Class<?> oldType, Class<?> newType) {
	if (oldType == null) {
		return newType;
	}
	if (oldType.isAssignableFrom(newType)) {
		return oldType;
	}
	Class<?> nextType = newType;
	while (nextType != Object.class) {
		if (nextType.isAssignableFrom(oldType)) {
			return nextType;
		}
		nextType = nextType.getSuperclass();
	}
	for (Class<?> nextInterface : ClassUtils.getAllInterfacesForClassAsSet(newType)) {
		if (nextInterface.isAssignableFrom(oldType)) {
			return nextInterface;
		}
	}
	return Object.class;
}
 
Example 3
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
	Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
	if (targetMethod.getDeclaringClass().isInterface()) {
		// Try to build the most specific interface possible for inherited methods to be
		// considered for sub-interface matches as well, in particular for proxy classes.
		// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
		Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
		if (ifcs.size() > 1) {
			try {
				Class<?> compositeInterface = ClassUtils.createCompositeInterface(
						ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
				targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
			}
			catch (IllegalArgumentException ex) {
				// Implemented interfaces probably expose conflicting method signatures...
				// Proceed with original target method.
			}
		}
	}
	return getShadowMatch(targetMethod, method);
}
 
Example 4
Source File: Projection.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Class<?> determineCommonType(@Nullable Class<?> oldType, Class<?> newType) {
	if (oldType == null) {
		return newType;
	}
	if (oldType.isAssignableFrom(newType)) {
		return oldType;
	}
	Class<?> nextType = newType;
	while (nextType != Object.class) {
		if (nextType.isAssignableFrom(oldType)) {
			return nextType;
		}
		nextType = nextType.getSuperclass();
	}
	for (Class<?> nextInterface : ClassUtils.getAllInterfacesForClassAsSet(newType)) {
		if (nextInterface.isAssignableFrom(oldType)) {
			return nextInterface;
		}
	}
	return Object.class;
}
 
Example 5
Source File: AbstractConditionalEnumConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	for (Class<?> interfaceType : ClassUtils.getAllInterfacesForClassAsSet(sourceType.getType())) {
		if (this.conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) {
			return false;
		}
	}
	return true;
}
 
Example 6
Source File: AbstractConditionalEnumConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	for (Class<?> interfaceType : ClassUtils.getAllInterfacesForClassAsSet(sourceType.getType())) {
		if (this.conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) {
			return false;
		}
	}
	return true;
}
 
Example 7
Source File: RaptorInterfaceUtils.java    From raptor with Apache License 2.0 5 votes vote down vote up
public static List<Class<?>> findRaptorInterfaces(Class<?> clazz) {
    List<Class<?>> raptorInterfaces = new ArrayList<>();
    Set<Class<?>> interfaceClasses = ClassUtils.getAllInterfacesForClassAsSet(clazz);
    for (Class<?> interfaceClass : interfaceClasses) {
        Annotation annotation = AnnotationUtils.findAnnotation(interfaceClass, RaptorInterface.class);
        if (annotation != null) {
            raptorInterfaces.add(interfaceClass);
        }
    }
    return raptorInterfaces;
}