public class ASTJCompilationUnit extends ASTJNode<CompilationUnit> implements JCompilationUnit
CompilationUnit
object.Modifier and Type | Class and Description |
---|---|
protected class |
ASTJCompilationUnit.AbstractRewriter
Base class for additional rewriters used during rewrite process.
|
protected class |
ASTJCompilationUnit.NodeCommenter |
protected class |
ASTJCompilationUnit.NodeContentsReplacer |
Modifier and Type | Field and Description |
---|---|
protected static java.util.regex.Pattern |
HEADER_PATTERN
Pattern to extract and replace header.
|
protected java.lang.String |
headerString
Header of the compilation unit to be set during rewrite.
|
static java.lang.String |
NAME_PROPERTY
Name for the name property of the compilation unit.
|
protected char[] |
originalContents
Original contents of the compilation unit
|
isCommentedOut, name, rewriter, UNITIALIZED_STRING
EMPTY_STRING_ARRAY, qualifiedName
Constructor and Description |
---|
ASTJCompilationUnit(CompilationUnit compilationUnit) |
Modifier and Type | Method and Description |
---|---|
boolean |
addChild(ASTJNode<?> child)
Adds a child to this node.
|
protected java.lang.String |
computeQualifiedName()
Same as the
getName() . |
void |
dispose() |
protected java.util.Map<ASTNode,java.lang.String> |
getAllTrackedContentsMap() |
java.util.List<JNode> |
getChildren()
Returns the list of children in order: package declaration (
JPackage ), imports (JImport ), and types (JType ). |
protected java.util.Set<ASTNode> |
getCommentedOutNodes() |
java.lang.String |
getContents()
Returns the rewritten text after applying all the changes made to JNode tree.
|
java.lang.String |
getHeader()
Returns the header comment for this compilation unit.
|
java.lang.String |
getName()
Returns the name of the main type suffixed with java extension.
|
char[] |
getOriginalContents() |
boolean |
insertSibling(ASTJNode<?> node,
ASTJNode<?> newSibling,
boolean before)
Inserts
newSibling as a child of this node before or after the given node . |
boolean |
remove(ASTJNode<?> node)
Removes the given node.
|
protected void |
setHeader(IDocument targetDoc)
Method to replace the header in the given document.
|
void |
setHeader(java.lang.String header)
This implementation remembers the header string, and does replacement of the header in the final
document after any other changes.
|
void |
setName(java.lang.String name)
Sets the name of the main type of compilation unit.
|
void |
setOriginalContents(char[] originalContents)
Sets original contents of the compilation unit to be used for converting nodes
to strings.
|
addValueToListProperty, addValueToListProperty, ancestorInserted, ancestorToBeRemoved, childToBeChanged, combineArrayAndList, commentOut, convertASTNodeListToStringArray, disableTrackAndReplace, enableTrackAndReplace, getASTNode, getFacadeHelper, getParent, getRemovedASTNode, getRewriter, getWrappedObject, insert, insertFirst, insertLast, isDisposed, nodeToBeMoved, nodeToBeRemoved, remove, removeNodeFromListProperty, removeTrackAndReplace, setASTNode, setFacadeHelper, setFlags, setListNodeProperty, setNodeProperty, setNodeProperty, setParent, setRemovedASTNode, setRewriter, setTrackedNodeProperty, setWrappedObject, trackAndReplace
computeQualifiedName, computeQualifiedName, computeQualifiedName, getFlags, getName, getQualifiedName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFlags, getParent, getQualifiedName, setFlags
public static final java.lang.String NAME_PROPERTY
protected static final java.util.regex.Pattern HEADER_PATTERN
protected java.lang.String headerString
protected char[] originalContents
public ASTJCompilationUnit(CompilationUnit compilationUnit)
compilationUnit
- public void setOriginalContents(char[] originalContents)
originalContents
- public char[] getOriginalContents()
public java.lang.String getName()
In the absence of type defaults to original name that compilation unit was created with.
Created for compatibility with JDOM implementation of getName()
for JCompilationUnit
.
getName
in interface JNode
JNode.getName()
public void setName(java.lang.String name)
setName
in interface JNode
FacadeHelper.getMainType(JCompilationUnit)
,
JNode.setName(java.lang.String)
,
JNode.getQualifiedName()
protected java.lang.String computeQualifiedName()
getName()
.computeQualifiedName
in class AbstractJNode
AbstractJNode.computeQualifiedName()
public java.util.List<JNode> getChildren()
JPackage
), imports (JImport
), and types (JType
).getChildren
in interface JNode
getChildren
in class AbstractJNode
AbstractJNode.getChildren()
public java.lang.String getHeader()
JCompilationUnit
getHeader
in interface JCompilationUnit
null
if
no header comment is presentpublic void setHeader(java.lang.String header)
For the files with no package declaration, the new header might be inserted at the beginning of the file instead of being replaced.
setHeader
in interface JCompilationUnit
header
- the header comment for this compilation unit, or null
if
indicating no header commentJCompilationUnit.setHeader(java.lang.String)
protected void setHeader(IDocument targetDoc)
setHeader
in interface JCompilationUnit
targetDoc
- public java.lang.String getContents()
getContents
in interface JNode
getContents
in class ASTJNode<CompilationUnit>
null
if this node has no contentsASTJNode.getContents()
public boolean addChild(ASTJNode<?> child)
ASTJNode
Default implementation does nothing and returns false
.
public boolean insertSibling(ASTJNode<?> node, ASTJNode<?> newSibling, boolean before)
ASTJNode
newSibling
as a child of this node before or after the given node
.
Default implementation does nothing and returns false
.
insertSibling
in class ASTJNode<CompilationUnit>
newSibling
- to insertbefore
- true
if newSibling
must be before node
, false
if aftertrue
if operation successful, false
otherwisepublic boolean remove(ASTJNode<?> node)
This implementation will not perform moving of the node if the node is inserted after being removed. Hence, the removed node must not be inserted again.
remove
in class ASTJNode<CompilationUnit>
node
- must be a child of this nodetrue
if operation successful, false
otherwiseASTJNode.remove(ASTJNode)
protected java.util.Map<ASTNode,java.lang.String> getAllTrackedContentsMap()
ASTNode
to String
contents of the node).
This map will be used during rewrite to track the nodes and set the exact contents of them.
protected java.util.Set<ASTNode> getCommentedOutNodes()