No default values in IAnnotationBinding? [message #649697] |
Thu, 20 January 2011 06:05  |
Eclipse User |
|
|
|
Hi,
I'm facing a strange inconsistency when dealing with annotation
bindings. In some cases, SourceTypes do not expose annotation defaults.
Please consider the following annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TestAnnotationWithStringDefault {
String emptyString() default "";
String string() default "string";
@TestAnnotationWithStringDefault
public static class Annotated {}
@TestAnnotationWithStringDefault
public interface AnnotatedInterface {}
}
and another interface
@TestAnnotationWithStringDefault
public interface AnnotatedInterfaceWithStringDefault {}
Everything is working like a charm when only the class files are
present. However, when I try to obtain the ITypeBinding from the source
for the inner type TestAnnotationWithStringDefault.Annotated and
navigate to the annotations via IBinging#getAnnotations, I'll get an
annotation binding with both defaults correctly set. Unfortunately that
is not the case when I'm starting with the type
AnnotatedInterfaceWithStringDefault. It exposes an annotation binding,
too but #getAllMemberValuePairs returns an array with two default value
pairs which both point to the value null - which is obviously not
correct. Am I doing something wrong?
This the downstripped code that I'm using:
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setProject(jdtType.getJavaProject());
// jdtType is AnnotatedInterfaceWithStringDefault
ITypeBinding binding = parser.createBindings(
new IJavaElement[] {jdtType}, null)[0];
for (IAnnotationBinding annotation : binding.getAnnotations()) {
for (IMemberValuePairBinding memberValuePair :
annotation.getAllMemberValuePairs()) {
Object value = memberValuePair.getValue();
// value is null :-(
..
}
}
If somebody is interested: the complete code can be reviewed here:
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plug ins/org.eclipse.xtext.common.types.ui/src/org/eclipse/xtext/ common/types/access/jdt/JdtBasedTypeFactory.java
starting with line #77
Thanks for any hints.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.26755 seconds