mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
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>
This commit is contained in:
parent
99de8fdda1
commit
2e2e1763bd
2 changed files with 35 additions and 21 deletions
|
@ -3199,3 +3199,19 @@ void foo();
|
|||
=>leading
|
||||
=>trailing
|
||||
=>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
|
||||
|
|
|
@ -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
|
||||
|
@ -54,28 +53,28 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
public class ASTCommenter {
|
||||
|
||||
private static final class PreprocessorRangeChecker extends ASTVisitor {
|
||||
int statementOffset;
|
||||
IASTFileLocation commentNodeLocation;
|
||||
boolean isPreStatementComment = true;
|
||||
int ppStmtOffset;
|
||||
IASTFileLocation commentLocation;
|
||||
boolean isPrePpStmtComment = true;
|
||||
|
||||
private PreprocessorRangeChecker(int statementOffset, IASTFileLocation commentNodeLocation) {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue