diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/WithAnnotationQuery.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/WithAnnotationQuery.java index d2d30c7..5b54b05 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/WithAnnotationQuery.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/WithAnnotationQuery.java @@ -50,40 +50,13 @@ default boolean matchesAnnotationQuery(SearchMatch match, List> ruleAnnotationElems = getAnnotationQuery().getElements().entrySet(); - for (IMemberValuePair member : memberValuePairs) { - for (Map.Entry ruleAnnotationElem : ruleAnnotationElems) { - if (ruleAnnotationElem.getKey().equals(member.getMemberName())) { - // Member values can be arrays. In this case, lets iterate over it and compare: - if (member.getValue() instanceof Object[]) { - Object[] values = (Object[]) member.getValue(); - // TODO: at the moment we are just toString()ing the values. - // We might want to make this more sophisticated, relying on - // member.getValueKind() to match on specific kinds. - return Arrays.stream(values).anyMatch(v -> Pattern.matches(ruleAnnotationElem.getValue(), v.toString())); - } else { - if (Pattern.matches(ruleAnnotationElem.getValue(), member.getValue().toString())) { - return true; - } - } - } - } - - } - } else { - // No annotation elements, but the annotation itself matches - return true; - } + return doElementsMatch((Annotation) annotation); } else { // The LS doesn't seem to be able to match on annotations within annotations, but - // if the main annotation doesn't match, there might be some annotations inside. + // if the main annotation doesn't match, there might be some annotations inside: for (IMemberValuePair member : annotation.getMemberValuePairs()) { if (member.getValueKind() == IMemberValuePair.K_ANNOTATION) { if (member.getValue() instanceof Object[]) { - System.out.println("Hola"); Object[] objs = (Object[]) member.getValue(); for (int i = 0; i < objs.length; i++) { Annotation innerAnnotation = (Annotation) objs[i]; @@ -165,7 +138,7 @@ private boolean doElementsMatch(Annotation annotation) throws JavaModelException Set> ruleAnnotationElems = getAnnotationQuery().getElements().entrySet(); boolean allElementsMatch = true; boolean oneElementMatched = false; - // TODO: there is a problem with defaults: they don't appear in the memberValuePairs, even when explicitly declared + // TODO: there is a problem with defaults: they don't appear in the memberValuePairs so they cannot be matched for (int i = 0; i < memberValuePairs.length && allElementsMatch; i++) { IMemberValuePair member = memberValuePairs[i]; for (Map.Entry ruleAnnotationElem : ruleAnnotationElems) { @@ -176,7 +149,7 @@ private boolean doElementsMatch(Annotation annotation) throws JavaModelException Object[] values = (Object[]) member.getValue(); // TODO: at the moment we are just toString()ing the values. // We might want to make this more sophisticated, relying on - // member.getValueKind() to match on specific kinds. + // member.getValueKind() to match on specific kinds. This however can match boolean valueMatches = Arrays.stream(values).anyMatch(v -> Pattern.matches(ruleAnnotationElem.getValue(), v.toString())); oneElementMatched |= valueMatches; allElementsMatch &= valueMatches;