1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 package com.helger.jcodemodel;
42
43 import java.lang.reflect.Modifier;
44 import java.util.Iterator;
45 import java.util.List;
46
47 import javax.annotation.Nonnull;
48 import javax.annotation.Nullable;
49
50 import com.helger.jcodemodel.util.JCNameUtilities;
51
52
53
54
55
56
57
58
59
60
61
62 class JReferencedClass extends AbstractJClass implements IJDeclaration
63 {
64 private final Class <?> m_aClass;
65
66 JReferencedClass (@Nonnull final JCodeModel aOwner, @Nonnull final Class <?> aClass)
67 {
68 super (aOwner);
69 m_aClass = aClass;
70 assert !m_aClass.isArray ();
71 }
72
73 @Override
74 public String name ()
75 {
76 return m_aClass.getSimpleName ();
77 }
78
79 @Override
80 @Nonnull
81 public String fullName ()
82 {
83 return JCNameUtilities.getFullName (m_aClass);
84 }
85
86 @Override
87 public String binaryName ()
88 {
89 return m_aClass.getName ();
90 }
91
92 @Override
93 public AbstractJClass outer ()
94 {
95 final Class <?> p = m_aClass.getDeclaringClass ();
96 if (p == null)
97 return null;
98 return owner ().ref (p);
99 }
100
101 @Override
102 @Nonnull
103 public JPackage _package ()
104 {
105 final String name = fullName ();
106
107
108 if (name.indexOf ('[') != -1)
109 return owner ()._package ("");
110
111
112 final int idx = name.lastIndexOf ('.');
113 if (idx < 0)
114 return owner ()._package ("");
115 return owner ()._package (name.substring (0, idx));
116 }
117
118 @Override
119 public AbstractJClass _extends ()
120 {
121 final Class <?> sp = m_aClass.getSuperclass ();
122 if (sp == null)
123 {
124 if (isInterface ())
125 return owner ().ref (Object.class);
126 return null;
127 }
128 return owner ().ref (sp);
129 }
130
131 @Override
132 public Iterator <AbstractJClass> _implements ()
133 {
134 final Class <?> [] aInterfaces = m_aClass.getInterfaces ();
135 return new Iterator <AbstractJClass> ()
136 {
137 private int m_nIdx = 0;
138
139 public boolean hasNext ()
140 {
141 return m_nIdx < aInterfaces.length;
142 }
143
144 @Nonnull
145 public AbstractJClass next ()
146 {
147 return owner ().ref (aInterfaces[m_nIdx++]);
148 }
149
150 public void remove ()
151 {
152 throw new UnsupportedOperationException ();
153 }
154 };
155 }
156
157 @Override
158 public boolean isInterface ()
159 {
160 return m_aClass.isInterface ();
161 }
162
163 @Override
164 public boolean isAbstract ()
165 {
166 return Modifier.isAbstract (m_aClass.getModifiers ());
167 }
168
169 @Override
170 @Nullable
171 public JPrimitiveType getPrimitiveType ()
172 {
173 final Class <?> v = JCodeModel.boxToPrimitive.get (m_aClass);
174 if (v != null)
175 return AbstractJType.parse (owner (), v.getName ());
176 return null;
177 }
178
179 public void declare (final JFormatter f)
180 {
181
182 }
183
184 @Override
185 public JTypeVar [] typeParams ()
186 {
187
188 return super.typeParams ();
189 }
190
191 @Override
192 protected AbstractJClass substituteParams (final JTypeVar [] variables,
193 final List <? extends AbstractJClass> bindings)
194 {
195
196 return this;
197 }
198 }