Class Comments

java.lang.Object
com.google.errorprone.util.Comments

public final class Comments extends Object
Utilities for attaching comments to relevant AST nodes
Author:
andrewrice@google.com (Andrew Rice)
  • Method Details

    • findCommentsForArguments

      public static com.google.common.collect.ImmutableList<Commented<com.sun.source.tree.ExpressionTree>> findCommentsForArguments(com.sun.source.tree.NewClassTree newClassTree, VisitorState state)
      Attach comments to nodes on arguments of constructor calls. Calls such as new Test( param1 /* c1 *&#47;, /* c2 *&#47; param2) will attach the comment c1 to param1 and the comment c2 to param2.

      Warning: this is expensive to compute as it involves re-tokenizing the source for this node.

      Currently this method will only tokenize the source code of the method call itself. However, the source positions in the returned Comment objects are adjusted so that they are relative to the whole file.

    • findCommentsForArguments

      public static com.google.common.collect.ImmutableList<Commented<com.sun.source.tree.ExpressionTree>> findCommentsForArguments(com.sun.source.tree.MethodInvocationTree methodInvocationTree, VisitorState state)
      Attach comments to nodes on arguments of method calls. Calls such as test(param1 /* c1 *&#47;, /* c2 *&#47; param2) will attach the comment c1 to param1 and the comment c2 to param2.

      Warning: this is expensive to compute as it involves re-tokenizing the source for this node

      Currently this method will only tokenize the source code of the method call itself. However, the source positions in the returned Comment objects are adjusted so that they are relative to the whole file.

    • getTextFromComment

      public static String getTextFromComment(ErrorProneComment comment)
      Extract the text body from a comment.

      This currently includes asterisks that start lines in the body of block comments. Do not rely on this behaviour.

      TODO(andrewrice) Update this method to handle block comments properly if we find the need