Class Link<S extends ASTNode,​T extends ASTNode>

  • All Implemented Interfaces:
    java.lang.Iterable<Link<?,​?>>

    public final class Link<S extends ASTNode,​T extends ASTNode>
    extends java.lang.Object
    implements java.lang.Iterable<Link<?,​?>>
    Represents a link between two ASTNodes.

    When writing transformations that translate from one AST to another, it is often cleaner not to translate all information in a single operation. Splitting this translation process however necessitates that sequentially executed translations always operate on the same source and target nodes. For this purpose a Link provides a way for the program to "remember" which source nodes are associated with which target nodes.

    Going beyond that, Links also form a tree that mirrors the structure in both ASTs. This is based on the assumption that the overall structure of both source and target AST will also be equivalent.

    • Constructor Summary

      Constructors 
      Constructor Description
      Link​(S source, T target, Link<?,​?> parent)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addChildLink​(Link<?,​?> childLink)  
      <O extends ASTNode,​D extends ASTNode>
      java.util.Set<Link<O,​D>>
      getLinks​(java.lang.Class<O> sourceType, java.lang.Class<D> targetType)
      Looks up all Links in the subtree spanned by this Link by type of source and target.
      java.util.Iterator<Link<?,​?>> iterator()  
      Link<?,​?> parent()  
      Link<?,​?> rootLink()  
      S source()  
      T target()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • source

        protected final S extends ASTNode source
      • target

        protected final T extends ASTNode target
      • parent

        protected final Link<?,​?> parent
      • childLinks

        protected final java.util.Set<Link<?,​?>> childLinks
    • Constructor Detail

      • Link

        public Link​(S source,
                    T target,
                    @Nullable
                    Link<?,​?> parent)
    • Method Detail

      • addChildLink

        protected void addChildLink​(Link<?,​?> childLink)
      • source

        public S source()
        Returns:
        the source node of this Link
      • target

        public T target()
        Returns:
        the target node of this Link
      • parent

        public Link<?,​?> parent()
        Returns:
        the parent Link of this Link
      • rootLink

        public Link<?,​?> rootLink()
        Returns:
        the topmost Link in the tree to which this Link belongs
      • iterator

        public java.util.Iterator<Link<?,​?>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<S extends ASTNode>
      • getLinks

        public <O extends ASTNode,​D extends ASTNode> java.util.Set<Link<O,​D>> getLinks​(java.lang.Class<O> sourceType,
                                                                                                   java.lang.Class<D> targetType)
        Looks up all Links in the subtree spanned by this Link by type of source and target. You can use super classes like 'ASTNode.class' if you want to filter more loosely.
        Parameters:
        sourceType - the class of the source node
        targetType - the class of the target node
        Returns:
        the set of all Links with the specified source and target types