Module suggest

Class BaseScope

java.lang.Object
de.grogra.suggest.scope.BaseScope
All Implemented Interfaces:
Member, Scope
Direct Known Subclasses:
LambdaScope, LocalScopeSymbol, SymbolWithScope

public abstract class BaseScope extends Object implements Scope
A scope where one key can be several symbols: e.g. one method name can be several method in the scope. Each having different parameters and possibly return type. The method are not differentiated with their parameters in the name to be easier to match with auto completion - in the case some parameters are not filed yet the method name can still match.
  • Field Details

    • enclosingScope

      protected Scope enclosingScope
    • symbols

      protected com.google.common.collect.Multimap<String,Symbol> symbols
      All symbols defined in this scope; can include classes, functions, variables, or anything else that is a Symbol impl. It does NOT include non-Symbol-based things like LocalScope. See nestedScopes.
    • nestedScopesNotSymbols

      protected Set<Scope> nestedScopesNotSymbols
      All directly contained scopes, typically LocalScopes within a LocalScope or a LocalScope within a FunctionSymbol. This does not include SymbolWithScope objects.
  • Constructor Details

    • BaseScope

      public BaseScope()
    • BaseScope

      public BaseScope(Scope enclosingScope)
  • Method Details

    • getMembers

      public com.google.common.collect.Multimap<String,Symbol> getMembers()
    • getSymbol

      public Collection<Symbol> getSymbol(String name, int flags)
      Description copied from interface: Scope
      Get symbol if name defined within this specific scope The symbol must have the flags bits.
      Specified by:
      getSymbol in interface Scope
    • setEnclosingScope

      public void setEnclosingScope(Scope enclosingScope)
      Description copied from interface: Scope
      What scope encloses this scope. E.g., if this scope is a function, the enclosing scope could be a class. The BaseScope class automatically adds this to nested scope list of s.
      Specified by:
      setEnclosingScope in interface Scope
    • getAllNestedScopedSymbols

      public Set<Scope> getAllNestedScopedSymbols()
    • getNestedScopedSymbols

      public Collection<Scope> getNestedScopedSymbols()
      Description copied from interface: Scope
      Return all immediately enclosed scoped symbols in insertion order. E.g., a class would return all nested classes and any methods. There does not have to be an explicit pointer to the nested scopes. This method generally searches the list of symbols looking for symbols that implement Scope. Gets only those scopes that are in the symbols list of "this" scope. E.g., does not get local scopes within a function. This returns a subset or same set as Scope.getNestedScopes().
      Specified by:
      getNestedScopedSymbols in interface Scope
    • getNestedScopes

      public Set<Scope> getNestedScopes()
      Description copied from interface: Scope
      Return a list of scopes nested within this scope. It has both ScopedSymbols and scopes without symbols, such as LocalScopes. This returns a superset or same set as Scope.getNestedScopedSymbols(). ScopedSymbols come first then all non-ScopedSymbols Scope objects. Insertion order is used within each sublist.
      Specified by:
      getNestedScopes in interface Scope
    • nest

      public void nest(Scope scope) throws IllegalArgumentException
      Add a nested scope to this scope; could also be a FunctionSymbol if your language allows nested functions.
      Specified by:
      nest in interface Scope
      Throws:
      IllegalArgumentException - if you pass in a SymbolWithScope.
    • resolve

      public Collection<Symbol> resolve(String name, int flags)
      Description copied from interface: Scope
      Look up name in this scope or recursively in parent scope if not here. Use the flags to reduce the space of symbol
      Specified by:
      resolve in interface Scope
    • resolveFirst

      public Symbol resolveFirst(String name, int flags)
      Specified by:
      resolveFirst in interface Scope
    • define

      public void define(Symbol sym) throws IllegalArgumentException
      Description copied from interface: Scope
      Define a symbol in this scope, throw IllegalArgumentException if sym already defined in this scope. This alters sym: 1. Set insertion order number of sym 2. Set sym's scope to be the scope. The order in which symbols are defined must be preserved so that
      invalid reference
      #getSymbols()
      returns the list in definition order.
      Specified by:
      define in interface Scope
      Throws:
      IllegalArgumentException
    • define

      public void define(Import imp) throws ParseException
      Specified by:
      define in interface Scope
      Throws:
      ParseException
    • getEnclosingScope

      public Scope getEnclosingScope()
      Description copied from interface: Scope
      Scope in which this scope defined. null if no enclosing scope
      Specified by:
      getEnclosingScope in interface Scope
    • getOuterMostEnclosingScope

      public Scope getOuterMostEnclosingScope()
      Walk up enclosingScope until we find topmost. Note this is enclosing scope not necessarily parent. This will usually be a global scope or something, depending on your scope tree.
    • getEnclosingScopeOfType

      public MethodSymbol getEnclosingScopeOfType(Class<?> type)
      Walk up enclosingScope until we find an object of a specific type. E.g., if you want to get enclosing method, you would pass in MethodSymbol.class, unless of course you have created a subclass for your language implementation.
    • getEnclosingPathToRoot

      public List<Scope> getEnclosingPathToRoot()
      Description copied from interface: Scope
      Return (inclusive) list of all scopes on path to root scope. The first element is the current scope and the last is the root scope.
      Specified by:
      getEnclosingPathToRoot in interface Scope
    • getSymbols

      public Collection<? extends Symbol> getSymbols(int flags)
      Description copied from interface: Scope
      Return the symbols defined within this scope. The order of insertion into the scope is the order returned in this list. Only symbol that match the flags are returned
      Specified by:
      getSymbols in interface Scope
    • getAllSymbols

      public Collection<? extends Symbol> getAllSymbols(int flags)
      Description copied from interface: Scope
      Return all symbols found in all nested scopes. The order of insertion into the scope is the order returned in this list for each scope. The scopes are traversed in the order in which they are encountered in the input.
      Specified by:
      getAllSymbols in interface Scope
    • getNumberOfSymbols

      public int getNumberOfSymbols(int flags)
      Description copied from interface: Scope
      Number of symbols in this specific scope
      Specified by:
      getNumberOfSymbols in interface Scope
    • getSymbolNames

      public Set<String> getSymbolNames(int flags)
      Description copied from interface: Scope
      Return the set of names associated with all symbols in the scope.
      Specified by:
      getSymbolNames in interface Scope
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toScopeStackString

      public String toScopeStackString(String separator)
    • toQualifierString

      public String toQualifierString(String separator)
      Description copied from interface: Scope
      Return scopes from to current with separator in between
      Specified by:
      toQualifierString in interface Scope
    • toTestString

      public String toTestString()
    • toTestString

      public String toTestString(String separator, String scopePathSeparator)