|
||||||||||
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>
org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
org.eclipse.emf.codegen.merge.java.facade.ast.ASTJField
public class ASTJField
Represents a single variable in a field declaration.
If multiple variables are declared in the same field declaration, there is a unique
ASTJField
for each variable. Each ASTJField
has reference
to FieldDeclaration
and VariableDeclarationFragment
. Multiple ASTJField
can share the same FieldDeclaration
.
If the field declaration referenced by ASJField
has more than 1 variable,
calls to some set...()
methods on the field and its children (e.g. annotations)
will result in a separation of the variable referenced by ASTJField
from
the field declaration. The new declaration is inserted before the original declaration.
After the separation, calls to get...()
methods will no longer return the correct
original content.
Field Summary | |
---|---|
protected java.lang.String |
initializer
Cached value of initializer of this field. |
protected boolean |
splitPerformed
Indicates whether the variable declaration fragment is the only fragment in the field declaration. |
protected java.lang.String |
type
Cached type of the field |
protected org.eclipse.jdt.core.dom.VariableDeclarationFragment |
variableDeclarationFragment
Variable declaration fragment that is wrapped by ASTJField and to be used by set... |
protected org.eclipse.jdt.core.dom.VariableDeclarationFragment |
wrappedVariableDeclarationFragment
Variable declaration fragment that is wrapped by ASTJField and reflects current node in the rewritten tree that is used by this field. |
Fields inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMember |
---|
comment |
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 | |
---|---|
ASTJField(org.eclipse.jdt.core.dom.VariableDeclarationFragment variableDeclarationFragment,
ASTFacadeHelper facadeHelper,
org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter)
Sets wrapped object to VariableDeclarationFragment , and prepares variable
separation if required |
Method Summary | |
---|---|
boolean |
addChild(ASTJNode<?> child)
Adds a child to this node. |
protected void |
childToBeChanged(ASTJNode<?> child)
Notifies the node that the child will be changed. |
void |
commentOut()
Commenting out a field results in splitting of the fields, and then commenting out only the field that is commented out. |
void |
dispose()
|
java.lang.String |
getComment()
Returns the comment associated with this member (including comment delimiters). |
java.lang.String |
getContents()
Return the original declaration contents (including all variable declaration fragments in the declaration). |
int |
getFlags()
Return original flags of the field declaration. |
java.lang.String |
getInitializer()
Returns original initializer of variable declaration fragment. |
java.lang.String |
getName()
Returns name of variable declaration fragment. |
org.eclipse.jdt.core.dom.FieldDeclaration |
getOriginalFieldDeclaration()
|
java.lang.String |
getType()
Returns original type of FieldDeclaration . |
org.eclipse.jdt.core.dom.VariableDeclarationFragment |
getVariableDeclarationFragment()
|
org.eclipse.jdt.core.dom.VariableDeclarationFragment |
getWrappedVariableDeclarationFragment()
|
boolean |
insertSibling(ASTJNode<?> node,
ASTJNode<?> newSibling,
boolean before)
Inserts newSibling as a child of this node before or after the given node . |
protected void |
performSplit()
If required, separates the variable declaration fragment into a new FieldDeclaration
object. |
protected void |
prepareSplit()
Ensures that the field wrapped by this ASTJField have only 1 variable in the declaration. |
boolean |
remove(ASTJNode<?> node)
Removes a node. |
protected void |
revertPrepareSplit()
Revert the changes made by prepareSplit() . |
void |
setComment(java.lang.String comment)
May split the declaration same way as setType(String) . |
void |
setFlags(int flags)
May split the declaration same way as setType(String)
If the declaration has been split, getFlags() might not return
the correct value. |
void |
setInitializer(java.lang.String initializer)
Sets initializer of variable declaration fragment. |
void |
setName(java.lang.String name)
Sets name of variable declaration fragment. |
void |
setType(java.lang.String type)
Sets the type of FieldDeclaration . |
protected void |
setWrappedObject(org.eclipse.jdt.core.dom.ASTNode node)
Sets wrapped object to be the given FieldDeclaration, and sets wrappedVariableDeclarationFragment attribute to be the first variable declaration fragment in the given FieldDeclaration. |
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMember |
---|
getAnnotationList, getChildren, insertLastAnnotation |
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode |
---|
addValueToListProperty, addValueToListProperty, ancestorInserted, ancestorToBeRemoved, combineArrayAndList, convertASTNodeListToStringArray, disableTrackAndReplace, enableTrackAndReplace, getASTNode, getFacadeHelper, getParent, getRemovedASTNode, getRewriter, getWrappedObject, insert, insertFirst, insertLast, isDisposed, nodeToBeMoved, nodeToBeRemoved, remove, removeNodeFromListProperty, removeTrackAndReplace, setASTNode, setFacadeHelper, setListNodeProperty, setNodeProperty, setNodeProperty, setParent, setRemovedASTNode, setRewriter, setTrackedNodeProperty, trackAndReplace |
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.AbstractJNode |
---|
computeQualifiedName, computeQualifiedName, computeQualifiedName, computeQualifiedName, 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 |
---|
getChildren, getParent, getQualifiedName |
Field Detail |
---|
protected java.lang.String initializer
Note that change in initializer should not result in splitting variables in the field declaration.
If setInitializer()
has been called, and performSplit()
is
called after, then performSplit()
should not overwrite the initializer.
protected java.lang.String type
getType()
,
setType(String)
protected boolean splitPerformed
protected org.eclipse.jdt.core.dom.VariableDeclarationFragment variableDeclarationFragment
set...
and get...
methods. Note that when field is removed, this variable is not changed.
On the other hand, wrappedVariableDeclarationFragment is updated to reflect current node in the tree.
Since the same FieldDeclaration
can have multiple variables declared in it,
but JField
object must be unique for 1 variable, each
ASTJField has reference to FieldDeclaration and VariableDeclarationFragment
.
VariableDeclarationFragment
protected org.eclipse.jdt.core.dom.VariableDeclarationFragment wrappedVariableDeclarationFragment
Actual wrapped object is FieldDeclaration object, while VariableDeclarationFragment is stored
as an attribute of ASTJField and returned by ASTJNode.getWrappedObject()
.
VariableDeclarationFragment
Constructor Detail |
---|
public ASTJField(org.eclipse.jdt.core.dom.VariableDeclarationFragment variableDeclarationFragment, ASTFacadeHelper facadeHelper, org.eclipse.jdt.core.dom.rewrite.ASTRewrite rewriter)
VariableDeclarationFragment
, and prepares variable
separation if required
variableDeclarationFragment
- must have parent of type FieldDeclaration
facadeHelper
- facade helper to use for this field, must not be null
rewriter
- to use, must not be null
prepareSplit()
Method Detail |
---|
public void dispose()
dispose
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
public org.eclipse.jdt.core.dom.FieldDeclaration getOriginalFieldDeclaration()
public org.eclipse.jdt.core.dom.VariableDeclarationFragment getWrappedVariableDeclarationFragment()
public org.eclipse.jdt.core.dom.VariableDeclarationFragment getVariableDeclarationFragment()
public boolean addChild(ASTJNode<?> child)
ASTJNode
Default implementation does nothing and returns false
.
addChild
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
child
- to add
true
if operation successful, false
otherwisepublic java.lang.String getComment()
JMember
getComment
in interface JMember
getComment
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
null
if this member has no associated
commentpublic void setComment(java.lang.String comment)
setType(String)
.
If the declaration has been split, getComment()
might not return the correct value.
setComment
in interface JMember
setComment
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
comment
- the comment, including comment delimiters, or
null
indicating this member should have no associated commentASTJMember.setComment(java.lang.String)
public java.lang.String getContents()
If the declaration has been split, the returned value will not be correct.
getContents
in interface JNode
getContents
in class ASTJNode<org.eclipse.jdt.core.dom.FieldDeclaration>
null
if this node has no contentsASTJNode.getContents()
public int getFlags()
getFlags
in interface JNode
getFlags
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
ASTJMember.getFlags()
public void setFlags(int flags)
setType(String)
If the declaration has been split, getFlags()
might not return
the correct value.
setFlags
in interface JNode
setFlags
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
flags
- the flagsASTJMember.setFlags(int)
public java.lang.String getInitializer()
getInitializer
in interface JField
null
if this field does
not have an initializerJField.getInitializer()
public void setInitializer(java.lang.String initializer)
setInitializer
in interface JField
initializer
- the initializer expression, or null
indicating
the field does not have an initializerJField.setInitializer(java.lang.String)
public java.lang.String getName()
getName
in interface JNode
null
if it has no nameJNode.getName()
public void setName(java.lang.String name)
setName
in interface JNode
JNode.setName(java.lang.String)
public java.lang.String getType()
FieldDeclaration
.
The dimensions declared after variable name are appended to the type.
getType
in interface JField
JField.getType()
public void setType(java.lang.String type)
FieldDeclaration
.
If there is only one VariableDeclarationFragment
in this declaration,
only the type of the FieldDeclaration is changed.
If there are multiple VariableDeclarationFragment
s in this declaration,
variable declaration fragment of this ASTJField is moved to a new
FieldDeclaration
, and the type of new declaration is set.
Note that if field declaration has been split,
getType()
, getContents()
, getComment()
,
getInitializer()
will not return
the original content.
setType
in interface JField
type
- the type nameJField.setType(String)
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 ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
newSibling
- to insertbefore
- true
if newSibling
must be before node
, false
if after
true
if operation successful, false
otherwiseprotected void childToBeChanged(ASTJNode<?> child)
ASTJNode
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.
childToBeChanged
in class ASTJNode<org.eclipse.jdt.core.dom.FieldDeclaration>
child
- that will be changedprotected void prepareSplit()
If required, this method creates a new field declaration, and sets rewritten AST node to it. The ASTNode of all annotations of the new field is updated to use the original node.
Note that the no changes are added to the rewriter or wrapped object until performSplit()
is called.
This method must be called when field is created to ensure that annotations are unique for each ASTJField
.
performSplit()
protected void revertPrepareSplit()
prepareSplit()
.
prepareSplit()
protected void performSplit()
FieldDeclaration
object. If this declaration does not need to be split, reverts the changes made by prepareSplit()
.
New field declaration will have only one variable declaration fragment.
New declaration is added to the ASTRewrite
.
The attributes of this ASTJField are updated to reference elements of the new declaration.
Only the javadoc, variable initializer, and annotations are copied as String, all other attributes are copied
using ASTNode.copySubtree(org.eclipse.jdt.core.dom.AST, ASTNode)
. All
formatting except for Javadoc, initializer, and annotations is lost.
If field declaration wrapped by ASTJField has only one variable declaration
fragment left, no changes are made.
Note that this method must be called after prepareSplit()
and before any
changes are made to the nodes.
prepareSplit()
public boolean remove(ASTJNode<?> node)
ASTJNode
Default implementation does nothing and returns false
.
remove
in class ASTJMember<org.eclipse.jdt.core.dom.FieldDeclaration>
node
- must be a child of this node
true
if operation successful, false
otherwiseprotected void setWrappedObject(org.eclipse.jdt.core.dom.ASTNode node)
This method is mainly used by remove(ASTJNode)
to create a move target to allow
insertion of the nodes later.
setWrappedObject
in class ASTJNode<org.eclipse.jdt.core.dom.FieldDeclaration>
node
- must be of type FieldDeclaration, ignored otherwiseASTJNode.setWrappedObject(org.eclipse.jdt.core.dom.ASTNode)
public void commentOut()
commentOut
in class ASTJNode<org.eclipse.jdt.core.dom.FieldDeclaration>
ASTJNode.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 |