## org.eclipse.emf.codegen.merge.java.facade.ast
Class ASTJNode<T extends org.eclipse.jdt.core.dom.ASTNode>

    java.lang.Object
      org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
          org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode<T>

Type Parameters:
  `T` - wrapped AST node type

All Implemented Interfaces:
  JNode

Direct Known Subclasses:
  ASTJAnnotation, ASTJCompilationUnit, ASTJImport, ASTJMember, ASTJPackage

    public abstract class ASTJNode<T extends org.eclipse.jdt.core.dom.ASTNode>

extends AbstractJNode

Each subclass of `ASTJNode` wraps subclass of `ASTNode`.

`ASTJNode` may have reference to multiple `ASTNode` objects.

Wrapped `ASTNode` (returned by `getWrappedObject()`) is always the node in the rewritten tree. Each object of `ASTJNode` wraps a unique `ASTNode`. After nodes are removed, wrapped `ASTNode` has reference to the move target node that allows the node to be inserted after, i.e. perform moving of the node.

Original ASTNode (returned by `getASTNode()`) is used to make modifications to the node and its children. This node must be used by get and set methods. Using this node allows to make modifications to the nodes after they are moved.

Some subclasses (e.g. `ASTJAnnotation` and `ASTJField`) may need a different `ASTNode` to be used by set methods. These subclasses use `getASTNode()` only for get methods.

Removed ASTNode (returned by `getRemovedASTNode()`) is used to keep reference to the node that was removed. This allows to notify the range computer when the removed node is inserted again.

Since:
  2.2.0
See Also:
  `getWrappedObject()`, `getASTNode()`, `getRemovedASTNode()`

Field Summary
`protected boolean` `isCommentedOut` `true` if the node is commented out, `false` otherwise
`protected java.lang.String` `name` Name of the node.
`protected org.eclipse.jdt.core.dom.rewrite.ASTRewrite` `rewriter` ASTRewrite object used to keep track of all modifications
`protected static java.lang.String` `UNITIALIZED_STRING` Default value used as default value of fields of subclasses.

Fields inherited from class org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
`EMPTY_STRING_ARRAY, qualifiedName`

Constructor Summary
`protected` `ASTJNode(T astNode)`

Method Summary
`boolean` `addChild(ASTJNode<?> child)` Adds a child to this node.
`protected void` `addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTNode value, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)` Adds `value` to the property of the node.
`protected void` `addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String value, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, int nodeType)` Adds `value` as a new string place-holder to the `property` of the `node`.
`protected void` `ancestorInserted()` Notifies the node that one of ancestors in the hierarchy or this node itself was inserted.
`protected void` `ancestorToBeRemoved()` Notifies the node that one of ancestors in the hierarchy or this node itself will be removed.
`protected void` `childToBeChanged(ASTJNode<?> child)` Notifies the node that the child will be changed.
`protected java.lang.String[]` `combineArrayAndList(java.lang.String[] strings, java.util.List<java.lang.String> stringsList)` Adds strings from strings list to existing array of strings, returns resulting string array, and clears the list of strings.
`void` `commentOut()` Comments out this node.
`protected java.lang.String[]` `convertASTNodeListToStringArray(java.util.List<? extends org.eclipse.jdt.core.dom.ASTNode> nodes)` Convert a given list of nodes to an array of strings.
`protected void` `disableTrackAndReplace()` Temporarily disables tracking for all AST nodes that are tracked by this `ASTJNode`.
`void` `dispose()`
`protected void` `enableTrackAndReplace()` Enables disabled tracking for all AST nodes that are tracked by this `ASTJNode`.
`protected T` `getASTNode()` Returns AST node used to read contents and make modifications to the nodes.
`java.lang.String` `getContents()` Get the original contents of the node using the source.
`ASTFacadeHelper` `getFacadeHelper()`
`ASTJNode<?>` `getParent()` Returns the parent of this node.
`protected org.eclipse.jdt.core.dom.ASTNode` `getRemovedASTNode()`
`org.eclipse.jdt.core.dom.rewrite.ASTRewrite` `getRewriter()`
`protected org.eclipse.jdt.core.dom.ASTNode` `getWrappedObject()` Returns wrapped AST node that is currently in the rewritten tree, or to be inserted into the tree.
`protected void` `insert(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, ASTJNode<?> targetNode, boolean before)` Inserts AST node wrapped by new node beside target node in the list defined by given property.
`protected void` `insertFirst(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)` Inserts AST node wrapped by new node at the beginning of the list of nodes defined by given property.
`protected void` `insertLast(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)` Inserts AST node wrapped by new node at the end of the list of nodes defined by given property.
`boolean` `insertSibling(ASTJNode<?> node, ASTJNode<?> newSibling, boolean before)` Inserts `newSibling` as a child of this node before or after the given `node`.
`boolean` `isDisposed()`
`protected void` `nodeToBeMoved(org.eclipse.jdt.core.dom.ASTNode node)` Notifies the range computer of `ASTRewrite` that the node will be moved.
`protected void` `nodeToBeRemoved(org.eclipse.jdt.core.dom.ASTNode node)` Notifies the range computer of `ASTRewrite` that the node will be removed.
`boolean` `remove(ASTJNode<?> node)` Removes a node.
`protected void` `remove(ASTJNode<?> node, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)` Removes AST node wrapped by given `ASTJNode` from the given property.
`protected void` `removeNodeFromListProperty(org.eclipse.jdt.core.dom.ASTNode parentNode, org.eclipse.jdt.core.dom.ASTNode nodeToRemove, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)` Removes value from list property.
`protected void` `removeTrackAndReplace(org.eclipse.jdt.core.dom.ASTNode node)` Permanently disables tracking for the given AST node.
`protected void` `setASTNode(T astNode)`
`void` `setFacadeHelper(FacadeHelper facadeHelper)`
`void` `setFlags(int flags)` Default implementation does nothing.
`protected void` `setListNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String[] values, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, int nodeType)` Sets the list property to the given array of values.
`protected void` `setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.Object value, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property)` Sets the property of the node to the given value.
`protected void` `setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String stringValue, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property, int nodeType)` Sets the property of the node to the given string value.
`void` `setParent(ASTJNode<?> parent)` Sets the parent of this node.
`protected void` `setRemovedASTNode(org.eclipse.jdt.core.dom.ASTNode removedASTNode)`
`void` `setRewriter(org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter)`
`protected void` `setTrackedNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String stringValue, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property, int nodeType)` Sets the property of the node.
`protected void` `setWrappedObject(org.eclipse.jdt.core.dom.ASTNode node)` Sets the wrapped object to the given `ASTNode`.
`protected void` `trackAndReplace(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String contents)` Records that the given `node` must have the given `contents`.

Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.AbstractJNode
`computeQualifiedName, computeQualifiedName, computeQualifiedName, computeQualifiedName, getChildren, 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
`getName, setName`

Field Detail

### UNITIALIZED_STRING

    protected static final java.lang.String UNITIALIZED_STRING

  Default value used as default value of fields of subclasses. Indicates that fields have not been initialized. This value should never be returned by any get...() methods.

  See Also:
    Constant Field Values

### name

    protected java.lang.String name

  Name of the node.

  See Also:
    `JNode.getName()`, `JNode.setName(String)`

### isCommentedOut

    protected boolean isCommentedOut

  `true` if the node is commented out, `false` otherwise

  See Also:
    `commentOut()`

### rewriter

    protected org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter

  ASTRewrite object used to keep track of all modifications

Constructor Detail

### ASTJNode

    protected ASTJNode(T astNode)

Parameters:
  `astNode` - to be used as wrapped object
See Also:
  `AbstractJNode.AbstractJNode()`

Method Detail

### dispose

    public void dispose()

  Specified by:
    `dispose` in class `AbstractJNode`

### isDisposed

    public boolean isDisposed()

  Specified by:
    `isDisposed` in class `AbstractJNode`

### getFacadeHelper

    public ASTFacadeHelper getFacadeHelper()

  Specified by:
    `getFacadeHelper` in class `AbstractJNode`

### setFacadeHelper

    public void setFacadeHelper(FacadeHelper facadeHelper)

  Specified by:
    `setFacadeHelper` in class `AbstractJNode`

### getASTNode

    protected T getASTNode()

  Returns AST node used to read contents and make modifications to the nodes.

  When the node is removed, the wrapped node returned by `getWrappedObject()` will be a place-holder node, while this method will return the original node that can be modified by `set...` methods.

  Returns:
    AST node

### setASTNode

    protected void setASTNode(T astNode)

  Parameters:
    `astNode` - the astNode to set

### getWrappedObject

    protected org.eclipse.jdt.core.dom.ASTNode getWrappedObject()

  Returns wrapped AST node that is currently in the rewritten tree, or to be inserted into the tree. This node can be a move target node or any other temporary node. Methods such as `set...` and `get...` should not use this node.

  Specified by:
    `getWrappedObject` in class `AbstractJNode`
  Returns:
    wrapped AST node
  See Also:
    `getASTNode()`, `getRemovedASTNode()`

### setWrappedObject

    protected void setWrappedObject(org.eclipse.jdt.core.dom.ASTNode node)

  Sets the wrapped object to the given `ASTNode`. Must be used with caution and only by subclasses.

  Parameters:
    `node` -
  See Also:
    `getWrappedObject()`

### getParent

    public ASTJNode<?> getParent()

  Description copied from interface: `JNode`
  Returns the parent of this node.

  Returns:
    the parent of this ASTJNode, or `null` if this node has been created or removed

### setParent

    public void setParent(ASTJNode<?> parent)

  Sets the parent of this node.

  Parameters:
    `parent` - the parent to set, `null` if the node does not have a parent

### getRewriter

    public org.eclipse.jdt.core.dom.rewrite.ASTRewrite getRewriter()

  Returns:
    the rewriter

### setRewriter

    public void setRewriter(org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter)

  Parameters:
    `rewriter` - the rewriter to set

### addChild

    public boolean addChild(ASTJNode<?> child)

  Adds a child to this node.

  Default implementation does nothing and returns `false`.

  Parameters:
    `child` - to add
  Returns:
    `true` if operation successful, `false` otherwise

### addValueToListProperty

    protected void addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                          org.eclipse.jdt.core.dom.ASTNode value,
                                          org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)

  Adds `value` to the property of the node.

  Parameters:
    `node` -
    `value` -
    `property` -

### addValueToListProperty

    protected void addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                          java.lang.String value,
                                          org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property,
                                          int nodeType)

  Adds `value` as a new string place-holder to the `property` of the `node`.

  If `value` is `null`, no changes are made.

  Parameters:
    `node` -
    `value` -
    `property` -
    `nodeType` - of the place-holder

### ancestorInserted

    protected void ancestorInserted()

  Notifies the node that one of ancestors in the hierarchy or this node itself was inserted. This means that this node was inserted as well.

  This implementation enables tracked contents for this node and calls itself on all of the children.

### ancestorToBeRemoved

    protected void ancestorToBeRemoved()

  Notifies the node that one of ancestors in the hierarchy or this node itself will be removed. This means that this node will be removed as well.

  This implementation disables tracked contents for this node and calls itself on all of the children.

### childToBeChanged

    protected void childToBeChanged(ASTJNode<?> child)

  Notifies the node that the child will be changed.

  Parents that are interested in changes to children must override this method. Children that need to notify the parents about changes have to call this method.

  Default implementation does nothing.

  Parameters:
    `child` - that will be changed

### convertASTNodeListToStringArray

    protected java.lang.String[] convertASTNodeListToStringArray(java.util.List<? extends org.eclipse.jdt.core.dom.ASTNode> nodes)

  Convert a given list of nodes to an array of strings.

  All nodes in the given array must have valid source range and belong to the original tree.

  Parameters:
    `nodes` -
  Returns:
    string array
  See Also:
    `ASTFacadeHelper.toString(ASTNode)`

### disableTrackAndReplace

    protected void disableTrackAndReplace()

  Temporarily disables tracking for all AST nodes that are tracked by this `ASTJNode`.

  Used when modified `ASTJNode`s are removed from the tree, and then possibly inserted again.

  See Also:
    `enableTrackAndReplace()`, `trackAndReplace(ASTNode, String)`

### enableTrackAndReplace

    protected void enableTrackAndReplace()

  Enables disabled tracking for all AST nodes that are tracked by this `ASTJNode`.

  Used when modified `ASTJNode`s are removed from the tree, and then inserted again.

  See Also:
    `disableTrackAndReplace()`, `trackAndReplace(ASTNode, String)`

### getContents

    public java.lang.String getContents()

  Get the original contents of the node using the source.

  The contents of the node in AST implementation includes only the node itself without the leading or trailing whitespace. If the node has a Javadoc comment, it is included in the contents. No other leading or trailing comments are included in the node contents.

  Note that this method returns the contents before any modifications. This method will not return the correct contents if the node has been cloned, removed or moved.

  Returns:
    the contents, or `null` if this node has no contents
  See Also:
    `JNode.getContents()`

### getRemovedASTNode

    protected org.eclipse.jdt.core.dom.ASTNode getRemovedASTNode()

  Returns:
    the removedASTNode

### insert

    protected void insert(ASTJNode<?> newNode,
                          org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property,
                          ASTJNode<?> targetNode,
                          boolean before)

  Inserts AST node wrapped by new node beside target node in the list defined by given property.

  No checks are performed if the new node can be inserted nor if the target node exists.

  Parameters:
    `newNode` -
    `property` -
    `targetNode` -
    `before` -

### insertFirst

    protected void insertFirst(ASTJNode<?> newNode,
                               org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)

  Inserts AST node wrapped by new node at the beginning of the list of nodes defined by given property.

  No checks are performed if the new node can be inserted nor if the target node exists.

  Parameters:
    `newNode` -
    `property` -

### insertLast

    protected void insertLast(ASTJNode<?> newNode,
                              org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)

  Inserts AST node wrapped by new node at the end of the list of nodes defined by given property.

  No checks are performed if the new node can be inserted nor if the target node exists.

  Parameters:
    `newNode` -
    `property` -

### insertSibling

    public boolean insertSibling(ASTJNode<?> node,
                                 ASTJNode<?> newSibling,
                                 boolean before)

  Inserts `newSibling` as a child of this node before or after the given `node`.

  Default implementation does nothing and returns `false`.

  Parameters:
    `node` -
    `newSibling` - to insert
    `before` - `true` if `newSibling` must be before `node`, `false` if after
  Returns:
    `true` if operation successful, `false` otherwise

### nodeToBeMoved

    protected void nodeToBeMoved(org.eclipse.jdt.core.dom.ASTNode node)

  Notifies the range computer of `ASTRewrite` that the node will be moved.

  Parameters:
    `node` - to be moved
  See Also:
    `CommentAwareSourceRangeComputer.computeSourceRange(ASTNode)`

### nodeToBeRemoved

    protected void nodeToBeRemoved(org.eclipse.jdt.core.dom.ASTNode node)

  Notifies the range computer of `ASTRewrite` that the node will be removed.

  Parameters:
    `node` - to be removed
  See Also:
    `CommentAwareSourceRangeComputer.computeSourceRange(ASTNode)`

### remove

    public boolean remove(ASTJNode<?> node)

  Removes a node.

  Default implementation does nothing and returns `false`.

  Parameters:
    `node` - must be a child of this node
  Returns:
    `true` if operation successful, `false` otherwise

### remove

    protected void remove(ASTJNode<?> node,
                          org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)

  Removes AST node wrapped by given `ASTJNode` from the given property.

  This method notifies children and source range computer that the node is removed, then creates a place-holder node that allows to insert the removed node later.

  No checks are performed if the node is a child of this node.

  Parameters:
    `node` -
    `property` -

### removeNodeFromListProperty

    protected void removeNodeFromListProperty(org.eclipse.jdt.core.dom.ASTNode parentNode,
                                              org.eclipse.jdt.core.dom.ASTNode nodeToRemove,
                                              org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)

  Removes value from list property.

  Parameters:
    `parentNode` -
    `nodeToRemove` -
    `property` -

### removeTrackAndReplace

    protected void removeTrackAndReplace(org.eclipse.jdt.core.dom.ASTNode node)

  Permanently disables tracking for the given AST node.

  The given `node` will be modified only by `ASTRewrite`.

  Parameters:
    `node` - to disable tracking for
  See Also:
    `disableTrackAndReplace()`, `trackAndReplace(ASTNode, String)`

### setFlags

    public void setFlags(int flags)

  Default implementation does nothing.

  Parameters:
    `flags` - the flags
  See Also:
    `JNode.setFlags(int)`

### setListNodeProperty

    protected void setListNodeProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                       java.lang.String[] values,
                                       org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property,
                                       int nodeType)

  Sets the list property to the given array of values. For each string in the array, a string place-holder node is created.

  Parameters:
    `node` -
    `values` -
    `property` -
    `nodeType` - of the string place holders to create

### setNodeProperty

    protected void setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                   java.lang.Object value,
                                   org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property)

  Sets the property of the node to the given value.

  Note that the type `value` parameter will only be checked by `ASTRewrite.set(ASTNode, StructuralPropertyDescriptor, Object, org.eclipse.text.edits.TextEditGroup)`

  Parameters:
    `node` -
    `value` -
    `property` -

### setNodeProperty

    protected void setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                   java.lang.String stringValue,
                                   org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property,
                                   int nodeType)

  Sets the property of the node to the given string value.

  Note that the type `value` parameter will only be checked by `ASTRewrite.set(ASTNode, StructuralPropertyDescriptor, Object, org.eclipse.text.edits.TextEditGroup)`

  Parameters:
    `node` -
    `stringValue` -
    `property` -
    `nodeType` -

### combineArrayAndList

    protected java.lang.String[] combineArrayAndList(java.lang.String[] strings,
                                                     java.util.List<java.lang.String> stringsList)

  Adds strings from strings list to existing array of strings, returns resulting string array, and clears the list of strings.

  Parameters:
    `strings` - can not be `null`
    `stringsList` - can be `null`

### setRemovedASTNode

    protected void setRemovedASTNode(org.eclipse.jdt.core.dom.ASTNode removedASTNode)

  Parameters:
    `removedASTNode` - the removedASTNode to set

### setTrackedNodeProperty

    protected void setTrackedNodeProperty(org.eclipse.jdt.core.dom.ASTNode node,
                                          java.lang.String stringValue,
                                          org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property,
                                          int nodeType)

  Sets the property of the node. The position of the property value is tracked and value is replaced by `stringValue` during rewrite process.

  Parameters:
    `node` - to set property of
    `stringValue` -
    `property` - must be `SimplePropertyDescriptor` or `ChildPropertyDescriptor`
    `nodeType` - to use if value is null, and new node has to be created

### trackAndReplace

    protected void trackAndReplace(org.eclipse.jdt.core.dom.ASTNode node,
                                   java.lang.String contents)

  Records that the given `node` must have the given `contents`.

  During rewrite process, the position of the `node` will be tracked, and the node will replaced by the given `contents`. No changes will be made to `contents`.

  This method should be used to undo correction of indentation done by `ASTRewrite.rewriteAST(org.eclipse.jface.text.IDocument, Map)` on string place-holder nodes (`ASTRewrite.createStringPlaceholder(String, int)`) during rewrite process.

  Note that all the tracked nodes must exist in the rewritten tree. If some tracked nodes are removed from rewritten tree, wrong contents may be replaced. Use `disableTrackAndReplace()` when `ASTJNode`s are removed.

  Parameters:
    `node` -
    `contents` -

### commentOut

    public void commentOut()

  Comments out this node. Node is not removed from the tree, and is still returned by getChildren().

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