Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2013-08-13 23:43:34 -0400
committerSergey Prigogin2013-08-14 12:27:35 -0400
commitca5586f8be131c5a77cf896e094d0a75bd6fada1 (patch)
treef7dad95a09e0c281645b3d32ef6985ee9ab01792 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler
parent7ae8b48608cac5073073e244241c10a03dcbb2a4 (diff)
downloadorg.eclipse.cdt-ca5586f8be131c5a77cf896e094d0a75bd6fada1.tar.gz
org.eclipse.cdt-ca5586f8be131c5a77cf896e094d0a75bd6fada1.tar.xz
org.eclipse.cdt-ca5586f8be131c5a77cf896e094d0a75bd6fada1.zip
Bug 414624 - Add Include command doesn't honor Organize Includes
preferences
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java
index 829c2ddd4e..74303f4def 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java
@@ -17,7 +17,9 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes;
/**
* The NodeCommentMap is the map where all the comments are assigned to a node. For better
@@ -147,4 +149,43 @@ public class NodeCommentMap {
comment.addAll(getTrailingCommentsForNode(node));
return comment;
}
+
+ public int getOffsetIncludingComments(IASTNode node) {
+ int offset = ASTNodes.offset(node);
+
+ // TODO(sprigogin): Iterate backwards and stop at the first blank line.
+ List<IASTComment> comments = leadingMap.get(node);
+ if (comments != null && !comments.isEmpty()) {
+ for (IASTComment comment : comments) {
+ int commentOffset = ASTNodes.offset(comment);
+ if (commentOffset < offset) {
+ offset = commentOffset;
+ }
+ }
+ }
+ return offset;
+ }
+
+ public int getEndOffsetIncludingComments(IASTNode node) {
+ int endOffset = 0;
+ while (true) {
+ IASTFileLocation fileLocation = node.getFileLocation();
+ if (fileLocation != null)
+ endOffset = Math.max(endOffset, fileLocation.getNodeOffset() + fileLocation.getNodeLength());
+ List<IASTComment> comments = trailingMap.get(node);
+ if (comments != null && !comments.isEmpty()) {
+ for (IASTComment comment : comments) {
+ int commentEndOffset = ASTNodes.endOffset(comment);
+ if (commentEndOffset >= endOffset) {
+ endOffset = commentEndOffset;
+ }
+ }
+ }
+ IASTNode[] children = node.getChildren();
+ if (children.length == 0)
+ break;
+ node = children[children.length - 1];
+ }
+ return endOffset;
+ }
}

Back to the top