Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 395663 - [1.8][ast rewrite] Add rewrite support for annotations on varargs
Summary: [1.8][ast rewrite] Add rewrite support for annotations on varargs
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: BETA J8   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 391898
Blocks: 398940
  Show dependency tree
 
Reported: 2012-12-04 02:06 EST by Manoj N Palat CLA
Modified: 2013-03-01 10:54 EST (History)
3 users (show)

See Also:


Attachments
Proposed Patch (15.98 KB, patch)
2012-12-04 21:21 EST, Manoj N Palat CLA
no flags Details | Diff
Proposed Patch (15.96 KB, patch)
2013-02-12 03:32 EST, Manoj N Palat CLA
no flags Details | Diff
Proposed Patch (13.90 KB, patch)
2013-02-19 21:09 EST, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manoj N Palat CLA 2012-12-04 02:06:22 EST

    
Comment 1 Manoj N Palat CLA 2012-12-04 21:21:06 EST
Created attachment 224287 [details]
Proposed Patch

Modified Patch to suit the changes made while reworking Bug 391898
Comment 2 Manoj N Palat CLA 2013-02-12 03:32:16 EST
Created attachment 226900 [details]
Proposed Patch

Patch updated to the latest source and additional tests added.
Comment 3 Markus Keller CLA 2013-02-14 13:58:26 EST
ASTRewriteAnalyzer:
- rewriteVarargsAnnotations(..) doesn't need the API level check.
- Don't create a third copy of rewriteModifiers2(..). Merge rewriteTypeAnnotations(..) and rewriteVarargsAnnotations(..) functionality into rewriteModifiers2(..). Moving lastChild up like in rewriteTypeAnnotations(..) makes sense.
- visit(SingleVariableDeclaration):
  - computes ellipsisEnd twice
  - node.varargsAnnotations().toString().length() is not correct

ASTRewriteFormatter:
- VARARGS_ANNOTATION_SEPARATION doesn't look correct nor necessary. PARAM_ANNOTATION_SEPARATION is already broken, since the first string contains a syntax error (missing parameter type). I'll fix that in BETA_JAVA8.

- If we need a new FormattingPrefix, then it would be one that measures the space between type/annotation and "...". But note that the formatter currently doesn't work for Java 8, see bug 400830.
The default formatting option for whitespace in front of "..." is "disabled", so there shouldn't be any space there in the tests.
Comment 4 Manoj N Palat CLA 2013-02-19 21:09:56 EST
Created attachment 227309 [details]
Proposed Patch

Comments addressed with the notes below:

- rewriteTypeAnnotations() and rewriteVarargsAnnotations() have been made as wrapper functions for rewriteModifiers2() and call sites have not been changed to enhance readability. Can modify the call sites as well if deemed better.

- Formatter changes : using the existing formatter without defining a new formatter. need to be reviewed closely.
Comment 5 Markus Keller CLA 2013-03-01 10:54:33 EST
The merging of ASTRewriteAnalyzer#rewriteModifiers2(..) looked good.

The tests had a nice selection of rewrites, but showed a few remaining problems:
- foo12 was not used. Added another variant for that one.
- Handling of spaces was not addressed. I know this is a tricky business, and it also took me a while to understand how things work. When I was done investigating, I already had the fix together, so I just released everything at once. As you can see, I also added a variant in testVarArgs_since_3 to test the "space before ellipsis" formatter option. This was already missing in 3.8, but it became more apparent now.

Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=6cb1a46319677820636b0fbe76d096b92fe1835a

Manoj, please have a look at my changes and speak up if you think something's weird.