From eaf94e1c04970944a0bd0e34994cc353a566cf34 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Tue, 13 Aug 2024 15:50:18 +0200 Subject: [PATCH] Annotation query can have empty pattern --- .../tackle/core/internal/RuleEntryParams.java | 2 +- .../tackle/core/internal/query/AnnotationQuery.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/RuleEntryParams.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/RuleEntryParams.java index 790cdd6..9dbbf7a 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/RuleEntryParams.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/RuleEntryParams.java @@ -26,7 +26,7 @@ public RuleEntryParams(final String commandId, final List 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) obj.get("annotationQuery"), location); + this.annotationQuery = AnnotationQuery.fromMap(this.query, (Map) obj.get("annotationQuery"), location); this.analysisMode = (String) obj.get("analysisMode"); this.includedPaths = (ArrayList) obj.get("includedPaths"); } diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/query/AnnotationQuery.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/query/AnnotationQuery.java index c6318ee..356a95b 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/query/AnnotationQuery.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/query/AnnotationQuery.java @@ -55,20 +55,21 @@ public boolean matchesAnnotation(String annotation) { } } - public static AnnotationQuery fromMap(Map query, int location) { - if (query == null) { + public static AnnotationQuery fromMap(String query, Map 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 elements = new HashMap<>(); - List> mapElements = (List>) query.get("elements"); + List> mapElements = (List>) 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); } }