Bug 249844 - IBinding#getJavaElement() always returns null for IAnnotationBindings declared in annotation or enum types
Summary: IBinding#getJavaElement() always returns null for IAnnotationBindings declare...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 236850
  Show dependency tree
 
Reported: 2008-10-06 14:03 EDT by Markus Keller CLA
Modified: 2008-10-27 16:01 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix + regression tests (3.31 KB, patch)
2008-10-16 11:30 EDT, Olivier Thomann CLA
no flags Details | Diff
Same fix and tests moved to ASTModelBridgeTests (3.21 KB, patch)
2008-10-17 10:55 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-10-06 14:03:24 EDT
I20080930-0921

IBinding#getJavaElement() always returns null for IAnnotationBindings. Fails for source and binary IAnnotationBindings. Javadoc explicitly says:
"[..] For annotations, this method
 * returns the Java element of the annotation (i.e. an {@link IAnnotation})."
Comment 1 Olivier Thomann CLA 2008-10-15 11:37:50 EDT
Could you please provide an example where you get null?
Comment 2 Markus Keller CLA 2008-10-15 12:32:55 EDT
E.g. open java.lang.annotation.Target from JDK6 and look at the binding for '@Documented'.

Same for source, e.g. on binding for @Test, IAnnotationBinding#getJavaElement() returns null:

@Test
public @interface Test {}


Expected: An IAnnotation that is equal to the annotation I get from IAnnotatable#getAnnotations() on the annotated IType.
Comment 3 Olivier Thomann CLA 2008-10-15 15:08:57 EDT
This seems to be the case only for annotations declared on annotation types.
If you write:
@Deprecated
public interface Test {}

it works fine.
Updating title accordingly.
Comment 4 Olivier Thomann CLA 2008-10-15 15:16:45 EDT
Annotations declared on enum types are also wrong.
Comment 5 Olivier Thomann CLA 2008-10-16 11:21:30 EDT
I have a patch for the source case.
Comment 6 Olivier Thomann CLA 2008-10-16 11:30:00 EDT
Created attachment 115260 [details]
Proposed fix + regression tests

Patch for source case. Not sure what can be done for the binary case.
Comment 7 Jerome Lanneluc CLA 2008-10-17 09:17:13 EDT
(In reply to comment #6)
> Created an attachment (id=115260) [details]
> Proposed fix + regression tests
Fix is good. Thanks.

> Not sure what can be done for the binary case.
I'm not sure what you mean. Your fix also solves the case of "@Documented" on java.lang.annotation.Target from JDK6. The only problem is that the element doesn't exist. But this is bug 248309.

Comment 8 Jerome Lanneluc CLA 2008-10-17 10:55:01 EDT
Created attachment 115402 [details]
Same fix and tests moved to ASTModelBridgeTests
Comment 9 Jerome Lanneluc CLA 2008-10-20 08:51:03 EDT
Fix and tests released for 3.5M3
Comment 10 Olivier Thomann CLA 2008-10-27 16:01:57 EDT
Verified for 3.5M3 using I20081026-2000