org.netbeans.modules.java.source 0.104.0 23

org.netbeans.api.java.source
Class GeneratorUtilities

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

public final class GeneratorUtilities
extends Object

Since:
0.20

Method Summary
 CompilationUnitTree addImports(CompilationUnitTree cut, Set<? extends Element> toImport)
          Adds import statements for given elements to a compilation unit.
 CompilationUnitTree appendToAnnotationValue(CompilationUnitTree compilationUnit, TypeElement annotation, String attributeName, ExpressionTree... attributeValuesToAdd)
          Ensures that the given compilationUnit contains annotation of the given type, which has attribute name attributeName, which contains values attributeValuesToAdd.
 ModifiersTree appendToAnnotationValue(ModifiersTree modifiers, TypeElement annotation, String attributeName, ExpressionTree... attributeValuesToAdd)
          Ensures that the given modifiers contains annotation of the given type, which has attribute name attributeName, which contains values attributeValuesToAdd.
 void copyComments(Tree source, Tree target, boolean preceding)
          Copy comments from source tree to target tree.
 MethodTree createAbstractMethodImplementation(TypeElement clazz, ExecutableElement method)
          Creates an implementation of an abstract method within a class.
 List<? extends MethodTree> createAbstractMethodImplementations(TypeElement clazz, Iterable<? extends ExecutableElement> methods)
          Creates implementations of abstract methods within a class.
 List<? extends MethodTree> createAllAbstractMethodImplementations(TypeElement clazz)
          Creates implementations of the all abstract methods within a class.
 MethodTree createConstructor(ClassTree clazz, Iterable<? extends VariableTree> fields)
          Creates a class constructor.
 MethodTree createConstructor(TypeElement clazz, Iterable<? extends VariableElement> fields, ExecutableElement constructor)
          Creates a class constructor.
 CompilationUnitTree createFromTemplate(FileObject sourceRoot, String path, ElementKind kind)
          Create a new CompilationUnitTree from a template.
 MethodTree createGetter(TypeElement clazz, VariableElement field)
          Creates a getter method for a field.
 MethodTree createGetter(VariableTree field)
          Creates a getter method for a field.
 MethodTree createMethod(DeclaredType asMemberOf, ExecutableElement method)
          Create a new method tree for the given method element.
 MethodTree createOverridingMethod(TypeElement clazz, ExecutableElement method)
          Creates an overriding method within a class.
 List<? extends MethodTree> createOverridingMethods(TypeElement clazz, Iterable<? extends ExecutableElement> methods)
          Creates overriding methods within a class.
 MethodTree createSetter(ClassTree clazz, VariableTree field)
          Creates a setter method for a field.
 MethodTree createSetter(TypeElement clazz, VariableElement field)
          Creates a setter method for a field.
static GeneratorUtilities get(WorkingCopy copy)
          Returns the instance of this class
<T extends Tree>
T
importComments(T original, CompilationUnitTree cut)
           
<T extends Tree>
T
importFQNs(T original)
          Take a tree as a parameter, replace resolved fully qualified names with simple names and add imports to compilation unit during task commit.
 ClassTree insertClassMember(ClassTree clazz, Tree member)
          Inserts a member to a class.
 ClassTree insertClassMembers(ClassTree clazz, Iterable<? extends Tree> members)
          Inserts members to a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static GeneratorUtilities get(WorkingCopy copy)
Returns the instance of this class

Parameters:
copy -
Returns:
the GeneratorUtilities instance
Since:
0.20

createFromTemplate

public CompilationUnitTree createFromTemplate(FileObject sourceRoot,
                                              String path,
                                              ElementKind kind)
                                       throws IOException
Create a new CompilationUnitTree from a template.

Parameters:
sourceRoot - a source root under which the new file is created
path - a relative path to file separated by '/'
kind - the kind of Element to use for the template, can be null or CLASS, INTERFACE, ANNOTATION_TYPE, ENUM, PACKAGE
Returns:
new CompilationUnitTree created from a template
Throws:
IOException - when an exception occurs while creating the template
Since:
0.101

insertClassMember

public ClassTree insertClassMember(ClassTree clazz,
                                   Tree member)
Inserts a member to a class. Using the rules specified in the CodeStyle it finds the proper place for the member and calls TreeMaker.insertClassMember

Parameters:
clazz - the class to insert the member to
member - the member to add
Returns:
the modified class
Since:
0.20

insertClassMembers

public ClassTree insertClassMembers(ClassTree clazz,
                                    Iterable<? extends Tree> members)
Inserts members to a class. Using the rules specified in the CodeStyle it finds the proper place for each of the members and calls TreeMaker.insertClassMember

Parameters:
clazz - the class to insert the members to
members - the members to insert
Returns:
the modified class
Since:
0.20

createAllAbstractMethodImplementations

public List<? extends MethodTree> createAllAbstractMethodImplementations(TypeElement clazz)
Creates implementations of the all abstract methods within a class.

Parameters:
clazz - the class to create the implementations within
Returns:
the abstract method implementations
Since:
0.20

createAbstractMethodImplementations

public List<? extends MethodTree> createAbstractMethodImplementations(TypeElement clazz,
                                                                      Iterable<? extends ExecutableElement> methods)
Creates implementations of abstract methods within a class.

Parameters:
clazz - the class to create the implementations within
methods - the abstract methods to implement
Returns:
the abstract method implementations
Since:
0.20

createAbstractMethodImplementation

public MethodTree createAbstractMethodImplementation(TypeElement clazz,
                                                     ExecutableElement method)
Creates an implementation of an abstract method within a class.

Parameters:
clazz - the class to create the implementation within
method - the abstract method to implement
Returns:
the abstract method implementation
Since:
0.20

createOverridingMethods

public List<? extends MethodTree> createOverridingMethods(TypeElement clazz,
                                                          Iterable<? extends ExecutableElement> methods)
Creates overriding methods within a class.

Parameters:
clazz - the class to create the methods within
methods - the methods to override
Returns:
the overriding methods
Since:
0.20

createOverridingMethod

public MethodTree createOverridingMethod(TypeElement clazz,
                                         ExecutableElement method)
Creates an overriding method within a class.

Parameters:
clazz - the class to create the method within
method - the method to override
Returns:
the overriding method
Since:
0.20

createMethod

public MethodTree createMethod(DeclaredType asMemberOf,
                               ExecutableElement method)
Create a new method tree for the given method element. The method will be created as if it were member of asMemberOf type (see also Types#asMemberOf(javax.lang.model.type.DeclaredType,javax.lang.model.element.Element)). The new method will have an empty body.

Parameters:
asMemberOf - create the method as if it were member of this type
method - method to create
Returns:
a newly created method
Since:
0.34
See Also:
Types#asMemberOf(javax.lang.model.type.DeclaredType,javax.lang.model.element.Element)

createConstructor

public MethodTree createConstructor(TypeElement clazz,
                                    Iterable<? extends VariableElement> fields,
                                    ExecutableElement constructor)
Creates a class constructor.

Parameters:
clazz - the class to create the constructor for
fields - fields to be initialized by the constructor
constructor - inherited constructor to be called
Returns:
the constructor
Since:
0.20

createConstructor

public MethodTree createConstructor(ClassTree clazz,
                                    Iterable<? extends VariableTree> fields)
Creates a class constructor.

Parameters:
clazz - the class to create the constructor for
fields - fields to be initialized by the constructor
Returns:
the constructor
Since:
0.20

createGetter

public MethodTree createGetter(TypeElement clazz,
                               VariableElement field)
Creates a getter method for a field.

Parameters:
clazz - the class to create the getter within
field - field to create getter for
Returns:
the getter method
Since:
0.20

createGetter

public MethodTree createGetter(VariableTree field)
Creates a getter method for a field.

Parameters:
field - field to create getter for
Returns:
the getter method
Since:
0.20

createSetter

public MethodTree createSetter(TypeElement clazz,
                               VariableElement field)
Creates a setter method for a field.

Parameters:
clazz - the class to create the setter within
field - field to create setter for
Returns:
the setter method
Since:
0.20

createSetter

public MethodTree createSetter(ClassTree clazz,
                               VariableTree field)
Creates a setter method for a field.

Parameters:
clazz - the class to create the setter within
field - field to create setter for
Returns:
the setter method
Since:
0.20

addImports

public CompilationUnitTree addImports(CompilationUnitTree cut,
                                      Set<? extends Element> toImport)
Adds import statements for given elements to a compilation unit. The import section of the given compilation unit is modified according to the rules specified in the CodeStyle.

Use TreeMaker.QualIdent, TreeMaker.Type or GeneratorUtilities.importFQNs instead of this method if possible. These methods will correctly resolve imports according to the user's preferences.

Parameters:
cut - the compilation unit to insert imports to
toImport - the elements to import.
Returns:
the modified compilation unit
Since:
0.86

importFQNs

public <T extends Tree> T importFQNs(T original)
Take a tree as a parameter, replace resolved fully qualified names with simple names and add imports to compilation unit during task commit.

Parameters:
original - resolved FQNs in the tree will be imported
Returns:
the new tree containing simple names (QualIdents). Imports for them will be added during task commit.

importComments

public <T extends Tree> T importComments(T original,
                                         CompilationUnitTree cut)

copyComments

public void copyComments(Tree source,
                         Tree target,
                         boolean preceding)
Copy comments from source tree to target tree.

Parameters:
source - tree to copy comments from
target - tree to copy comments to
preceding - true iff preceding comments should be copied
Since:
0.51

appendToAnnotationValue

public ModifiersTree appendToAnnotationValue(ModifiersTree modifiers,
                                             TypeElement annotation,
                                             String attributeName,
                                             ExpressionTree... attributeValuesToAdd)
Ensures that the given modifiers contains annotation of the given type, which has attribute name attributeName, which contains values attributeValuesToAdd. The annotation or the attribute will be added as needed, as will be the attribute value converted from a single value into an array. The typical trees passed as attributeValuesToAdd are:
attribute type expected tree type
primitive type LiteralTree created by TreeMaker.Literal(java.lang.Object)
java.lang.String LiteralTree created by TreeMaker.Literal(java.lang.Object)
java.lang.Class MemberSelectTree created by TreeMaker.MemberSelect(com.sun.source.tree.ExpressionTree, java.lang.CharSequence), with identifier class and expression created by TreeMaker.QualIdent(javax.lang.model.element.Element)
enum constant MemberSelectTree, with identifier representing the enum constant and expression created by TreeMaker.QualIdent(javax.lang.model.element.Element)
annotation type AnnotationTree created by TreeMaker.Annotation(com.sun.source.tree.Tree, java.util.List)
array (of a supported type) NewArrayTree created by TreeMaker.NewArray(com.sun.source.tree.Tree, java.util.List, java.util.List), where elemtype is null, dimensions is Collections.<ExpressionTree>emptyList(), initializers should contain the elements that should appear in the array

Parameters:
modifiers - into which the values should be added
annotation - the annotation type that should be added or augmented
attributeName - the attribute that should be added or augmented
attributeValuesToAdd - values that should be added into the given attribute of the given annotation
Returns:
modifiers augmented in such a way that it contains the given annotation, with the given values
Since:
0.99

appendToAnnotationValue

public CompilationUnitTree appendToAnnotationValue(CompilationUnitTree compilationUnit,
                                                   TypeElement annotation,
                                                   String attributeName,
                                                   ExpressionTree... attributeValuesToAdd)
Ensures that the given compilationUnit contains annotation of the given type, which has attribute name attributeName, which contains values attributeValuesToAdd. The annotation or the attribute will be added as needed, as will be the attribute value converted from a single value into an array. This method is intended to be called on CompilationUnitTree from package-info.java. The typical trees passed as attributeValuesToAdd are:
attribute type expected tree type
primitive type LiteralTree created by TreeMaker.Literal(java.lang.Object)
java.lang.String LiteralTree created by TreeMaker.Literal(java.lang.Object)
java.lang.Class MemberSelectTree created by TreeMaker.MemberSelect(com.sun.source.tree.ExpressionTree, java.lang.CharSequence), with identifier class and expression created by TreeMaker.QualIdent(javax.lang.model.element.Element)
enum constant MemberSelectTree, with identifier representing the enum constant and expression created by TreeMaker.QualIdent(javax.lang.model.element.Element)
annotation type AnnotationTree created by TreeMaker.Annotation(com.sun.source.tree.Tree, java.util.List)
array (of a supported type) NewArrayTree created by TreeMaker.NewArray(com.sun.source.tree.Tree, java.util.List, java.util.List), where elemtype is null, dimensions is Collections.<ExpressionTree>emptyList(), initializers should contain the elements that should appear in the array

Parameters:
compilationUnit - into which the values should be added
annotation - the annotation type that should be added or augmented
attributeName - the attribute that should be added or augmented
attributeValuesToAdd - values that should be added into the given attribute of the given annotation
Returns:
compilationUnit augmented in such a way that it contains the given annotation, with the given values
Since:
0.99

org.netbeans.modules.java.source 0.104.0 23

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.