Comment #6 on issue 771 by [email protected]:
Annotations.isAllDefaultMethods returns false for method less interfaces.
http://code.google.com/p/google-guice/issues/detail?id=771
So if it is designed to do what it should do, maybe it is used incorrectly
here:
static AnnotationStrategy strategyFor(Class<? extends Annotation>
annotationType) {
annotationType = Annotations.canonicalizeIfNamed(annotationType);
if (isAllDefaultMethods(annotationType)) {
return strategyFor(generateAnnotation(annotationType));
}
checkNotNull(annotationType, "annotation type");
ensureRetainedAtRuntime(annotationType);
ensureIsBindingAnnotation(annotationType);
return new AnnotationTypeStrategy(annotationType, null);
}
This guy returns an AnnotationTypeStrategy with an annotation type and null
for an annotation if the class has no methods at all or it has methods that
have no default value but an AnnotationInstanceStrategy (which in turn has
both an annotation type and an annotation instance) if it has at least one
method and all methods have default values.
I still think that this is confusing behavior. Also, the
strategyFor(Annotation) method might have a similar bug here (it returns an
AnnotationTypeStrategy for a marker interface, but one that has an
annotation type and an annotation) and an AnnotationInstanceStrategy
otherwise.
Why am I beating around on this? I want go get rid (or at least simplify)
this ugly piece of code:
private static Key<?> findDependencyKey(TypeLiteral<?> type, Key<?>
clazzKey) {
if (clazzKey.getAnnotation() != null) {
return Key.get(type, clazzKey.getAnnotation());
}
else if (clazzKey.getAnnotationType() != null) {
return Key.get(type, clazzKey.getAnnotationType());
}
else {
throw new ProviderException("Neither annotation nor annotation type
found!");
}
it would be great if there were a halfway predictable way to know whether
Key.getAnnotationType() or Key.getAnnotation() return something, no matter
whether they have been constructed from a Named or a marker annotation.
Right now, no matter what style is used to generate the key, one of the
methods returns null. And the reason for that is that piece of code in
strategyFor() above which in turn relies on isAllDefaultMethods.
}
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/groups/opt_out.