xtc.type
Class Type

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.type.Type
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable
Direct Known Subclasses:
BooleanT, DerivedT, ErrorT, InternalT, LabelT, NumberT, PackageT, Parameter, UnitT, VoidT, WrappedT

public abstract class Type
extends Node

The superclass of all types.

The class hierarchy for types distinguishes basic from wrapped types, with wrapped types providing additional information for basic types. For each basic type, this class provides isName() and toName() methods to replace instanceof tests and casts, respectively. For each wrapped type, this class additionally provides a hasName() method, which identifies instances of the wrapped type even if they are wrapped inside another (wrapped) type. In other words, invocations of hasName() are forwarded across wrapped types while invocations of isName() only apply to the outermost type object. For wrapped types, invocations of toName() are also forwarded across (other) wrapped types.

As an example, consider an int type wrapped in an annotated type and an alias type:

 Type i = NumberT.INT;
 Type j = new AnnotatedT(i);
 Type k = new AliasT("alias", j);
 
Then the following method invocations have the following results:
 k.isAlias()        ⇒ true
 k.hasAlias()       ⇒ true
 k.toAlias()        ⇒ k

 k.isAnnotated()    ⇒ false
 k.hasAnnotated()   ⇒ true
 k.toAnnotated()    ⇒ j

 k.isInteger()      ⇒ false
 k.toInteger()      ⇒ error
 
The resolve() method can be used to strip any wrapped types:
 Type r = k.resolve();

 r.isAlias()        ⇒ false
 r.isAnnotated()    ⇒ false
 r.isInteger()      ⇒ true
 r.toInteger()      ⇒ i
 

The Type.Tag enumeration also identifies particular types. A type's tag can be accessed through tag(), which is forwarded across wrapped types, and through wtag(), which is not forwarded across wrapped types. As a result, tag() identifies basic types independent of whether they are wrapped or not, while wtag() always identifies the outermost type:

 k.tag()            ⇒ Tag.INTEGER
 k.wtag()           ⇒ Tag.ALIAS

 i.tag()            ⇒ Tag.INTEGER
 i.tag()            ⇒ Tag.INTEGER
 

Each type can have one or more of the following annotations:

For each kind of annotation, this class defines tester, getter, and setter methods. The tester and getter methods come in two versions, one that is forwarded across wrapped types and one that uses a boolean parameter to control forwarding.

Version:
$Revision: 1.112 $
Author:
Robert Grimm

Nested Class Summary
static class Type.Tag
          A type's tag.
 
Constructor Summary
Type()
          Create a new type.
Type(Type template)
          Create a new type.
 
Method Summary
 void addAttribute(Attribute att)
          Add the specified attribute.
 Type annotate()
          Annotate this type.
 Type attribute(Attribute att)
          Annotate this type with the specified attribute.
 Type attribute(java.util.List<Attribute> attributes)
          Annotate this type with the specified attributes.
 Type attribute(Type template)
          Annotate this type with the specified type's attributes.
 java.util.List<Attribute> attributes()
          Get this type's attributes.
static Type cast(java.lang.Object type)
          Cast the specified object to a type.
protected  void checkNotSealed()
          Ensure that this type is not sealed.
 Type constant(boolean value)
          Set this type's constant.
 Type constant(java.lang.Object value)
          Set this type's constant.
abstract  Type copy()
          Create a deep copy of this type.
static
<T extends Type>
java.util.List<T>
copy(java.util.List<T> types)
          Copy the specified list of types.
 Type deannotate()
          Deannotate this type.
 Attribute getAttribute(java.lang.String name)
          Get the attribute with the specified name.
 Attribute getAttribute(java.lang.String name, boolean forward)
          Get the attribute with the specified name.
 Constant getConstant()
          Get this type's or any wrapped type's constant.
 Constant getConstant(boolean forward)
          Get this type's or any wrapped type's constant.
 Language getLanguage()
          Get this type's or any wrapped type's language.
 Language getLanguage(boolean forward)
          Get this type's or any wrapped type's language.
 Location getLocation()
          Get this type's or any wrapped type's location.
 Location getLocation(boolean forward)
          Get this type's or any wrapped type's location.
 java.lang.String getScope()
          Get this type's or any wrapped type's scope.
 java.lang.String getScope(boolean forward)
          Get this type's or any wrapped type's scope.
 Reference getShape()
          Get this type's or any wrapped type's shape.
 Reference getShape(boolean forward)
          Get this type's or any wrapped type's shape.
 boolean hasAlias()
          Determine whether this type contains an alias.
 boolean hasAnnotated()
          Determine whether this type has an annotated type.
 boolean hasAttribute(Attribute att)
          Determine whether this type or any wrapped type has the specified attribute.
 boolean hasAttribute(Attribute att, boolean forward)
          Determine whether this type or any wrapped type has the specified attribute.
 boolean hasAttribute(java.lang.String name)
          Determine whether this type has an attribute with the specified name.
 boolean hasAttribute(java.lang.String name, boolean forward)
          Determine whether this type has an attribute with the specified name.
 boolean hasAttributes()
          Determine whether this type has any attributes.
 boolean hasConstant()
          Determine whether this type or any wrapped type has a constant.
 boolean hasConstant(boolean forward)
          Determine whether this type or any wrapped type has a constant.
 boolean hasEnum()
          Determine whether this type contains an enum.
 boolean hasEnumerator()
          Determine whether this type contains an enumerator.
 boolean hasError()
          Determine whether this type has an error.
 boolean hasInstantiated()
          Determine whether this type has an instantiated type.
 boolean hasLanguage()
          Determine whether this type or any wrapped type has a language.
 boolean hasLanguage(boolean forward)
          Determine whether this type or any wrapped type has a language.
 boolean hasLocation()
          Determine whether this type or any wrapped type has a location.
 boolean hasLocation(boolean forward)
          Determine whether this type or any wrapped type has a location.
 boolean hasParameterized()
          Determine whether this type has a parameterized type.
 boolean hasScope()
          Determine whether this type or any wrapped type has a scope.
 boolean hasScope(boolean forward)
          Determine whether this type or any wrapped type has a scope.
 boolean hasShape()
          Determine whether this type or any wrapped type has a shape.
 boolean hasShape(boolean forward)
          Determine whether this type or any wrapped type has a shape.
 boolean hasStructOrUnion()
          Determine whether this type contains a struct or union.
 boolean hasTag(Type.Tag tag)
          Determine whether this type has the specified tag.
 boolean hasTagged()
          Determine whether this type is tagged.
 boolean hasVariable()
          Determine whether this type contains a variable.
 boolean hasWTag(Type.Tag tag)
          Determine whether this wrapped type has the specified tag.
 boolean isAlias()
          Determine whether this type is an alias.
 boolean isAnnotated()
          Determine whether this type is annotated.
 boolean isArray()
          Determine whether this type is an array.
 boolean isBoolean()
          Determine whether this type is a boolean.
 boolean isClass()
          Determine whether this type is a class.
 boolean isConcrete()
          Determine whether this type is concrete.
 boolean isDerived()
          Determine whether this type is derived.
 boolean isEnum()
          Determine whether this type is an enum.
 boolean isEnumerator()
          Determine whether this type is an enumerator.
 boolean isError()
          Determine whether this type is an error.
 boolean isFloat()
          Determine whether this type is a float.
 boolean isFunction()
          Determine whether this type is a function.
 boolean isInstantiated()
          Determine whether this type is instantiated.
 boolean isInteger()
          Determine whether this type is an integer.
 boolean isInterface()
          Determine whether this type is an interface.
 boolean isInternal()
          Determine whether this type is internal.
 boolean isInternalParameter()
          Determine whether this type is an internal parameter.
 boolean isLabel()
          Determine whether this type is a label.
 boolean isMethod()
          Determine whether this type is a method.
 boolean isNamedParameter()
          Determine whether this type is a named parameter.
 boolean isNumber()
          Determine whether this type is a number.
 boolean isPackage()
          Determine whether this type is a package.
 boolean isParameter()
          Determine whether this type is a type parameter.
 boolean isParameterized()
          Determine whether this type is parameterized.
 boolean isPointer()
          Determine whether this type is a pointer.
 boolean isSealed()
          Determine whether this type is sealed.
 boolean isStruct()
          Determine whether this type is a struct.
 boolean isTuple()
          Determine whether this type is an tuple.
 boolean isUnion()
          Determine whether this type is a union.
 boolean isUnit()
          Determine whether this type is the unit type.
 boolean isVariable()
          Determine whether this type is a variable.
 boolean isVariant()
          Determine whether this type is an variant.
 boolean isVoid()
          Determine whether this type is void.
 boolean isWildcard()
          Determine whether this type is a wildcard.
 boolean isWrapped()
          Determine whether this type is wrapped.
 Type language(Language language)
          Set this type's language.
 Type locate(Locatable locatable)
          Set this type's location.
 Type locate(Location location)
          Set this type's location.
 void mark(Node node)
          Mark the specified node as having this type.
 java.util.Set<java.lang.String> properties()
          Get the set of property names.
 boolean removeAttribute(Attribute att)
          Remove the specified attribute.
 java.lang.Object removeProperty(java.lang.String name)
          Remove a property.
 Type resolve()
          Resolve this type.
static Type resolve(java.lang.Object type)
          Resolve the specified object as type.
 Type scope(java.lang.String scope)
          Set this type's scope.
 Type seal()
          Seal this type.
static
<T extends Type>
java.util.List<T>
seal(java.util.List<T> types)
          Seal the specified list of types.
 void setLocation(Locatable locatable)
          Set this object's location to the specified locatable's location.
 void setLocation(Location location)
          Set this object's location.
 java.lang.Object setProperty(java.lang.String name, java.lang.Object value)
          Set the value of a property.
 Type shape(boolean isStatic, java.lang.String name)
          Set this type's shape to a variable reference with the specified name.
 Type shape(Reference shape)
          Set this type's shape.
abstract  Type.Tag tag()
          Get this type's tag.
 AliasT toAlias()
          Get this type as an alias.
 AnnotatedT toAnnotated()
          Get this type as an annotated type.
 ArrayT toArray()
          Get this type as an array.
 BooleanT toBoolean()
          Get this type as a boolean.
 ClassT toClass()
          Get this type as a class.
 EnumT toEnum()
          Get this type as an enum.
 EnumeratorT toEnumerator()
          Get this type as an enumerator.
 FloatT toFloat()
          Get this type as a float.
 FunctionT toFunction()
          Get this type as a function.
 InstantiatedT toInstantiated()
          Get this type as an instantiated type.
 IntegerT toInteger()
          Get this type as an integer.
 InterfaceT toInterface()
          Get this type as an interface.
 InternalT toInternal()
          Get this type as an internal type.
 InternalParameter toInternalParameter()
          Get this type as an internal parameter.
 LabelT toLabel()
          Get this type as a label.
 MethodT toMethod()
          Get this type as a method.
 NamedParameter toNamedParameter()
          Get this type as a named parameter.
 NumberT toNumber()
          Get this type as a number.
 PackageT toPackage()
          Get this type as a package.
 Parameter toParameter()
          Get this type as a type parameter.
 ParameterizedT toParameterized()
          Get this type as a parameterized type.
 PointerT toPointer()
          Get this type as a pointer.
 StructT toStruct()
          Get this type as a struct.
 StructOrUnionT toStructOrUnion()
          Get this type as a struct or union.
 Tagged toTagged()
          Get this type as a tagged type.
 TupleT toTuple()
          Get this type as an tuple.
 UnionT toUnion()
          Get this type as a union.
 UnitT toUnit()
          Get this type as a unit type.
 VariableT toVariable()
          Get this type as a variable.
 VariantT toVariant()
          Get this type as an variant.
 VoidT toVoid()
          Get this type as a void type.
 Wildcard toWildcard()
          Get this type as a wildcard.
 WrappedT toWrapped()
          Get this type as a wrapped type.
 void trace(Runtime runtime)
          Trace this type to the runtime's console.
 Type.Tag wtag()
          Get this wrapped type's tag.
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, get, getBoolean, getBooleanProperty, getGeneric, getList, getName, getNode, getProperty, getString, getStringProperty, getTokenText, hasName, hasProperty, hasTraversal, indexOf, isAnnotation, isEmpty, isGeneric, isList, isToken, iterator, lastIndexOf, remove, set, size, strip, toAnnotation, toList, toString, toToken, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Type

public Type()
Create a new type. The newly created type does not have any annotations and is not sealed.


Type

public Type(Type template)
Create a new type. The newly created type is not sealed. Its annotations are a copy of the specified template's annotations.

Parameters:
template - The type whose annotations to copy.
Method Detail

copy

public abstract Type copy()
Create a deep copy of this type. The resulting type is not sealed.

Returns:
A deep copy of this type.

isSealed

public boolean isSealed()
Determine whether this type is sealed.

Returns:
true if this type is sealed.

seal

public Type seal()
Seal this type. Subclasses that reference other types must override this method and, if the instance is not sealed, first invoke the superclass' version and then seal all referenced types. For example, if a subclass references a single type type, the corresponding overridden method reads:
 public Type seal() {
   if (! isSealed()) {
     super.seal();
     type.seal();
   }
   return this;
 }
 
First testing whether a type is sealed and then invoking the superclass' seal() method avoids infinite recursions for mutually recursive types.

Returns:
This type.
See Also:
seal(List)

checkNotSealed

protected void checkNotSealed()
Ensure that this type is not sealed. This method must be called by any subclass before modifying its internal state.

Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

annotate

public Type annotate()
Annotate this type. If this type is not an annotated type or a sealed annotated type, this method wraps this type in a new AnnotatedT.

Returns:
The annotated type.

deannotate

public Type deannotate()
Deannotate this type. This method strips away any AnnotatedT from this type.

Returns:
The deannotated type.

setProperty

public java.lang.Object setProperty(java.lang.String name,
                                    java.lang.Object value)
Description copied from class: Node
Set the value of a property.

Overrides:
setProperty in class Node
Parameters:
name - The property name.
value - The new property value.
Returns:
The property's old value or null if the property didn't have a value.

removeProperty

public java.lang.Object removeProperty(java.lang.String name)
Description copied from class: Node
Remove a property.

Overrides:
removeProperty in class Node
Parameters:
name - The property name.
Returns:
The property's old value or null if the property didn't have a value.

properties

public java.util.Set<java.lang.String> properties()
Description copied from class: Node
Get the set of property names.

Overrides:
properties in class Node
Returns:
The set of property names.

hasLocation

public boolean hasLocation()
Determine whether this type or any wrapped type has a location. Calling this method on type t is equivalent to:
 t.hasLocation(true)
 

Specified by:
hasLocation in interface Locatable
Overrides:
hasLocation in class Node
Returns:
true if this type or any wrapped type has a location.
See Also:
hasLocation(boolean)

hasLocation

public boolean hasLocation(boolean forward)
Determine whether this type or any wrapped type has a location.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has a location.

getLocation

public Location getLocation()
Get this type's or any wrapped type's location. Calling this method on type t is equivalent to:
 t.getLocation(true)
 

Specified by:
getLocation in interface Locatable
Overrides:
getLocation in class Node
Returns:
The location or null if this type or any wrapped type does not have a location.
See Also:
getLocation(boolean)

getLocation

public Location getLocation(boolean forward)
Get this type's or any wrapped type's location.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
The location or null if this type or any wrapped type does not have a location.

locate

public Type locate(Location location)
Set this type's location.

Parameters:
location - The location.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

locate

public Type locate(Locatable locatable)
Set this type's location.

Parameters:
locatable - The locatable.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

setLocation

public void setLocation(Location location)
Description copied from interface: Locatable
Set this object's location.

Specified by:
setLocation in interface Locatable
Overrides:
setLocation in class Node
Parameters:
location - This object's location.

setLocation

public void setLocation(Locatable locatable)
Description copied from interface: Locatable
Set this object's location to the specified locatable's location.

Specified by:
setLocation in interface Locatable
Overrides:
setLocation in class Node
Parameters:
locatable - The locatable object.

hasLanguage

public boolean hasLanguage()
Determine whether this type or any wrapped type has a language. Calling this method on type t is equivalent to:
 t.hasLanguage(true)
 

Returns:
true if this type or any wrapped type has a language.
See Also:
hasLanguage(boolean)

hasLanguage

public boolean hasLanguage(boolean forward)
Determine whether this type or any wrapped type has a language.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has a language.

getLanguage

public Language getLanguage()
Get this type's or any wrapped type's language. Calling this method on type t is equivalent to:
 t.getLanguage(true)
 

Returns:
The language or null if this type or any wrapped type does not have a language.
See Also:
getLanguage(boolean)

getLanguage

public Language getLanguage(boolean forward)
Get this type's or any wrapped type's language.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
The language or null if this type or any wrapped type does not have a language.

language

public Type language(Language language)
Set this type's language.

Parameters:
language - The language.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

hasScope

public boolean hasScope()
Determine whether this type or any wrapped type has a scope. Calling this method on type t is equivalent to:
 t.hasScope(true)
 

Returns:
true if this type or any wrapped type has a scope.
See Also:
hasScope(boolean)

hasScope

public boolean hasScope(boolean forward)
Determine whether this type or any wrapped type has a scope.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has a scope.

getScope

public java.lang.String getScope()
Get this type's or any wrapped type's scope. Calling this method on type t is equivalent to:
 t.getScope(true)
 

Returns:
The scope or null if this type or any wrapped type does not have a scope.
See Also:
getScope(boolean)

getScope

public java.lang.String getScope(boolean forward)
Get this type's or any wrapped type's scope.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
The scope or null if this type or any wrapped type does not have a scope.

scope

public Type scope(java.lang.String scope)
Set this type's scope.

Parameters:
scope - The scope.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

hasConstant

public boolean hasConstant()
Determine whether this type or any wrapped type has a constant. Calling this method on type t is equivalent to:
 t.hasConstant(true)
 

Returns:
true if this type has a constant.
See Also:
hasConstant(boolean)

hasConstant

public boolean hasConstant(boolean forward)
Determine whether this type or any wrapped type has a constant.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has a constant.

getConstant

public Constant getConstant()
Get this type's or any wrapped type's constant. Calling this method on type t is equivalent to:
 t.getConstant(true)
 

Returns:
The constant or null if this type or any wrapped type does not have a constant.
See Also:
getConstant(boolean)

getConstant

public Constant getConstant(boolean forward)
Get this type's or any wrapped type's constant.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
The constant or null if this type or any wrapped type does not have a constant.

constant

public Type constant(boolean value)
Set this type's constant.

Parameters:
value - The value.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.
See Also:
constant(Object)

constant

public Type constant(java.lang.Object value)
Set this type's constant.

Parameters:
value - The value.
Returns:
This type.
Throws:
java.lang.IllegalArgumentException - Signals an invalid value.
java.lang.IllegalStateException - Signals that this type is sealed.

hasShape

public boolean hasShape()
Determine whether this type or any wrapped type has a shape. Calling this method on type t is equivalent to:
 t.hasShape(true)
 

Returns:
true if this type or any wrapped type has a shape.
See Also:
hasShape(boolean)

hasShape

public boolean hasShape(boolean forward)
Determine whether this type or any wrapped type has a shape.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has a shape.

getShape

public Reference getShape()
Get this type's or any wrapped type's shape. Calling this method on type t is equivalent to:
 t.getShape(true)
 

Returns:
The shape or null if this type or any wrapped type does not have a shape.
See Also:
getShape(boolean)

getShape

public Reference getShape(boolean forward)
Get this type's or any wrapped type's shape.

Parameters:
forward - The flag for whether to forward this method across wrapped types.
Returns:
The shape or null if this type or any wrapped type does not have a shape.

shape

public Type shape(boolean isStatic,
                  java.lang.String name)
Set this type's shape to a variable reference with the specified name.

Parameters:
isStatic - The flag for whether the variable is static.
name - The variable name.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.
See Also:
StaticReference, DynamicReference, shape(Reference)

shape

public Type shape(Reference shape)
Set this type's shape.

Parameters:
shape - The shape represented as a reference.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

hasAttributes

public boolean hasAttributes()
Determine whether this type has any attributes. Note that this method does not check any wrapped types.

Returns:
true if this type has any attributes.

attributes

public java.util.List<Attribute> attributes()
Get this type's attributes.

Returns:
This type's attributes.

hasAttribute

public boolean hasAttribute(Attribute att)
Determine whether this type or any wrapped type has the specified attribute. Calling this method on type t is equivalent to:
 t.hasAttribute(att, true)
 

Parameters:
att - The attribute.
Returns:
true if this type or any wrapped type has the attribute.
See Also:
hasAttribute(Attribute,boolean)

hasAttribute

public boolean hasAttribute(Attribute att,
                            boolean forward)
Determine whether this type or any wrapped type has the specified attribute.

Parameters:
att - The attribute.
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has the attribute.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Determine whether this type has an attribute with the specified name. Calling this method on type t is equivalent to:
 null != t.getAttribute(name, true)
 

Parameters:
name - The name.
Returns:
true if this type or any wrapped type has an attribute with the specified name.
See Also:
getAttribute(String,boolean)

hasAttribute

public boolean hasAttribute(java.lang.String name,
                            boolean forward)
Determine whether this type has an attribute with the specified name. Calling this method on type t is equivalent to:
 null != t.getAttribute(name, forward)
 

Parameters:
name - The name.
forward - The flag for whether to forward this method across wrapped types.
Returns:
true if this type or any wrapped type has an attribute with the specified name.

getAttribute

public Attribute getAttribute(java.lang.String name)
Get the attribute with the specified name. Calling this method on type t is equivalent to:
 t.getAttribute(name, true)
 

Parameters:
name - The name.
Returns:
An attribute with that name or null if this type or any wrapped type does not have such an attribute.
See Also:
getAttribute(String,boolean)

getAttribute

public Attribute getAttribute(java.lang.String name,
                              boolean forward)
Get the attribute with the specified name.

Parameters:
name - The name.
forward - The flag for whether to forward this method across wrapped types.
Returns:
An attribute with the name or null if this or any wrapped type does not have such an attribute.

addAttribute

public void addAttribute(Attribute att)
Add the specified attribute. This method adds the specified attribute to this type's list of attributes — without checking whether the type already has that attribute. For almost all applications of attributes, it is preferable to use attribute(Attribute), attribute(List), or attribute(Type).

Parameters:
att - The new attribute.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

removeAttribute

public boolean removeAttribute(Attribute att)
Remove the specified attribute. Note that this method does not remove the attribute from any wrapped types.

Parameters:
att - The attribute.
Returns:
true if this type had the specified attribute.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

attribute

public Type attribute(Attribute att)
Annotate this type with the specified attribute. If this type or any wrapped type does not have the specified attribute, this method adds the attribute to this type's list of attributes.

Parameters:
att - The attribute.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

attribute

public Type attribute(java.util.List<Attribute> attributes)
Annotate this type with the specified attributes.

Parameters:
attributes - The attributes.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.
See Also:
attribute(Attribute)

attribute

public Type attribute(Type template)
Annotate this type with the specified type's attributes.

Parameters:
template - The type whose annotations to copy.
Returns:
This type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

mark

public void mark(Node node)
Mark the specified node as having this type. This method sets the node's type property to this type.

Parameters:
node - The node.
Throws:
java.lang.IllegalArgumentException - Signals that the node already has a type property.

hasTag

public boolean hasTag(Type.Tag tag)
Determine whether this type has the specified tag. Invocations to this method are forwarded across wrapped types. Calling this method on type t is equivalent to:
 tag == t.tag()
 

Parameters:
tag - The tag.
Returns:
true if this type has the specified tag.
See Also:
tag()

tag

public abstract Type.Tag tag()
Get this type's tag. Invocations to this method are forwarded across wrapped types.

Returns:
This type's tag.
See Also:
wtag()

hasWTag

public boolean hasWTag(Type.Tag tag)
Determine whether this wrapped type has the specified tag. Invocations to this method are not forwarded across wrapped types. Calling this method on type t is equivalent to:
 tag == wtag()
 

Parameters:
tag - The tag.
Returns:
true if this wrapped type has the specified tag.
See Also:
wtag()

wtag

public Type.Tag wtag()
Get this wrapped type's tag. Invocations to this method are not forwarded across wrapped types.

Returns:
This wrapped type's tag.
See Also:
tag()

isError

public boolean isError()
Determine whether this type is an error.

Returns:
true if this type is internal.

hasError

public boolean hasError()
Determine whether this type has an error. This method identifies the error type even if it is wrapped. Calling this method on type t is equivalent to:
 Type.Tag.Error == tag()
 

Returns:
true if this type has an error.
See Also:
tag()

isParameter

public boolean isParameter()
Determine whether this type is a type parameter.

Returns:
true if this type is a parameter.

toParameter

public Parameter toParameter()
Get this type as a type parameter.

Returns:
This type as a parameter.
Throws:
java.lang.ClassCastException - Signals that this type is not a parameter.

isNamedParameter

public boolean isNamedParameter()
Determine whether this type is a named parameter.

Returns:
true if this type is a named parameter.

toNamedParameter

public NamedParameter toNamedParameter()
Get this type as a named parameter.

Returns:
This type as a named parameter.
Throws:
java.lang.ClassCastException - Signals that this type is not a named parameter.

isInternalParameter

public boolean isInternalParameter()
Determine whether this type is an internal parameter.

Returns:
true if this type is an internal parameter.

toInternalParameter

public InternalParameter toInternalParameter()
Get this type as an internal parameter.

Returns:
This type as an internal parameter.
Throws:
java.lang.ClassCastException - Signals that this type is not an internal parameter.

isWildcard

public boolean isWildcard()
Determine whether this type is a wildcard.

Returns:
true if this type is a wildcard.

toWildcard

public Wildcard toWildcard()
Get this type as a wildcard.

Returns:
This type as a wildcard.
Throws:
java.lang.ClassCastException - Signals that this type is not a wildcard.

isVoid

public boolean isVoid()
Determine whether this type is void.

Returns:
true if this type is void.

toVoid

public VoidT toVoid()
Get this type as a void type.

Returns:
This type as a void type.
Throws:
java.lang.ClassCastException - Signals that this type is not a void type.

isUnit

public boolean isUnit()
Determine whether this type is the unit type.

Returns:
true if this type is the unit type.

toUnit

public UnitT toUnit()
Get this type as a unit type.

Returns:
This type as a unit type.
Throws:
java.lang.ClassCastException - Signals that this type is not a unit type.

isBoolean

public boolean isBoolean()
Determine whether this type is a boolean.

Returns:
true if this type is a boolean.

toBoolean

public BooleanT toBoolean()
Get this type as a boolean.

Returns:
This type as a boolean.
Throws:
java.lang.ClassCastException - Signals that this type is a not a boolean.

isNumber

public boolean isNumber()
Determine whether this type is a number.

Returns:
true if this type is a number.

toNumber

public NumberT toNumber()
Get this type as a number.

Returns:
This type as a number.
Throws:
java.lang.ClassCastException - Signals that this type is not a number.

isInteger

public boolean isInteger()
Determine whether this type is an integer.

Returns:
true if this type is an integer.

toInteger

public IntegerT toInteger()
Get this type as an integer.

Returns:
This type as an integer.
Throws:
java.lang.ClassCastException - Signals that this type is not an integer.

isFloat

public boolean isFloat()
Determine whether this type is a float.

Returns:
true if this type is a float.

toFloat

public FloatT toFloat()
Get this type as a float.

Returns:
This type as a float.
Throws:
java.lang.ClassCastException - Signals that this type is not a float.

isInternal

public boolean isInternal()
Determine whether this type is internal.

Returns:
true if this type is internal.

toInternal

public InternalT toInternal()
Get this type as an internal type.

Returns:
This type as an internal type.
Throws:
java.lang.ClassCastException - Signals that this type is not an internal type.

isLabel

public boolean isLabel()
Determine whether this type is a label.

Returns:
true if this type is a label.

toLabel

public LabelT toLabel()
Get this type as a label.

Returns:
This type as a label.
Throws:
java.lang.ClassCastException - Signals that this type is not a label.

isPackage

public boolean isPackage()
Determine whether this type is a package.

Returns:
true if this type is a package.

toPackage

public PackageT toPackage()
Get this type as a package.

Returns:
This type as a package.
Throws:
java.lang.ClassCastException - Signals that this type is not a package.

isDerived

public boolean isDerived()
Determine whether this type is derived.

Returns:
true if this type is derived.

isPointer

public boolean isPointer()
Determine whether this type is a pointer.

Returns:
true if this type is a pointer.

toPointer

public PointerT toPointer()
Get this type as a pointer.

Returns:
This type as a pointer.
Throws:
java.lang.ClassCastException - Signals that this type is not a pointer.

isArray

public boolean isArray()
Determine whether this type is an array.

Returns:
true if this type is an array.

toArray

public ArrayT toArray()
Get this type as an array.

Returns:
This type as an array.
Throws:
java.lang.ClassCastException - Signals that this type is not an array.

hasStructOrUnion

public boolean hasStructOrUnion()
Determine whether this type contains a struct or union.

Returns:
true if this type contains a struct or union.

toStructOrUnion

public StructOrUnionT toStructOrUnion()
Get this type as a struct or union.

Returns:
This type as a struct or union.
Throws:
java.lang.ClassCastException - Signals that this type is not a struct or union.

isStruct

public boolean isStruct()
Determine whether this type is a struct.

Returns:
true if this type is a struct.

toStruct

public StructT toStruct()
Get this type as a struct.

Returns:
This type as a struct.
Throws:
java.lang.ClassCastException - Signas that this type is not a struct.

isUnion

public boolean isUnion()
Determine whether this type is a union.

Returns:
true if this type is a union.

toUnion

public UnionT toUnion()
Get this type as a union.

Returns:
This type as a union.
Throws:
java.lang.ClassCastException - Signals that this type is not a union.

isFunction

public boolean isFunction()
Determine whether this type is a function.

Returns:
true if this type is a function.

toFunction

public FunctionT toFunction()
Get this type as a function.

Returns:
This type has a function.
Throws:
java.lang.ClassCastException - Signals that this type is not a function.

isMethod

public boolean isMethod()
Determine whether this type is a method.

Returns:
true if this type is a method.

toMethod

public MethodT toMethod()
Get this type as a method.

Returns:
This type as a method.
Throws:
java.lang.ClassCastException - Signals that this type is not a method.

isClass

public boolean isClass()
Determine whether this type is a class.

Returns:
true if this type is a class.

toClass

public ClassT toClass()
Get this type as a class.

Returns:
This type as a class.
Throws:
java.lang.ClassCastException - Signals that this type is not a class.

isInterface

public boolean isInterface()
Determine whether this type is an interface.

Returns:
true if this type is an interface.

toInterface

public InterfaceT toInterface()
Get this type as an interface.

Returns:
This type as an interface.
Throws:
java.lang.ClassCastException - Signals that this type is not an interface.

isTuple

public boolean isTuple()
Determine whether this type is an tuple.

Returns:
true if this type is an tuple.

toTuple

public TupleT toTuple()
Get this type as an tuple.

Returns:
This type as an tuple.
Throws:
java.lang.ClassCastException - Signals that this type is not an tuple.

isVariant

public boolean isVariant()
Determine whether this type is an variant.

Returns:
true if this type is an variant.

toVariant

public VariantT toVariant()
Get this type as an variant.

Returns:
This type as an variant.
Throws:
java.lang.ClassCastException - Signals that this type is not an variant.

isWrapped

public boolean isWrapped()
Determine whether this type is wrapped.

Returns:
true if this type is wrapped.

toWrapped

public WrappedT toWrapped()
Get this type as a wrapped type.

Returns:
This type as a wrapped type.
Throws:
java.lang.ClassCastException - Signals that this type is not wrapped.

isAnnotated

public boolean isAnnotated()
Determine whether this type is annotated.

Returns:
true if this type is annotated.

hasAnnotated

public boolean hasAnnotated()
Determine whether this type has an annotated type.

Returns:
true if this type has an annotated type.

toAnnotated

public AnnotatedT toAnnotated()
Get this type as an annotated type.

Returns:
This type as an annotated type.
Throws:
java.lang.ClassCastException - Signas that this type is not an annotated type.

isAlias

public boolean isAlias()
Determine whether this type is an alias.

Returns:
true if this type is an alias.

hasAlias

public boolean hasAlias()
Determine whether this type contains an alias.

Returns:
true if this type contains an alias.

toAlias

public AliasT toAlias()
Get this type as an alias.

Returns:
This type as an alias.
Throws:
java.lang.ClassCastException - Signals that this type is not an alias.

isEnum

public boolean isEnum()
Determine whether this type is an enum.

Returns:
true if this type is an enum.

hasEnum

public boolean hasEnum()
Determine whether this type contains an enum.

Returns:
true if this type contains an enum.

toEnum

public EnumT toEnum()
Get this type as an enum.

Returns:
This type as an enum.
Throws:
java.lang.ClassCastException - Signals that this type is not an enum.

isEnumerator

public boolean isEnumerator()
Determine whether this type is an enumerator.

Returns:
true if this type is an enumerator.

hasEnumerator

public boolean hasEnumerator()
Determine whether this type contains an enumerator.

Returns:
true if this type contains an enumerator.

toEnumerator

public EnumeratorT toEnumerator()
Get this type as an enumerator.

Returns:
This type as an enumerator.
Throws:
java.lang.ClassCastException - Signals that this type is not an enumerator.

isInstantiated

public boolean isInstantiated()
Determine whether this type is instantiated.

Returns:
true if this type is instantiated.

hasInstantiated

public boolean hasInstantiated()
Determine whether this type has an instantiated type.

Returns:
true if this type has an instantiated type.

toInstantiated

public InstantiatedT toInstantiated()
Get this type as an instantiated type.

Returns:
This type as an instantiated type.
Throws:
java.lang.ClassCastException - Signas that this type is not an instantiated type.

isParameterized

public boolean isParameterized()
Determine whether this type is parameterized.

Returns:
true if this type is parameterized.

hasParameterized

public boolean hasParameterized()
Determine whether this type has a parameterized type.

Returns:
true if this type has a parameterized type.

toParameterized

public ParameterizedT toParameterized()
Get this type as a parameterized type.

Returns:
This type as a parameterized type.
Throws:
java.lang.ClassCastException - Signas that this type is not a parameterized type.

isVariable

public boolean isVariable()
Determine whether this type is a variable.

Returns:
true if this type is a variable.

hasVariable

public boolean hasVariable()
Determine whether this type contains a variable.

Overrides:
hasVariable in class Node
Returns:
true if this type contains a variable.
See Also:
Node.hasTraversal()

toVariable

public VariableT toVariable()
Get this type as a variable.

Returns:
This type as a variable.
Throws:
java.lang.ClassCastException - Signals that this type does not contain a variable.

hasTagged

public boolean hasTagged()
Determine whether this type is tagged.

Returns:
true if this type is tagged.

toTagged

public Tagged toTagged()
Get this type as a tagged type.

Returns:
This type as a tagged type.
Throws:
java.lang.ClassCastException - Signals that this type is not tagged.
See Also:
hasTagged()

isConcrete

public boolean isConcrete()
Determine whether this type is concrete. This method returns true if this type is not parameterized or is both parameterized and instantiated.

Returns:
true if this type is concrete.

resolve

public Type resolve()
Resolve this type. This method removes any symbolic information, i.e., wrapped types, and returns the underlying, "raw" type.

Returns:
The resolved type.

trace

public void trace(Runtime runtime)
Trace this type to the runtime's console. This method prints this type to the runtime's console using a new instance of TypePrinter; it is useful for debugging.

Parameters:
runtime - The runtime.

cast

public static Type cast(java.lang.Object type)
Cast the specified object to a type.

Parameters:
type - The type as an object.
Returns:
The type as a type.
Throws:
java.lang.ClassCastException - Signals that the specified object is not a type.

resolve

public static Type resolve(java.lang.Object type)
Resolve the specified object as type.

Parameters:
type - The type.
Returns:
The resolved type.
Throws:
java.lang.ClassCastException - Signals that the specified object is not a type.

copy

public static <T extends Type> java.util.List<T> copy(java.util.List<T> types)
Copy the specified list of types. A null list is ignored.

Parameters:
types - The list of types.
Returns:
A new list of the types' copies.

seal

public static <T extends Type> java.util.List<T> seal(java.util.List<T> types)
Seal the specified list of types. A null list is ignored.

Parameters:
types - The list of types.
Returns:
An unmodifiable list of sealed types.


Copyright © 2012. All Rights Reserved.