Bug 333919 - JDT doesn't support parameter annotations
Summary: JDT doesn't support parameter annotations
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-10 16:51 EST by BensonN CLA
Modified: 2011-02-18 12:08 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description BensonN CLA 2011-01-10 16:51:28 EST
Build Identifier: M20101215-0800

I have a method like this:

@Inject
public Test(@Default Test1 processor) {...}

I can get annotation (@Inject) for the method (Test) by calling ((IAnnotatable)method).getAnnotations(), but I didn't see a way to get @Default annotation from the same JDT model.

Reproducible: Always
Comment 1 Srikanth Sankaran CLA 2011-01-11 01:01:05 EST
ILocalVariable implements IAnnotatable and so you should be able
to use that route ?
Comment 2 Olivier Thomann CLA 2011-01-11 09:07:18 EST
You should be able to get it using the following code:

((ICodeAssist) this.compilationUnit).codeSelect(startPositionOfProcessor, "processor".length())

=> this returns a ILocalVariable from which you can simply ask for getAnnotations().

Closing as INVALID.
Comment 3 BensonN CLA 2011-01-13 18:41:29 EST
If there is no "direct" way to get this ILocalVariable object from the existing model (IMethod), for the recommended API, what's the best way to get the offset for each parameter (I have to do my own scan?)? Thanks for the help.
Comment 4 Srikanth Sankaran CLA 2011-01-19 04:30:20 EST
(In reply to comment #3)
> If there is no "direct" way to get this ILocalVariable object from the existing
> model (IMethod), for the recommended API, what's the best way to get the offset
> for each parameter (I have to do my own scan?)? Thanks for the help.

Alternatively, you can try the DOM/AST route and (in particular
org.eclipse.jdt.core.dom.IMethodBinding.getParameterAnnotations(int))

Olivier, do you have firm recommendation for Benson ?
Comment 5 Olivier Thomann CLA 2011-01-19 09:02:07 EST
(In reply to comment #4)
> Alternatively, you can try the DOM/AST route and (in particular
> org.eclipse.jdt.core.dom.IMethodBinding.getParameterAnnotations(int))
> 
> Olivier, do you have firm recommendation for Benson ?
Not really. I think we should ease the retrieval of such annotations. I opened bug 334783 to request an API addition to ease this process.
Comment 6 Jay Arthanareeswaran CLA 2011-01-25 05:00:15 EST
Verified for 3.7M5
Comment 7 Olivier Thomann CLA 2011-02-17 18:40:31 EST
Benson, we are planning to add a new API on IMethod to ease the retrieval of such annotations. Let us know how you like it inside bug 334783.
Comment 8 BensonN CLA 2011-02-18 10:17:33 EST
(In reply to comment #7)
> Benson, we are planning to add a new API on IMethod to ease the retrieval of
> such annotations. Let us know how you like it inside bug 334783.

Hi Olivier and Jay, 

Thanks for helping on this, the API looks good to me, since Kim is taking over the role, she will take a quick look as well, anyway, Thanks again.