01: package com.sun.codemodel;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: /**
07: * Represents a wildcard type like "? extends Foo".
08: *
09: * <p>
10: * Instances of this class can be obtained from {@link JClass#wildcard()}
11: *
12: * TODO: extend this to cover "? super Integer".
13: *
14: * <p>
15: * Our modeling of types are starting to look really ugly.
16: * ideally it should have been done somewhat like APT,
17: * but it's too late now.
18: *
19: * @author Kohsuke Kawaguchi
20: */
21: final class JTypeWildcard extends JClass {
22:
23: private final JClass bound;
24:
25: JTypeWildcard(JClass bound) {
26: super (bound.owner());
27: this .bound = bound;
28: }
29:
30: public String name() {
31: return "? extends " + bound.name();
32: }
33:
34: public String fullName() {
35: return "? extends " + bound.fullName();
36: }
37:
38: public JPackage _package() {
39: return null;
40: }
41:
42: /**
43: * Returns the class bound of this variable.
44: *
45: * <p>
46: * If no bound is given, this method returns {@link Object}.
47: */
48: public JClass _extends() {
49: if (bound != null)
50: return bound;
51: else
52: return owner().ref(Object.class);
53: }
54:
55: /**
56: * Returns the interface bounds of this variable.
57: */
58: public Iterator<JClass> _implements () {
59: return bound._implements ();
60: }
61:
62: public boolean isInterface() {
63: return false;
64: }
65:
66: public boolean isAbstract() {
67: return false;
68: }
69:
70: protected JClass substituteParams(JTypeVar[] variables,
71: List<JClass> bindings) {
72: JClass nb = bound.substituteParams(variables, bindings);
73: if (nb == bound)
74: return this ;
75: else
76: return new JTypeWildcard(nb);
77: }
78:
79: public void generate(JFormatter f) {
80: if (bound._extends() == null)
81: f.p("?"); // instead of "? extends Object"
82: else
83: f.p("? extends").g(bound);
84: }
85: }
|