edu.rice.cs.javalanglevels
Class Data

java.lang.Object
  extended by edu.rice.cs.javalanglevels.Data
Direct Known Subclasses:
BodyData, TypeData

public abstract class Data
extends Object

Abstract class epresenting the data for a given braced body: a class, interface, method, or just a body.


Nested Class Summary
static class Data.DataTest
          Test the methods in the above class.
 
Field Summary
protected  Iterator<BlockData> _blockIterator
          Iterator over _blocks
protected  LinkedList<BlockData> _blocks
          All blocks defined within this data, in lexical order.
protected  LinkedList<Data> _enclosingData
          All enclosing data are in this list.
protected  LinkedList<SymbolData> _innerClasses
          Any inner classes that are defined in this data.
protected  ModifiersAndVisibility _modifiersAndVisibility
          The modifiers and visibility of this data.
protected  String _name
          The fully qualified name of this data.
protected  Data _outerData
          The outer data--what directly encloses this data.
protected  LinkedList<VariableData> _vars
          The vars defined in the lexical scope of this data.
 
Constructor Summary
Data(Data outerData)
          The default constructor for a Data.
 
Method Summary
 void addBlock(BlockData b)
          Add a BlockData to this Data's list of blocks.
 void addEnclosingData(Data enclosingData)
          Add to the front because we want the outer data to be the last thing in the list.
 boolean addFinalVars(VariableData[] vars)
          Add the array of variable datas to the list of variables defined in this scope, unless a name has already been used.
 void addInnerClass(SymbolData innerClass)
          Add the specified SymbolData to the end of the list of inner classes.
 void addModifier(String modifier)
          Add the specified modifier to the modifiers and visibility for this data, if it is not already present.
 boolean addVar(VariableData var)
          Add the specified Variable Data to the list of variables defined in this scope, unless its name has already been used.
 boolean addVars(VariableData[] vars)
          Add the array of variable datas to the list of variables defined in this scope, unless a name has already been used.
 String createUniqueName(String varName)
          Check if varName is used in this Data's scope.
static String dollarSignsToDots(String s)
          Loop over the specified string, and replace any '$' with '.' This is used to change an inner class name to a standard format.
static String dotsToDollarSigns(String s)
          Loop over the specified string, and replace any '.' with '$' This is used to change an inner class name from external (as in Java source) to internal (as in class files) format.
 SymbolData getEnclosingClass()
           
 LinkedList<Data> getEnclosingData()
           
 LinkedList<SymbolData> getInnerClasses()
           
 SymbolData getInnerClassOrInterface(String relName)
          Takes in a relative name and tries to match it with one of this Data's inner classes or inner interfaces.
protected  SymbolData getInnerClassOrInterfaceHelper(String relName, int firstIndexOfDot)
          Takes in a relative name and tries to match it with one of this Data's inner classes or inner interfaces.
 ModifiersAndVisibility getMav()
           
 String getName()
           
 SymbolData getNextAnonymousInnerClass()
          Determines the name of the next anonymous inner class (enclosing class name + '$' + sequence number).
 BlockData getNextBlock()
          Returns the next block contained within this data.
 Data getOuterData()
           
abstract  SymbolData getSymbolData()
          Return the enclosing getSymbolData()
 VariableData getVar(String name)
          Finds and returns the particular VariableData declared in this Data's context.
 LinkedList<VariableData> getVars()
           
 boolean hasModifier(String modifier)
           
 Iterator<SymbolData> innerClassesAndInterfacesIterator()
           
 Boolean isAnonymousClass()
           
 Boolean isDoublyAnonymous()
           
 boolean isOuterData(Data d)
           
 void removeAllBlocks()
          Remove all blocks from this data's list of enclosed blocks.
 void resetBlockIterator()
          Reset the block iterator to the beginning of the list of blocks.
 void setEnclosingData(LinkedList<Data> d)
           
 void setInnerClasses(LinkedList<SymbolData> innerClasses)
          Sets the inner classes of this Data.
 void setMav(ModifiersAndVisibility modifiersAndVisibility)
          Assigns the specified modifiersAndVisiblity to this data.
 void setOuterData(Data outerData)
          Sets the outer data to the specified value--throw an exception if the data already has an outer data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_name

protected String _name
The fully qualified name of this data.


_vars

protected LinkedList<VariableData> _vars
The vars defined in the lexical scope of this data.


_enclosingData

protected LinkedList<Data> _enclosingData
All enclosing data are in this list.


_modifiersAndVisibility

protected ModifiersAndVisibility _modifiersAndVisibility
The modifiers and visibility of this data.


_outerData

protected Data _outerData
The outer data--what directly encloses this data.


_innerClasses

protected LinkedList<SymbolData> _innerClasses
Any inner classes that are defined in this data.


_blocks

protected LinkedList<BlockData> _blocks
All blocks defined within this data, in lexical order.


_blockIterator

protected Iterator<BlockData> _blockIterator
Iterator over _blocks

Constructor Detail

Data

public Data(Data outerData)
The default constructor for a Data. It takes in the outerData, and sets all lists and the name to empty, except that the outer data is asdded to the enclosing data list.

Method Detail

getName

public String getName()
Returns:
the name of this data.

isAnonymousClass

public Boolean isAnonymousClass()

isDoublyAnonymous

public Boolean isDoublyAnonymous()

getVar

public VariableData getVar(String name)
Finds and returns the particular VariableData declared in this Data's context.

Parameters:
name - Name of the variable
Returns:
The VariableData with the matching name or null if it was not found.

getVars

public LinkedList<VariableData> getVars()
Returns:
the list of variables declared in the scope of this data.

getEnclosingData

public LinkedList<Data> getEnclosingData()
Returns:
the list of enclosing data.

addEnclosingData

public void addEnclosingData(Data enclosingData)
Add to the front because we want the outer data to be the last thing in the list.


setEnclosingData

public void setEnclosingData(LinkedList<Data> d)

addVar

public boolean addVar(VariableData var)
Add the specified Variable Data to the list of variables defined in this scope, unless its name has already been used. Return true if it was successfully added, and false otherwise.

Parameters:
var - The variable we want to add to this scope.
Returns:
true if it was successfully added, false otherwise.

addVars

public boolean addVars(VariableData[] vars)
Add the array of variable datas to the list of variables defined in this scope, unless a name has already been used. Return true if all variables were added successfully, false otherwise.

Parameters:
vars - The VariableData[] that we want to add.
Returns:
true if all VariableDatas were added successfully, false otherwise.

addFinalVars

public boolean addFinalVars(VariableData[] vars)
Add the array of variable datas to the list of variables defined in this scope, unless a name has already been used. Return true if all variables were added successfully, false otherwise. Set each of the variable datas in the array to be final before adding them.

Parameters:
vars - the VariableData[] that we want to add.
Returns:
true if all VariableDatas were added successfully, false otherwise.

getMav

public ModifiersAndVisibility getMav()
Returns:
the modifiersAndVisibility for this data.

setMav

public void setMav(ModifiersAndVisibility modifiersAndVisibility)
Assigns the specified modifiersAndVisiblity to this data.

Parameters:
modifiersAndVisibility - The ModifiersAndVisibility to assign to this data.

getSymbolData

public abstract SymbolData getSymbolData()
Return the enclosing getSymbolData()


getOuterData

public Data getOuterData()
Returns:
the directly enclosing outer data.

setOuterData

public void setOuterData(Data outerData)
Sets the outer data to the specified value--throw an exception if the data already has an outer data.

Parameters:
outerData - The Data that encloses this data.

isOuterData

public boolean isOuterData(Data d)
Returns:
true if d is an outer data of this data. TODO: What if d is a library class?

getEnclosingClass

public SymbolData getEnclosingClass()
Returns:
the enclosing class of this.

dollarSignsToDots

public static String dollarSignsToDots(String s)
Loop over the specified string, and replace any '$' with '.' This is used to change an inner class name to a standard format. It fails if the inner class is local or anonymous!

Parameters:
s - The String to change.
Returns:
The converted string.

dotsToDollarSigns

public static String dotsToDollarSigns(String s)
Loop over the specified string, and replace any '.' with '$' This is used to change an inner class name from external (as in Java source) to internal (as in class files) format.

Parameters:
s - The String to change.
Returns:
The converted string.

getNextAnonymousInnerClass

public SymbolData getNextAnonymousInnerClass()
Determines the name of the next anonymous inner class (enclosing class name + '$' + sequence number). Looks through the list of inner classes of this data to see if there is a match. (It should succeed).

Returns:
the SymbolData for next anonymous inner class of this data; null if it cannot be found

resetBlockIterator

public void resetBlockIterator()
Reset the block iterator to the beginning of the list of blocks.


getNextBlock

public BlockData getNextBlock()
Returns the next block contained within this data.

Returns:
a BlockData, or null if none exists.

addBlock

public void addBlock(BlockData b)
Add a BlockData to this Data's list of blocks.


removeAllBlocks

public void removeAllBlocks()
Remove all blocks from this data's list of enclosed blocks. (Used to simplify testing.)


getInnerClassOrInterface

public SymbolData getInnerClassOrInterface(String relName)
Takes in a relative name and tries to match it with one of this Data's inner classes or inner interfaces. The relName argument is a name relative to this SymbolData (such as B to request the the class with this relative name within some enclosing symbol data or B$C to request the class A.B.C from class A) and may be delimited by '.' or '$' (??). If the name is not found in this Data, checks the outer data (if there is one), which will recursively search up the chain of enclosing Datas. If no matching visible inner classes or interfaces are found, but one or more that are not visible are found, one of the non-visible ones will be returned. This means that checkAccess should be called after this method. TODO: Is support for '$' delimiter required to process inner classes in class files? Yes. !!! Eliminate the kludge in this method.

Parameters:
relName - The name of the inner class or interface to find RELATIVE to this SymbolData
Returns:
The SymbolData for the matching inner class or interface is null if there isn't one.

getInnerClassOrInterfaceHelper

protected SymbolData getInnerClassOrInterfaceHelper(String relName,
                                                    int firstIndexOfDot)
Takes in a relative name and tries to match it with one of this Data's inner classes or inner interfaces. The relName argument is a name relative to this SymbolData (such as B.C to request the class A.B.C from class A) and may be delimited by '.' or '$'. This method is overridden in SymbolData (but not other concrete Data classes) to handle the fact that classes must check their super classes and interfaces and interfaces must check their super interfaces. TODO: Kludge! Only use dots to separate segments!!!

Returns:
The SymbolData for the matching inner class or interface or null if there isn't one.

innerClassesAndInterfacesIterator

public Iterator<SymbolData> innerClassesAndInterfacesIterator()

getInnerClasses

public LinkedList<SymbolData> getInnerClasses()
Returns:
The inner classes of this Data.

setInnerClasses

public void setInnerClasses(LinkedList<SymbolData> innerClasses)
Sets the inner classes of this Data.


addInnerClass

public void addInnerClass(SymbolData innerClass)
Add the specified SymbolData to the end of the list of inner classes.

Parameters:
innerClass - The SymbolData to add.

hasModifier

public boolean hasModifier(String modifier)
Returns:
true if this data has the specified String modifier, and false otherwise.

addModifier

public void addModifier(String modifier)
Add the specified modifier to the modifiers and visibility for this data, if it is not already present.

Parameters:
modifier - The String to add.

createUniqueName

public String createUniqueName(String varName)
Check if varName is used in this Data's scope. If so, find a new name for the variable by appending a counter to its name until an unused variable name results. Return the new name.

Parameters:
varName - The initial String name of the variable we are creating.
Returns:
The new variable name which does not shadow anything in vars.