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.util.List;
022:
023: import xtc.util.Utilities;
024:
025: /**
026: * The superclass of class and interface types.
027: *
028: * @author Robert Grimm
029: * @version $Revision: 1.21 $
030: */
031: public abstract class ClassOrInterfaceT extends DerivedT {
032:
033: /** The fully qualfied name. */
034: protected String qname;
035:
036: /** The list of {@link InterfaceT interfaces}. */
037: protected List<Type> interfaces;
038:
039: /** The list of {@link VariableT fields}. */
040: protected List<Type> fields;
041:
042: /** The list of {@link MethodT methods}. */
043: protected List<Type> methods;
044:
045: /**
046: * Create a new class or interface type.
047: *
048: * @param template The template whose annotations to copy.
049: * @param qname The fully qualified name.
050: * @param interfaces The list of interfaces.
051: * @param fields The list of fields.
052: * @param methods The list of methods.
053: */
054: public ClassOrInterfaceT(Type template, String qname,
055: List<Type> interfaces, List<Type> fields, List<Type> methods) {
056: super (template);
057: this .qname = qname;
058: this .interfaces = interfaces;
059: this .fields = fields;
060: this .methods = methods;
061: }
062:
063: public Type seal() {
064: if (!isSealed()) {
065: super .seal();
066: interfaces = Type.seal(interfaces);
067: fields = Type.seal(fields);
068: methods = Type.seal(methods);
069: }
070: return this ;
071: }
072:
073: /**
074: * Get the qualified name.
075: *
076: * @return The qualified name.
077: */
078: public String getQName() {
079: return qname;
080: }
081:
082: /**
083: * Get the qualifier for this class' or interface's name.
084: *
085: * @return The qualifier.
086: */
087: public String getQualifier() {
088: return Utilities.getQualifier(qname);
089: }
090:
091: /**
092: * Get the unqualified name.
093: *
094: * @return The unqualified name.
095: */
096: public String getName() {
097: return Utilities.getName(qname);
098: }
099:
100: /**
101: * Get the list of interfaces.
102: *
103: * @return The list of interfaces.
104: */
105: public List<Type> getInterfaces() {
106: return interfaces;
107: }
108:
109: /**
110: * Get the list of fields.
111: *
112: * @return The list of fields.
113: */
114: public List<Type> getFields() {
115: return fields;
116: }
117:
118: /**
119: * Get the list of methods.
120: *
121: * @return The list of methods.
122: */
123: public List<Type> getMethods() {
124: return methods;
125: }
126:
127: public int hashCode() {
128: return qname.hashCode();
129: }
130:
131: /**
132: * Determine whether this type equals the specified object. This
133: * class or interface equals the specified object if the specified
134: * object also is a class or interface with the same name.
135: *
136: * @param o The object.
137: * @return <code>true</code> if this type equals the object.
138: */
139: public boolean equals(Object o) {
140: if (!(o instanceof Type))
141: return false;
142: Type t = resolve(o);
143:
144: if (this == t)
145: return true;
146: if (!getClass().equals(t.getClass()))
147: return false;
148: return qname.equals(((ClassOrInterfaceT) t).qname);
149: }
150:
151: }
|