Lombok - v0.11.0

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

java.lang.Object
  extended by lombok.core.LombokNode<A,L,N>
All Implemented Interfaces:
DiagnosticsReceiver
Direct Known Subclasses:
EclipseNode, JavacNode

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

An instance of this class wraps an Eclipse/javac internal node object.


Field Summary
protected  A ast
           
protected  List<L> children
           
protected  boolean isStructurallySignificant
          structurally significant are those nodes that can be annotated in java 1.6 or are method-like toplevels, so fields, local declarations, method arguments, methods, types, the Compilation Unit itself, and initializers.
protected  AST.Kind kind
           
protected  N node
           
protected  L parent
           
 
Fields inherited from interface lombok.core.DiagnosticsReceiver
CONSOLE
 
Constructor Summary
protected LombokNode(A ast, N node, List<L> children, AST.Kind kind)
          Creates a new Node object that represents the provided node.
 
Method Summary
 L add(N newChild, AST.Kind newChildKind)
          Adds the stated node as a direct child of this node.
protected abstract  boolean calculateIsStructurallySignificant(N parent)
          See isStructurallySignificant.
 L directUp()
          Returns the direct parent node in the AST tree of this node.
 Collection<L> down()
          Returns all children nodes.
protected abstract  boolean fieldContainsAnnotation(N field, N annotation)
          Return true if the annotation is attached to the field.
 N get()
           
 A getAst()
           
 String getFileName()
          Convenient shortcut to the owning ast object's getFileName method.
 Collection<String> getImportStatements()
          Convenient shortcut to the owning ast object's getImportStatements method.
 AST.Kind getKind()
           
abstract  String getName()
          Return the name of your type (simple name), method, field, or local variable.
 L getNodeFor(N obj)
          Convenient shortcut to the owning ast object's get method.
 String getPackageDeclaration()
          Convenient shortcut to the owning ast object's getPackageDeclaration method.
 boolean isStructurallySignificant()
          Structurally significant means: LocalDeclaration, TypeDeclaration, MethodDeclaration, ConstructorDeclaration, FieldDeclaration, Initializer, and CompilationUnitDeclaration.
 void rebuild()
          Reparses the AST node represented by this node.
 void removeChild(L child)
          Removes the stated node, which must be a direct child of this node, from the AST.
 void replaceChildNode(N oldN, N newN)
          Replaces the stated node with a new one.
 L replaceWith(N newN, AST.Kind newNodeKind)
          Replaces the AST node represented by this node object with the provided node.
 L top()
          Convenient shortcut to the owning ast object's top method.
 String toString()
          
 L up()
          Returns the structurally significant node that encloses this one.
 Collection<L> upFromAnnotationToFields()
          @Foo int x, y; is stored in both javac and ecj as 2 FieldDeclarations, both with the same annotation as child.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface lombok.core.DiagnosticsReceiver
addError, addWarning
 

Field Detail

ast

protected final A extends AST<A,L,N> ast

kind

protected final AST.Kind kind

node

protected final N node

children

protected final List<L extends LombokNode<A,L,N>> children

parent

protected L extends LombokNode<A,L,N> parent

isStructurallySignificant

protected boolean isStructurallySignificant
structurally significant are those nodes that can be annotated in java 1.6 or are method-like toplevels, so fields, local declarations, method arguments, methods, types, the Compilation Unit itself, and initializers.

Constructor Detail

LombokNode

protected LombokNode(A ast,
                     N node,
                     List<L> children,
                     AST.Kind kind)
Creates a new Node object that represents the provided node.

Parameters:
ast - The owning AST - this node is part of this AST's tree of nodes.
node - The AST object in the target parser's own internal AST tree that this node object will represent.
children - A list of child nodes. Passing in null results in the children list being empty, not null.
kind - The kind of node represented by this object.
Method Detail

getAst

public A getAst()

toString

public String toString()

Overrides:
toString in class Object

getPackageDeclaration

public String getPackageDeclaration()
Convenient shortcut to the owning ast object's getPackageDeclaration method.

See Also:
AST.getPackageDeclaration()

getImportStatements

public Collection<String> getImportStatements()
Convenient shortcut to the owning ast object's getImportStatements method.

See Also:
AST.getImportStatements()

calculateIsStructurallySignificant

protected abstract boolean calculateIsStructurallySignificant(N parent)
See isStructurallySignificant.


getNodeFor

public L getNodeFor(N obj)
Convenient shortcut to the owning ast object's get method.

See Also:
AST.get(Object)

get

public N get()
Returns:
The javac/Eclipse internal AST object wrapped by this LombokNode object.

replaceWith

public L replaceWith(N newN,
                     AST.Kind newNodeKind)
Replaces the AST node represented by this node object with the provided node. This node must have a parent, obviously, for this to work. Also affects the underlying (Eclipse/javac) AST.


replaceChildNode

public void replaceChildNode(N oldN,
                             N newN)
Replaces the stated node with a new one. The old node must be a direct child of this node. Also affects the underlying (Eclipse/javac) AST.


getKind

public AST.Kind getKind()

getName

public abstract String getName()
Return the name of your type (simple name), method, field, or local variable. Return null if this node doesn't really have a name, such as initializers, while statements, etc.


up

public L up()
Returns the structurally significant node that encloses this one.

See Also:
isStructurallySignificant()

upFromAnnotationToFields

public Collection<L> upFromAnnotationToFields()
@Foo int x, y; is stored in both javac and ecj as 2 FieldDeclarations, both with the same annotation as child. The normal up() method can't handle having multiple parents, but this one can.


fieldContainsAnnotation

protected abstract boolean fieldContainsAnnotation(N field,
                                                   N annotation)
Return true if the annotation is attached to the field.


directUp

public L directUp()
Returns the direct parent node in the AST tree of this node. For example, a local variable declaration's direct parent can be e.g. an If block, but its up() LombokNode is the Method that contains it.


down

public Collection<L> down()
Returns all children nodes. A copy is created, so changing the list has no effect. Also, while iterating through this list, you may add, remove, or replace children without causing ConcurrentModificationExceptions.


top

public L top()
Convenient shortcut to the owning ast object's top method.

See Also:
AST.top()

getFileName

public String getFileName()
Convenient shortcut to the owning ast object's getFileName method.

See Also:
AST.getFileName()

add

public L add(N newChild,
             AST.Kind newChildKind)
Adds the stated node as a direct child of this node. Does not change the underlying (javac/Eclipse) AST, only the wrapped view.


rebuild

public void rebuild()
Reparses the AST node represented by this node. Any existing nodes that occupy a different space in the AST are rehomed, any nodes that no longer exist are removed, and new nodes are created. Careful - the node you call this on must not itself have been removed or rehomed - it rebuilds all children.


removeChild

public void removeChild(L child)
Removes the stated node, which must be a direct child of this node, from the AST. Does not change the underlying (javac/Eclipse) AST, only the wrapped view.


isStructurallySignificant

public boolean isStructurallySignificant()
Structurally significant means: LocalDeclaration, TypeDeclaration, MethodDeclaration, ConstructorDeclaration, FieldDeclaration, Initializer, and CompilationUnitDeclaration. The rest is e.g. if statements, while loops, etc.


Lombok - v0.11.0

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