Skip to content

Commit

Permalink
Annotation query can have empty pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jmle committed Aug 13, 2024
1 parent 7877f14 commit eaf94e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public RuleEntryParams(final String commandId, final List<Object> arguments) {
this.projectName = (String) obj.get("project");
this.query = (String) obj.get("query");
this.location = Integer.parseInt((String) obj.get("location"));
this.annotationQuery = AnnotationQuery.fromMap((Map<String, Object>) obj.get("annotationQuery"), location);
this.annotationQuery = AnnotationQuery.fromMap(this.query, (Map<String, Object>) obj.get("annotationQuery"), location);
this.analysisMode = (String) obj.get("analysisMode");
this.includedPaths = (ArrayList<String>) obj.get("includedPaths");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ public boolean matchesAnnotation(String annotation) {
}
}

public static AnnotationQuery fromMap(Map<String, Object> query, int location) {
if (query == null) {
public static AnnotationQuery fromMap(String query, Map<String, Object> annotationQuery, int location) {
if (annotationQuery == null) {
return null;
}

String typePattern = (String) query.get("pattern");
boolean isOnAnnotation = location == 4;
String typePattern = isOnAnnotation && annotationQuery.get("pattern").equals("") ? query : (String) annotationQuery.get("pattern");;
final Map<String, String> elements = new HashMap<>();
List<Map<String, String>> mapElements = (List<Map<String, String>>) query.get("elements");
List<Map<String, String>> mapElements = (List<Map<String, String>>) annotationQuery.get("elements");
for (int i = 0; mapElements != null && i < mapElements.size(); i++) {
String key = mapElements.get(i).get("name");
String value = mapElements.get(i).get("value");
elements.put(key, value);
}

return new AnnotationQuery(typePattern, elements, location == 4);
return new AnnotationQuery(typePattern, elements, isOnAnnotation);
}
}

0 comments on commit eaf94e1

Please sign in to comment.