Class TreeBuilder
java.lang.Object
org.checkerframework.javacutil.trees.TreeBuilder
- Direct Known Subclasses:
CFTreeBuilder
The TreeBuilder permits the creation of new AST Trees using the non-public Java compiler API
TreeMaker.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Elementsprotected final ProcessingEnvironmentprotected final com.sun.tools.javac.code.Typesprotected final com.sun.tools.javac.tree.TreeMakerprotected final Typesprotected final com.sun.tools.javac.util.Namesprotected final com.sun.tools.javac.code.Symtab -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.sun.source.tree.ArrayAccessTreebuildArrayAccess(com.sun.source.tree.ExpressionTree array, com.sun.source.tree.ExpressionTree index) Builds an AST Tree to dereference an array.com.sun.source.tree.MemberSelectTreebuildArrayLengthAccess(com.sun.source.tree.ExpressionTree expression) Builds an AST Tree to dereference the length field of an array.com.sun.source.tree.AssignmentTreebuildAssignment(com.sun.source.tree.ExpressionTree lhs, com.sun.source.tree.ExpressionTree rhs) Builds an AST Tree to assign an RHS expression to an LHS expression.com.sun.source.tree.StatementTreebuildAssignment(com.sun.source.tree.VariableTree variable, com.sun.source.tree.ExpressionTree expr) Builds an AST Tree to assign an expression to a variable.com.sun.source.tree.BinaryTreebuildBinary(TypeMirror type, com.sun.source.tree.Tree.Kind op, com.sun.source.tree.ExpressionTree left, com.sun.source.tree.ExpressionTree right) Builds an AST Tree to perform a binary operation.com.sun.source.tree.IdentifierTreebuildClassUse(Element elt) Builds an AST Tree to refer to a class name.com.sun.source.tree.MemberSelectTreebuildHasNextMethodAccess(com.sun.source.tree.ExpressionTree iteratorExpr) Builds an AST Tree to access the hasNext() method of an iterator.com.sun.source.tree.MemberSelectTreebuildIteratorMethodAccess(com.sun.source.tree.ExpressionTree iterableExpr) Builds an AST Tree to access the iterator() method of some iterable expression.com.sun.source.tree.BinaryTreebuildLessThan(com.sun.source.tree.ExpressionTree left, com.sun.source.tree.ExpressionTree right) Builds an AST Tree to compare two operands with less than.com.sun.source.tree.LiteralTreebuildLiteral(Object value) Builds an AST Tree representing a literal value of primitive or String type.com.sun.source.tree.MethodInvocationTreebuildMethodInvocation(com.sun.source.tree.ExpressionTree methodExpr) Builds an AST Tree to call a method designated by the argument expression.com.sun.source.tree.MethodInvocationTreebuildMethodInvocation(com.sun.source.tree.ExpressionTree methodExpr, com.sun.source.tree.ExpressionTree argExpr) Builds an AST Tree to call a method designated by methodExpr, with one argument designated by argExpr.com.sun.source.tree.NewArrayTreebuildNewArray(TypeMirror componentType, List<com.sun.source.tree.ExpressionTree> elems) Builds an AST Tree to create a new array with initializers.com.sun.source.tree.MemberSelectTreebuildNextMethodAccess(com.sun.source.tree.ExpressionTree iteratorExpr) Builds an AST Tree to access the next() method of an iterator.com.sun.source.tree.MemberSelectTreebuildPrimValueMethodAccess(com.sun.source.tree.Tree expr) Builds an AST Tree to access the *Value() method of a boxed type such as Short or Float, where * is the corresponding primitive type (i.e.com.sun.source.tree.TypeCastTreebuildTypeCast(TypeMirror type, com.sun.source.tree.ExpressionTree expr) Builds an AST Tree to cast the type of an expression.com.sun.source.tree.MemberSelectTreebuildValueOfMethodAccess(com.sun.source.tree.Tree expr) Builds an AST Tree to access the valueOf() method of boxed type such as Short or Float.com.sun.source.tree.VariableTreebuildVariableDecl(com.sun.source.tree.Tree type, String name, Element owner, com.sun.source.tree.ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable.com.sun.source.tree.VariableTreebuildVariableDecl(TypeMirror type, String name, Element owner, com.sun.source.tree.ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable, with no modifiers.com.sun.source.tree.IdentifierTreebuildVariableUse(com.sun.source.tree.VariableTree decl) Builds an AST Tree to refer to a variable.static com.sun.tools.javac.code.Symbol.MethodSymbolgetValueOfMethod(ProcessingEnvironment env, TypeMirror boxedType) Returns the valueOf method of a boxed type such as Short or Float.com.sun.tools.javac.tree.JCTree.TagkindToTag(com.sun.source.tree.Tree.Kind kind) Map public AST Tree.Kinds to internal javac JCTree.Tags.
-
Field Details
-
elements
-
modelTypes
-
javacTypes
protected final com.sun.tools.javac.code.Types javacTypes -
maker
protected final com.sun.tools.javac.tree.TreeMaker maker -
names
protected final com.sun.tools.javac.util.Names names -
symtab
protected final com.sun.tools.javac.code.Symtab symtab -
env
-
-
Constructor Details
-
TreeBuilder
-
-
Method Details
-
buildIteratorMethodAccess
public com.sun.source.tree.MemberSelectTree buildIteratorMethodAccess(com.sun.source.tree.ExpressionTree iterableExpr) Builds an AST Tree to access the iterator() method of some iterable expression.- Parameters:
iterableExpr- an expression whose type is a subtype of Iterable- Returns:
- a MemberSelectTree that accesses the iterator() method of the expression
-
buildHasNextMethodAccess
public com.sun.source.tree.MemberSelectTree buildHasNextMethodAccess(com.sun.source.tree.ExpressionTree iteratorExpr) Builds an AST Tree to access the hasNext() method of an iterator.- Parameters:
iteratorExpr- an expression whose type is a subtype of Iterator- Returns:
- a MemberSelectTree that accesses the hasNext() method of the expression
-
buildNextMethodAccess
public com.sun.source.tree.MemberSelectTree buildNextMethodAccess(com.sun.source.tree.ExpressionTree iteratorExpr) Builds an AST Tree to access the next() method of an iterator.- Parameters:
iteratorExpr- an expression whose type is a subtype of Iterator- Returns:
- a MemberSelectTree that accesses the next() method of the expression
-
buildArrayLengthAccess
public com.sun.source.tree.MemberSelectTree buildArrayLengthAccess(com.sun.source.tree.ExpressionTree expression) Builds an AST Tree to dereference the length field of an array.- Parameters:
expression- the array expression whose length is being accessed- Returns:
- a MemberSelectTree to dereference the length of the array
-
buildMethodInvocation
public com.sun.source.tree.MethodInvocationTree buildMethodInvocation(com.sun.source.tree.ExpressionTree methodExpr) Builds an AST Tree to call a method designated by the argument expression.- Parameters:
methodExpr- an expression denoting a method with no arguments- Returns:
- a MethodInvocationTree to call the argument method
-
buildMethodInvocation
public com.sun.source.tree.MethodInvocationTree buildMethodInvocation(com.sun.source.tree.ExpressionTree methodExpr, com.sun.source.tree.ExpressionTree argExpr) Builds an AST Tree to call a method designated by methodExpr, with one argument designated by argExpr.- Parameters:
methodExpr- an expression denoting a method with one argumentargExpr- an expression denoting an argument to the method- Returns:
- a MethodInvocationTree to call the argument method
-
buildVariableDecl
public com.sun.source.tree.VariableTree buildVariableDecl(TypeMirror type, String name, Element owner, com.sun.source.tree.ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable, with no modifiers.- Parameters:
type- the type of the variablename- the name of the variableowner- the element containing the new symbolinitializer- the initializer expression- Returns:
- a VariableDeclTree declaring the new variable
-
buildVariableDecl
public com.sun.source.tree.VariableTree buildVariableDecl(com.sun.source.tree.Tree type, String name, Element owner, com.sun.source.tree.ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable. The type of the variable is specified by a Tree.- Parameters:
type- the type of the variable, as a Treename- the name of the variableowner- the element containing the new symbolinitializer- the initializer expression- Returns:
- a VariableDeclTree declaring the new variable
-
buildVariableUse
public com.sun.source.tree.IdentifierTree buildVariableUse(com.sun.source.tree.VariableTree decl) Builds an AST Tree to refer to a variable.- Parameters:
decl- the declaration of the variable- Returns:
- an IdentifierTree to refer to the variable
-
buildTypeCast
public com.sun.source.tree.TypeCastTree buildTypeCast(TypeMirror type, com.sun.source.tree.ExpressionTree expr) Builds an AST Tree to cast the type of an expression.- Parameters:
type- the type to cast toexpr- the expression to be cast- Returns:
- a cast of the expression to the type
-
buildAssignment
public com.sun.source.tree.StatementTree buildAssignment(com.sun.source.tree.VariableTree variable, com.sun.source.tree.ExpressionTree expr) Builds an AST Tree to assign an expression to a variable.- Parameters:
variable- the declaration of the variable to assign toexpr- the expression to be assigned- Returns:
- a statement assigning the expression to the variable
-
buildAssignment
public com.sun.source.tree.AssignmentTree buildAssignment(com.sun.source.tree.ExpressionTree lhs, com.sun.source.tree.ExpressionTree rhs) Builds an AST Tree to assign an RHS expression to an LHS expression.- Parameters:
lhs- the expression to be assigned torhs- the expression to be assigned- Returns:
- a statement assigning the expression to the variable
-
buildLiteral
Builds an AST Tree representing a literal value of primitive or String type. -
buildLessThan
public com.sun.source.tree.BinaryTree buildLessThan(com.sun.source.tree.ExpressionTree left, com.sun.source.tree.ExpressionTree right) Builds an AST Tree to compare two operands with less than.- Parameters:
left- the left operand treeright- the right operand tree- Returns:
- a Tree representing "left < right"
-
buildArrayAccess
public com.sun.source.tree.ArrayAccessTree buildArrayAccess(com.sun.source.tree.ExpressionTree array, com.sun.source.tree.ExpressionTree index) Builds an AST Tree to dereference an array.- Parameters:
array- the array to dereferenceindex- the index at which to dereference- Returns:
- a Tree representing the dereference
-
buildClassUse
Builds an AST Tree to refer to a class name.- Parameters:
elt- an element representing the class- Returns:
- an IdentifierTree referring to the class
-
buildValueOfMethodAccess
public com.sun.source.tree.MemberSelectTree buildValueOfMethodAccess(com.sun.source.tree.Tree expr) Builds an AST Tree to access the valueOf() method of boxed type such as Short or Float.- Parameters:
expr- an expression whose type is a boxed type- Returns:
- a MemberSelectTree that accesses the valueOf() method of the expression
-
getValueOfMethod
public static com.sun.tools.javac.code.Symbol.MethodSymbol getValueOfMethod(ProcessingEnvironment env, TypeMirror boxedType) Returns the valueOf method of a boxed type such as Short or Float. -
buildPrimValueMethodAccess
public com.sun.source.tree.MemberSelectTree buildPrimValueMethodAccess(com.sun.source.tree.Tree expr) Builds an AST Tree to access the *Value() method of a boxed type such as Short or Float, where * is the corresponding primitive type (i.e. shortValue or floatValue).- Parameters:
expr- an expression whose type is a boxed type- Returns:
- a MemberSelectTree that accesses the *Value() method of the expression
-
kindToTag
public com.sun.tools.javac.tree.JCTree.Tag kindToTag(com.sun.source.tree.Tree.Kind kind) Map public AST Tree.Kinds to internal javac JCTree.Tags. -
buildBinary
public com.sun.source.tree.BinaryTree buildBinary(TypeMirror type, com.sun.source.tree.Tree.Kind op, com.sun.source.tree.ExpressionTree left, com.sun.source.tree.ExpressionTree right) Builds an AST Tree to perform a binary operation.- Parameters:
type- result type of the operationop- AST Tree operatorleft- the left operand treeright- the right operand tree- Returns:
- a Tree representing "left < right"
-
buildNewArray
public com.sun.source.tree.NewArrayTree buildNewArray(TypeMirror componentType, List<com.sun.source.tree.ExpressionTree> elems) Builds an AST Tree to create a new array with initializers.- Parameters:
componentType- component type of the new arrayelems- expression trees of initializers- Returns:
- a NewArrayTree to create a new array with initializers
-