Lombok - v0.10.8

lombok.core
Class AST<A extends AST<A,L,N>,L extends LombokNode<A,L,N>,N>

java.lang.Object
  extended by lombok.core.AST<A,L,N>
Direct Known Subclasses:
EclipseAST, JavacAST

public abstract class AST<A extends AST<A,L,N>,L extends LombokNode<A,L,N>,N>
extends Object

Lombok wraps the AST produced by a target platform into its own AST system, mostly because both Eclipse and javac do not allow upward traversal (from a method to its owning type, for example).


Nested Class Summary
protected static class AST.FieldAccess
          Represents a field that contains AST children.
static class AST.Kind
          The kind of node represented by a given AST.Node object.
 
Constructor Summary
protected AST(String fileName, String packageDeclaration, Collection<String> imports)
           
 
Method Summary
protected abstract  L buildTree(N item, AST.Kind kind)
          Build an AST.Node object for the stated internal (javac/Eclipse) AST Node object.
protected  Collection<L> buildWithField(Class<L> nodeType, N statement, AST.FieldAccess fa)
          buildTree implementation that uses reflection to find all child nodes by way of inspecting the fields.
protected  void clearChanged()
           
protected  void clearState()
          Clears the registry that avoids endless loops, and empties the node map.
protected  Collection<AST.FieldAccess> fieldsOf(Class<?> c)
          Returns FieldAccess objects for the stated class.
 L get(N node)
          Maps a javac/Eclipse internal AST Node to the appropriate AST.Node object.
 String getFileName()
           
 Collection<String> getImportStatements()
          Return the contents of each non-static import statement on this AST's top (Compilation Unit) node.
protected  Map<N,L> getNodeMap()
          Returns the node map, that can map javac/Eclipse internal AST objects to AST.Node objects.
 String getPackageDeclaration()
          Return the content of the package declaration on this AST's top (Compilation Unit) node.
protected abstract  Collection<Class<? extends N>> getStatementTypes()
          The supertypes which are considered AST Node children.
 boolean isChanged()
           
protected  L putInMap(L node)
          Puts the given node in the map so that javac/Eclipse's own internal AST object can be translated to an AST.Node object.
protected  boolean replaceStatementInNode(N statement, N oldN, N newN)
          Uses reflection to find the given direct child on the given statement, and replace it with a new child.
protected  boolean setAndGetAsHandled(N node)
          Marks the stated node as handled (to avoid endless loops if 2 nodes refer to each other, or a node refers to itself).
 void setChanged()
           
protected  void setElementInASTCollection(Field field, Object fieldRef, List<Collection<?>> chain, Collection<?> collection, int idx, N newN)
          Override if your AST collection does not support the set method.
protected  void setTop(L top)
          Set the node object that wraps the internal Compilation Unit node.
 L top()
          The AST.Node object representing the Compilation Unit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AST

protected AST(String fileName,
              String packageDeclaration,
              Collection<String> imports)
Method Detail

setChanged

public void setChanged()

clearChanged

protected void clearChanged()

isChanged

public boolean isChanged()

setTop

protected void setTop(L top)
Set the node object that wraps the internal Compilation Unit node.


getPackageDeclaration

public final String getPackageDeclaration()
Return the content of the package declaration on this AST's top (Compilation Unit) node. Example: "java.util".


getImportStatements

public final Collection<String> getImportStatements()
Return the contents of each non-static import statement on this AST's top (Compilation Unit) node. Example: "java.util.IOException".


putInMap

protected L putInMap(L node)
Puts the given node in the map so that javac/Eclipse's own internal AST object can be translated to an AST.Node object. Also registers the object as visited to avoid endless loops.


getNodeMap

protected Map<N,L> getNodeMap()
Returns the node map, that can map javac/Eclipse internal AST objects to AST.Node objects.


clearState

protected void clearState()
Clears the registry that avoids endless loops, and empties the node map. The existing node map object is left untouched, and instead a new map is created.


setAndGetAsHandled

protected boolean setAndGetAsHandled(N node)
Marks the stated node as handled (to avoid endless loops if 2 nodes refer to each other, or a node refers to itself). Will then return true if it was already set as handled before this call - in which case you should do nothing lest the AST build process loops endlessly.


getFileName

public String getFileName()

top

public L top()
The AST.Node object representing the Compilation Unit.


get

public L get(N node)
Maps a javac/Eclipse internal AST Node to the appropriate AST.Node object.


buildTree

protected abstract L buildTree(N item,
                               AST.Kind kind)
Build an AST.Node object for the stated internal (javac/Eclipse) AST Node object.


fieldsOf

protected Collection<AST.FieldAccess> fieldsOf(Class<?> c)
Returns FieldAccess objects for the stated class. Each field that contains objects of the kind returned by getStatementTypes(), either directly or inside of an array or java.util.collection (or array-of-arrays, or collection-of-collections, etcetera), is returned.


getStatementTypes

protected abstract Collection<Class<? extends N>> getStatementTypes()
The supertypes which are considered AST Node children. Usually, the Statement, and the Expression, though some platforms (such as Eclipse) group these under one common supertype.


buildWithField

protected Collection<L> buildWithField(Class<L> nodeType,
                                       N statement,
                                       AST.FieldAccess fa)
buildTree implementation that uses reflection to find all child nodes by way of inspecting the fields.


replaceStatementInNode

protected boolean replaceStatementInNode(N statement,
                                         N oldN,
                                         N newN)
Uses reflection to find the given direct child on the given statement, and replace it with a new child.


setElementInASTCollection

protected void setElementInASTCollection(Field field,
                                         Object fieldRef,
                                         List<Collection<?>> chain,
                                         Collection<?> collection,
                                         int idx,
                                         N newN)
                                  throws IllegalAccessException
Override if your AST collection does not support the set method. Javac's for example, does not.

Parameters:
field - The field that contains the array or list of AST nodes.
fieldRef - The object that you can supply to the field's get method.
chain - If the collection is immutable, you need to update the pointer to the collection in each element in the chain.
Throws:
IllegalAccessException - This exception won't happen, but we allow you to throw it so you can avoid having to catch it.

Lombok - v0.10.8

Copyright © 2009-2011 The Project Lombok Authors, licensed under the MIT licence.