/** * 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); } } }
if (cppComments.containsKey(lineNo)) { comment = cppComments.get(lineNo); lineBefore = line.substring(0, comment.getStartColNo()); lineBefore = line.substring(0, comment.getStartColNo()); if (comment.getText().length == 1 && !CommonUtil.isBlank(line .substring(comment.getEndColNo() + 1))) { continue;
/** * Checks if given comment is legal (single-line and matches to the * pattern). * @param comment comment to check. * @return true if the comment if legal. */ private boolean isLegalComment(final TextBlock comment) { final boolean legal; // multi-line comment can not be legal if (legalComment == null || comment.getStartLineNo() != comment.getEndLineNo()) { legal = false; } else { String commentText = comment.getText()[0]; // remove chars which start comment commentText = commentText.substring(2); // if this is a C-style comment we need to remove its end if (commentText.endsWith("*/")) { commentText = commentText.substring(0, commentText.length() - 2); } commentText = commentText.trim(); legal = legalComment.matcher(commentText).find(); } return legal; }
/** * Whether the C style comment is trailing. * @param comment the comment to check. * @param line the line where the comment starts. * @return true if the comment is trailing. */ private static boolean isTrailingBlockComment(TextBlock comment, String line) { return comment.getText().length != 1 || CommonUtil.isBlank(line.substring(comment.getEndColNo() + 1)); }
/** * Checks that the Javadoc is not empty. * * @param comment the source lines that make up the Javadoc comment. */ private void checkJavadocIsNotEmpty(TextBlock comment) { final String commentText = getCommentText(comment.getText()); if (commentText.isEmpty()) { log(comment.getStartLineNo(), MSG_EMPTY); } }
/** * Checks to see if the text block contains a inheritDoc tag. * * @param javadoc the javadoc of the AST * @return true if contains the tag */ private static boolean containsJavadocTag(final TextBlock javadoc) { boolean javadocTag = false; if (javadoc != null) { final String[] lines = javadoc.getText(); for (final String line : lines) { final Matcher matchInheritDoc = MATCH_INHERIT_DOC.matcher(line); if (matchInheritDoc.find()) { javadocTag = true; break; } } } return javadocTag; }
/** * 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 (final TextBlock comment : comments) { final int startLineNo = comment.getStartLineNo(); final String[] text = comment.getText(); tagCommentLine(text[0], startLineNo); for (int i = 1; i < text.length; i++) { tagCommentLine(text[i], startLineNo + i); } } }
@Override public void visitToken(DetailAST ast) { final FileContents contents = getFileContents(); final int lineNo = ast.getLineNo(); final TextBlock cmt = contents.getJavadocBefore(lineNo); if (cmt == null) { log(lineNo, MSG_MISSING_TAG, tag); } else { checkTag(lineNo, cmt.getText()); } }
/** * Whether the C style comment is trailing. * @param comment the comment to check. * @param line the line where the comment starts. * @return true if the comment is trailing. */ private static boolean isTrailingBlockComment(TextBlock comment, String line) { return comment.getText().length != 1 || CommonUtil.isBlank(line.substring(comment.getEndColNo() + 1)); }
final String[] lines = comment.getText(); final List<JavadocTag> tags = new ArrayList<>(); int currentLine = comment.getStartLineNo() - 1; final int startColumnNumber = comment.getStartColNo();
/** * Checks that the first sentence ends with proper punctuation. This method * uses a regular expression that checks for the presence of a period, * question mark, or exclamation mark followed either by whitespace, an * HTML element, or the end of string. This method ignores {_AT_inheritDoc} * comments for TokenTypes that are valid for {_AT_inheritDoc}. * * @param ast the current node * @param comment the source lines that make up the Javadoc comment. */ private void checkFirstSentenceEnding(final DetailAST ast, TextBlock comment) { final String commentText = getCommentText(comment.getText()); if (!commentText.isEmpty() && !endOfSentenceFormat.matcher(commentText).find() && !(commentText.startsWith("{@inheritDoc}") && JavadocTagInfo.INHERIT_DOC.isValidOn(ast))) { log(comment.getStartLineNo(), MSG_NO_PERIOD); } }
@Test public void testExtractBlockComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Arrays.asList(" ", " ", " /* test ", " */ ", " "))); fileContents.reportCComment(3, 2, 4, 2); final Map<Integer, List<TextBlock>> blockComments = fileContents.getBlockComments(); final String[] text = blockComments.get(3).get(0).getText(); assertArrayEquals("Invalid comment text", new String[] {"/* test ", " *"}, text); }
/** * Checks if given comment is legal (single-line and matches to the * pattern). * @param comment comment to check. * @return true if the comment if legal. */ private boolean isLegalComment(final TextBlock comment) { final boolean legal; // multi-line comment can not be legal if (legalComment == null || comment.getStartLineNo() != comment.getEndLineNo()) { legal = false; } else { String commentText = comment.getText()[0]; // remove chars which start comment commentText = commentText.substring(2); // if this is a C-style comment we need to remove its end if (commentText.endsWith("*/")) { commentText = commentText.substring(0, commentText.length() - 2); } commentText = commentText.trim(); legal = legalComment.matcher(commentText).find(); } return legal; }
if (cppComments.containsKey(lineNo)) { comment = cppComments.get(lineNo); lineBefore = line.substring(0, comment.getStartColNo()); lineBefore = line.substring(0, comment.getStartColNo()); if (comment.getText().length == 1 && !CommonUtil.isBlank(line .substring(comment.getEndColNo() + 1))) { continue;
final String[] text = aCmt.getText(); final List<JavadocTag> tags = Lists.newArrayList(); final List<InvalidJavadocTag> invalidTags = Lists.newArrayList(); content = content.substring(0, content.length() - 2); final int line = aCmt.getStartLineNo() + i; int col = blockTagMatcher.start(1) - 1; if (i == 0) { col += aCmt.getStartColNo(); final String tagName = tagMatcher.group(1); final String tagValue = tagMatcher.group(2).trim(); final int line = aCmt.getStartLineNo() + i; int col = commentOffset + (tagMatcher.start(1) - 1); if (i == 0) { col += aCmt.getStartColNo();
boolean found = false; if (javadoc != null) { final String[] lines = javadoc.getText(); int currentLine = javadoc.getStartLineNo() - 1;
private static boolean isSeeJavaDoc(final List<TextBlock> comment) { // Check whether there is a line containing (non-Javadoc) in the comment for (final TextBlock block : comment) { for (final String line : block.getText()) { if (line.toLowerCase(Locale.ENGLISH).contains("(non-javadoc)")) { return true; } } } return false; }
/** * 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); } } }
tags.addAll(BlockTagUtil.extractBlockTags(textBlock.getText())); tags.addAll(InlineTagUtil.extractInlineTags(textBlock.getText())); final int line = textBlock.getStartLineNo() + tag.getPosition().getLine() - 1;
private static boolean isJavadocComment(final List<TextBlock> comment) { return comment.get(0).getText()[0].startsWith("/**"); }