Skip to content

Commit 6f1a20e

Browse files
committed
start
1 parent 2cf2362 commit 6f1a20e

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/TypeAnnotationReader.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.lang.model.element.AnnotationMirror;
99
import javax.lang.model.element.TypeElement;
1010
import javax.lang.model.type.DeclaredType;
11+
import javax.lang.model.util.ElementFilter;
1112

1213
/**
1314
* Read the annotations on the type.
@@ -38,9 +39,19 @@ void process() {
3839
for (AnnotationMirror annotationMirror : beanType.getAnnotationMirrors()) {
3940
DeclaredType annotationType = annotationMirror.getAnnotationType();
4041
String annType = annotationType.toString();
41-
42+
4243
if (QualifierPrism.isPresent(annotationType.asElement())) {
43-
qualifierName = Util.shortName(annType).toLowerCase();
44+
45+
final var shortName = Util.shortName(annotationType.toString());
46+
var fqn = APContext.asTypeElement(annotationType).getQualifiedName().toString();
47+
qualifierName =
48+
annotationMirror
49+
.toString()
50+
.substring(1)
51+
.replace(fqn, shortName)
52+
.replace("\"", "\\\"")
53+
.toLowerCase();
54+
4455
} else if (annType.indexOf('.') == -1) {
4556
logWarn("skip when no package on annotation " + annType);
4657
} else if (IncludeAnnotations.include(annType)) {

inject-generator/src/main/java/io/avaje/inject/generator/Util.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.lang.model.element.Element;
99
import javax.lang.model.type.DeclaredType;
1010
import javax.lang.model.type.TypeMirror;
11+
import javax.lang.model.util.ElementFilter;
1112

1213
final class Util {
1314
// whitespace not in quotes
@@ -250,7 +251,15 @@ public static String getNamed(Element p) {
250251
final DeclaredType annotationType = annotationMirror.getAnnotationType();
251252
final var hasQualifier = QualifierPrism.isPresent(annotationType.asElement());
252253
if (hasQualifier) {
253-
return Util.shortName(annotationType.toString()).toLowerCase();
254+
final var shortName = Util.shortName(annotationType.toString());
255+
256+
var fqn = APContext.asTypeElement(annotationType).getQualifiedName().toString();
257+
return annotationMirror
258+
.toString()
259+
.substring(1)
260+
.replace(fqn, shortName)
261+
.replace("\"", "\\\"")
262+
.toLowerCase();
254263
}
255264
}
256265
return null;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ private String name(Field field) {
119119
return named.value().toLowerCase();
120120
}
121121
for (Annotation annotation : field.getAnnotations()) {
122-
for (Annotation metaAnnotation : annotation.annotationType().getAnnotations()) {
122+
final var annotationType = annotation.annotationType();
123+
for (Annotation metaAnnotation : annotationType.getAnnotations()) {
123124
if (metaAnnotation.annotationType().equals(Qualifier.class)) {
124-
return annotation.annotationType().getSimpleName().toLowerCase();
125+
var toString =
126+
annotation
127+
.toString()
128+
.substring(1)
129+
.replace(annotationType.getCanonicalName(), annotationType.getSimpleName());
130+
if (toString.endsWith("()")) {
131+
toString = toString.substring(0, toString.length() - 2);
132+
}
133+
return toString.toLowerCase();
125134
}
126135
}
127136
}

0 commit comments

Comments
 (0)