org.springframework.util.ClassUtils#getAllInterfacesForClassAsSet ( )源码实例Demo

下面列出了org.springframework.util.ClassUtils#getAllInterfacesForClassAsSet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
}
 
源代码2 项目: spring-analysis-note   文件: Projection.java
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;
}
 
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);
}
 
源代码4 项目: java-technology-stack   文件: Projection.java
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;
}
 
@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;
}
 
@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;
}
 
源代码7 项目: raptor   文件: RaptorInterfaceUtils.java
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;
}