001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 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: import java.util.ArrayList;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: /**
028: * A parameterized type.
029: *
030: * @author Robert Grimm
031: * @version $Revision: 1.2 $
032: */
033: public class ParameterizedT extends WrappedT {
034:
035: /** The list of parameters. */
036: private List<Parameter> parameters;
037:
038: /**
039: * Create a new parameterized type.
040: *
041: * @param parameter The single parameter.
042: * @param type The type.
043: */
044: public ParameterizedT(Parameter parameter, Type type) {
045: super (type);
046: this .parameters = new ArrayList<Parameter>(1);
047: this .parameters.add(parameter);
048: }
049:
050: /**
051: * Create a new parameterized type.
052: *
053: * @param parameters The parameters.
054: * @param type The type.
055: */
056: public ParameterizedT(List<Parameter> parameters, Type type) {
057: super (type);
058: this .parameters = parameters;
059: }
060:
061: /**
062: * Create a new parameterized type.
063: *
064: * @param template The type whose annotations to copy.
065: * @param parameters The parameters.
066: * @param type The type.
067: */
068: public ParameterizedT(Type template, List<Parameter> parameters,
069: Type type) {
070: super (template, type);
071: this .parameters = parameters;
072: }
073:
074: public ParameterizedT copy() {
075: return new ParameterizedT(this , Type.copy(parameters),
076: getType().copy());
077: }
078:
079: public Type seal() {
080: if (!isSealed()) {
081: super .seal();
082: parameters = Type.seal(parameters);
083: }
084: return this ;
085: }
086:
087: public Type.Tag wtag() {
088: return Type.Tag.PARAMETERIZED;
089: }
090:
091: public boolean isParameterized() {
092: return true;
093: }
094:
095: public boolean hasParameterized() {
096: return true;
097: }
098:
099: public ParameterizedT toParameterized() {
100: return this ;
101: }
102:
103: /**
104: * Get this parameterized type's parameters.
105: *
106: * @return The parameters.
107: */
108: public List<Parameter> getParameters() {
109: return parameters;
110: }
111:
112: public void write(Appendable out) throws IOException {
113: out.append('<');
114: for (Iterator<Parameter> iter = parameters.iterator(); iter
115: .hasNext();) {
116: iter.next().write(out);
117: if (iter.hasNext())
118: out.append(", ");
119: }
120: out.append("> ");
121: getType().write(out);
122: }
123:
124: }
|