Summary: | [dom] CompilationUnit.rewrite throws AssertionFailedException with legal AST (bug in recoding ast modifications) | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Rodrigo Kumpera <kumpera> | ||||
Component: | Core | Assignee: | David Audel <david_audel> | ||||
Status: | CLOSED FIXED | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | ||||||
Version: | 3.0.2 | ||||||
Target Milestone: | 3.1 RC2 | ||||||
Hardware: | PC | ||||||
OS: | Windows NT | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Rodrigo Kumpera
2005-04-28 21:25:41 EDT
Created attachment 20487 [details]
JUnit testcase for the bug
I've found a workaround for this bug. Instead of copying the subtree, make the node orfan and use it. This might even save some bits of memory since copySubTree does not perform COW. This method does the kludge: public static void killParent(ASTNode node) { StructuralPropertyDescriptor locationInParent = node .getLocationInParent(); if (!locationInParent.isChildListProperty()) node.getParent().setStructuralProperty(locationInParent, node.getAST ().newNullLiteral()); else { List list = (List) node.getParent().getStructuralProperty( locationInParent); list.remove(node); } } Martin, could you please check if this occurs in HEAD? Bug is in the modifying ast rewrite: A close on a new (non-original) node should not create a copy event. New end original nodes can be distinguised with the 'ASTNode.ORIGINAL' flag. Moving to Daniel +1 for RC2 Fixed and test added ASTRewritingModifyingCopyTest#test0007() Replaced void postCloneNodeEvent(ASTNode node, ASTNode clone) { this.clonedNodes.put(clone, node); this.cloneDepth--; } by void postCloneNodeEvent(ASTNode node, ASTNode clone) { if(node.ast == root.ast && clone.ast == root.ast) { if((node.getFlags() & ASTNode.ORIGINAL) != 0) { this.clonedNodes.put(clone, node); } else { // node can be a cloned node Object original = this.clonedNodes.get(node); if(original != null) { this.clonedNodes.put(clone, original); } } } this.cloneDepth--; } Verified in N20050609-0010 + JDT/Core HEAD. Verified that the attached Junit test passed. Result in System.out is: package test; public class Test { void foo(){this.x;} } Verified in I20050610-0010. |