Skip to content

Commit 90e34a9

Browse files
committed
Update AnnotationReader.java
1 parent 61c6dee commit 90e34a9

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

inject-test/src/main/java/io/avaje/inject/test/AnnotationReader.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.avaje.inject.test;
22

3-
import java.util.Map;
4-
import java.util.TreeMap;
3+
import java.util.Collections;
4+
import java.util.TreeSet;
55
import java.util.regex.Matcher;
66
import java.util.regex.Pattern;
77

88
final class AnnotationReader {
9+
private AnnotationReader() {}
910

1011
private static final Pattern ANNOTATION_TYPE_PATTERN = Pattern.compile("@([\\w.]+)\\.");
12+
1113
private static final Pattern ANNOTATION_TYPE_PATTERN$ = Pattern.compile("@[\\w.]+\\$");
1214

1315
private static final Pattern VALUE_ATTRIBUTE_PATTERN = Pattern.compile("(\\w+)=([\\w.]+)");
@@ -53,22 +55,15 @@ public static String rearrangeAnnotations(String input) {
5355
String[] annotations = annotationContent.split(",\\s*");
5456

5557
// Creating a TreeMap to store annotations sorted by key
56-
Map<String, String> sortedAnnotations = new TreeMap<>();
58+
var sortedkeys = new TreeSet<String>();
5759

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);
6362

6463
// Constructing the sorted annotation string
6564
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(", ");
7267
}
7368
// Removing the trailing comma and space
7469
sortedOutput.setLength(sortedOutput.length() - 2);

0 commit comments

Comments
 (0)