Extract name from javax.inject.Named if found

This commit is contained in:
kashike
2018-04-17 13:41:33 -07:00
committed by Taylor Wicksell
parent b2a767e51a
commit 752091fcf7
2 changed files with 11 additions and 4 deletions

View File

@@ -13,6 +13,7 @@
package org.springframework.guice.annotation;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -127,8 +128,11 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor
}
private String extractName(Key<?> key) {
if (key.getAnnotation() instanceof Named) {
return ((Named) key.getAnnotation()).value();
final Annotation annotation = key.getAnnotation();
if (annotation instanceof Named) {
return ((Named) annotation).value();
} else if (annotation instanceof javax.inject.Named) {
return ((javax.inject.Named) annotation).value();
}
return key.getTypeLiteral().getRawType().getSimpleName();
}

View File

@@ -136,8 +136,11 @@ public class SpringInjector implements Injector {
}
private String extractName(Key<?> key) {
if (key.getAnnotation() instanceof Named) {
return ((Named) key.getAnnotation()).value();
final Annotation annotation = key.getAnnotation();
if (annotation instanceof Named) {
return ((Named) annotation).value();
} else if (annotation instanceof javax.inject.Named) {
return ((javax.inject.Named) annotation).value();
}
return key.getTypeLiteral().getRawType().getSimpleName();
}