Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Felber2014-01-29 12:29:26 -0500
committerThomas Corbat2014-01-30 05:18:32 -0500
commit2e2e1763bde6bb76a5fd96dcd25eb1d0b5736a86 (patch)
treebc26fb8e02ca25ba79ff7c7639cdd3e40cc27d8b
parent99de8fdda101bdceb0da2567ba83e816d3cec0ce (diff)
downloadorg.eclipse.cdt-2e2e1763bde6bb76a5fd96dcd25eb1d0b5736a86.tar.gz
org.eclipse.cdt-2e2e1763bde6bb76a5fd96dcd25eb1d0b5736a86.tar.xz
org.eclipse.cdt-2e2e1763bde6bb76a5fd96dcd25eb1d0b5736a86.zip
Bug 426888 -fixed comment assignment bug.
Change-Id: I3fb9b68c6c543c09ee9c7d546a2c61086f808a44 Signed-off-by: Lukas Felber <l.felber@gmx.ch> Reviewed-on: https://git.eclipse.org/r/21307 Reviewed-by: Thomas Corbat <tcorbat@hsr.ch> IP-Clean: Thomas Corbat <tcorbat@hsr.ch> Tested-by: Thomas Corbat <tcorbat@hsr.ch>
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java38
2 files changed, 35 insertions, 21 deletions
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts b/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts
index c89f4945db..7addf4d1e0 100644
--- a/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts
@@ -3198,4 +3198,20 @@ void foo();
//=
=>leading
=>trailing
-=>freestanding \ No newline at end of file
+=>freestanding
+//!CommentRecognition comment in empty compound statement width include guard
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@A.h
+#ifndef A_H_
+#define A_H_
+void foo() {
+ // comment in body
+}
+#endif
+//=
+=>leading
+=>trailing
+=>freestanding
+{
+ // comment in body
+} = // comment in body
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 6713964575..8fc605eee4 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
@@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
* This is the starting point of the entire comment handling process. The creation of the
@@ -52,30 +51,30 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
* @author Guido Zgraggen IFS
*/
public class ASTCommenter {
-
+
private static final class PreprocessorRangeChecker extends ASTVisitor {
- int statementOffset;
- IASTFileLocation commentNodeLocation;
- boolean isPreStatementComment = true;
-
- private PreprocessorRangeChecker(int statementOffset, IASTFileLocation commentNodeLocation) {
+ int ppStmtOffset;
+ IASTFileLocation commentLocation;
+ boolean isPrePpStmtComment = true;
+
+ private PreprocessorRangeChecker(int statementOffset, IASTFileLocation commentLocation) {
super(true);
- this.statementOffset = statementOffset;
- this.commentNodeLocation = commentNodeLocation;
+ this.ppStmtOffset = statementOffset;
+ this.commentLocation = commentLocation;
}
private int checkOffsets(IASTNode node) {
- int offset = ((ASTNode) node).getOffset();
+ IASTFileLocation nodeLocation = node.getFileLocation();
+ int nodeEndOffset = nodeLocation.getNodeOffset() + nodeLocation.getNodeLength();
int status = PROCESS_CONTINUE;
-
- if (isCommentOnSameLine(node)
- || offset > commentNodeLocation.getNodeOffset()
- && offset < statementOffset) {
- isPreStatementComment = false;
+
+ boolean nodeInBetweenCommentAndPpStmt = nodeEndOffset > commentLocation.getNodeOffset() && nodeEndOffset < ppStmtOffset;
+ if (isCommentOnSameLine(node) || nodeInBetweenCommentAndPpStmt) {
+ isPrePpStmtComment = false;
status = PROCESS_ABORT;
- } else if ((offset + ((ASTNode) node).getLength() < commentNodeLocation.getNodeOffset())) {
+ } else if (nodeEndOffset < commentLocation.getNodeOffset()) {
status = PROCESS_SKIP;
- } else if (offset > statementOffset) {
+ } else if (nodeLocation.getNodeOffset() > ppStmtOffset) {
status = PROCESS_ABORT;
}
@@ -84,8 +83,7 @@ public class ASTCommenter {
private boolean isCommentOnSameLine(IASTNode node) {
IASTFileLocation fileLocation = node.getFileLocation();
- return fileLocation != null &&
- commentNodeLocation.getStartingLineNumber() == fileLocation.getEndingLineNumber();
+ return fileLocation != null && commentLocation.getStartingLineNumber() == fileLocation.getEndingLineNumber();
}
@Override
@@ -205,7 +203,7 @@ public class ASTCommenter {
if (preprocessorOffset > commentLocation.getNodeOffset()) {
PreprocessorRangeChecker visitor = new PreprocessorRangeChecker(preprocessorOffset, commentLocation);
tu.accept(visitor);
- return visitor.isPreStatementComment;
+ return visitor.isPrePpStmtComment;
}
return false;
}

Back to the top