org.eclipse.emf.codegen.merge.java.facade.ast
Class ASTJCompilationUnit

java.lang.Object
  extended by org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
      extended by org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
          extended by org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit
All Implemented Interfaces:
JCompilationUnit, JNode

public class ASTJCompilationUnit
extends ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
implements JCompilationUnit

Wraps CompilationUnit object.

Since:
2.2.0

Nested Class Summary
protected  class ASTJCompilationUnit.AbstractRewriter
          Base class for additional rewriters used during rewrite process.
protected  class ASTJCompilationUnit.NodeCommenter
           
protected  class ASTJCompilationUnit.NodeContentsReplacer
           
 
Field Summary
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
 
Fields inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode
isCommentedOut, name, rewriter, UNITIALIZED_STRING
 
Fields inherited from class org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
EMPTY_STRING_ARRAY, qualifiedName
 
Constructor Summary
ASTJCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit)
           
 
Method Summary
 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<org.eclipse.jdt.core.dom.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<org.eclipse.jdt.core.dom.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.
 
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode
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
 
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
computeQualifiedName, computeQualifiedName, computeQualifiedName, getFlags, getName, getQualifiedName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.codegen.merge.java.facade.JNode
getFlags, getParent, getQualifiedName, setFlags
 

Field Detail

NAME_PROPERTY

public static final java.lang.String NAME_PROPERTY
Name for the name property of the compilation unit.

See Also:
Constant Field Values

HEADER_PATTERN

protected static final java.util.regex.Pattern HEADER_PATTERN
Pattern to extract and replace header. Header is any number of block or line comments, spaces or newline characters before any Java code (package, import or type declaration).


headerString

protected java.lang.String headerString
Header of the compilation unit to be set during rewrite. If it is null, the header will not be modified.


originalContents

protected char[] originalContents
Original contents of the compilation unit

Constructor Detail

ASTJCompilationUnit

public ASTJCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit)
Parameters:
compilationUnit -
Method Detail

dispose

public void dispose()
Overrides:
dispose in class ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>

setOriginalContents

public void setOriginalContents(char[] originalContents)
Sets original contents of the compilation unit to be used for converting nodes to strings.

Parameters:
originalContents -

getOriginalContents

public char[] getOriginalContents()
Returns:
original contents of the compilation unit

getName

public java.lang.String getName()
Returns the name of the main type suffixed with java extension.

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.

Specified by:
getName in interface JNode
Returns:
name of the main type suffixed with java extension
See Also:
JNode.getName()

setName

public void setName(java.lang.String name)
Sets the name of the main type of compilation unit.

Specified by:
setName in interface JNode
See Also:
FacadeHelper.getMainType(JCompilationUnit), JNode.setName(java.lang.String), JNode.getQualifiedName()

computeQualifiedName

protected java.lang.String computeQualifiedName()
Same as the getName().

Overrides:
computeQualifiedName in class AbstractJNode
See Also:
AbstractJNode.computeQualifiedName()

getChildren

public java.util.List<JNode> getChildren()
Returns the list of children in order: package declaration (JPackage), imports (JImport), and types (JType).

Specified by:
getChildren in interface JNode
Overrides:
getChildren in class AbstractJNode
Returns:
a list of the children
See Also:
AbstractJNode.getChildren()

getHeader

public java.lang.String getHeader()
Description copied from interface: JCompilationUnit
Returns the header comment for this compilation unit. The header comment appears before the first declaration in a compilation unit.

Specified by:
getHeader in interface JCompilationUnit
Returns:
the header comment for this compilation unit, or null if no header comment is present

setHeader

public 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.

For the files with no package declaration, the new header might be inserted at the beginning of the file instead of being replaced.

Specified by:
setHeader in interface JCompilationUnit
Parameters:
header - the header comment for this compilation unit, or null if indicating no header comment
See Also:
JCompilationUnit.setHeader(java.lang.String)

setHeader

protected void setHeader(IDocument targetDoc)
Method to replace the header in the given document.

Parameters:
targetDoc -

getContents

public java.lang.String getContents()
Returns the rewritten text after applying all the changes made to JNode tree.

Specified by:
getContents in interface JNode
Overrides:
getContents in class ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
Returns:
the contents, or null if this node has no contents
See Also:
ASTJNode.getContents()

addChild

public boolean addChild(ASTJNode<?> child)
Description copied from class: ASTJNode
Adds a child to this node.

Default implementation does nothing and returns false.

Overrides:
addChild in class ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
Parameters:
child - to add
Returns:
true if operation successful, false otherwise

insertSibling

public boolean insertSibling(ASTJNode<?> node,
                             ASTJNode<?> newSibling,
                             boolean before)
Description copied from class: ASTJNode
Inserts newSibling as a child of this node before or after the given node.

Default implementation does nothing and returns false.

Overrides:
insertSibling in class ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
newSibling - to insert
before - true if newSibling must be before node, false if after
Returns:
true if operation successful, false otherwise

remove

public boolean remove(ASTJNode<?> node)
Removes the given 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.

Overrides:
remove in class ASTJNode<org.eclipse.jdt.core.dom.CompilationUnit>
Parameters:
node - must be a child of this node
Returns:
true if operation successful, false otherwise
See Also:
ASTJNode.remove(ASTJNode)

getAllTrackedContentsMap

protected java.util.Map<org.eclipse.jdt.core.dom.ASTNode,java.lang.String> getAllTrackedContentsMap()
Returns:
map of all nodes of the compilation unit and its children (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.


getCommentedOutNodes

protected java.util.Set<org.eclipse.jdt.core.dom.ASTNode> getCommentedOutNodes()
Returns:
set of nodes that have been commented out

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.