CompilationUnit
This class represents the entire compilation unit. Each java file denotes a compilation unit.
A compilation unit start with an optional package declaration, followed by zero or more import declarations, followed by zero or more type declarations.Author
Julio Vilmar Gesser
See also
Constructors
Link copied to clipboard
constructor()
constructor(packageDeclaration: PackageDeclaration, imports: NodeList<ImportDeclaration>, types: NodeList<TypeDeclaration<out Any>>, module: ModuleDeclaration)
constructor(tokenRange: TokenRange, packageDeclaration: PackageDeclaration, imports: NodeList<ImportDeclaration>, types: NodeList<TypeDeclaration<out Any>>, module: ModuleDeclaration)
This constructor is used by the parser and is considered private.
Types
Properties
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
This can be used to sort nodes on position.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Functions
Link copied to clipboard
Add a public annotation declaration to the types of this compilation unit
open fun addAnnotationDeclaration(name: String, modifiers: Array<Modifier.DefaultKeyword>): AnnotationDeclaration
Add an annotation declaration to the types of this compilation unit
Link copied to clipboard
Add a public class to the types of this compilation unit
open fun addClass(name: String, modifiers: Array<Modifier.DefaultKeyword>): ClassOrInterfaceDeclaration
Add a class to the types of this compilation unit
Link copied to clipboard
Add a public enum to the types of this compilation unit
Add an enum to the types of this compilation unit
Link copied to clipboard
adds an import if not implicitly imported by java (i.e.
Add an import to the list of ImportDeclaration of this compilation unit shorthand for addImport with clazz.
Add an import to the list of ImportDeclaration of this compilation unit shorthand for addImport with name,false,false,false
Add a non-module import to the list of ImportDeclaration of this compilation unitThis method check if no import with the same name is already in the list
open fun addImport(name: String, isStatic: Boolean, isAsterisk: Boolean, isModule: Boolean): CompilationUnit
Add an import to the list of ImportDeclaration of this compilation unitThis method check if no import with the same name is already in the list
Link copied to clipboard
Add a public interface class to the types of this compilation unit
open fun addInterface(name: String, modifiers: Array<Modifier.DefaultKeyword>): ClassOrInterfaceDeclaration
Add an interface to the types of this compilation unit
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Checks whether the range of the given
Node is contained within the range of this NodeWithRange.Link copied to clipboard
Walks the AST with pre-order traversal, returning all nodes of type "nodeType".
Walks the AST with specified traversal order, returning all nodes of type "nodeType".
Walks the AST with pre-order traversal, returning all nodes of type "nodeType" that match the predicate.
Link copied to clipboard
Walks the parents of this node and returns the first node of type
type, or empty() if none is found.Walks the parents of this node and returns the first node of type
type that matches predicate, or empty() if none is found.Walks the parents of this node and returns the first node that matches one of types
types, or empty() if none is found.Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Walks the AST with pre-order traversal, returning the first node of type "nodeType" or empty() if none is found.
Walks the AST, applying the function for every node, with traversal algorithm "traversal".
Walks the AST with pre-order traversal, returning the first node of type "nodeType" that matches "predicate" or empty() if none is found.
Link copied to clipboard
Finds the root node of this AST by finding the topmost parent.
Link copied to clipboard
Return a list containing all comments declared in this compilation unit.
Link copied to clipboard
This is the list of Comment which are contained in the Node either because they are properly associated to one of its children or because they are floating around inside the Node
Link copied to clipboard
Try to get a top level annotation type declaration by its name
Link copied to clipboard
This field is used by key to associated (JML) comments to this node.
Link copied to clipboard
Contains all nodes that have this node set as their parent.
Link copied to clipboard
Link copied to clipboard
Try to get a top level class declaration by its name
Link copied to clipboard
This is a comment associated with this node.
Link copied to clipboard
Link copied to clipboard
This method was added to support the clone method.
Link copied to clipboard
Try to get a top level enum declaration by its name
Link copied to clipboard
Link copied to clipboard
Try to get a top level interface declaration by its name
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Try to get all local class declarations ending by its name (top level or inner class)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
This is a list of Comment which are inside the node and are not associated with any meaningful AST Node.
Link copied to clipboard
Retrieves the package declaration of this compilation unit.
Link copied to clipboard
Returns the parent node, or
Optional.empty if no parent is set.Link copied to clipboard
Returns the parent node from the perspective of the children of this node.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Try to get a top level record declaration by its name
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Convenience method that wraps
getTypes().Link copied to clipboard
Returns true if the parent has a parent
Link copied to clipboard
Link copied to clipboard
Determines whether this node is an ancestor of the given node.
Link copied to clipboard
Determines whether this
HasParentNode node is a descendant of the given node.Link copied to clipboard
Was this observer registered?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Declare a specific printer
Link copied to clipboard
Recalculates the ranges of all nodes by looking at the sizes of the tokens.
Link copied to clipboard
Register an observer.
Register a new observer for the given node.
Link copied to clipboard
Register the observer for the current node and all the contained node and nodelists, recursively.
Link copied to clipboard
Link copied to clipboard
Remove data by key.
Link copied to clipboard
Forcibly removes this node from the AST.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun setAssociatedSpecificationComments(@Nullable associatedSpecificationComments: @Nullable NodeList<Comment>): Node
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Create (or overwrite) a module declaration in this compilation unit with name "name".
Link copied to clipboard
open fun setPackageDeclaration(@Nullable packageDeclaration: @Nullable PackageDeclaration): CompilationUnit
Sets or clear the package declarations of this compilation unit.
sets the package declaration of this compilation unit
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Unregister an observer.
Link copied to clipboard
Walks the AST, calling the consumer for every node with pre-order traversal.
Walks the AST, calling the consumer for every node, with traversal algorithm "traversal".
Walks the AST with pre-order traversal, calling the consumer for every node of type "nodeType".