edu.rice.cs.javalanglevels
Class VariableData

java.lang.Object
  extended by edu.rice.cs.javalanglevels.VariableData

public class VariableData
extends java.lang.Object

Represents the data for a given variable (including fields).


Nested Class Summary
static class VariableData.VariableDataTest
          Test the methods defined in the above class.
 
Constructor Summary
VariableData(java.lang.String name, ModifiersAndVisibility modifiersAndVisibility, SymbolData type, boolean hasBeenAssigned, Data enclosingData)
          Constructor for VariableData.
VariableData(SymbolData type)
          This constructor is only used when reading method parameters in a class file because class files only store the types of method parameters.
 
Method Summary
 void addModifier(java.lang.String s)
          Add the specified modifier to the modifiers and visibility for this class, if it is not already there.
 VariableData copyWithoutVisibility()
          Make a copy of this VariableData erasing all visibility modifiers and setting hasBeenAssigned to true.
 boolean equals(java.lang.Object obj)
          Checks the values of the fields
 Data getEnclosingData()
           
 InstanceData getInstanceData()
          Assumes _type != null
 ModifiersAndVisibility getMav()
           
 java.lang.String getName()
           
 SymbolData getType()
           
 boolean gotValue()
          If this VariableData has not been given a value, set _hasBeenAssigned to true, and return true.
 int hashCode()
          Hash on the name and enclosing data, since within each enclosing data, the variable name should be unique
 boolean hasInitializer()
          Returns true iff this variable was declared with an initial value
 boolean hasModifier(java.lang.String modifier)
          Returns true if this variable has the modifier specified.
 boolean hasValue()
          Returns true if this VariableData has been given a value.
 boolean isFinal()
          Returns true if this VariableData is final.
 boolean isGenerated()
           
 boolean isLocalVariable()
           
 boolean isPrivate()
          Returns true if this VariableData is private.
 boolean isStatic()
          Returns true if this VariableData is static.
static boolean isVisibility(java.lang.String s)
           
 boolean lostValue()
          If this VariableData has a value, set _hasBeenAssigned to false, and return true.
 void setEnclosingData(Data d)
          Sets the enclosing data to the specified value.
 void setFinal()
          Adds "final" to the modifiers and visibility for this class, if it is not already there.
 void setFinalAndStatic()
          Adds "final" and "static" to the modifiers and visibility for this class, if it is not already there.
 void setGenerated(boolean value)
          Set the generated flag to the specified value
 void setHasInitializer(boolean value)
          Set the "hasInitializer" flag
 void setHasValue()
          Set _hasBeenAssigned flag.
 void setIsLocalVariable(boolean b)
          Sets the isLocalVariable flag to the specified value.
 void setMav(ModifiersAndVisibility mav)
          Set the modifiers and visibility to the specified value.
 void setName(java.lang.String s)
          Set the name of this variable to the specified string.
 void setPrivate()
          Adds "private" to the modifiers and visibility for this class, if it is not already there.
 void setPrivateAndFinal()
          Adds "private" and "final" to the modifiers and visibility for this class, if it is not already there.
 void setType(SymbolData type)
          Sets the SymbolData representing the type of this variable.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VariableData

public VariableData(java.lang.String name,
                    ModifiersAndVisibility modifiersAndVisibility,
                    SymbolData type,
                    boolean hasBeenAssigned,
                    Data enclosingData)
Constructor for VariableData. hasInitializer and generated are set to false.

Parameters:
name - The name of the variable
modifiersAndVisibility - The modifiersAndVisibility
type - The SymbolData type of the variable.
hasBeenAssigned - true if this variable has a value
enclosingData - the enclosing data

VariableData

public VariableData(SymbolData type)
This constructor is only used when reading method parameters in a class file because class files only store the types of method parameters.

Method Detail

copyWithoutVisibility

public VariableData copyWithoutVisibility()
Make a copy of this VariableData erasing all visibility modifiers and setting hasBeenAssigned to true. Used in LanguageLevelVisitor.createConstructor to generate the parameter list of the created constructor.

Returns:
a new Variable Data identical to this except for erasing visibility modifiers.

equals

public boolean equals(java.lang.Object obj)
Checks the values of the fields

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Hash on the name and enclosing data, since within each enclosing data, the variable name should be unique

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a readable representation of the Variable data

getName

public java.lang.String getName()
Returns:
the name of this field or variable

setName

public void setName(java.lang.String s)
Set the name of this variable to the specified string.


getMav

public ModifiersAndVisibility getMav()
Returns:
the modifiers and visibility.

setMav

public void setMav(ModifiersAndVisibility mav)
Set the modifiers and visibility to the specified value.


getType

public SymbolData getType()
Returns:
the SymbolData representing the type of this variable.

setType

public void setType(SymbolData type)
Sets the SymbolData representing the type of this variable.


getInstanceData

public InstanceData getInstanceData()
Assumes _type != null

Returns:
the InstanceData corresponding to the type of this variable.

getEnclosingData

public Data getEnclosingData()
Returns:
the enclosing data.

setEnclosingData

public void setEnclosingData(Data d)
Sets the enclosing data to the specified value.


isLocalVariable

public boolean isLocalVariable()
Returns:
the _isLocalVariable flag.

setIsLocalVariable

public void setIsLocalVariable(boolean b)
Sets the isLocalVariable flag to the specified value.


setFinal

public void setFinal()
Adds "final" to the modifiers and visibility for this class, if it is not already there.


setPrivate

public void setPrivate()
Adds "private" to the modifiers and visibility for this class, if it is not already there.


addModifier

public void addModifier(java.lang.String s)
Add the specified modifier to the modifiers and visibility for this class, if it is not already there.


setPrivateAndFinal

public void setPrivateAndFinal()
Adds "private" and "final" to the modifiers and visibility for this class, if it is not already there.


setFinalAndStatic

public void setFinalAndStatic()
Adds "final" and "static" to the modifiers and visibility for this class, if it is not already there.


isFinal

public boolean isFinal()
Returns true if this VariableData is final.


isPrivate

public boolean isPrivate()
Returns true if this VariableData is private.


isStatic

public boolean isStatic()
Returns true if this VariableData is static.


isVisibility

public static boolean isVisibility(java.lang.String s)

hasModifier

public boolean hasModifier(java.lang.String modifier)
Returns true if this variable has the modifier specified.


setGenerated

public void setGenerated(boolean value)
Set the generated flag to the specified value


isGenerated

public boolean isGenerated()
Returns:
the generated flag

hasInitializer

public boolean hasInitializer()
Returns true iff this variable was declared with an initial value


setHasInitializer

public void setHasInitializer(boolean value)
Set the "hasInitializer" flag


hasValue

public boolean hasValue()
Returns true if this VariableData has been given a value.


setHasValue

public void setHasValue()
Set _hasBeenAssigned flag.


gotValue

public boolean gotValue()
If this VariableData has not been given a value, set _hasBeenAssigned to true, and return true. Otherwise, return false to indicate it already has a value and should not be reassigned.


lostValue

public boolean lostValue()
If this VariableData has a value, set _hasBeenAssigned to false, and return true. Otherwise, return false.