View | Details | Raw Unified | Return to bug 77538
Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java (-6 / +34 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
11
package org.eclipse.jdt.core.dom;
12
12
13
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.List;
14
17
15
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.InvalidInputException;
19
import org.eclipse.jdt.core.compiler.InvalidInputException;
Lines 367-374 Link Here
367
		int nodeEnd = node.getStartPosition()+node.getLength()-1;
370
		int nodeEnd = node.getStartPosition()+node.getLength()-1;
368
		if (nodeEnd == nextStart) {
371
		if (nodeEnd == nextStart) {
369
			// special case for last child of its parent
372
			// special case for last child of its parent
370
			this.trailingComments.put(node, new int[] { -1, -1 });
373
//			this.trailingComments.put(node, new int[] { -1, -1 });
371
			return nodeEnd;
374
//			return nodeEnd;
375
			return -1;
372
		}
376
		}
373
		int extended = nodeEnd;
377
		int extended = nodeEnd;
374
		
378
		
Lines 453-459 Link Here
453
457
454
	class CommentMapperVisitor extends DefaultASTVisitor {
458
	class CommentMapperVisitor extends DefaultASTVisitor {
455
459
456
		HashMap waitingSiblings = new HashMap(10);
460
		HashMap waitingSiblings = new HashMap();
461
		HashMap unresolvedNodes = new HashMap();
457
462
458
		protected boolean visitNode(ASTNode node) {
463
		protected boolean visitNode(ASTNode node) {
459
464
Lines 462-472 Link Here
462
			int previousEnd = parent.getStartPosition();
467
			int previousEnd = parent.getStartPosition();
463
468
464
			// Look for sibling node
469
			// Look for sibling node
465
			ASTNode sibling = (ASTNode) this.waitingSiblings.get(parent);
470
			ASTNode sibling = (ASTNode) this.waitingSiblings.remove(parent);
466
			if (sibling != null) {
471
			if (sibling != null) {
467
				// Found one previous sibling, so compute its trailing comments using current node start position
472
				// Found one previous sibling, so compute its trailing comments using current node start position
468
				try {
473
				try {
469
					previousEnd = storeTrailingComments(sibling, node.getStartPosition(), false);
474
					previousEnd = storeTrailingComments(sibling, node.getStartPosition(), false);
475
					if (previousEnd == -1) previousEnd = node.getStartPosition();
470
				} catch (Exception ex) {
476
				} catch (Exception ex) {
471
					// Give up extended ranges at this level if unexpected exception happens...
477
					// Give up extended ranges at this level if unexpected exception happens...
472
				}
478
				}
Lines 488-498 Link Here
488
		
494
		
489
		protected void endVisitNode(ASTNode node) {
495
		protected void endVisitNode(ASTNode node) {
490
496
497
			// Look for unresolved extended position at level n+2...
498
			List list = (List) this.unresolvedNodes.remove(node);
499
			if (list != null) {
500
				Iterator grandChildren = list.listIterator();
501
				while (grandChildren.hasNext()) {
502
					ASTNode grandChild = (ASTNode) grandChildren.next();
503
					int[] range = (int[]) trailingComments.get(grandChild.getParent());
504
					if (range != null) {
505
						trailingComments.put(grandChild, range);
506
					}
507
				}
508
			}
509
491
			// Look if a child node is waiting for trailing comments computing
510
			// Look if a child node is waiting for trailing comments computing
492
			ASTNode sibling = (ASTNode) this.waitingSiblings.get(node);
511
			ASTNode sibling = (ASTNode) this.waitingSiblings.remove(node);
493
			if (sibling != null) {
512
			if (sibling != null) {
494
				try {
513
				try {
495
					storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true);
514
					if (storeTrailingComments(sibling, node.getStartPosition()+node.getLength()-1, true) == -1) {
515
						// Unable to resolve extended position for this node
516
						ASTNode parent = node.getParent();
517
						if (parent != null) {
518
							List grandChildren = (List) unresolvedNodes.get(parent);
519
							if (grandChildren == null)
520
								unresolvedNodes.put(parent, grandChildren = new ArrayList());
521
							grandChildren.add(sibling);
522
						}
523
					}
496
				} catch (Exception ex) {
524
				} catch (Exception ex) {
497
					// Give up extended ranges at this level if unexpected exception happens...
525
					// Give up extended ranges at this level if unexpected exception happens...
498
				}
526
				}

Return to bug 77538