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 SummaryFieldsModifier 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbuildArrayAccess(ExpressionTree array, ExpressionTree index) Builds an AST Tree to dereference an array.buildArrayLengthAccess(ExpressionTree expression) Builds an AST Tree to dereference the length field of an array.buildAssignment(ExpressionTree lhs, ExpressionTree rhs) Builds an AST Tree to assign an RHS expression to an LHS expression.buildAssignment(VariableTree variable, ExpressionTree expr) Builds an AST Tree to assign an expression to a variable.buildBinary(TypeMirror type, Tree.Kind op, ExpressionTree left, ExpressionTree right) Builds an AST Tree to perform a binary operation.buildClassUse(Element elt) Builds an AST Tree to refer to a class name.buildHasNextMethodAccess(ExpressionTree iteratorExpr) Builds an AST Tree to access the hasNext() method of an iterator.buildIteratorMethodAccess(ExpressionTree iterableExpr) Builds an AST Tree to access the iterator() method of some iterable expression.buildLessThan(ExpressionTree left, ExpressionTree right) Builds an AST Tree to compare two operands with less than.buildLiteral(Object value) Builds an AST Tree representing a literal value of primitive or String type.buildMethodInvocation(ExpressionTree methodExpr) Builds an AST Tree to call a method designated by the argument expression.buildMethodInvocation(ExpressionTree methodExpr, ExpressionTree argExpr) Builds an AST Tree to call a method designated by methodExpr, with one argument designated by argExpr.buildNewArray(TypeMirror componentType, List<ExpressionTree> elems) Builds an AST Tree to create a new array with initializers.buildNextMethodAccess(ExpressionTree iteratorExpr) Builds an AST Tree to access the next() method of an iterator.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.buildTypeCast(TypeMirror type, ExpressionTree expr) Builds an AST Tree to cast the type of an expression.buildValueOfMethodAccess(Tree expr) Builds an AST Tree to access the valueOf() method of boxed type such as Short or Float.buildVariableDecl(Tree type, String name, Element owner, ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable.buildVariableDecl(TypeMirror type, String name, Element owner, ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable, with no modifiers.buildVariableUse(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.TagMap public AST Tree.Kinds to internal javac JCTree.Tags.
- 
Field Details- 
elements
- 
modelTypes
- 
javacTypesprotected final com.sun.tools.javac.code.Types javacTypes
- 
makerprotected final com.sun.tools.javac.tree.TreeMaker maker
- 
namesprotected final com.sun.tools.javac.util.Names names
- 
symtabprotected final com.sun.tools.javac.code.Symtab symtab
- 
env
 
- 
- 
Constructor Details- 
TreeBuilder
 
- 
- 
Method Details- 
buildIteratorMethodAccessBuilds 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
 
- 
buildHasNextMethodAccessBuilds 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
 
- 
buildNextMethodAccessBuilds 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
 
- 
buildArrayLengthAccessBuilds 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
 
- 
buildMethodInvocationBuilds 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
 
- 
buildMethodInvocationpublic MethodInvocationTree buildMethodInvocation(ExpressionTree methodExpr, 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 argument
- argExpr- an expression denoting an argument to the method
- Returns:
- a MethodInvocationTree to call the argument method
 
- 
buildVariableDeclpublic VariableTree buildVariableDecl(TypeMirror type, String name, Element owner, ExpressionTree initializer) Builds an AST Tree to declare and initialize a variable, with no modifiers.- Parameters:
- type- the type of the variable
- name- the name of the variable
- owner- the element containing the new symbol
- initializer- the initializer expression
- Returns:
- a VariableDeclTree declaring the new variable
 
- 
buildVariableDeclpublic VariableTree buildVariableDecl(Tree type, String name, Element owner, 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 Tree
- name- the name of the variable
- owner- the element containing the new symbol
- initializer- the initializer expression
- Returns:
- a VariableDeclTree declaring the new variable
 
- 
buildVariableUseBuilds an AST Tree to refer to a variable.- Parameters:
- decl- the declaration of the variable
- Returns:
- an IdentifierTree to refer to the variable
 
- 
buildTypeCastBuilds an AST Tree to cast the type of an expression.- Parameters:
- type- the type to cast to
- expr- the expression to be cast
- Returns:
- a cast of the expression to the type
 
- 
buildAssignmentBuilds an AST Tree to assign an expression to a variable.- Parameters:
- variable- the declaration of the variable to assign to
- expr- the expression to be assigned
- Returns:
- a statement assigning the expression to the variable
 
- 
buildAssignmentBuilds an AST Tree to assign an RHS expression to an LHS expression.- Parameters:
- lhs- the expression to be assigned to
- rhs- the expression to be assigned
- Returns:
- a statement assigning the expression to the variable
 
- 
buildLiteralBuilds an AST Tree representing a literal value of primitive or String type.
- 
buildLessThanBuilds an AST Tree to compare two operands with less than.- Parameters:
- left- the left operand tree
- right- the right operand tree
- Returns:
- a Tree representing "left < right"
 
- 
buildArrayAccessBuilds an AST Tree to dereference an array.- Parameters:
- array- the array to dereference
- index- the index at which to dereference
- Returns:
- a Tree representing the dereference
 
- 
buildClassUseBuilds an AST Tree to refer to a class name.- Parameters:
- elt- an element representing the class
- Returns:
- an IdentifierTree referring to the class
 
- 
buildValueOfMethodAccessBuilds 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
 
- 
getValueOfMethodpublic 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.
- 
buildPrimValueMethodAccessBuilds 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
 
- 
kindToTagMap public AST Tree.Kinds to internal javac JCTree.Tags.
- 
buildBinarypublic BinaryTree buildBinary(TypeMirror type, Tree.Kind op, ExpressionTree left, ExpressionTree right) Builds an AST Tree to perform a binary operation.- Parameters:
- type- result type of the operation
- op- AST Tree operator
- left- the left operand tree
- right- the right operand tree
- Returns:
- a Tree representing "left < right"
 
- 
buildNewArrayBuilds an AST Tree to create a new array with initializers.- Parameters:
- componentType- component type of the new array
- elems- expression trees of initializers
- Returns:
- a NewArrayTree to create a new array with initializers
 
 
-