Bug 325131 - ASTRewrite should offer get/setProperty() like ASTNode
Summary: ASTRewrite should offer get/setProperty() like ASTNode
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 319069
  Show dependency tree
 
Reported: 2010-09-13 12:33 EDT by Markus Keller CLA
Modified: 2010-10-26 14:46 EDT (History)
3 users (show)

See Also:
Olivier_Thomann: review+
markus.kell.r: review+


Attachments
proposed fix v1.0 (5.00 KB, patch)
2010-09-27 07:09 EDT, Ayushman Jain CLA
no flags Details | Diff
Proposed fix + regression tests (10.18 KB, patch)
2010-09-27 14:46 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (9.92 KB, patch)
2010-09-28 08:56 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (13.03 KB, patch)
2010-10-06 10:29 EDT, Olivier Thomann 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 2010-09-13 12:33:20 EDT
HEAD

ASTRewrite should offer get/setProperty() methods like ASTNode. E.g. for bug 319069, I need to modify our VariableDeclarationRewrite#rewriteModifiers(..) to store additional information about nodes that have already been touched by a rewrite. Storing this information externally and rippling it through all APIs where the ASTRewrite is currently passed through is a pain.
Comment 1 Ayushman Jain CLA 2010-09-14 01:46:40 EDT
I'll follow up.
Comment 2 Dani Megert CLA 2010-09-14 01:58:06 EDT
I'd like to see this fixed for M3 so that we can fix the bug in JDT UI. Thanks.
Comment 3 Ayushman Jain CLA 2010-09-27 07:09:15 EDT
Created attachment 179620 [details]
proposed fix v1.0

Here's the fix to introduce the same get/setProperty functionality as in ASTNode.
Olivier, can you please do a quick review? Thanks!
Comment 4 Olivier Thomann CLA 2010-09-27 14:44:50 EDT
Looks good. I'll attach a new patch with a few cosmetic changes (typo, remove reference to HashMap to keep Map only, add throws clauses in javadoc) + some regression tests.
It would be good if Markus could also use the patch to see if this is helping him to solve bug 319069. Looking at the existing patch for 319069, I believe this is good enough.
Comment 5 Olivier Thomann CLA 2010-09-27 14:46:01 EDT
Created attachment 179676 [details]
Proposed fix + regression tests

Ayushman, please double check the new patch. If ok, you can release it.
Comment 6 Dani Megert CLA 2010-09-28 02:40:27 EDT
Markus is away until next Monday.
Comment 7 Ayushman Jain CLA 2010-09-28 05:25:47 EDT
(In reply to comment #5)
> Created an attachment (id=179676) [details] [diff]
> Proposed fix + regression tests
> 
> Ayushman, please double check the new patch. If ok, you can release it.

Looks good to me. I'll release after Markus reviews.
Comment 8 Olivier Thomann CLA 2010-09-28 08:56:15 EDT
Created attachment 179735 [details]
Proposed fix + regression test

Renamed the test in the test suite to something more meaningful.
Comment 9 Markus Keller CLA 2010-10-05 08:46:54 EDT
The API looks good. Things that should be changed in the implementation:

- Javadoc of ASTRewrite#property1 talks about an unmodifiable map in #property2, but that's never the case (in ASTNode, the unmodifiable map is created lazily in #properties()).

- I've compared the implementation with ASTNode and found some changes. These should also be backported into ASTNode so that the implementations match up again. Hint: Search for declarations of methods "org.eclipse.jdt.core.dom*.AST*.?etProperty" and then select the two methods and perform Compare With > Each Other.
Comment 10 Olivier Thomann CLA 2010-10-06 10:09:18 EDT
(In reply to comment #9)
> The API looks good. Things that should be changed in the implementation:
> - Javadoc of ASTRewrite#property1 talks about an unmodifiable map in
> #property2, but that's never the case (in ASTNode, the unmodifiable map is
> created lazily in #properties()).
This is not exposed. We would need to add a #properties() method on ASTRewrite if this is needed.
Do you want such a method ?
Comment 11 Markus Keller CLA 2010-10-06 10:20:32 EDT
No, I don't need #properties() and I wouldn't add it (ASTNode#properties() is not used anywhere in the SDK). I just saw that the internal Javadoc on the field is wrong.
Comment 12 Olivier Thomann CLA 2010-10-06 10:29:40 EDT
Created attachment 180334 [details]
Proposed fix + regression test

This patch should take care of all your comments.
Comment 13 Olivier Thomann CLA 2010-10-06 10:30:29 EDT
I don't think there is a need to say that property2 is null if property1 is a Map.
Comment 14 Olivier Thomann CLA 2010-10-06 11:33:43 EDT
I am committing the last patch to get going with this bug.
Released for 3.7M3.
Added regression test in:
org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritePropertyTest.

Markus, if you have further comment, we will adjust the code.
Comment 15 Olivier Thomann CLA 2010-10-26 14:46:44 EDT
Verified for 3.7M3 using I20101025-1602 (4.1 build)