Extract @Named value from a wrapped annotation
This commit is contained in:
@@ -264,7 +264,19 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor
|
||||
return ((javax.inject.Named) key.getAnnotation()).value();
|
||||
}
|
||||
else if (key.getAnnotationType() != null) {
|
||||
return key.getAnnotationType().getName();
|
||||
String value = key.getAnnotationType().getName();
|
||||
|
||||
if (key.getAnnotation() != null) {
|
||||
// Edge case when the Named annotation is wrapped
|
||||
String annotationString = key.getAnnotation().toString();
|
||||
String wrappedNamedValue = substringBetween(annotationString, "@com.google.inject.name.Named(\"",
|
||||
"\")");
|
||||
if (wrappedNamedValue != null) {
|
||||
value = wrappedNamedValue + "_" + value;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -361,6 +373,20 @@ class ModuleRegistryConfiguration implements BeanDefinitionRegistryPostProcessor
|
||||
}
|
||||
}
|
||||
|
||||
private static String substringBetween(String str, String open, String close) {
|
||||
if (str == null || open == null || close == null) {
|
||||
return null;
|
||||
}
|
||||
int start = str.indexOf(open);
|
||||
if (start != -1) {
|
||||
int end = str.indexOf(close, start + open.length());
|
||||
if (end != -1) {
|
||||
return str.substring(start + open.length(), end);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Guice injector and registers it.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user