TypeDefinitionNode.java
package edu.udel.cis.vsl.tass.ast.impl;
import java.util.NoSuchElementException;
import edu.udel.cis.vsl.tass.ast.IF.type.TypeNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.ASTNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.IdentifierNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.TypeDefinitionNodeIF;
/**
* A type definition.
*
* @author Timothy K. Zirkel (zirkel)
*
*/
public class TypeDefinitionNode extends ASTNode implements TypeDefinitionNodeIF {
private IdentifierNodeIF identifier;
private TypeNodeIF type;
public TypeDefinitionNode(long id) {
super(id);
}
/**
* The parameter identifier is the name of this type definition.
* The type is the base type being given a new name.
*/
public TypeDefinitionNode(long id, IdentifierNodeIF identifier,
TypeNodeIF type) {
super(id);
this.identifier = identifier;
this.type = type;
}
@Override
public int numChildren() {
return 2;
}
@Override
public ASTNodeIF child(int index) throws NoSuchElementException {
if (index == 0) {
return identifier;
} else if (index == 1) {
return type;
}
throw new NoSuchElementException("Node " + id()
+ " does not have a child with index " + index + ".");
}
@Override
public void setChild(int i, ASTNodeIF child) throws NoSuchElementException {
if (i ==0) {
this.identifier = (IdentifierNodeIF) child;
} else if (i ==1) {
this.type = (TypeNodeIF) child;
}
throw new NoSuchElementException("Node " + id()
+ " does not have a child with index " + i + ".");
}
@Override
public IdentifierNodeIF identifier() {
return identifier;
}
@Override
public TypeNodeIF type() {
return type;
}
@Override
public void setIdentifier(IdentifierNodeIF identifier) {
this.identifier = identifier;
}
@Override
public void setType(TypeNodeIF type) {
this.type = type;
}
}