@Nullable private static Comment findOrphanedJavadoc(Name name, List<ErrorProneToken> tokens) { for (ErrorProneToken token : tokens) { for (Comment comment : token.comments()) { if (comment.getText().startsWith("/**")) { return comment; } } if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(name)) { return null; } } return null; } }
private static String removeJavadoc( VisitorState state, int startPos, Comment danglingJavadoc, SuggestedFix.Builder builder) { int javadocStart = startPos + danglingJavadoc.getSourcePos(0); int javadocEnd = javadocStart + danglingJavadoc.getText().length(); // Capturing an extra newline helps the formatter. if (state.getSourceCode().charAt(javadocEnd) == '\n') { javadocEnd++; } builder.replace(javadocStart, javadocEnd, ""); return danglingJavadoc.getText(); }
/** * 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(); } }
/** * 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 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(); } } } } }
public String getCommentText(JCTree tree) { Comment c = getComment(tree); return (c == null) ? null : c.getText(); }
@Override public String getText() { return wrapped.getText(); }
@Nullable private static Comment findOrphanedJavadoc(Name name, List<ErrorProneToken> tokens) { for (ErrorProneToken token : tokens) { for (Comment comment : token.comments()) { if (comment.getText().startsWith("/**")) { return comment; } } if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(name)) { return null; } } return null; } }
private static void fixParamComment( SuggestedFix.Builder fix, Commented<ExpressionTree> commented, VarSymbol param, Comment c) { fix.prefixWith(commented.tree(), String.format("/* %s= */ ", param.getSimpleName())) .replace(c.getSourcePos(0), c.getSourcePos(0) + c.getText().length(), ""); } }
private static int commentEnd(DCDocComment doc) { int length = doc.comment.getText().length(); return doc.comment.getSourcePos(length-1); }
public String getCommentText(JCTree tree) { Comment c = getComment(tree); return (c == null) ? null : c.getText(); }
private static String removeJavadoc( VisitorState state, int startPos, Comment danglingJavadoc, SuggestedFix.Builder builder) { int javadocStart = startPos + danglingJavadoc.getSourcePos(0); int javadocEnd = javadocStart + danglingJavadoc.getText().length(); // Capturing an extra newline helps the formatter. if (state.getSourceCode().charAt(javadocEnd) == '\n') { javadocEnd++; } builder.replace(javadocStart, javadocEnd, ""); return danglingJavadoc.getText(); }
Comment comment = compilationUnit.docComments.getComment(element); String commentText = JSDoc.adaptDocComment(context, getCompilationUnit(), element, comment == null ? null : comment.getText());
int endOfCommentPos = comment.getSourcePos(comment.getText().length() - 1); String stringBetweenComments = source.substring(endOfCommentPos, startPos); if (stringBetweenComments.chars().filter(c -> c == '\n').count() > 1) {
RangeSet<Integer> emittedFixes = TreeRangeSet.create(); Comment comment = ((DCDocComment) path.getDocComment()).comment; Matcher matcher = GENERIC.matcher(comment.getText()); while (matcher.find()) { Range<Integer> range =
private static void fixParamComment( SuggestedFix.Builder fix, Commented<ExpressionTree> commented, VarSymbol param, Comment c) { fix.prefixWith(commented.tree(), String.format("/* %s= */ ", param.getSimpleName())) .replace(c.getSourcePos(0), c.getSourcePos(0) + c.getText().length(), ""); } }
@Override public String getText() { return wrapped.getText(); }