Class SourceCode

java.lang.Object
tech.picnic.errorprone.bugpatterns.util.SourceCode

public final class SourceCode extends Object
A collection of Error Prone utility methods for dealing with the source code representation of AST nodes.
  • Method Details

    • treeToString

      public static String treeToString(Tree tree, com.google.errorprone.VisitorState state)
      Returns a string representation of the given Tree, preferring the original source code (if available) over its prettified representation.
      Parameters:
      tree - The AST node of interest.
      state - A VisitorState describing the context in which the given Tree is found.
      Returns:
      A non-null string.
    • deleteWithTrailingWhitespace

      public static com.google.errorprone.fixes.SuggestedFix deleteWithTrailingWhitespace(Tree tree, com.google.errorprone.VisitorState state)
      Creates a SuggestedFix for the deletion of the given Tree, including any whitespace that follows it.

      Removing trailing whitespace may prevent the introduction of an empty line at the start of a code block; such empty lines are not removed when formatting the code using Google Java Format.

      Parameters:
      tree - The AST node of interest.
      state - A VisitorState describing the context in which the given Tree is found.
      Returns:
      A non-null SuggestedFix similar to one produced by SuggestedFix.delete(Tree).