org.eclipse.emf.codegen.merge.java.facade
Class FacadeHelper

java.lang.Object
  extended by org.eclipse.emf.codegen.merge.java.facade.FacadeHelper
Direct Known Subclasses:
ASTFacadeHelper, JDOMFacadeHelper

public abstract class FacadeHelper
extends java.lang.Object


Field Summary
protected static java.lang.String CLASS_PREFIX
           
protected  JControlModel controlModel
           
protected  java.util.Map<java.lang.Object,JNode> objectToNodeMap
           
 
Constructor Summary
FacadeHelper()
           
 
Method Summary
 boolean addChild(JNode node, JNode child)
          Adds the given orphan node (document fragment) as the last child of the specified node.
 java.lang.String applyFormatRules(java.lang.String value)
          Formats the specified string using the CodeGenUtil.convertFormat(String, boolean, String) method.
 boolean canMerge()
           
 boolean canYieldWrongJavadoc()
          Returns whether this facade implementation may return the wrong Javadoc for a node when there are 2 or more javadoc blocks preceding the node.
abstract  JNode cloneNode(java.lang.Object context, JNode node)
          Clones the specified node, returning an object that is related to the given context.
 void commentOut(JNode node)
          Comment out the node and its children.
 JNode convertToNode(java.lang.Object object)
           
abstract  JCompilationUnit createCompilationUnit(java.lang.String name, java.lang.String contents)
           
 void dispose(JNode node)
          Disposes the node and its children.
protected  void disposeNode(JNode node)
          Disposes a single node.
protected abstract  JNode doConvertToNode(java.lang.Object object)
           
 boolean fixInterfaceBrace()
           
<T extends JNode>
java.util.List<T>
getChildren(JNode node, java.lang.Class<T> cls)
          Returns a list with the children of the specified node that are instances of the given class.
 java.lang.String getClassPrefix()
           
 JCompilationUnit getCompilationUnit(JNode node)
          Returns the compilation unit of the specified node.
abstract  java.lang.Object getContext(JNode node)
          Returns the context of a node.
 JControlModel getControlModel()
           
 JNode getFirstChild(JNode node)
          Returns the first child of the specified node.
 JType getMainType(JCompilationUnit compilationUnit)
          Returns the first public type in of a compilation unit.
 JNode getNext(JNode node)
          Returns the sibling node immediately following the specified node.
 NodeConverter getNodeConverter()
           
protected  java.util.Map<java.lang.Object,JNode> getObjectToNodeMap()
           
 java.lang.String getOriginalContents(JCompilationUnit compilationUnit)
          Returns the original, unmodified, content of the compilation unit.
 JPackage getPackage(JNode node)
          Returns the package of the specified node.
 JNode getPrevious(JNode node)
          Returns the sibling node immediately preceding the specified node.
protected  JNode getSibiling(JNode node, int pos)
          Returns the sibling of the specified node that is located in a specific position relative to the node.
 boolean insertSibling(JNode node, JNode newSibling, boolean before)
          Inserts the given orphan node as a sibling of the specified node, immediately before or after it.
 boolean isDisposed(JNode node)
          Returns true if a node is disposed.
 boolean isSibilingTraversalExpensive()
          Returns whether using the getPrevious(JNode) and getNext(JNode) methods is slower than using JNode.getChildren() directly.
 boolean remove(JNode node)
          Separates the specified node from its parent and siblings, maintaining any ties that this node has to the underlying document fragment.
 void reset()
           
 void setControlModel(JControlModel controlModel)
          Sets this facade helper's control model.
 java.lang.String toString(java.lang.Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_PREFIX

protected static final java.lang.String CLASS_PREFIX
See Also:
Constant Field Values

controlModel

protected JControlModel controlModel

objectToNodeMap

protected java.util.Map<java.lang.Object,JNode> objectToNodeMap
Constructor Detail

FacadeHelper

public FacadeHelper()
Method Detail

reset

public void reset()

canMerge

public boolean canMerge()
Returns:
whether this facade helper can be used on a merge operation. Typically subclasses would return false depending on some environment requirement.
Since:
2.4

getObjectToNodeMap

protected java.util.Map<java.lang.Object,JNode> getObjectToNodeMap()

getClassPrefix

public java.lang.String getClassPrefix()

dispose

public void dispose(JNode node)

Disposes the node and its children. If the node is null, this method doesn't do anything.

After being disposed, the node and its children should not be reused.

Parameters:
node -

disposeNode

protected void disposeNode(JNode node)
Disposes a single node.

Parameters:
node -

isDisposed

public boolean isDisposed(JNode node)
Returns true if a node is disposed.

Parameters:
node -
Returns:
boolean
See Also:
dispose(JNode)

setControlModel

public void setControlModel(JControlModel controlModel)
                     throws java.lang.IllegalArgumentException
Sets this facade helper's control model.

Parameters:
controlModel -
Throws:
java.lang.IllegalArgumentException - if the control model's facade helper is different than this facade helper.

getControlModel

public JControlModel getControlModel()

convertToNode

public JNode convertToNode(java.lang.Object object)

cloneNode

public abstract JNode cloneNode(java.lang.Object context,
                                JNode node)
Clones the specified node, returning an object that is related to the given context. On some implementations the context may be null.

Parameters:
context -
node -
Returns:
a cloned version of the specified node

getContext

public abstract java.lang.Object getContext(JNode node)
Returns the context of a node. The context is usually an object that would be used to create a child or sibling of the node.

Returns:
the context of a node.

createCompilationUnit

public abstract JCompilationUnit createCompilationUnit(java.lang.String name,
                                                       java.lang.String contents)

doConvertToNode

protected abstract JNode doConvertToNode(java.lang.Object object)

getOriginalContents

public java.lang.String getOriginalContents(JCompilationUnit compilationUnit)
Returns the original, unmodified, content of the compilation unit. Not all facade implementation may be able to provide this information.

Parameters:
compilationUnit -
Returns:
the original contents or null

getNodeConverter

public NodeConverter getNodeConverter()
Returns:
converter that can be used to convert nodes, or null if none

getCompilationUnit

public JCompilationUnit getCompilationUnit(JNode node)
Returns the compilation unit of the specified node.

Parameters:
node -
Returns:
the JCompilationUnit of a JNode or null.

getPackage

public JPackage getPackage(JNode node)
Returns the package of the specified node.

Parameters:
node -
Returns:
the JPackage of a JNode or null

getMainType

public JType getMainType(JCompilationUnit compilationUnit)
Returns the first public type in of a compilation unit.

Parameters:
compilationUnit -
Returns:
the first public type of a compilation unit

getChildren

public <T extends JNode> java.util.List<T> getChildren(JNode node,
                                                       java.lang.Class<T> cls)
Returns a list with the children of the specified node that are instances of the given class. The list should be an unmodifiable list if it doesn't support changes.

Parameters:
node -
cls - class of the child
Returns:
the list of children of a JNode

getFirstChild

public JNode getFirstChild(JNode node)
Returns the first child of the specified node. Children appear in the order in which they exist in the source code.

Parameters:
node -
Returns:
the first child, or null if this node has no children
See Also:
getChildren(JNode, Class)

getPrevious

public JNode getPrevious(JNode node)
Returns the sibling node immediately preceding the specified node.

Parameters:
node -
Returns:
the previous node, or null if there is no preceding node

getNext

public JNode getNext(JNode node)
Returns the sibling node immediately following the specified node.

Parameters:
node -
Returns:
the next node, or null if there is no following node

getSibiling

protected JNode getSibiling(JNode node,
                            int pos)
Returns the sibling of the specified node that is located in a specific position relative to the node.

Parameters:
node -
pos - position of the sibling, relative to the node (can be a negative number)
Returns:
the sibling, or null if this node has no children
See Also:
getChildren(JNode, Class)

addChild

public boolean addChild(JNode node,
                        JNode child)
Adds the given orphan node (document fragment) as the last child of the specified node.

Parameters:
node - the parent of the child to be added
child - the new child node
Returns:
whether the operation was successful.
See Also:
insertSibling(JNode, JNode, boolean), remove(JNode)

insertSibling

public boolean insertSibling(JNode node,
                             JNode newSibling,
                             boolean before)
Inserts the given orphan node as a sibling of the specified node, immediately before or after it.

Parameters:
node - the node that will be after the new sibling
newSibling - the new sibling node
before - whether the sibling should be added before the node
See Also:
addChild(JNode, JNode), remove(JNode)

remove

public boolean remove(JNode node)
Separates the specified node from its parent and siblings, maintaining any ties that this node has to the underlying document fragment. A document fragment that is removed from its host document may still be dependent on that host document until it is inserted into a different document. Removing a root node has no effect.

Parameters:
node - the node to be removed
Returns:
whether the operation was successful.
See Also:
addChild(JNode, JNode), insertSibling(JNode, JNode, boolean)

commentOut

public void commentOut(JNode node)
Comment out the node and its children. The node may still be returned by JNode.getChildren()

Parameters:
node -

applyFormatRules

public java.lang.String applyFormatRules(java.lang.String value)
Formats the specified string using the CodeGenUtil.convertFormat(String, boolean, String) method.

Parameters:
value -
Returns:
the formatted String.

toString

public java.lang.String toString(java.lang.Object object)
Parameters:
object -

fixInterfaceBrace

public boolean fixInterfaceBrace()

canYieldWrongJavadoc

public boolean canYieldWrongJavadoc()
Returns whether this facade implementation may return the wrong Javadoc for a node when there are 2 or more javadoc blocks preceding the node.

Returns:
boolean

isSibilingTraversalExpensive

public boolean isSibilingTraversalExpensive()
Returns whether using the getPrevious(JNode) and getNext(JNode) methods is slower than using JNode.getChildren() directly.

Returns:
boolean

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