|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.codegen.merge.java.facade.AbstractJNode
org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode<T>
T
- wrapped AST node typepublic abstract class ASTJNode<T extends org.eclipse.jdt.core.dom.ASTNode>
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.
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 |
---|
protected static final java.lang.String UNITIALIZED_STRING
protected java.lang.String name
JNode.getName()
,
JNode.setName(String)
protected boolean isCommentedOut
true
if the node is commented out, false
otherwise
commentOut()
protected org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter
Constructor Detail |
---|
protected ASTJNode(T astNode)
astNode
- to be used as wrapped objectAbstractJNode.AbstractJNode()
Method Detail |
---|
public void dispose()
dispose
in class AbstractJNode
public boolean isDisposed()
isDisposed
in class AbstractJNode
public ASTFacadeHelper getFacadeHelper()
getFacadeHelper
in class AbstractJNode
public void setFacadeHelper(FacadeHelper facadeHelper)
setFacadeHelper
in class AbstractJNode
protected T getASTNode()
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.
protected void setASTNode(T astNode)
astNode
- the astNode to setprotected org.eclipse.jdt.core.dom.ASTNode getWrappedObject()
set...
and get...
should not use this node.
getWrappedObject
in class AbstractJNode
getASTNode()
,
getRemovedASTNode()
protected void setWrappedObject(org.eclipse.jdt.core.dom.ASTNode node)
ASTNode
. Must be
used with caution and only by subclasses.
node
- getWrappedObject()
public ASTJNode<?> getParent()
JNode
null
if this node has been created or removedpublic void setParent(ASTJNode<?> parent)
parent
- the parent to set, null
if the node does not have a parentpublic org.eclipse.jdt.core.dom.rewrite.ASTRewrite getRewriter()
public void setRewriter(org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter)
rewriter
- the rewriter to setpublic boolean addChild(ASTJNode<?> child)
Default implementation does nothing and returns false
.
child
- to add
true
if operation successful, false
otherwiseprotected void addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTNode value, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)
value
to the property of the node.
node
- value
- property
- protected void addValueToListProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String value, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, int nodeType)
value
as a new string place-holder to the property
of the node
.
If value
is null
, no changes are made.
node
- value
- property
- nodeType
- of the place-holderprotected void ancestorInserted()
This implementation enables tracked contents for this node and calls itself on all of the children.
protected void ancestorToBeRemoved()
This implementation disables tracked contents for this node and calls itself on all of the children.
protected void childToBeChanged(ASTJNode<?> child)
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.
child
- that will be changedprotected java.lang.String[] convertASTNodeListToStringArray(java.util.List<? extends org.eclipse.jdt.core.dom.ASTNode> nodes)
All nodes in the given array must have valid source range and belong to the original tree.
nodes
-
ASTFacadeHelper.toString(ASTNode)
protected void disableTrackAndReplace()
ASTJNode
.
Used when modified ASTJNode
s are removed from the tree, and then possibly inserted again.
enableTrackAndReplace()
,
trackAndReplace(ASTNode, String)
protected void enableTrackAndReplace()
ASTJNode
.
Used when modified ASTJNode
s are removed from the tree, and then inserted again.
disableTrackAndReplace()
,
trackAndReplace(ASTNode, String)
public java.lang.String getContents()
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.
null
if this node has no contentsJNode.getContents()
protected org.eclipse.jdt.core.dom.ASTNode getRemovedASTNode()
protected void insert(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, ASTJNode<?> targetNode, boolean before)
No checks are performed if the new node can be inserted nor if the target node exists.
newNode
- property
- targetNode
- before
- protected void insertFirst(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)
No checks are performed if the new node can be inserted nor if the target node exists.
newNode
- property
- protected void insertLast(ASTJNode<?> newNode, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)
No checks are performed if the new node can be inserted nor if the target node exists.
newNode
- property
- public boolean insertSibling(ASTJNode<?> node, ASTJNode<?> newSibling, boolean before)
newSibling
as a child of this node before or after the given node
.
Default implementation does nothing and returns false
.
node
- newSibling
- to insertbefore
- true
if newSibling
must be before node
, false
if after
true
if operation successful, false
otherwiseprotected void nodeToBeMoved(org.eclipse.jdt.core.dom.ASTNode node)
ASTRewrite
that the node will be moved.
node
- to be movedCommentAwareSourceRangeComputer.computeSourceRange(ASTNode)
protected void nodeToBeRemoved(org.eclipse.jdt.core.dom.ASTNode node)
ASTRewrite
that the node will be removed.
node
- to be removedCommentAwareSourceRangeComputer.computeSourceRange(ASTNode)
public boolean remove(ASTJNode<?> node)
Default implementation does nothing and returns false
.
node
- must be a child of this node
true
if operation successful, false
otherwiseprotected void remove(ASTJNode<?> node, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property)
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.
node
- 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)
parentNode
- nodeToRemove
- property
- protected void removeTrackAndReplace(org.eclipse.jdt.core.dom.ASTNode node)
The given node
will be modified only by ASTRewrite
.
node
- to disable tracking fordisableTrackAndReplace()
,
trackAndReplace(ASTNode, String)
public void setFlags(int flags)
flags
- the flagsJNode.setFlags(int)
protected void setListNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String[] values, org.eclipse.jdt.core.dom.ChildListPropertyDescriptor property, int nodeType)
node
- values
- property
- nodeType
- of the string place holders to createprotected void setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.Object value, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property)
Note that the type value
parameter will only be checked by
ASTRewrite.set(ASTNode, StructuralPropertyDescriptor, Object, org.eclipse.text.edits.TextEditGroup)
node
- value
- property
- protected void setNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String stringValue, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property, int nodeType)
Note that the type value
parameter will only be checked by
ASTRewrite.set(ASTNode, StructuralPropertyDescriptor, Object, org.eclipse.text.edits.TextEditGroup)
node
- stringValue
- property
- nodeType
- protected java.lang.String[] combineArrayAndList(java.lang.String[] strings, java.util.List<java.lang.String> stringsList)
strings
- can not be null
stringsList
- can be null
protected void setRemovedASTNode(org.eclipse.jdt.core.dom.ASTNode removedASTNode)
removedASTNode
- the removedASTNode to setprotected void setTrackedNodeProperty(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String stringValue, org.eclipse.jdt.core.dom.StructuralPropertyDescriptor property, int nodeType)
stringValue
during rewrite process.
node
- to set property ofstringValue
- property
- must be SimplePropertyDescriptor
or ChildPropertyDescriptor
nodeType
- to use if value is null, and new node has to be createdprotected void trackAndReplace(org.eclipse.jdt.core.dom.ASTNode node, java.lang.String contents)
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.
node
- contents
- public void commentOut()
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |