Summary: | [dom] AST rewrite fails to generate the modified code | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Olivier Thomann <Olivier_Thomann> | ||||||||
Component: | Core | Assignee: | Frederic Fusier <frederic_fusier> | ||||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||||
Severity: | blocker | ||||||||||
Priority: | P3 | CC: | eclipse.felipe, philippe_mulet | ||||||||
Version: | 3.1 | ||||||||||
Target Milestone: | 3.1 M3 | ||||||||||
Hardware: | PC | ||||||||||
OS: | Windows XP | ||||||||||
Whiteboard: | |||||||||||
Attachments: |
|
Description
Olivier Thomann
2004-11-02 15:59:24 EST
Created attachment 15577 [details]
Install in your workspace
Created attachment 15578 [details]
A.java test case
As soon as we have a comment in the code, it is failing. Pls investigate: 1. is this a regression from M2 ? 2. can it be fixed (easily) for M3 ? Already happens in 3.1 M2 and 3.0.1... Understand what happens... DefaultCommentMapper return extended positions of parent for some specific nodes. This is the case in this example: a TryStatement with one child Block. But the block was this of foo method body (so ORIGINAL) but its parent was created and its start position = -1 and length = 0...! => modify algorithm in DefaultCommentMapper not to return parent extended positions when parent is NOT ORIGINAL: public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingComments != null) { int[] range = (int[]) this.trailingComments.get(node); if (range != null) { if (range[0] == -1 && range[1] == -1) { ASTNode parent = node.getParent(); if (parent != null && ((parent.getFlags() & ASTNode.ORIGINAL) != 0)) { return getExtendedEnd(parent); } } else { Comment lastComment = this.comments[range[1]]; end = lastComment.getStartPosition() + lastComment.getLength(); } } } return end-1; } All tests are green: - JDT/Core - DefaultCommentMapper - JDT/UI => I think it's a good candidate for M3... Created attachment 15599 [details]
More complete fix
Previous change was not enough as while rewriting parent may be original but
different. Then, returned extended position would be wrong although not equals
to -1!
A better solution is to resolved extended positions for this kind of nodes
during the initialzation and first visit of the ASTNodes hierarchy...
Using this new patch, all JDT/Core tests are green but DefaultCommentMapper specific tests failed... Furthermore, this may be time consuming. So for M3, as deeper investigation is needed to complete this fix, only first version can be released and I'd open a new bug in case this one was fixed... Ok for me. In case a block has a new statement, I don't think it should be considered as orignal anymore. Olivier, the problem is on parent, not on node itself. So, even if you keep the same block content but just move it to a new parent created by the parser (ie. ORIGINAL), then you 'll get wrong extended positions with the fix written in comment 6... I've opened bug 77644 to track this issue and put you in CC list Fixed. Click on banana icon now modifies correctly the file A.java... [jdt-core-internal] Change done in DefaultCommentMapper.getExtendedEnd(ASTNode) as described in comment 6. Test case added: ASTRewritingMethodDeclTests#testMethodDeclChangesBug77538() Ok for M3 Verified with build I200411040100 for 3.1M3 |