org.netbeans.modules.java.source 0.40.0 7

org.netbeans.api.java.source
Class TreeMaker

java.lang.Object
  extended by org.netbeans.api.java.source.TreeMaker

public final class TreeMaker
extends Object

Factory interface for creating new com.sun.source.tree instances. The parameters for each method correspond as closely as possible to the accessor methods for each tree interface.
You can obtain appropriate instance of this class by getting it from working copy:

 CancellableTask task = new CancellableTask() {

        public void run(WorkingCopy workingCopy) throws Exception {
            TreeMaker make = workingCopy.getTreeMaker();
            ... your modification code here
        }
        ...
    }; 
 

See Also:
How do I do modification to a source file?

Method Summary
 AnnotationTree addAnnotationAttrValue(AnnotationTree annotation, ExpressionTree attrValue)
          Appends specified element attrValue to the end of attribute values list.
 BlockTree addBlockStatement(BlockTree block, StatementTree statement)
          Appends specified element statement to the end of statements list.
 CaseTree addCaseStatement(CaseTree kejs, StatementTree statement)
          Appends specified element statement to the end of statements list.
 ClassTree addClassImplementsClause(ClassTree clazz, Tree implementsClause)
          Appends specified element implementsClause to the end of implements list.
 ClassTree addClassMember(ClassTree clazz, Tree member)
          Appends specified element member to the end of members list.
 ClassTree addClassTypeParameter(ClassTree clazz, TypeParameterTree typeParameter)
          Appends specified element typeParameter to the end of type parameters list.
 void addComment(Tree tree, Comment comment, boolean preceding)
          Append a comment to the list of comments attached to a given tree.
 CompilationUnitTree addCompUnitImport(CompilationUnitTree compilationUnit, ImportTree importt)
          Appends specified element importt to the end of imports list.
 CompilationUnitTree addCompUnitTypeDecl(CompilationUnitTree compilationUnit, Tree typeDeclaration)
          Appends specified element typeDeclaration to the end of type declarations list.
 ForLoopTree addForLoopInitializer(ForLoopTree forLoop, StatementTree initializer)
          Appends specified element initializer to the end of initializers list.
 ForLoopTree addForLoopUpdate(ForLoopTree forLoop, ExpressionStatementTree update)
          Appends specified element update to the end of updates list.
 MethodInvocationTree addMethodInvocationArgument(MethodInvocationTree methodInvocation, ExpressionTree argument)
          Appends specified element argument.
 MethodInvocationTree addMethodInvocationTypeArgument(MethodInvocationTree methodInvocation, ExpressionTree typeArgument)
          Appends specified element type argument to the end of type arguments list.
 MethodTree addMethodParameter(MethodTree method, VariableTree parameter)
          Appends specified element parameter to the end of parameters list.
 MethodTree addMethodThrows(MethodTree method, ExpressionTree throwz)
          Appends specified element throwz to the end of throws list.
 MethodTree addMethodTypeParameter(MethodTree method, TypeParameterTree typeParameter)
          Appends specified element typeParameter to the end of type parameters list.
 ModifiersTree addModifiersAnnotation(ModifiersTree modifiers, AnnotationTree annotation)
          Appends specified element annotation to the end of annotations list.
 ModifiersTree addModifiersModifier(ModifiersTree modifiers, Modifier modifier)
           
 NewArrayTree addNewArrayDimension(NewArrayTree newArray, ExpressionTree dimension)
          Appends specified element dimension to the end of dimensions list.
 NewArrayTree addNewArrayInitializer(NewArrayTree newArray, ExpressionTree initializer)
          Appends specified element initializer to the end of initializers list.
 NewClassTree addNewClassArgument(NewClassTree newClass, ExpressionTree argument)
          Appends specified element argument to the end of arguments list.
 NewClassTree addNewClassTypeArgument(NewClassTree newClass, ExpressionTree typeArgument)
          Appends specified element typeArgument to the end of type arguments list.
 ParameterizedTypeTree addParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, ExpressionTree argument)
          Appends specified element argument to the end of type arguments list.
 SwitchTree addSwitchCase(SwitchTree swic, CaseTree kejs)
          Appends specified element kejs to the end of cases list.
 TryTree addTryCatch(TryTree traj, CatchTree kec)
          Appends specified element kec to the end of catches list.
 TypeParameterTree addTypeParameterBound(TypeParameterTree typeParameter, ExpressionTree bound)
          Appends specified element bound to the end of bounds list.
 AnnotationTree Annotation(Tree type, List<? extends ExpressionTree> arguments)
          Creates a new AnnotationTree.
 ClassTree AnnotationType(ModifiersTree modifiers, CharSequence simpleName, List<? extends Tree> memberDecls)
          Creates a new ClassTree representing annotation type.
 ArrayAccessTree ArrayAccess(ExpressionTree array, ExpressionTree index)
          Creates a new ArrayAccessTree.
 ArrayTypeTree ArrayType(Tree type)
          Creates a new ArrayTypeTree.
 AssertTree Assert(ExpressionTree condition, ExpressionTree detail)
          Creates a new AssertTree.
 AssignmentTree Assignment(ExpressionTree variable, ExpressionTree expression)
          Creates a new AssignmentTree.
 BinaryTree Binary(Tree.Kind operator, ExpressionTree left, ExpressionTree right)
          Creates a new BinaryTree.
 BlockTree Block(List<? extends StatementTree> statements, boolean isStatic)
          Creates a new BlockTree.
 BreakTree Break(CharSequence label)
          Creates a new BreakTree.
 CaseTree Case(ExpressionTree expression, List<? extends StatementTree> statements)
          Creates a new CaseTree.
 CatchTree Catch(VariableTree parameter, BlockTree block)
          Creates a new CatchTree.
 ClassTree Class(ModifiersTree modifiers, CharSequence simpleName, List<? extends TypeParameterTree> typeParameters, Tree extendsClause, List<? extends Tree> implementsClauses, List<? extends Tree> memberDecls)
          Creates a new ClassTree.
 CompilationUnitTree CompilationUnit(ExpressionTree packageName, List<? extends ImportTree> imports, List<? extends Tree> typeDeclarations, JavaFileObject sourceFile)
          Creates a new CompilationUnitTree.
 CompilationUnitTree CompilationUnit(FileObject sourceRoot, String path, List<? extends ImportTree> imports, List<? extends Tree> typeDeclarations)
          Creates a new CompilationUnitTree.
 CompoundAssignmentTree CompoundAssignment(Tree.Kind operator, ExpressionTree variable, ExpressionTree expression)
          Creates a new CompoundAssignmentTree.
 ConditionalExpressionTree ConditionalExpression(ExpressionTree condition, ExpressionTree trueExpression, ExpressionTree falseExpression)
          Creates a new ConditionalExpressionTree.
 MethodTree Constructor(ModifiersTree modifiers, List<? extends TypeParameterTree> typeParameters, List<? extends VariableTree> parameters, List<? extends ExpressionTree> throwsList, BlockTree body)
          Creates a new MethodTree representing constructor.
 MethodTree Constructor(ModifiersTree modifiers, List<? extends TypeParameterTree> typeParameters, List<? extends VariableTree> parameters, List<? extends ExpressionTree> throwsList, String bodyText)
          Creates a new MethodTree representing constructor.
 ContinueTree Continue(CharSequence label)
          Creates a new ContinueTree.
 BlockTree createMethodBody(MethodTree method, String bodyText)
          Creates a new BlockTree for provided bodyText.
 DoWhileLoopTree DoWhileLoop(ExpressionTree condition, StatementTree statement)
          Creates a new DoWhileLoopTree.
 EmptyStatementTree EmptyStatement()
          Creates a new EmptyStatementTree.
 EnhancedForLoopTree EnhancedForLoop(VariableTree variable, ExpressionTree expression, StatementTree statement)
          Creates a new EnhancedForLoopTree.
 ClassTree Enum(ModifiersTree modifiers, CharSequence simpleName, List<? extends Tree> implementsClauses, List<? extends Tree> memberDecls)
          Creates a new ClassTree representing enum.
 ErroneousTree Erroneous(List<? extends Tree> errorTrees)
          Creates a new ErroneousTree.
 ExpressionStatementTree ExpressionStatement(ExpressionTree expression)
          Creates a new ExpressionStatementTree.
 ForLoopTree ForLoop(List<? extends StatementTree> initializer, ExpressionTree condition, List<? extends ExpressionStatementTree> update, StatementTree statement)
          Creates a new ForLoopTree.
 IdentifierTree Identifier(CharSequence name)
          Creates a new IdentifierTree.
 IdentifierTree Identifier(Element element)
          Creates a new IdentifierTree from an Element.
 IfTree If(ExpressionTree condition, StatementTree thenStatement, StatementTree elseStatement)
          Creates a new IfTree.
 ImportTree Import(Tree qualid, boolean importStatic)
          Creates a new ImportTree.
 AnnotationTree insertAnnotationAttrValue(AnnotationTree annotation, int index, ExpressionTree attrValue)
          Inserts the specified element attrValue at the specified position in attribute values list.
 BlockTree insertBlockStatement(BlockTree block, int index, StatementTree statement)
          Inserts the specified element statement at the specified position in statements list.
 CaseTree insertCaseStatement(CaseTree kejs, int index, StatementTree statement)
          Inserts the specified element statement at the specified position in statements list.
 ClassTree insertClassImplementsClause(ClassTree clazz, int index, Tree implementsClause)
          Inserts the specified element implementsClause at the specified position in implements list.
 ClassTree insertClassMember(ClassTree clazz, int index, Tree member)
          Inserts the specified element member at the specified position in members list.
 ClassTree insertClassTypeParameter(ClassTree clazz, int index, TypeParameterTree typeParameter)
          Inserts the specified element member at the specified position in type parameters list.
 void insertComment(Tree tree, Comment comment, int index, boolean preceding)
          Insert a comment to the list of comments attached to a given tree (to a specified position).
 CompilationUnitTree insertCompUnitImport(CompilationUnitTree compilationUnit, int index, ImportTree importt)
          Inserts the specified element importt at the specified position in imports list.
 CompilationUnitTree insertCompUnitTypeDecl(CompilationUnitTree compilationUnit, int index, Tree typeDeclaration)
          Inserts the specified element typeDeclaration at the specified position in type declarations list.
 ForLoopTree insertForLoopInitializer(ForLoopTree forLoop, int index, StatementTree initializer)
          Inserts the specified element initializer at the specified position in initializers list.
 ForLoopTree insertForLoopUpdate(ForLoopTree forLoop, int index, ExpressionStatementTree update)
          Inserts the specified element update at the specified position in updates list.
 MethodInvocationTree insertMethodInvocationArgument(MethodInvocationTree methodInvocation, int index, ExpressionTree argument)
          Inserts the specified element argument.
 MethodInvocationTree insertMethodInvocationTypeArgument(MethodInvocationTree methodInvocation, int index, ExpressionTree typeArgument)
          Inserts the specified element typeArgument at the specified position in type arguments list.
 MethodTree insertMethodParameter(MethodTree method, int index, VariableTree parameter)
          Inserts the specified element parameter at the specified position in parameters list.
 MethodTree insertMethodThrows(MethodTree method, int index, ExpressionTree throwz)
          Inserts the specified element throws at the specified position in throws list.
 MethodTree insertMethodTypeParameter(MethodTree method, int index, TypeParameterTree typeParameter)
          Inserts the specified element typeParameter at the specified position in type parameters list.
 ModifiersTree insertModifiersAnnotation(ModifiersTree modifiers, int index, AnnotationTree annotation)
          Inserts the specified element annotation at the specified position in annotations list.
 NewArrayTree insertNewArrayDimension(NewArrayTree newArray, int index, ExpressionTree dimension)
          Inserts the specified element dimension at the specified position in dimensions list.
 NewArrayTree insertNewArrayInitializer(NewArrayTree newArray, int index, ExpressionTree initializer)
          Inserts the specified element initializer at the specified position in initializers list.
 NewClassTree insertNewClassArgument(NewClassTree newClass, int index, ExpressionTree argument)
          Inserts the specified element argument at the specified position in type arguments list.
 NewClassTree insertNewClassTypeArgument(NewClassTree newClass, int index, ExpressionTree typeArgument)
          Inserts the specified element typeArgument at the specified position in type arguments list.
 ParameterizedTypeTree insertParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, int index, ExpressionTree argument)
          Inserts the specified element argument at the specified position in type arguments list.
 SwitchTree insertSwitchCase(SwitchTree swic, int index, CaseTree kejs)
          Inserts the specified element kejs at the specified position in cases list.
 TryTree insertTryCatch(TryTree traj, int index, CatchTree kec)
          Inserts the specified element kec at the specified position in catches list.
 TypeParameterTree insertTypeParameterBound(TypeParameterTree typeParameter, int index, ExpressionTree bound)
          Inserts the specified element bound at the specified position in bounds list.
 InstanceOfTree InstanceOf(ExpressionTree expression, Tree type)
          Creates a new InstanceOfTree.
 ClassTree Interface(ModifiersTree modifiers, CharSequence simpleName, List<? extends TypeParameterTree> typeParameters, List<? extends Tree> extendsClauses, List<? extends Tree> memberDecls)
          Creates a new ClassTree representing interface.
 LabeledStatementTree LabeledStatement(CharSequence label, StatementTree statement)
          Creates a new LabeledStatementTree.
 LiteralTree Literal(Object value)
          Creates a new LiteralTree.
 MemberSelectTree MemberSelect(ExpressionTree expression, CharSequence identifier)
          Creates a new MemberSelectTree.
 MemberSelectTree MemberSelect(ExpressionTree expression, Element element)
          Creates a new MemberSelectTree from an expression and an element.
 MethodTree Method(ExecutableElement element, BlockTree body)
          Creates a new MethodTree from an ExecutableElement and a BlockTree.
 MethodTree Method(ModifiersTree modifiers, CharSequence name, Tree returnType, List<? extends TypeParameterTree> typeParameters, List<? extends VariableTree> parameters, List<? extends ExpressionTree> throwsList, BlockTree body, ExpressionTree defaultValue)
          Creates a new MethodTree.
 MethodTree Method(ModifiersTree modifiers, CharSequence name, Tree returnType, List<? extends TypeParameterTree> typeParameters, List<? extends VariableTree> parameters, List<? extends ExpressionTree> throwsList, String bodyText, ExpressionTree defaultValue)
          Creates a new MethodTree.
 MethodInvocationTree MethodInvocation(List<? extends ExpressionTree> typeArguments, ExpressionTree method, List<? extends ExpressionTree> arguments)
          Creates a new MethodInvocationTree.
 ModifiersTree Modifiers(long flags, List<? extends AnnotationTree> annotations)
          Creates a new ModifiersTree with a new flags and annotation.
 ModifiersTree Modifiers(ModifiersTree oldMods, List<? extends AnnotationTree> annotations)
          Creates a new ModifiersTree with a new set of annotations.
 ModifiersTree Modifiers(Set<Modifier> flags)
          Creates a new ModifiersTree without any annotations specified.
 ModifiersTree Modifiers(Set<Modifier> flags, List<? extends AnnotationTree> annotations)
          Creates a new ModifiersTree with a new set of flags and annotations.
 NewArrayTree NewArray(Tree elemtype, List<? extends ExpressionTree> dimensions, List<? extends ExpressionTree> initializers)
          Creates a new NewArrayTree.
 NewClassTree NewClass(ExpressionTree enclosingExpression, List<? extends ExpressionTree> typeArguments, ExpressionTree identifier, List<? extends ExpressionTree> arguments, ClassTree classBody)
          Creates a new NewClassTree.
 ParameterizedTypeTree ParameterizedType(Tree type, List<? extends Tree> typeArguments)
          Creates a new ParameterizedTypeTree.
 ParenthesizedTree Parenthesized(ExpressionTree expression)
          Creates a new ParenthesizedTree.
 PrimitiveTypeTree PrimitiveType(TypeKind typekind)
          Creates a new PrimitiveTypeTree.
 ExpressionTree QualIdent(Element element)
          Creates a qualified identifier from an element.
 AnnotationTree removeAnnotationAttrValue(AnnotationTree annotation, ExpressionTree attrValue)
          Removes the first occurrence in attribute values list of the specified element.
 AnnotationTree removeAnnotationAttrValue(AnnotationTree annotation, int index)
          Removes the element at the specified position in attribute values list.
 BlockTree removeBlockStatement(BlockTree block, int index)
          Removes the element at the specified position in statements list.
 BlockTree removeBlockStatement(BlockTree block, StatementTree statement)
          Removes the first occurrence in statements list of the specified element.
 CaseTree removeCaseStatement(CaseTree kejs, int index)
          Removes the element at the specified position in statements list.
 CaseTree removeCaseStatement(CaseTree kejs, StatementTree statement)
          Removes the first occurrence in statements list of the specified element.
 ClassTree removeClassImplementsClause(ClassTree clazz, int index)
          Removes the element at the specified position in implements list.
 ClassTree removeClassImplementsClause(ClassTree clazz, Tree implementsClause)
          Removes the first occurrence in implements list of the specified element.
 ClassTree removeClassMember(ClassTree clazz, int index)
          Removes the element at the specified position in members list.
 ClassTree removeClassMember(ClassTree clazz, Tree member)
          Removes the first occurrence in members list of the specified element.
 ClassTree