com.sun.tools.javac.code
Class Scope

java.lang.Object
  extended by com.sun.tools.javac.code.Scope
Direct Known Subclasses:
Scope.DelegatedScope, Scope.ErrorScope, Scope.ImportScope

public class Scope
extends java.lang.Object

A scope represents an area of visibility in a Java program. The Scope class is a container for symbols which provides efficient access to symbols given their names. Scopes are implemented as hash tables. Scopes can be nested; the next field of a scope points to its next outer scope. Nested scopes can share their hash tables.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
static class Scope.DelegatedScope
          An empty scope, into which you can't place anything.
static class Scope.Entry
          A class for scope entries.
static class Scope.ErrorScope
          An error scope, for which the owner should be an error symbol.
static class Scope.ImportScope
           
 
Field Summary
 Scope.Entry elems
          A linear list that also contains all entries in reverse order of appearance (i.e later entries are pushed on top).
static Scope emptyScope
          A value for the empty scope.
(package private)  int hashMask
          Mask for hash codes, always equal to (table.length - 1).
private static int INITIAL_SIZE
          The hash table's initial size.
 Symbol.Level level
           
 int nelems
          The number of elements in this scope.
 Scope next
          Next enclosing scope (with whom this scope may share a hashtable)
 Symbol owner
          The scope's owner.
private static Scope.Entry sentinel
          Every hash bucket is a list of Entry's which ends in sentinel.
private  int shared
          The number of scopes that share this scope's hash table.
 Scope.Entry[] table
          A hash table for the scope's entries.
 
Constructor Summary
Scope(Scope next, Symbol owner, Scope.Entry[] table, Symbol.Level l)
          Construct a new scope, within scope next, with given owner, using given table.
Scope(Symbol owner)
          Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.
Scope(Symbol owner, int l)
          Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.
Scope(Symbol owner, Symbol.Level l)
          Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.
 
Method Summary
private  void copy(Scope.Entry e)
          Copy the given entry and all entries shadowed by it to table
private  void dble()
          Double size of hash table.
 Scope dup()
          Construct a fresh scope within this scope, with same owner, which shares its table with the outer scope.
 Scope dup(Symbol newOwner)
          Construct a fresh scope within this scope, with new owner, which shares its table with the outer scope.
 Scope dupUnshared()
          Construct a fresh scope within this scope, with same owner, with a new hash table, whose contents initially are those of the table of its outer scope.
 void enter(Symbol sym)
          Enter symbol sym in this scope.
 void enter(Symbol sym, Scope s)
           
 void enter(Symbol sym, Scope s, Scope origin)
          Enter symbol sym in this scope, but mark that it comes from given scope `s' accessed through `origin'.
 void enterIfAbsent(Symbol sym)
          Enter symbol sym in this scope if not already there.
 java.lang.Iterable<Symbol> getElements()
           
 int getLevel()
           
 boolean includes(Symbol c)
          Given a class, is there already a class with same fully qualified name in this (import) scope?
 Scope leave()
          Remove all entries of this scope from its table, if shared with next.
 Scope.Entry lookup(Name name)
          Return the entry associated with given name, starting in this scope and proceeding outwards.
(package private)  Scope.Entry makeEntry(Symbol sym, Scope.Entry shadowed, Scope.Entry sibling, Scope scope, Scope origin)
           
 void remove(Symbol sym)
          Remove symbol from this scope.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

shared

private int shared
The number of scopes that share this scope's hash table.


next

public Scope next
Next enclosing scope (with whom this scope may share a hashtable)


owner

public Symbol owner
The scope's owner.


table

public Scope.Entry[] table
A hash table for the scope's entries.


hashMask

int hashMask
Mask for hash codes, always equal to (table.length - 1).


elems

public Scope.Entry elems
A linear list that also contains all entries in reverse order of appearance (i.e later entries are pushed on top).


nelems

public int nelems
The number of elements in this scope.


level

public Symbol.Level level

sentinel

private static final Scope.Entry sentinel
Every hash bucket is a list of Entry's which ends in sentinel.


INITIAL_SIZE

private static final int INITIAL_SIZE
The hash table's initial size.

See Also:
Constant Field Values

emptyScope

public static final Scope emptyScope
A value for the empty scope.

Constructor Detail

Scope

Scope(Scope next,
      Symbol owner,
      Scope.Entry[] table,
      Symbol.Level l)
Construct a new scope, within scope next, with given owner, using given table. The table's length must be an exponent of 2.


Scope

public Scope(Symbol owner,
             Symbol.Level l)
Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.


Scope

public Scope(Symbol owner,
             int l)
Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.


Scope

public Scope(Symbol owner)
Construct a new scope, within scope next, with given owner, using a fresh table of length INITIAL_SIZE.

Method Detail

getLevel

public int getLevel()

dup

public Scope dup()
Construct a fresh scope within this scope, with same owner, which shares its table with the outer scope. Used in connection with method leave if scope access is stack-like in order to avoid allocation of fresh tables.


dup

public Scope dup(Symbol newOwner)
Construct a fresh scope within this scope, with new owner, which shares its table with the outer scope. Used in connection with method leave if scope access is stack-like in order to avoid allocation of fresh tables.


dupUnshared

public Scope dupUnshared()
Construct a fresh scope within this scope, with same owner, with a new hash table, whose contents initially are those of the table of its outer scope.


leave

public Scope leave()
Remove all entries of this scope from its table, if shared with next.


dble

private void dble()
Double size of hash table.


copy

private void copy(Scope.Entry e)
Copy the given entry and all entries shadowed by it to table


enter

public void enter(Symbol sym)
Enter symbol sym in this scope.


enter

public void enter(Symbol sym,
                  Scope s)

enter

public void enter(Symbol sym,
                  Scope s,
                  Scope origin)
Enter symbol sym in this scope, but mark that it comes from given scope `s' accessed through `origin'. The last two arguments are only used in import scopes.


makeEntry

Scope.Entry makeEntry(Symbol sym,
                      Scope.Entry shadowed,
                      Scope.Entry sibling,
                      Scope scope,
                      Scope origin)

remove

public void remove(Symbol sym)
Remove symbol from this scope. Used when an inner class attribute tells us that the class isn't a package member.


enterIfAbsent

public void enterIfAbsent(Symbol sym)
Enter symbol sym in this scope if not already there.


includes

public boolean includes(Symbol c)
Given a class, is there already a class with same fully qualified name in this (import) scope?


lookup

public Scope.Entry lookup(Name name)
Return the entry associated with given name, starting in this scope and proceeding outwards. If no entry was found, return the sentinel, which is characterized by having a null in both its scope and sym fields, whereas both fields are non-null for regular entries.


getElements

public java.lang.Iterable<Symbol> getElements()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object