xtc.type
Class VariantT

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.type.Type
          extended by xtc.type.DerivedT
              extended by xtc.type.VariantT
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable

public class VariantT
extends DerivedT

A variant type. Variants can be monomorphic or polymorphic, with the latter possibly sharing tuples with other variants. Monomorphic variants must be named and are compared through name equivalence. Polymorphic variants may be anonymous and are compared through structural equivalence.

Version:
$Revision: 1.12 $
Author:
Robert Grimm

Nested Class Summary
 
Nested classes/interfaces inherited from class xtc.type.Type
Type.Tag
 
Constructor Summary
VariantT(java.lang.String name)
          Create a new incomplete variant type.
VariantT(java.lang.String name, boolean polymorphic, java.util.List<TupleT> tuples)
          Create a new variant type.
VariantT(java.lang.String name, java.util.List<TupleT> tuples)
          Create a new variant type.
VariantT(Type template, java.lang.String name, boolean polymorphic, java.util.List<TupleT> tuples)
          Create a new variant type.
 
Method Summary
 VariantT copy()
          Create a deep copy of this type.
 boolean equals(java.lang.Object o)
          Determine whether this variant equals the specified object.
 java.lang.String getName()
          Get this variant's name.
 java.lang.String getQualifier()
          Get this variant's qualifier.
 java.lang.String getSimpleName()
          Get this variant's simple name.
 java.util.List<TupleT> getTuples()
          Get this variant's tuples.
 int hashCode()
           
 boolean isPolymorphic()
          Determine whether the variant is polymorphic.
 boolean isVariant()
          Determine whether this type is an variant.
 Type lookup(java.lang.String name)
          Look up the tuple with the specified name.
 Type lookupSimple(java.lang.String name)
          Look up the tuple with the specified simple name.
 Type seal()
          Seal this type.
 void setTuples(java.util.List<TupleT> tuples)
          Set this variant's tuples.
 Type.Tag tag()
          Get this type's tag.
 VariantT toVariant()
          Get this type as an variant.
 void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 
Methods inherited from class xtc.type.DerivedT
isDerived
 
Methods inherited from class xtc.type.Type
addAttribute, annotate, attribute, attribute, attribute, attributes, cast, checkNotSealed, constant, constant, copy, deannotate, getAttribute, getAttribute, getConstant, getConstant, getLanguage, getLanguage, getLocation, getLocation, getScope, getScope, getShape, getShape, hasAlias, hasAnnotated, hasAttribute, hasAttribute, hasAttribute, hasAttribute, hasAttributes, hasConstant, hasConstant, hasEnum, hasEnumerator, hasError, hasInstantiated, hasLanguage, hasLanguage, hasLocation, hasLocation, hasParameterized, hasScope, hasScope, hasShape, hasShape, hasStructOrUnion, hasTag, hasTagged, hasVariable, hasWTag, isAlias, isAnnotated, isArray, isBoolean, isClass, isConcrete, isEnum, isEnumerator, isError, isFloat, isFunction, isInstantiated, isInteger, isInterface, isInternal, isInternalParameter, isLabel, isMethod, isNamedParameter, isNumber, isPackage, isParameter, isParameterized, isPointer, isSealed, isStruct, isTuple, isUnion, isUnit, isVariable, isVoid, isWildcard, isWrapped, language, locate, locate, mark, properties, removeAttribute, removeProperty, resolve, resolve, scope, seal, setLocation, setLocation, setProperty, shape, shape, toAlias, toAnnotated, toArray, toBoolean, toClass, toEnum, toEnumerator, toFloat, toFunction, toInstantiated, toInteger, toInterface, toInternal, toInternalParameter, toLabel, toMethod, toNamedParameter, toNumber, toPackage, toParameter, toParameterized, toPointer, toStruct, toStructOrUnion, toTagged, toTuple, toUnion, toUnit, toVariable, toVoid, toWildcard, toWrapped, trace, wtag
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, get, getBoolean, getBooleanProperty, getGeneric, getList, getNode, getProperty, getString, getStringProperty, getTokenText, hasName, hasProperty, hasTraversal, indexOf, isAnnotation, isEmpty, isGeneric, isList, isToken, iterator, lastIndexOf, remove, set, size, strip, toAnnotation, toList, toString, toToken
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VariantT

public VariantT(java.lang.String name)
Create a new incomplete variant type. The new variant type is not polymorphic.

Parameters:
name - The name.
Throws:
java.lang.NullPointerException - Signals that the name is null.

VariantT

public VariantT(java.lang.String name,
                java.util.List<TupleT> tuples)
Create a new variant type. The new variant type is not polymorphic.

Parameters:
name - The name.
tuples - The tuples.
Throws:
java.lang.NullPointerException - Signals that the name is null.

VariantT

public VariantT(java.lang.String name,
                boolean polymorphic,
                java.util.List<TupleT> tuples)
Create a new variant type. Note that polymorphic variants may be anonymous, i.e., have a null name.

Parameters:
name - The name.
polymorphic - The flag for polymorphic variants.
tuples - The tuples.
Throws:
java.lang.NullPointerException - Signals that the name is null for a monomorphic variant.

VariantT

public VariantT(Type template,
                java.lang.String name,
                boolean polymorphic,
                java.util.List<TupleT> tuples)
Create a new variant type.

Parameters:
template - The type whose annotations to copy.
name - The name.
polymorphic - The flag for polymorphic variants.
tuples - The tuples.
Throws:
java.lang.NullPointerException - Signals that the name is null for a monomorphic variant.
Method Detail

seal

public Type seal()
Description copied from class: Type
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.

Overrides:
seal in class Type
Returns:
This type.
See Also:
Type.seal(List)

copy

public VariantT copy()
Description copied from class: Type
Create a deep copy of this type. The resulting type is not sealed.

Specified by:
copy in class Type
Returns:
A deep copy of this type.

tag

public Type.Tag tag()
Description copied from class: Type
Get this type's tag. Invocations to this method are forwarded across wrapped types.

Specified by:
tag in class Type
Returns:
This type's tag.
See Also:
Type.wtag()

isVariant

public boolean isVariant()
Description copied from class: Type
Determine whether this type is an variant.

Overrides:
isVariant in class Type
Returns:
true if this type is an variant.

toVariant

public VariantT toVariant()
Description copied from class: Type
Get this type as an variant.

Overrides:
toVariant in class Type
Returns:
This type as an variant.

getName

public java.lang.String getName()
Get this variant's name.

Overrides:
getName in class Node
Returns:
The name or null if this variant is anonymous.

getQualifier

public java.lang.String getQualifier()
Get this variant's qualifier.

Returns:
The qualifier or null if this variant does not have a qualified name.

getSimpleName

public java.lang.String getSimpleName()
Get this variant's simple name.

Returns:
The simple name or null if this variant is anonymous.

isPolymorphic

public boolean isPolymorphic()
Determine whether the variant is polymorphic.

Returns:
true if the variant is polymorphic.

lookup

public Type lookup(java.lang.String name)
Look up the tuple with the specified name.

Parameters:
name - The name.
Returns:
The tuple or ErrorT.TYPE if this variant has no such tuple.

lookupSimple

public Type lookupSimple(java.lang.String name)
Look up the tuple with the specified simple name.

Parameters:
name - The simple name.
Returns:
The first such tuple or ErrorT.TYPE if this variant has no such tuple.

getTuples

public java.util.List<TupleT> getTuples()
Get this variant's tuples.

Returns:
The list of tuples.

setTuples

public void setTuples(java.util.List<TupleT> tuples)
Set this variant's tuples.

Parameters:
tuples - The new list of tuples.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Determine whether this variant equals the specified object. This method implements name equivalence for non-polymorphic variants and structural equivalence for polymorphic variants.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object.
Returns:
true if this variant equals the object.

write

public void write(java.lang.Appendable out)
           throws java.io.IOException
Description copied from class: Node
Write a human readable representation to the specified appendable. If this node supports generic traversal, the default implementation writes this node in algebraic term-format; otherwise, it writes the string returned by Object.toString().

Overrides:
write in class Node
Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.


Copyright © 2012. All Rights Reserved.