/** * Tests if the given {@link ImmutableClassType} matches the class sensor assignment. This * method allows option for non-checking the annotation, which can be helpful with method sensor * assignments as the annotation matching must be also done on the method level. * * @param classSensorAssignment * assignment. * @param classType * classType * @param checkAnnotation * if annotation matching has to be checked on the {@link ClassType} * @return <code>true</code> if class type matches the assignment. */ public boolean matches(AbstractClassSensorAssignment<?> classSensorAssignment, ImmutableClassType classType, boolean checkAnnotation) { if (!matchesClassName(classSensorAssignment, classType)) { return false; } if (checkAnnotation && !matchesAnnotation(classSensorAssignment, classType)) { return false; } return true; }
/** * Checks if the annotation matches the {@link MethodSensorAssignment}. * * @param methodSensorAssignment * {@link MethodSensorAssignment}. * @param methodType * method type to check * @return <code>true</code> if the method parameters matches the {@link MethodSensorAssignment} */ private boolean matchesAnnotation(MethodSensorAssignment methodSensorAssignment, ImmutableMethodType methodType) { // first check if annotation is defined at all if (StringUtils.isEmpty(methodSensorAssignment.getAnnotation())) { return true; } ImmutableTypeWithMethods type = methodType.getImmutableClassOrInterfaceType(); // Safety check for class type // it has to be class type if (!type.isClass()) { return false; } // check if class matches, if yes, then all methods match as well boolean classMatches = super.matchesAnnotation(methodSensorAssignment, type.castToClass()); if (classMatches) { return true; } IMatchPattern pattern = PatternFactory.getPattern(methodSensorAssignment.getAnnotation()); // if not check if the method has annotation return checkAnnotations(methodType.getImmutableAnnotations(), pattern); }