Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » No default values in IAnnotationBinding?
No default values in IAnnotationBinding? [message #649697] Thu, 20 January 2011 11:05 Go to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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
Re: No default values in IAnnotationBinding? [message #649740 is a reply to message #649697] Thu, 20 January 2011 13:50 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Hi,

Nice description of the problem, but you don't provide the build id.
What version of org.eclipse.jdt.core are you using ?

Thanks,

Olivier
Re: No default values in IAnnotationBinding? [message #649762 is a reply to message #649740] Thu, 20 January 2011 14:44 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
I think I know what is going on. The binding for TestAnnotationWithStringDefault is not fully resolved when the binding is requested.
I'll investigate. Please open a bug report against JDT/Core with the steps in the first comment.
Thanks.
--
Olivier
Re: No default values in IAnnotationBinding? [message #649885 is a reply to message #649762] Thu, 20 January 2011 20:25 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Oliver,

the issue was filed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=334943

All this is executed against Eclipse 3.5.2 but I could test it with 3.6
or 3.7.Mx as well (if that would be helpful).

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.01.11 15:44, schrieb Olivier Thomann:
> I think I know what is going on. The binding for
> TestAnnotationWithStringDefault is not fully resolved when the binding
> is requested.
> I'll investigate. Please open a bug report against JDT/Core with the
> steps in the first comment.
> Thanks.
> --
> Olivier
Re: No default values in IAnnotationBinding? [message #649905 is a reply to message #649885] Thu, 20 January 2011 22:01 Go to previous message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
With the testing I have done, the problem still exists. It is related to incomplete binding initialization when the binding is indirectly referenced.
Not sure how fast this can be fixed.

Thanks for the bug report.

Olivier
Previous Topic:[SOLVED] How to create hierarchy search scope from a MethodDeclaration instance?
Next Topic:The server does not support version 3.0 of the J2EE Web module specification
Goto Forum:
  


Current Time: Fri Apr 26 11:51:02 GMT 2024

Powered by FUDForum. Page generated in 0.03570 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top