Class CachingIntervalSet

java.lang.Object
org.antlr.v4.runtime.misc.IntervalSet
io.github.douira.glsl_transformer.generic.CachingIntervalSet
All Implemented Interfaces:
org.antlr.v4.runtime.misc.IntSet

public class CachingIntervalSet extends org.antlr.v4.runtime.misc.IntervalSet
The caching interval set is a regular interval set IntervalSet but the @link org.antlr.v4.runtime.misc.IntervalSet#contains(int)} method also does caching of the queries if the set has been set to readonly. Repeatedly requesting the same query is a common operation and therefore caching it like this can be helpful.
  • Field Summary

    Fields inherited from class org.antlr.v4.runtime.misc.IntervalSet

    COMPLETE_CHAR_SET, EMPTY_SET, intervals, readonly
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(org.antlr.v4.runtime.misc.Interval interval)
    Adds the given interval to the set.
    boolean
    contains(int el)
    Copied from ANTLR's IntervalSet.contains(int) but with an addition of caching.
    boolean
    isTokenAllowed(org.antlr.v4.runtime.Token token)
    Checks if the given token is covered by this set if it's being used as an omission set.

    Methods inherited from class org.antlr.v4.runtime.misc.IntervalSet

    add, add, addAll, and, clear, complement, complement, elementName, elementName, equals, get, getIntervals, getMaxElement, getMinElement, hashCode, isNil, isReadonly, of, of, or, or, remove, setReadonly, size, subtract, subtract, toArray, toIntegerList, toList, toSet, toString, toString, toString, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CachingIntervalSet

      public CachingIntervalSet()
  • Method Details

    • contains

      public boolean contains(int el)
      Copied from ANTLR's IntervalSet.contains(int) but with an addition of caching. The cache size is 1. If the interval set has been marked as readonly, it will return the last hit if the query is the same.
      Specified by:
      contains in interface org.antlr.v4.runtime.misc.IntSet
      Overrides:
      contains in class org.antlr.v4.runtime.misc.IntervalSet
    • add

      public void add(org.antlr.v4.runtime.misc.Interval interval)
      Adds the given interval to the set.
      Overrides:
      add in class org.antlr.v4.runtime.misc.IntervalSet
      Parameters:
      interval - The interval to add to this interval set
    • isTokenAllowed

      public boolean isTokenAllowed(org.antlr.v4.runtime.Token token)
      Checks if the given token is covered by this set if it's being used as an omission set. Tokens that are included in one of this interval set's sets and aren't hidden are not printed.
      Parameters:
      token - The token to check
      Returns:
      true if the token should be printed