public abstract class GoloElement<T extends GoloElement<T>> extends java.lang.Object
The IR tree represents a more abstract representation of the Golo code.
Constructor and Description |
---|
GoloElement() |
Modifier and Type | Method and Description |
---|---|
abstract void |
accept(GoloIrVisitor visitor)
Accept the visitor.
|
GoloElement<?> |
ancestor(FunctionReference predicate)
Returns the first ancestor of this node matching the given predicate.
|
GoloElement<?> |
ancestor(java.util.function.Predicate<GoloElement<?>> predicate)
Returns the first ancestor of this node matching the given predicate.
|
<C extends GoloElement<?>> |
ancestorOfType(java.lang.Class<C> cls)
Returns the first ancestor of this node being an instance of the given class.
|
protected static java.lang.RuntimeException |
cantConvert(java.lang.String expected,
java.lang.Object value) |
protected java.lang.RuntimeException |
cantReplace() |
protected java.lang.RuntimeException |
cantReplace(GoloElement<?> original,
GoloElement<?> replacement) |
java.util.List<GoloElement<?>> |
children()
Returns a list of all the direct children of this node.
|
java.util.List<GoloElement<?>> |
children(FunctionReference predicate)
Returns a iterable on the direct children of this node matching the given predicate.
|
java.util.List<GoloElement<?>> |
children(java.util.function.Predicate<GoloElement<?>> predicate)
Returns a list the direct children of this node matching the given predicate.
|
java.util.stream.Stream<GoloElement<?>> |
descendants() |
java.util.List<GoloElement<?>> |
descendants(FunctionReference predicate)
Returns a list of all the descendants of this node matching the given predicate.
|
java.util.List<GoloElement<?>> |
descendants(java.util.function.Predicate<GoloElement<?>> predicate)
Returns a list of all the descendants of this node matching the given predicate.
|
java.lang.String |
documentation() |
T |
documentation(java.lang.String doc) |
protected java.lang.RuntimeException |
doesNotContain(GoloElement<?> element) |
GoloModule |
enclosingModule()
Returns the module containing this element.
|
java.util.Optional<ReferenceTable> |
getLocalReferenceTable() |
boolean |
hasParent() |
boolean |
hasPosition() |
java.lang.Object |
inheritedMetadata(java.lang.String name)
Retrieve metadata, searching all element hierarchy.
|
protected <C extends GoloElement<?>> |
makeParentOf(C childElement) |
java.lang.Object |
metadata(java.lang.String name)
Retrieve a previously stored meta-data.
|
T |
metadata(java.lang.String name,
java.lang.Object value)
Stores a meta-data in this element.
|
GoloElement<?> |
next()
Returns the next sibling of this element.
|
GoloElement<?> |
next(FunctionReference predicate)
Returns the next sibling of this element matching the given predicate.
|
GoloElement<?> |
next(java.util.function.Predicate<GoloElement<?>> predicate)
Returns the next sibling of this element matching the given predicate.
|
T |
ofAST(GoloASTNode node)
Init the position and documentation from the given AST node.
|
GoloElement<?> |
parent() |
PositionInSourceCode |
positionInSourceCode() |
T |
positionInSourceCode(PositionInSourceCode pos) |
GoloElement<?> |
previous()
Returns the previous sibling of this element.
|
GoloElement<?> |
previous(FunctionReference predicate)
Returns the previous sibling of this element matching the given predicate.
|
GoloElement<?> |
previous(java.util.function.Predicate<GoloElement<?>> predicate)
Returns the previous sibling of this element matching the given predicate.
|
protected abstract void |
replaceElement(GoloElement<?> original,
GoloElement<?> newElement)
Replace a child.
|
void |
replaceInParentBy(GoloElement<?> newElement)
Replaces this element by the given one in its parent node.
|
protected abstract T |
self() |
void |
walk(GoloIrVisitor visitor)
Walk the visitor through this node children.
|
public GoloElement()
public final T ofAST(GoloASTNode node)
node
- the GoloASTNode
to reference.public final boolean hasParent()
public final GoloElement<?> parent()
public GoloModule enclosingModule()
public <C extends GoloElement<?>> C ancestorOfType(java.lang.Class<C> cls)
public GoloElement<?> ancestor(java.util.function.Predicate<GoloElement<?>> predicate)
public GoloElement<?> ancestor(FunctionReference predicate)
public java.util.List<GoloElement<?>> descendants(java.util.function.Predicate<GoloElement<?>> predicate)
public java.util.List<GoloElement<?>> descendants(FunctionReference predicate)
public java.util.stream.Stream<GoloElement<?>> descendants()
public java.util.List<GoloElement<?>> children()
public java.util.List<GoloElement<?>> children(java.util.function.Predicate<GoloElement<?>> predicate)
public java.util.List<GoloElement<?>> children(FunctionReference predicate)
public GoloElement<?> previous()
public GoloElement<?> previous(java.util.function.Predicate<GoloElement<?>> predicate)
public GoloElement<?> previous(FunctionReference predicate)
public GoloElement<?> next()
public GoloElement<?> next(FunctionReference predicate)
public GoloElement<?> next(java.util.function.Predicate<GoloElement<?>> predicate)
protected final <C extends GoloElement<?>> C makeParentOf(C childElement)
public final java.lang.Object metadata(java.lang.String name)
public final java.lang.Object inheritedMetadata(java.lang.String name)
public final T metadata(java.lang.String name, java.lang.Object value)
A meta-data can be any object. The main purpose is to allow visitors or macros to store some generic informations in the IR that can be used later by other macros or compilation steps (for instance add some Java annotations to the generated methods).
protected final java.lang.RuntimeException cantReplace()
protected final java.lang.RuntimeException cantReplace(GoloElement<?> original, GoloElement<?> replacement)
protected final java.lang.RuntimeException doesNotContain(GoloElement<?> element)
protected static final java.lang.RuntimeException cantConvert(java.lang.String expected, java.lang.Object value)
public final void replaceInParentBy(GoloElement<?> newElement)
This method is typically used during the sugar and macros expansion stages to replace the element by a desugarized version, or the macro call by its result.
newElement
- the element to replace this one with.java.lang.IllegalStateException
- if this element has no parent.public final java.lang.String documentation()
public final T documentation(java.lang.String doc)
public final PositionInSourceCode positionInSourceCode()
public final T positionInSourceCode(PositionInSourceCode pos)
public final boolean hasPosition()
public java.util.Optional<ReferenceTable> getLocalReferenceTable()
public abstract void accept(GoloIrVisitor visitor)
This method should only call the visitor visitXXXX
method.
The children of this node will be visited by the
walk(GoloIrVisitor)
method.
public void walk(GoloIrVisitor visitor)
protected abstract void replaceElement(GoloElement<?> original, GoloElement<?> newElement)
Replace original
with newElement
if original
is a child of this node
and type matches.
original
- the original value to replace. Must be a child of this nodenewElement
- the element to replace with. Type must match.java.lang.UnsupportedOperationException
- if this node does not support replacementjava.util.NoSuchElementException
- if original
is not a child of this nodejava.lang.ClassCastException
- if the type of newElement
does not matchcantReplace()
,
cantReplace(GoloElement, GoloElement)
,
doesNotContain(GoloElement)
,
cantConvert(String, Object)