private static boolean hasParameterComment(ErrorProneToken token) { return token.comments().stream() .filter(c -> c.getStyle() == BLOCK) .anyMatch( c -> NamedParameterComment.PARAMETER_COMMENT_PATTERN .matcher(Comments.getTextFromComment(c)) .matches()); }
private static boolean isApproximateMatchingComment(Comment comment, String formal) { switch (comment.getStyle()) { case BLOCK: case LINE: // sometimes people use comments around arguments for higher level structuring - such as // dividing two separate blocks of arguments. In these cases we want to avoid concluding // that its a match. Therefore we also check to make sure that the comment is not really // long and that it doesn't contain acsii-art style markup. String commentText = Comments.getTextFromComment(comment); boolean textMatches = Arrays.asList(commentText.split("[^a-zA-Z0-9_]+", -1)).contains(formal); boolean tooLong = commentText.length() > formal.length() + 5 && commentText.length() > 50; boolean tooMuchMarkup = CharMatcher.anyOf("-*!@<>").countIn(commentText) > 5; return textMatches && !tooLong && !tooMuchMarkup; default: return false; } }
Optional<Comment> lastBlockComment = Streams.findLast( actual.beforeComments().stream().filter(c -> c.getStyle() == CommentStyle.BLOCK));
List<Comment> matches = new ArrayList<>(); for (Comment comment : token.comments()) { if (comment.getStyle() != BLOCK) { continue;
Optional<Comment> lastBlockComment = Streams.findLast( actual.beforeComments().stream().filter(c -> c.getStyle() == CommentStyle.BLOCK));
/** * Extract the text body from a comment. * * <p>This currently includes asterisks that start lines in the body of block comments. Do not * rely on this behaviour. * * <p>TODO(andrewrice) Update this method to handle block comments properly if we find the need */ public static String getTextFromComment(Comment comment) { switch (comment.getStyle()) { case BLOCK: return comment.getText().replaceAll("^\\s*/\\*\\s*(.*?)\\s*\\*/\\s*", "$1"); case LINE: return comment.getText().replaceAll("^\\s*//\\s*", ""); default: return comment.getText(); } }
private static boolean isApproximateMatchingComment(Comment comment, String formal) { switch (comment.getStyle()) { case BLOCK: case LINE: // sometimes people use comments around arguments for higher level structuring - such as // dividing two separate blocks of arguments. In these cases we want to avoid concluding // that its a match. Therefore we also check to make sure that the comment is not really // long and that it doesn't contain acsii-art style markup. String commentText = Comments.getTextFromComment(comment); boolean textMatches = Arrays.asList(commentText.split("[^a-zA-Z0-9_]+", -1)).contains(formal); boolean tooLong = commentText.length() > formal.length() + 5 && commentText.length() > 50; boolean tooMuchMarkup = CharMatcher.anyOf("-*!@<>").countIn(commentText) > 5; return textMatches && !tooLong && !tooMuchMarkup; default: return false; } }
private List<Comment> getComments(Comment.CommentStyle style) { if (comments == null) { return List.nil(); } else { ListBuffer<Comment> buf = new ListBuffer<>(); for (Comment c : comments) { if (c.getStyle() == style) { buf.add(c); } } return buf.toList(); } } }
private static void replaceDescrition(JCClassDecl classDecl, DocCommentTable docComments) { for (JCTree def : classDecl.defs) { if (def.getClass().getSimpleName().equals("JCClassDecl")) { replaceDescrition((JCClassDecl) def, docComments); } else if (def.getClass().getSimpleName().equals("JCVariableDecl")) { JCVariableDecl variable = (JCVariableDecl) def; Tokens.Comment comment = docComments.getComment(def); if (comment != null && comment.getStyle().equals(JAVADOC)) { ((JCLiteral) ((JCVariableDecl) def).init).value = comment.getText(); } } } } }
private List<Comment> getComments(Comment.CommentStyle style) { if (comments == null) { return List.nil(); } else { ListBuffer<Comment> buf = new ListBuffer<>(); for (Comment c : comments) { if (c.getStyle() == style) { buf.add(c); } } return buf.toList(); } } }
private static boolean hasParameterComment(ErrorProneToken token) { return token.comments().stream() .filter(c -> c.getStyle() == BLOCK) .anyMatch( c -> NamedParameterComment.PARAMETER_COMMENT_PATTERN .matcher(Comments.getTextFromComment(c)) .matches()); }
@Override public CommentStyle getStyle() { return wrapped.getStyle(); }
List<Comment> matches = new ArrayList<>(); for (Comment comment : token.comments()) { if (comment.getStyle() != BLOCK) { continue;
/** * Extract the text body from a comment. * * <p>This currently includes asterisks that start lines in the body of block comments. Do not * rely on this behaviour. * * <p>TODO(andrewrice) Update this method to handle block comments properly if we find the need */ public static String getTextFromComment(Comment comment) { switch (comment.getStyle()) { case BLOCK: return comment.getText().replaceAll("^\\s*/\\*\\s*(.*?)\\s*\\*/\\s*", "$1"); case LINE: return comment.getText().replaceAll("^\\s*//\\s*", ""); default: return comment.getText(); } }
@Override public CommentStyle getStyle() { return wrapped.getStyle(); }