/** * Checks if the given {@link ImmutableClassType} or any of it's super classes have an * annotation that matches given annotation pattern. * * @param classType * Type to check. * @param annotationPattern * Pattern to test annotation FQNs with. * @return <code>true</code> if class or any super-classes have annotation that matches the * pattern. */ private boolean checkClassAndSuperClassForAnnotation(ImmutableClassType classType, IMatchPattern annotationPattern) { if (checkAnnotations(classType.getImmutableAnnotations(), annotationPattern)) { return true; } for (ImmutableClassType superClassType : classType.getImmutableSuperClasses()) { if (checkClassAndSuperClassForAnnotation(superClassType, annotationPattern)) { return true; } } return false; }
/** * Checks if the {@link AbstractClassSensorAssignment} matches the given * {@link ImmutableClassType} in terms of annotation specified in the * {@link AbstractClassSensorAssignment}. * * @param classSensorAssignment * Assignment defining the annotations. * @param classType * Type to check. * @return <code>true</code> if class or any of it super-classes or realized interfaces are * implementing the specified annotation. */ protected boolean matchesAnnotation(AbstractClassSensorAssignment<?> classSensorAssignment, ImmutableClassType classType) { // only check if we have annotation set if (StringUtils.isEmpty(classSensorAssignment.getAnnotation())) { return true; } IMatchPattern pattern = PatternFactory.getPattern(classSensorAssignment.getAnnotation()); // check class and super classes first if (checkClassAndSuperClassForAnnotation(classType, pattern)) { return true; } // then all interfaces. for (ImmutableAbstractInterfaceType interfaceType : classType.getImmutableRealizedInterfaces()) { if (interfaceType.isInterface() && checkInterfaceAndSuperInterfaceForAnnotation(interfaceType.castToInterface(), pattern)) { return true; } } return false; }