Class TreeParser

java.lang.Object
org.checkerframework.javacutil.trees.TreeParser

public class TreeParser extends Object
A utility class for parsing Java expression snippets, and converting them to proper Javac AST nodes.

This is useful for parsing EnsuresNonNull*, and KeyFor values.

Currently, it handles four tree types only:

  • Identifier tree (e.g. id)
  • Literal tree (e.g. 2, 3)
  • Method invocation tree (e.g. method(2, 3))
  • Member select tree (e.g. Class.field, instance.method())
  • Array access tree (e.g. array[id])
Notable limitation: Doesn't handle spaces, or non-method-argument parenthesis.

It's implemented via a Recursive-Descend parser.

  • Constructor Details

  • Method Details

    • parseTree

      public ExpressionTree parseTree(String s)
      Parses the snippet in the string as an internal Javac AST expression node.
      Parameters:
      s - the Java snippet
      Returns:
      the AST corresponding to the snippet