java.lang.Object
io.github.douira.glsl_transformer.ast.query.NodeIndex
All Implemented Interfaces:
Index<ASTNode>
Direct Known Subclasses:
SuperclassNodeIndex

public class NodeIndex extends Object implements Index<ASTNode>
Indexes nodes based on their ASTNode subclass and enables fast queries for nodes by type. Only the exact class is added to the index which means querying for the superclass Expression returns no results. Use SuperclassNodeIndex to index nodes by the chain of their superclasses. Unchecked casts are used but they are safe because each set in the map only has the right types of nodes.
  • Field Details

  • Constructor Details

    • NodeIndex

      public NodeIndex(Supplier<Set<ASTNode>> bucketConstructor)
    • NodeIndex

      public NodeIndex()
  • Method Details

    • withHashSetBuckets

      public static NodeIndex withHashSetBuckets()
    • withLinkedHashSetBuckets

      public static NodeIndex withLinkedHashSetBuckets()
    • add

      public void add(ASTNode node)
      Method used internally to add a node to the index. This is only meant to be called by Root.
      Specified by:
      add in interface Index<ASTNode>
    • remove

      public void remove(ASTNode node)
      Method used internally to remove a node from the index. This is only meant to be called by Root.
      Specified by:
      remove in interface Index<ASTNode>
    • get

      public <T extends ASTNode> Set<T> get(Class<T> clazz)
      Returns a set of all nodes with the given type.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class of nodes to return
      Returns:
      a set of nodes with the given type
    • getStream

      public <T extends ASTNode> Stream<T> getStream(Class<T> clazz)
      Returns a stream of all nodes with the given type.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class of nodes to return
      Returns:
      a stream of nodes with the given type
    • getOne

      public <T extends ASTNode> T getOne(Class<T> clazz)
      Returns an arbitrary node with the given type.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class of the node to return
      Returns:
      an arbitrary node with the given type
    • has

      public boolean has(Class<? extends ASTNode> clazz)
      Checks if the index contains any nodes of the given type.
      Parameters:
      clazz - the class of the nodes to check for
      Returns:
      true if the index contains any nodes of the given type
    • get

      public <T extends ASTNode> Set<T> get(T node)
      Returns the set of nodes that have the same class as the given node.
      Type Parameters:
      T - The type of the nodes
      Parameters:
      node - The node to get the set of
      Returns:
      The set of nodes that have the same class as the given node
    • getOne

      public <T extends ASTNode> T getOne(T node)
      Returns an arbitrary node that has the same class as the given node.
      Type Parameters:
      T - The type of the node
      Parameters:
      node - The node to get a node from the index for
      Returns:
      An arbitrary node that has the same class as the given node
    • has

      public boolean has(ASTNode node)
      Checks if the index contains a node of the given type.
      Parameters:
      node - the node to check for
      Returns:
      true if the index contains the node
    • hasExact

      public boolean hasExact(ASTNode node)
      Checks if the index contains the given node itself.
      Parameters:
      node - the node to check for
      Returns:
      true if the index contains the node
    • merge

      public void merge(NodeIndex other)
      Merges the given node index into this one.
      Parameters:
      other - the other index to merge