/** * Checks if the given {@link ImmutableInterfaceType} or any of it's super interfaces have an * annotation that matches given annotation pattern. * * @param interfaceType * Type to check. * @param annotationPattern * Pattern to test annotation FQNs with. * @return <code>true</code> if interface or any super-interfaces have annotation that matches * the pattern. */ private boolean checkInterfaceAndSuperInterfaceForAnnotation(ImmutableInterfaceType interfaceType, IMatchPattern annotationPattern) { if (checkAnnotations(interfaceType.getImmutableAnnotations(), annotationPattern)) { return true; } for (ImmutableInterfaceType superInterfaceType : interfaceType.getImmutableSuperInterfaces()) { if (checkInterfaceAndSuperInterfaceForAnnotation(superInterfaceType, 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; }