01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2007 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.type;
20:
21: import java.io.IOException;
22:
23: /**
24: * A type wildcard.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.2 $
28: */
29: public class Wildcard extends Parameter {
30:
31: /** The canonical wildcard. */
32: public static final Wildcard TYPE;
33:
34: static {
35: TYPE = new Wildcard();
36: TYPE.seal();
37: }
38:
39: /** Create a new wildcard. */
40: public Wildcard() {
41: super ("?");
42: }
43:
44: /**
45: * Create a new wildcard.
46: *
47: * @param template The type whose annotations to copy.
48: */
49: public Wildcard(Type template) {
50: super (template, "?");
51: }
52:
53: public Wildcard copy() {
54: return new Wildcard(this );
55: }
56:
57: public Type.Tag tag() {
58: return Type.Tag.WILDCARD;
59: }
60:
61: public boolean isWildcard() {
62: return true;
63: }
64:
65: public Wildcard toWildcard() {
66: return this ;
67: }
68:
69: /**
70: * Bind this wildcard. Wildcards cannot be bound.
71: *
72: * @param type The type.
73: * @throws IllegalStateException Signals that wildcards cannot be
74: * bound.
75: */
76: public void bind(Type type) {
77: throw new IllegalStateException("Unable to bind wildcard");
78: }
79:
80: public Type lookup() {
81: return this ;
82: }
83:
84: public int hashCode() {
85: return 63;
86: }
87:
88: public boolean equals(Object o) {
89: if (!(o instanceof Type))
90: return false;
91: Type t = resolve(o);
92:
93: if (this == t)
94: return true;
95: return t.isWildcard();
96: }
97:
98: }
|