Index: dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java,v retrieving revision 1.19 diff -u -r1.19 DefaultCommentMapper.java --- dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 6 Oct 2004 10:50:51 -0000 1.19 +++ dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java 3 Nov 2004 12:58:07 -0000 @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.jdt.core.dom; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; @@ -367,8 +370,9 @@ int nodeEnd = node.getStartPosition()+node.getLength()-1; if (nodeEnd == nextStart) { // special case for last child of its parent - this.trailingComments.put(node, new int[] { -1, -1 }); - return nodeEnd; +// this.trailingComments.put(node, new int[] { -1, -1 }); +// return nodeEnd; + return -1; } int extended = nodeEnd; @@ -453,7 +457,8 @@ class CommentMapperVisitor extends DefaultASTVisitor { - HashMap waitingSiblings = new HashMap(10); + HashMap waitingSiblings = new HashMap(); + HashMap unresolvedNodes = new HashMap(); protected boolean visitNode(ASTNode node) { @@ -462,11 +467,12 @@ int previousEnd = parent.getStartPosition(); // Look for sibling node - ASTNode sibling = (ASTNode) this.waitingSiblings.get(parent); + ASTNode sibling = (ASTNode) this.waitingSiblings.remove(parent); if (sibling != null) { // Found one previous sibling, so compute its trailing comments using current node start position try { previousEnd = storeTrailingComments(sibling, node.getStartPosition(), false); + if (previousEnd == -1) previousEnd = node.getStartPosition(); } catch (Exception ex) { // Give up extended ranges at this level if unexpected exception happens... } @@ -488,11 +494,33 @@ protected void endVisitNode(ASTNode node) { + // Look for unresolved extended position at level n+2... + List list = (List) this.unresolvedNodes.remove(node); + if (list != null) { + Iterator grandChildren = list.listIterator(); + while (grandChildren.hasNext()) { + ASTNode grandChild = (ASTNode) grandChildren.next(); + int[] range = (int[]) trailingComments.get(grandChild.getParent()); + if (range != null) { + trailingComments.put(grandChild, range); + } + } + } + // Look if a child node is waiting for trailing comments computing - ASTNode sibling = (ASTNode) this.waitingSiblings.get(node); + ASTNode sibling = (ASTNode) this.waitingSiblings.remove(node); if (sibling != null) { try { - storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true); + if (storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true) == -1) { + // Unable to resolve extended position for this node + ASTNode parent = node.getParent(); + if (parent != null) { + List grandChildren = (List) unresolvedNodes.get(parent); + if (grandChildren == null) + unresolvedNodes.put(parent, grandChildren = new ArrayList()); + grandChildren.add(sibling); + } + } } catch (Exception ex) { // Give up extended ranges at this level if unexpected exception happens... }