use of com.puppycrawl.tools.checkstyle.api.TextBlock in project checkstyle by checkstyle.
the class TrailingCommentCheck method beginTree.
@Override
public void beginTree(DetailAST rootAST) {
final Map<Integer, TextBlock> cppComments = getFileContents().getSingleLineComments();
final Map<Integer, List<TextBlock>> cComments = getFileContents().getBlockComments();
final Set<Integer> lines = new HashSet<>();
lines.addAll(cppComments.keySet());
lines.addAll(cComments.keySet());
for (Integer lineNo : lines) {
final String line = getLines()[lineNo - 1];
final String lineBefore;
final TextBlock comment;
if (cppComments.containsKey(lineNo)) {
comment = cppComments.get(lineNo);
lineBefore = line.substring(0, comment.getStartColNo());
} else {
final List<TextBlock> commentList = cComments.get(lineNo);
comment = commentList.get(commentList.size() - 1);
lineBefore = line.substring(0, comment.getStartColNo());
// do not check comment which doesn't end line
if (comment.getText().length == 1 && !line.substring(comment.getEndColNo() + 1).trim().isEmpty()) {
continue;
}
}
if (!format.matcher(lineBefore).find() && !isLegalComment(comment)) {
log(lineNo, MSG_KEY);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.TextBlock in project checkstyle by checkstyle.
the class SuppressionCommentFilter method tagSuppressions.
/**
* Appends the suppressions in a collection of comments to the full
* set of suppression tags.
* @param comments the set of comments.
*/
private void tagSuppressions(Collection<TextBlock> comments) {
for (TextBlock comment : comments) {
final int startLineNo = comment.getStartLineNo();
final String[] text = comment.getText();
tagCommentLine(text[0], startLineNo, comment.getStartColNo());
for (int i = 1; i < text.length; i++) {
tagCommentLine(text[i], startLineNo + i, 0);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.TextBlock in project checkstyle by checkstyle.
the class AvoidEscapedUnicodeCharactersCheck method hasTrailComment.
/**
* Check if trail comment is present after ast token.
* @param ast current token.
* @return true if trail comment is present after ast token.
*/
private boolean hasTrailComment(DetailAST ast) {
boolean result = false;
final int lineNo = ast.getLineNo();
if (singlelineComments.containsKey(lineNo)) {
result = true;
} else {
final String line = getLines()[lineNo - 1];
final List<TextBlock> commentList = blockComments.get(lineNo);
if (commentList != null) {
final TextBlock comment = commentList.get(commentList.size() - 1);
result = isTrailingBlockComment(comment, line);
}
}
return result;
}
use of com.puppycrawl.tools.checkstyle.api.TextBlock in project checkstyle by checkstyle.
the class MissingDeprecatedCheck method visitToken.
@Override
public void visitToken(final DetailAST ast) {
final TextBlock javadoc = getFileContents().getJavadocBefore(ast.getLineNo());
final boolean containsAnnotation = AnnotationUtility.containsAnnotation(ast, DEPRECATED) || AnnotationUtility.containsAnnotation(ast, FQ_DEPRECATED);
final boolean containsJavadocTag = containsJavadocTag(javadoc);
if (containsAnnotation ^ containsJavadocTag && !(skipNoJavadoc && javadoc == null)) {
log(ast.getLineNo(), MSG_KEY_ANNOTATION_MISSING_DEPRECATED);
}
}
use of com.puppycrawl.tools.checkstyle.api.TextBlock in project checkstyle by checkstyle.
the class MissingOverrideCheck method visitToken.
// -@cs[CyclomaticComplexity] Too complex to break apart.
@Override
public void visitToken(final DetailAST ast) {
final TextBlock javadoc = getFileContents().getJavadocBefore(ast.getLineNo());
final boolean containsTag = containsJavadocTag(javadoc);
if (containsTag && !JavadocTagInfo.INHERIT_DOC.isValidOn(ast)) {
log(ast.getLineNo(), MSG_KEY_TAG_NOT_VALID_ON, JavadocTagInfo.INHERIT_DOC.getText());
} else {
boolean check = true;
if (javaFiveCompatibility) {
final DetailAST defOrNew = ast.getParent().getParent();
if (defOrNew.branchContains(TokenTypes.EXTENDS_CLAUSE) || defOrNew.branchContains(TokenTypes.IMPLEMENTS_CLAUSE) || defOrNew.getType() == TokenTypes.LITERAL_NEW) {
check = false;
}
}
if (check && containsTag && !AnnotationUtility.containsAnnotation(ast, OVERRIDE) && !AnnotationUtility.containsAnnotation(ast, FQ_OVERRIDE)) {
log(ast.getLineNo(), MSG_KEY_ANNOTATION_MISSING_OVERRIDE);
}
}
}