|
1 | 1 | package io.avaje.inject.test;
|
2 | 2 |
|
3 |
| -import java.util.Map; |
4 |
| -import java.util.TreeMap; |
| 3 | +import java.util.Collections; |
| 4 | +import java.util.TreeSet; |
5 | 5 | import java.util.regex.Matcher;
|
6 | 6 | import java.util.regex.Pattern;
|
7 | 7 |
|
8 | 8 | final class AnnotationReader {
|
| 9 | + private AnnotationReader() {} |
9 | 10 |
|
10 | 11 | private static final Pattern ANNOTATION_TYPE_PATTERN = Pattern.compile("@([\\w.]+)\\.");
|
| 12 | + |
11 | 13 | private static final Pattern ANNOTATION_TYPE_PATTERN$ = Pattern.compile("@[\\w.]+\\$");
|
12 | 14 |
|
13 | 15 | private static final Pattern VALUE_ATTRIBUTE_PATTERN = Pattern.compile("(\\w+)=([\\w.]+)");
|
@@ -53,22 +55,15 @@ public static String rearrangeAnnotations(String input) {
|
53 | 55 | String[] annotations = annotationContent.split(",\\s*");
|
54 | 56 |
|
55 | 57 | // Creating a TreeMap to store annotations sorted by key
|
56 |
| - Map<String, String> sortedAnnotations = new TreeMap<>(); |
| 58 | + var sortedkeys = new TreeSet<String>(); |
57 | 59 |
|
58 |
| - // Sorting annotations by key |
59 |
| - for (String annotation : annotations) { |
60 |
| - String[] keyValue = annotation.split("=", 1); |
61 |
| - sortedAnnotations.put(keyValue[0], keyValue.length > 1 ? keyValue[1] : ""); |
62 |
| - } |
| 60 | + // Sorting by key |
| 61 | + Collections.addAll(sortedkeys, annotations); |
63 | 62 |
|
64 | 63 | // Constructing the sorted annotation string
|
65 | 64 | StringBuilder sortedOutput = new StringBuilder(input.substring(0, indexOfParanthesis + 1));
|
66 |
| - for (Map.Entry<String, String> entry : sortedAnnotations.entrySet()) { |
67 |
| - sortedOutput.append(entry.getKey()); |
68 |
| - if (!entry.getValue().isEmpty()) { |
69 |
| - sortedOutput.append("=").append(entry.getValue()); |
70 |
| - } |
71 |
| - sortedOutput.append(", "); |
| 65 | + for (var key : sortedkeys) { |
| 66 | + sortedOutput.append(key).append(", "); |
72 | 67 | }
|
73 | 68 | // Removing the trailing comma and space
|
74 | 69 | sortedOutput.setLength(sortedOutput.length() - 2);
|
|
0 commit comments