public final class Augmentation extends GoloElement<Augmentation> implements FunctionContainer, ToplevelGoloElement
Represents all the augmentations applied to a type, i.e. functions and named augmentations
applied with the with
construct.
This represents code such
augment MyType {
function foo = |this| -> ...
}
or
augment MyType with MyAugmentation
Modifier and Type | Method and Description |
---|---|
void |
accept(GoloIrVisitor visitor)
Accept the visitor.
|
void |
addFunction(GoloFunction func)
Adds a function to this container.
|
void |
addMacroInvocation(MacroInvocation macroCall)
Adds a macro invocation to this container.
|
java.util.List<GoloElement<?>> |
children()
Returns a list of all the direct children of this node.
|
java.util.List<GoloFunction> |
getFunctions() |
java.util.Set<java.lang.String> |
getNames()
Returns the names of the applied named augmentations.
|
PackageAndClass |
getPackageAndClass() |
PackageAndClass |
getTarget()
Returns the target type of this augmentation.
|
boolean |
hasFunctions() |
boolean |
hasNames()
Checks if named augmentations were applied.
|
void |
merge(Augmentation other)
Merge two augmentations applied to the same target.
|
static Augmentation |
of(java.lang.Object target)
Creates an augmentation on the target name.
|
protected void |
replaceElement(GoloElement<?> original,
GoloElement<?> newElement)
Replace a child.
|
protected Augmentation |
self() |
java.lang.String |
toString() |
Augmentation |
with(java.util.Collection<?> objects)
Define the functions or named augmentations to add to the target.
|
Augmentation |
with(java.lang.Object... objects)
Define the functions or named augmentations to add to the target.
|
ancestor, ancestor, ancestorOfType, cantConvert, cantReplace, cantReplace, children, children, descendants, descendants, descendants, documentation, documentation, doesNotContain, enclosingModule, getLocalReferenceTable, hasParent, hasPosition, inheritedMetadata, makeParentOf, metadata, metadata, next, next, next, ofAST, parent, positionInSourceCode, positionInSourceCode, previous, previous, previous, replaceInParentBy, walk
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addElement, addFunctions, getFunction, iterator
protected Augmentation self()
self
in class GoloElement<Augmentation>
public static Augmentation of(java.lang.Object target)
target
- the name of the target (compatible with PackageAndClass.of(Object)
)PackageAndClass.of(Object)
public PackageAndClass getTarget()
Note that since resolution is done at runtime, the target is only referenced by its name (here a
PackageAndClass
).
public PackageAndClass getPackageAndClass()
getPackageAndClass
in interface FunctionContainer
public java.util.List<GoloFunction> getFunctions()
getFunctions
in interface FunctionContainer
public void addFunction(GoloFunction func)
addFunction
in interface FunctionContainer
public void addMacroInvocation(MacroInvocation macroCall)
The macro is supposed to return a GoloFunction
when expanded.
addMacroInvocation
in interface FunctionContainer
public boolean hasFunctions()
hasFunctions
in interface FunctionContainer
public java.util.Set<java.lang.String> getNames()
public boolean hasNames()
public Augmentation with(java.lang.Object... objects)
The objects to add can be a function or a string representing the name of a named augmentation.
This is a builder method.
objects
- functions or named augmentations to addpublic Augmentation with(java.util.Collection<?> objects)
The objects to add can be a function or a string representing the name of a named augmentation.
This is a builder method.
objects
- a collection of functions or named augmentations to addpublic void merge(Augmentation other)
Warning:the functions contained in the other augmentation being move to this one and not copied, the other augmentation references functions but is no more their parent. Therefore, the other augmentation is not in a consistent state and should be dropped, since no more needed.
public java.lang.String toString()
toString
in class java.lang.Object
protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement)
Replace original
with newElement
if original
is a child of this node
and type matches.
replaceElement
in class GoloElement<Augmentation>
original
- the original value to replace. Must be a child of this nodenewElement
- the element to replace with. Type must match.GoloElement.cantReplace()
,
GoloElement.cantReplace(GoloElement, GoloElement)
,
GoloElement.doesNotContain(GoloElement)
,
GoloElement.cantConvert(String, Object)
public void accept(GoloIrVisitor visitor)
This method should only call the visitor visitXXXX
method.
The children of this node will be visited by the
GoloElement.walk(GoloIrVisitor)
method.
accept
in class GoloElement<Augmentation>
public java.util.List<GoloElement<?>> children()
children
in class GoloElement<Augmentation>