@SuppressWarnings("unchecked")
private static ScopeInfo getScopeInfo(
AnnotatedElement annotatedGuy,
Descriptor defaultScope,
Collector collector) {
AnnotatedElement topLevelElement = annotatedGuy;
Annotation winnerScope = null;
while (annotatedGuy != null) {
Annotation current = internalGetScopeAnnotationType(
annotatedGuy,
collector);
if (current != null) {
if (annotatedGuy.equals(topLevelElement)) {
// We found a winner, no matter the inherited state
winnerScope = current;
break;
}
if (current.annotationType().isAnnotationPresent(Inherited.class)) {
winnerScope = current;
break;
}
// This non-inherited annotation wipes out all scopes above it
break;
}
if (annotatedGuy instanceof Class) {
annotatedGuy = ((Class<?>) annotatedGuy).getSuperclass();
} else {
Method theMethod = (Method) annotatedGuy;
Class<?> methodClass = theMethod.getDeclaringClass();
annotatedGuy = null;
Class<?> methodSuperclass = methodClass.getSuperclass();
while (methodSuperclass != null) {
if (Factory.class.isAssignableFrom(methodSuperclass)) {
annotatedGuy = getFactoryProvideMethod(methodSuperclass);
break;
}
methodSuperclass = methodSuperclass.getSuperclass();
}
}
}
if (winnerScope != null) {
return new ScopeInfo(winnerScope, winnerScope.annotationType());
}
if (topLevelElement.isAnnotationPresent(Service.class)) {
return new ScopeInfo(null, Singleton.class);
}
if (defaultScope != null && defaultScope.getScope() != null) {
Class<? extends Annotation> descScope = (Class<? extends Annotation>)