001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2005-2007 Robert Grimm
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * version 2 as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.type;
020:
021: import java.io.IOException;
022:
023: /**
024: * A type alias.
025: *
026: * @author Robert Grimm
027: * @version $Revision: 1.28 $
028: */
029: public class AliasT extends WrappedT {
030:
031: /** The name. */
032: private String name;
033:
034: /**
035: * Create a new type alias.
036: *
037: * @param name The name.
038: */
039: public AliasT(String name) {
040: super (null);
041: this .name = name;
042: }
043:
044: /**
045: * Create a new type alias.
046: *
047: * @param name The name.
048: * @param type The type.
049: */
050: public AliasT(String name, Type type) {
051: super (type);
052: this .name = name;
053: }
054:
055: /**
056: * Create a new type alias.
057: *
058: * @param template The type whose annotations to copy.
059: * @param name The name.
060: * @param type The type.
061: */
062: public AliasT(Type template, String name, Type type) {
063: super (template, type);
064: this .name = name;
065: }
066:
067: /**
068: * Seal this alias. If this alias is incomplete, i.e., does not
069: * have a type, invocations to this method have no effect.
070: */
071: public Type seal() {
072: if (null != getType()) {
073: if (!isSealed()) {
074: super .seal();
075: }
076: }
077: return this ;
078: }
079:
080: public AliasT copy() {
081: return new AliasT(this , name, getType().copy());
082: }
083:
084: public Type.Tag wtag() {
085: return Type.Tag.ALIAS;
086: }
087:
088: public boolean isAlias() {
089: return true;
090: }
091:
092: public boolean hasAlias() {
093: return true;
094: }
095:
096: public AliasT toAlias() {
097: return this ;
098: }
099:
100: /**
101: * Get the name.
102: *
103: * @return The name.
104: */
105: public String getName() {
106: return name;
107: }
108:
109: public void write(Appendable out) throws IOException {
110: out.append("alias(");
111: out.append(name);
112: if (null != getType()) {
113: out.append(", ");
114: getType().write(out);
115: }
116: out.append(')');
117: }
118:
119: }
|