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

java.lang.Object
  extended by org.eclipse.emf.codegen.merge.java.facade.FacadeHelper
      extended by org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper

public class ASTFacadeHelper
extends FacadeHelper

Since:
2.2.0

Nested Class Summary
static class ASTFacadeHelper.ASTRewriteWithRemove
           
 
Field Summary
protected static boolean DEBUG
          Debug output setting
protected  java.util.Map javaCoreOptions
          Map of options set by default from JavaCore.getOptions()
protected  java.util.Map<org.eclipse.jdt.core.dom.ASTNode,java.lang.String> nodeContents
          Map of nodes to node contents.
protected  ASTNodeConverter nodeConverter
           
 
Fields inherited from class org.eclipse.emf.codegen.merge.java.facade.FacadeHelper
CLASS_PREFIX, controlModel, objectToNodeMap
 
Constructor Summary
ASTFacadeHelper()
           
 
Method Summary
 boolean addChild(JNode node, JNode child)
          Adds the given orphan node (document fragment) as the last child of the specified node.
protected  ASTJField cloneField(ASTJField originalField, ASTJNode<?> contextNode)
          Copies the ASTJField node.
 ASTJNode<?> cloneNode(java.lang.Object context, JNode node)
          Creates a copy of the node to be inserted in the tree that context node belongs to.
 void commentOut(JNode node)
          Comment out the node and its children.
protected  org.eclipse.jdt.core.dom.ASTParser createASTParser()
          Creates and returns ASTParser.
 ASTJCompilationUnit createCompilationUnit(java.lang.String name, java.lang.String contents)
           
protected  ASTJNode<?> doConvertToNode(java.lang.Object object)
           
 ASTJNode<?> findParent(org.eclipse.jdt.core.dom.ASTNode node)
          Finds the parent node based on the parent of wrapped AST node.
 java.lang.Object getContext(JNode node)
          Returns the context of a node.
 java.util.Map getJavaCoreOptions()
          Accessor for options to be used during parsing and rewriting.
 ASTNodeConverter getNodeConverter()
           
 java.lang.String getOriginalContents(JCompilationUnit compilationUnit)
          Returns the original, unmodified, content of the compilation unit.
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.ArrayType arrayType)
           
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.ParameterizedType parameterizedType)
           
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.PrimitiveType primitiveType)
           
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.QualifiedType qualifiedType)
           
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.SimpleType simpleType)
           
static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.Type type)
          Converts Type to string representation, erasing type parameters information.
 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.
 void logError(java.lang.String string)
          Adds a new entry to the log using ERROR level.
 void logError(java.lang.String string, java.lang.Exception e)
          Adds a new entry to the log using ERROR level.
 void logInfo(java.lang.String string)
          Adds a new entry to the log using INFO level.
 boolean remove(JNode node)
          Removes the given node.
 void reset()
           
 java.lang.String toString(org.eclipse.jdt.core.dom.ASTNode node)
          Gets the original contents of the node.
static java.lang.String toString(org.eclipse.jdt.core.dom.Name name)
          Converts Name to string representation.
 java.lang.String toString(java.lang.Object object)
           
 void updateObjectToNodeMap(ASTJNode<?> node)
          Updates wrapped objects to nodes map.
protected  void useCurrentOption(java.util.Map<java.lang.Object,java.lang.String> options, java.lang.String option)
           
 
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.FacadeHelper
applyFormatRules, canMerge, canYieldWrongJavadoc, convertToNode, dispose, disposeNode, fixInterfaceBrace, getChildren, getClassPrefix, getCompilationUnit, getControlModel, getFirstChild, getMainType, getNext, getObjectToNodeMap, getPackage, getPrevious, getSibiling, isDisposed, isSibilingTraversalExpensive, setControlModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
Debug output setting

See Also:
Constant Field Values

nodeConverter

protected ASTNodeConverter nodeConverter

javaCoreOptions

protected java.util.Map javaCoreOptions
Map of options set by default from JavaCore.getOptions()


nodeContents

protected java.util.Map<org.eclipse.jdt.core.dom.ASTNode,java.lang.String> nodeContents
Map of nodes to node contents. Used for caching only.

Constructor Detail

ASTFacadeHelper

public ASTFacadeHelper()
Method Detail

toString

public static java.lang.String toString(org.eclipse.jdt.core.dom.Name name)
Converts Name to string representation.

Parameters:
name -
Returns:
fully qualified name or null if name parameter is null

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.ArrayType arrayType)

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.ParameterizedType parameterizedType)

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.PrimitiveType primitiveType)

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.SimpleType simpleType)

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.QualifiedType qualifiedType)

getTypeErasure

public static java.lang.String getTypeErasure(org.eclipse.jdt.core.dom.Type type)
Converts Type to string representation, erasing type parameters information.

This method is used to create a method signature, and match methods by signature.

Parameters:
type -
Returns:
string representing the type

reset

public void reset()
Overrides:
reset in class FacadeHelper

createASTParser

protected org.eclipse.jdt.core.dom.ASTParser createASTParser()
Creates and returns ASTParser.

Returns:
new ASTParser object

createCompilationUnit

public ASTJCompilationUnit createCompilationUnit(java.lang.String name,
                                                 java.lang.String contents)
Specified by:
createCompilationUnit in class FacadeHelper

getOriginalContents

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

Overrides:
getOriginalContents in class FacadeHelper
Returns:
the original contents or null

getJavaCoreOptions

public java.util.Map getJavaCoreOptions()
Accessor for options to be used during parsing and rewriting.

If options are null, uses options provided by getDefaultJavaCoreOptions().

Returns:
map of options
See Also:
getDefaultJavaCoreOptions()

useCurrentOption

protected void useCurrentOption(java.util.Map<java.lang.Object,java.lang.String> options,
                                java.lang.String option)

getNodeConverter

public ASTNodeConverter getNodeConverter()
Overrides:
getNodeConverter in class FacadeHelper
Returns:
converter that can be used to convert nodes, or null if none

getContext

public java.lang.Object getContext(JNode node)
Description copied from class: FacadeHelper
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.

Specified by:
getContext in class FacadeHelper
Returns:
the context of a node.

cloneNode

public ASTJNode<?> cloneNode(java.lang.Object context,
                             JNode node)
Creates a copy of the node to be inserted in the tree that context node belongs to.

Note that in this implementation the original and returned cloned node can not be modified. Calls to get...() methods on the cloned node will not return the original content. The returned node can only be inserted in the same tree that context node belongs to.

Specified by:
cloneNode in class FacadeHelper
Parameters:
context - ASTJNode that belongs to the same tree that cloned node will be inserted to
node - node that needs to be cloned
Returns:
new node
See Also:
FacadeHelper.cloneNode(java.lang.Object, org.eclipse.emf.codegen.merge.java.facade.JNode)

cloneField

protected ASTJField cloneField(ASTJField originalField,
                               ASTJNode<?> contextNode)
Copies the ASTJField node.

The copied field should not be modified (using set methods) nor read (using get methods), and can only be inserted into the same tree that context node belongs to.

If the source field has only 1 variable, returned field is replaced by contents of original field declaration. The returned field will have no internal structure.

If the source field has multiple variables declared in it, the returned field will contain only 1 variable. Annotations, javadoc and initializer are replaced by original contents with formatting preserved. Other parts of the declaration is not guaranteed to have formatting preserved. The copied field will have source ranges for all nodes relative to the source file, hence, get methods might return incorrect contents.

Parameters:
originalField -
contextNode -

findParent

public ASTJNode<?> findParent(org.eclipse.jdt.core.dom.ASTNode node)
Finds the parent node based on the parent of wrapped AST node.

Returns:
parent JNode

doConvertToNode

protected ASTJNode<?> doConvertToNode(java.lang.Object object)
Specified by:
doConvertToNode in class FacadeHelper

updateObjectToNodeMap

public void updateObjectToNodeMap(ASTJNode<?> node)
Updates wrapped objects to nodes map. This method must be called when wrapped ASTNode of ASTJNode is changed.

Parameters:
node -

addChild

public boolean addChild(JNode node,
                        JNode child)
Description copied from class: FacadeHelper
Adds the given orphan node (document fragment) as the last child of the specified node.

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

remove

public boolean remove(JNode node)
Removes the given node.

Most get...() operations on the removed node will not give the correct results even after insertion of the node.

Overrides:
remove in class FacadeHelper
Parameters:
node - the node to be removed
Returns:
whether the operation was successful.
See Also:
FacadeHelper.remove(org.eclipse.emf.codegen.merge.java.facade.JNode)

commentOut

public void commentOut(JNode node)
Description copied from class: FacadeHelper
Comment out the node and its children. The node may still be returned by JNode.getChildren()

Overrides:
commentOut in class FacadeHelper

insertSibling

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

Overrides:
insertSibling in class FacadeHelper
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:
FacadeHelper.addChild(JNode, JNode), FacadeHelper.remove(JNode)

toString

public java.lang.String toString(java.lang.Object object)
Overrides:
toString in class FacadeHelper

toString

public java.lang.String toString(org.eclipse.jdt.core.dom.ASTNode node)
Gets the original contents of the node.

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.

The given node must be one of the nodes of the AST tree created by createCompilationUnit(String, String).

Note that contents is cached on the first access. Therefore, returned contents will not reflect any changes to the nodes.

Parameters:
node - node to get contents for
Returns:
original contents of the node

logInfo

public void logInfo(java.lang.String string)
Adds a new entry to the log using INFO level.

Parameters:
string - to add to the log

logError

public void logError(java.lang.String string)
Adds a new entry to the log using ERROR level.

Parameters:
string - to add to the log

logError

public void logError(java.lang.String string,
                     java.lang.Exception e)
Adds a new entry to the log using ERROR level.

Parameters:
string - to add to the log
e - exception to record

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