mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +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
|
=>leading
|
||||||
=>trailing
|
=>trailing
|
||||||
=>freestanding
|
=>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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
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
|
* 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 {
|
public class ASTCommenter {
|
||||||
|
|
||||||
private static final class PreprocessorRangeChecker extends ASTVisitor {
|
private static final class PreprocessorRangeChecker extends ASTVisitor {
|
||||||
int statementOffset;
|
int ppStmtOffset;
|
||||||
IASTFileLocation commentNodeLocation;
|
IASTFileLocation commentLocation;
|
||||||
boolean isPreStatementComment = true;
|
boolean isPrePpStmtComment = true;
|
||||||
|
|
||||||
private PreprocessorRangeChecker(int statementOffset, IASTFileLocation commentNodeLocation) {
|
private PreprocessorRangeChecker(int statementOffset, IASTFileLocation commentLocation) {
|
||||||
super(true);
|
super(true);
|
||||||
this.statementOffset = statementOffset;
|
this.ppStmtOffset = statementOffset;
|
||||||
this.commentNodeLocation = commentNodeLocation;
|
this.commentLocation = commentLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int checkOffsets(IASTNode node) {
|
private int checkOffsets(IASTNode node) {
|
||||||
int offset = ((ASTNode) node).getOffset();
|
IASTFileLocation nodeLocation = node.getFileLocation();
|
||||||
|
int nodeEndOffset = nodeLocation.getNodeOffset() + nodeLocation.getNodeLength();
|
||||||
int status = PROCESS_CONTINUE;
|
int status = PROCESS_CONTINUE;
|
||||||
|
|
||||||
if (isCommentOnSameLine(node)
|
boolean nodeInBetweenCommentAndPpStmt = nodeEndOffset > commentLocation.getNodeOffset() && nodeEndOffset < ppStmtOffset;
|
||||||
|| offset > commentNodeLocation.getNodeOffset()
|
if (isCommentOnSameLine(node) || nodeInBetweenCommentAndPpStmt) {
|
||||||
&& offset < statementOffset) {
|
isPrePpStmtComment = false;
|
||||||
isPreStatementComment = false;
|
|
||||||
status = PROCESS_ABORT;
|
status = PROCESS_ABORT;
|
||||||
} else if ((offset + ((ASTNode) node).getLength() < commentNodeLocation.getNodeOffset())) {
|
} else if (nodeEndOffset < commentLocation.getNodeOffset()) {
|
||||||
status = PROCESS_SKIP;
|
status = PROCESS_SKIP;
|
||||||
} else if (offset > statementOffset) {
|
} else if (nodeLocation.getNodeOffset() > ppStmtOffset) {
|
||||||
status = PROCESS_ABORT;
|
status = PROCESS_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +83,7 @@ public class ASTCommenter {
|
||||||
|
|
||||||
private boolean isCommentOnSameLine(IASTNode node) {
|
private boolean isCommentOnSameLine(IASTNode node) {
|
||||||
IASTFileLocation fileLocation = node.getFileLocation();
|
IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
return fileLocation != null &&
|
return fileLocation != null && commentLocation.getStartingLineNumber() == fileLocation.getEndingLineNumber();
|
||||||
commentNodeLocation.getStartingLineNumber() == fileLocation.getEndingLineNumber();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -205,7 +203,7 @@ public class ASTCommenter {
|
||||||
if (preprocessorOffset > commentLocation.getNodeOffset()) {
|
if (preprocessorOffset > commentLocation.getNodeOffset()) {
|
||||||
PreprocessorRangeChecker visitor = new PreprocessorRangeChecker(preprocessorOffset, commentLocation);
|
PreprocessorRangeChecker visitor = new PreprocessorRangeChecker(preprocessorOffset, commentLocation);
|
||||||
tu.accept(visitor);
|
tu.accept(visitor);
|
||||||
return visitor.isPreStatementComment;
|
return visitor.isPrePpStmtComment;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue