Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qualifiers preserve their case (no longer forced lower case) for BeanEntry and @QualifierMap keys (but still using case insensitive matching for wiring) #548

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void process() {
var shortName = Util.shortName(annotationType.toString());
qualifierName = AnnotationCopier.toSimpleAnnotationString(annotationMirror)
.replaceFirst(annotationType.toString(), shortName)
.replace("\"", "\\\"")
.toLowerCase();
.replace("\"", "\\\"");

} else if (annType.indexOf('.') == -1) {
logWarn("skip when no package on annotation " + annType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void process(boolean forBean) {
final String baseName = baseType.getSimpleName().toString();
final String superName = superElement.getSimpleName().toString();
if (baseName.endsWith(superName)) {
qualifierName = baseName.substring(0, baseName.length() - superName.length()).toLowerCase();
qualifierName = baseName.substring(0, baseName.length() - superName.length());
}
}
addSuperType(superElement, superMirror, proxyBean);
Expand Down Expand Up @@ -226,7 +226,7 @@ private void readInterfacesOf(TypeMirror anInterface) {
final String iShortName = Util.shortName(mainType);
if (beanSimpleName.endsWith(iShortName)) {
// derived qualifier name based on prefix to interface short name
qualifierName = beanSimpleName.substring(0, beanSimpleName.length() - iShortName.length()).toLowerCase();
qualifierName = beanSimpleName.substring(0, beanSimpleName.length() - iShortName.length());
}
}
interfaceTypes.add(rawUType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void process() {
String name() {
NamedPrism named = NamedPrism.getInstanceOn(beanType);
if (named != null) {
return named.value().toLowerCase();
return named.value();
}
if (annotationReader.hasQualifierName()) {
return annotationReader.qualifierName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static String commonParent(String currentTop, String aPackage) {
static String getNamed(Element p) {
final NamedPrism named = NamedPrism.getInstanceOn(p);
if (named != null) {
return named.value().toLowerCase();
return named.value();
}
for (final AnnotationMirror annotationMirror : p.getAnnotationMirrors()) {
final DeclaredType annotationType = annotationMirror.getAnnotationType();
Expand All @@ -294,8 +294,7 @@ static String getNamed(Element p) {

return AnnotationCopier.toSimpleAnnotationString(annotationMirror)
.replaceFirst(annotationType.toString(), shortName)
.replace("\"", "\\\"")
.toLowerCase();
.replace("\"", "\\\"");
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void deleteGeneratedFiles() throws IOException {
.map(Path::toFile)
.forEach(File::delete);
Paths.get("io.avaje.inject.spi.Module").toAbsolutePath().toFile().delete();
Paths.get("io.avaje.inject.spi.ModuleOrdering").toAbsolutePath().toFile().delete();

} catch (final Exception e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,15 @@ private FieldTarget newTarget(Field field) {
private String name(Field field) {
final Named named = field.getAnnotation(Named.class);
if (named != null) {
return named.value().toLowerCase();
return named.value();
}
for (Annotation annotation : field.getAnnotations()) {
final var annotationType = annotation.annotationType();
for (Annotation metaAnnotation : annotationType.getAnnotations()) {
if (metaAnnotation.annotationType().equals(Qualifier.class)) {
return AnnotationReader.simplifyAnnotation(annotation.toString())
.replaceFirst(annotationType.getCanonicalName(), annotationType.getSimpleName())
.replace("()", "").substring(1)
.toLowerCase();
.replace("()", "").substring(1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ void beanScope_all() {
assertThat(bsomeEntry).isPresent();

final BeanEntry entry = bsomeEntry.get();
assertThat(entry.qualifierName()).isEqualTo("b");
assertThat(entry.qualifierName()).isEqualTo("B");
assertThat(entry.keys()).containsExactlyInAnyOrder(name(BSomei.class), name(Somei.class));
assertThat(entry.type()).isEqualTo(BSomei.class);
assertThat(entry.priority()).isEqualTo(0);
assertThat(entry.bean()).isEqualTo(context.get(Somei.class, "b"));
assertThat(entry.bean()).isEqualTo(context.get(Somei.class, "B"));
assertThat(entry.bean()).isEqualTo(context.get(BSomei.class));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void test_map() {
try (BeanScope context = BeanScope.builder().build()) {
CombinedMapSomei bean = context.get(CombinedMapSomei.class);
List<String> keys = bean.someKeys();
assertThat(keys).containsOnly("a", "b", "a2");
assertThat(keys).containsOnly("A", "B", "A2");
List<String> vals = bean.someVals();
assertThat(vals).containsOnly("a", "b", "a2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void test() {
SomeStore blueStore = beanScope.get(SomeStore.class, "blue");
Map<String, SomeStore> stores = beanScope.map(SomeStore.class);

SomeStore green = stores.get("green");
SomeStore green = stores.get("Green");
assertThat(green).isSameAs(greenStore);
SomeStore blue = stores.get("blue");
SomeStore blue = stores.get("Blue");
assertThat(blue).isSameAs(blueStore);

// a map with unnamed component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void customScopeAll() {

assertThat(customBeanEntry).isPresent();
assertThat(customBeanEntry.get().bean()).isSameAs(customBean);
assertThat(customBeanEntry.get().qualifierName()).isEqualTo("hello");
assertThat(customBeanEntry.get().qualifierName()).isEqualTo("Hello");
assertThat(customBeanEntry.get().priority()).isEqualTo(0);
assertThat(customBeanEntry.get().keys()).containsExactly(CustomBean.class.getCanonicalName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void test() {
try (BeanScope beanScope = BeanScope.builder()
.forTesting()
.spy(SomeStore.class, "blue")
.spy(SomeStore.class, "Green")
.spy(SomeStore.class, "green")
.build()) {

final StoreManagerWithSetterQualifier storeManager = beanScope.get(StoreManagerWithSetterQualifier.class);
Expand Down
6 changes: 3 additions & 3 deletions inject/src/main/java/io/avaje/inject/spi/DBeanMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Object getStrict(Type type, String name) {
if (entry == null) {
return null;
}
return entry.getStrict(KeyUtil.lower(name));
return entry.getStrict(name);
}

boolean contains(String type) {
Expand All @@ -112,7 +112,7 @@ <T> T get(Type type, String name) {
if (entry == null) {
return null;
}
return (T) entry.get(KeyUtil.lower(name));
return (T) entry.get(name);
}

@SuppressWarnings("unchecked")
Expand All @@ -121,7 +121,7 @@ <T> Provider<T> provider(Type type, String name) {
if (entry == null) {
return null;
}
return (Provider<T>) entry.provider(KeyUtil.lower(name));
return (Provider<T>) entry.provider(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static DContextEntryBean provider(boolean prototype, Provider<?> provider, Strin

private DContextEntryBean(Object source, String name, int flag) {
this.source = source;
this.name = KeyUtil.lower(name);
this.name = name;
this.flag = flag;
}

Expand All @@ -64,14 +64,14 @@ final DEntry entry() {
* Return true if qualifierName is null or matched.
*/
final boolean isNameMatch(String qualifierName) {
return qualifierName == null || qualifierName.equals(name);
return qualifierName == null || qualifierName.equalsIgnoreCase(name);
}

/**
* Return true if qualifierName is matched including null.
*/
final boolean isNameEqual(String qualifierName) {
return Objects.equals(qualifierName, name);
return qualifierName == null ? name == null : qualifierName.equalsIgnoreCase(name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/spi/EnrichBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class EnrichBean<B> {

public EnrichBean(Type type, String name, Consumer<B> consumer) {
this.type = type;
this.name = KeyUtil.lower(name);
this.name = name;
this.consumer = consumer;
}

Expand Down
5 changes: 1 addition & 4 deletions inject/src/main/java/io/avaje/inject/spi/KeyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
*/
final class KeyUtil {

static String lower(String name) {
return name == null ? null : name.toLowerCase();
}

static String key(Type type, String name) {
return name == null ? type.getTypeName() : type.getTypeName() + "|" + name;
return name == null ? type.getTypeName() : type.getTypeName() + "|" + name.toLowerCase();
}

}
Loading