Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-05-15 03:34:10 -0400
committerMarkus Schorn2008-05-15 03:34:10 -0400
commitfec33bb137d97b952f9f007b38c68d3bbc666def (patch)
treef590c60b638afeedad66a7796e4d94e47a578e2b /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler
parente250ee6a33f50d2fb0b47726700c1dc52b15184b (diff)
downloadorg.eclipse.cdt-fec33bb137d97b952f9f007b38c68d3bbc666def.tar.gz
org.eclipse.cdt-fec33bb137d97b952f9f007b38c68d3bbc666def.tar.xz
org.eclipse.cdt-fec33bb137d97b952f9f007b38c68d3bbc666def.zip
Proper handling of comments before preprocessing statements by Emanuel Graf, bug 232232.
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/ASTCommenter.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
index b3f17609b5..53aa825070 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
@@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.TreeMap;
import org.eclipse.cdt.core.dom.ast.IASTComment;
@@ -83,10 +84,12 @@ public class ASTCommenter {
private static ArrayList<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, ArrayList<IASTComment> comments) {
IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements();
TreeMap<Integer,Object> treeOfPreProcessorLines = new TreeMap<Integer,Object>();
+ ArrayList<Integer> listOfPreProcessorOffset = new ArrayList<Integer>();
for (IASTPreprocessorStatement statement : preprocessorStatements) {
if (isInWorkspace(statement)) {
treeOfPreProcessorLines.put(OffsetHelper.getStartingLineNumber(statement),null);
+ listOfPreProcessorOffset.add(statement.getFileLocation().getNodeOffset());
}
}
@@ -96,11 +99,41 @@ public class ASTCommenter {
if (treeOfPreProcessorLines.containsKey(comStartLineNumber)) {
continue;
}
+ if(commentIsAtTheBeginningBeforePreprocessorStatements(comment, listOfPreProcessorOffset)) {
+ continue;
+ }
commentsInCode.add(comment);
}
return commentsInCode;
}
+ private static boolean commentIsAtTheBeginningBeforePreprocessorStatements(
+ IASTComment comment,
+ ArrayList<Integer> listOfPreProcessorOffset) {
+ if(listOfPreProcessorOffset.size() <1) {
+ return false;
+ }
+
+ if(comment.getTranslationUnit()==null || comment.getTranslationUnit().getDeclarations().length < 1) {
+ return true;
+ }
+ IASTDeclaration decl = comment.getTranslationUnit().getDeclarations()[0];
+ if(decl.getFileLocation().getNodeOffset() < comment.getFileLocation().getNodeOffset()) {
+ return false;
+ }
+
+ Collections.sort(listOfPreProcessorOffset);
+ if(listOfPreProcessorOffset.get(0) < comment.getFileLocation().getNodeOffset()) {
+ return false;
+ }
+
+ if(listOfPreProcessorOffset.get(0) < decl.getFileLocation().getNodeOffset()) {
+ return true;
+ }
+
+ return false;
+ }
+
private static boolean isInWorkspace(IASTNode node) {
IPath workspacePath = Platform.getLocation();
IPath nodePath = new Path(node.getContainingFilename());

Back to the top