dk.brics.string.intermediate
Enum VariableType

java.lang.Object
  extended by java.lang.Enum<VariableType>
      extended by dk.brics.string.intermediate.VariableType
All Implemented Interfaces:
Serializable, Comparable<VariableType>

public enum VariableType
extends Enum<VariableType>

Describes the possible types of a variable. The types are named after their repsective Java-types, but are defined independently of Java. The three string-types we operate with are:

The types are arranged into the following simple lattice:

           OBJECT
          /   |  \        \
         /    |   \        \
        /     |    \        \
       /      |     \        \
      /       |      \        \
     /        |       \        \
 STRING  STRINGBUFFER  ARRAY   PRIMITIVE
      \       |       /       /
       \      |      /       /
        \     |     /       /
         \    |    /       /
          \   |   /       /
            NONE
              |
            NULL 
 

The methods in the Types class are the preferred ways to create a type from a Java type, since it is non-trivial to do so in a sound way. For example, a variable of type Cloneable might be an array, and the non-public type AbstractStringBuilder is in fact the superclass of StringBuffer and StringBuilder, and not Object like documented.

Note that mutable strings (STRINGBUFFER) cannot be members of a string collection (ARRAY). This means that Java array types like StringBuffer[] cannot be modelled precisely.


Enum Constant Summary
ARRAY
          A mutable collection of immutable strings.
NONE
          An irrelevant type, or the value null.
NULL
          The value null (and not the string-value "null").
OBJECT
          Any type we care about.
PRIMITIVE
           
STRING
          An immutable string object.
STRINGBUFFER
          A mutable string object.
 
Method Summary
 boolean cannotBeAliasOf(VariableType other)
          Returns whether a variable of this type can never be an alias of a variable of the other type.
 boolean cannotBeUsefulAliasOf(VariableType other)
          Returns whether a variable of this type can never be a useful alias of a variable of the other type.
 VariableType greatestLowerBound(VariableType other)
          Returns the most specific variable type that might be alias of both this type, and the specified type.
 VariableType leastUpperBound(VariableType other)
          Returns the most specific variable type that might be alias of either this type, or the specified type, but not necessarily both.
 boolean mightBeAliasOf(VariableType other)
          Returns whether a variable of this type might be an alias of a variable of the other type.
 boolean mightBeUsefulAliasOf(VariableType other)
          Returns whether a variable of this type might be a useful alias of a variable of the other type.
 boolean mightBeUsefulMutable()
          Returns true if this is STRINGBUFFER, ARRAY, or OBJECT.
static VariableType valueOf(String name)
          Returns the enum constant of this type with the specified name.
static VariableType[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

ARRAY

public static final VariableType ARRAY
A mutable collection of immutable strings.

The variable might have type array (of arbitrary dimension) of String, but is definitely not String, StringBuffer, or StringBuilder.


NONE

public static final VariableType NONE
An irrelevant type, or the value null.


NULL

public static final VariableType NULL
The value null (and not the string-value "null").


OBJECT

public static final VariableType OBJECT
Any type we care about.


PRIMITIVE

public static final VariableType PRIMITIVE

STRING

public static final VariableType STRING
An immutable string object.

In Java, the variable might have type String, but definitely not StringBuffer, StringBuilder or array.


STRINGBUFFER

public static final VariableType STRINGBUFFER
A mutable string object.

In Java, the variable might have type StringBuffer or StringBuilder, but definitely not String or array.

Method Detail

cannotBeAliasOf

public boolean cannotBeAliasOf(VariableType other)
Returns whether a variable of this type can never be an alias of a variable of the other type. For example, a variable of type Cloneable might be an alias of String[], but definitely not an alias of String.

Variables of type NONE are never considered useful aliases of anything, not even each other.

Variables are not considered aliases if either has the type NULL.

Parameters:
other - the other variable type
Returns:
false if they might be aliases, true otherwise.

cannotBeUsefulAliasOf

public boolean cannotBeUsefulAliasOf(VariableType other)
Returns whether a variable of this type can never be a useful alias of a variable of the other type. For example, a variable of type Cloneable might be an alias of String[], but definitely not an alias of String.

To variables are useful aliases if they refer to the same string buffer, or to the same string array (ie. aliases and useful and mutable).

Variables of type NONE are never considered aliases of anything, not even each other.

Variables are not considered aliases if either has the type NULL.

This is method always returns the opposite of mightBeUsefulAliasOf(VariableType), and is only here for convenience.

Parameters:
other - the other variable type
Returns:
false if they might be aliases, true otherwise.

greatestLowerBound

public VariableType greatestLowerBound(VariableType other)
Returns the most specific variable type that might be alias of both this type, and the specified type.

Refer to the lattice in VariableType's description to see how the greatest lower bound is defined.

Parameters:
other - the other variable type
Returns:
a variable type thay might be an alias with both variable types, or NONE if no such type exists.

leastUpperBound

public VariableType leastUpperBound(VariableType other)
Returns the most specific variable type that might be alias of either this type, or the specified type, but not necessarily both. For example, STRING.leastUpperBound(STRINGBUFFER) = CHARSEQUENCE.

Refer to the lattice in VariableType's description to see how the least upper bound is defined.

Parameters:
other - the other variable type
Returns:
a variable type thay might be an alias with either variable type.

mightBeAliasOf

public boolean mightBeAliasOf(VariableType other)
Returns whether a variable of this type might be an alias of a variable of the other type. For example, a variable of type Cloneable might be an alias of String[], but definitely not an alias of String.

Variables of type NONE are never considered useful aliases of anything, not even each other.

Variables are not considered aliases if either has the type NULL.

Parameters:
other - the other variable type
Returns:
true if they might be aliases, false otherwise.

mightBeUsefulAliasOf

public boolean mightBeUsefulAliasOf(VariableType other)
Returns whether a variable of this type might be a useful alias of a variable of the other type. For example, a variable of type Cloneable might be an alias of String[], but definitely not an alias of String.

To variables are useful aliases if they refer to the same string buffer, or to the same string array (ie. aliases and useful and mutable).

Variables of type NONE are never considered useful aliases of anything, not even each other.

Variables are not considered aliases if either has the type NULL.

Parameters:
other - the other variable type
Returns:
true if they might be aliases, false otherwise.

mightBeUsefulMutable

public boolean mightBeUsefulMutable()
Returns true if this is STRINGBUFFER, ARRAY, or OBJECT.


valueOf

public static VariableType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

values

public static VariableType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (VariableType c : VariableType.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared


Copyright © 2003-2009 Anders Møller, Aske Simon Christensen, Asger Feldthaus.