1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.beans.gen;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.SortedSet;
21 import java.util.TreeSet;
22
23
24
25
26
27
28 class GeneratableBean {
29
30
31 private final SortedSet<String> currentImports = new TreeSet<String>();
32
33 private final SortedSet<String> newImports = new TreeSet<String>();
34
35 private int lastImportLine;
36
37 private boolean constructable;
38
39 private String typeFull;
40
41 private String typeRaw;
42
43 private String typeGenericName;
44
45 private String typeGenericExtends;
46
47 private String superTypeFull;
48
49 private String superTypeRaw;
50
51 private String superTypeGeneric;
52
53 private List<GeneratableProperty> properties = new ArrayList<GeneratableProperty>();
54
55 private boolean manualEqualsHashCode;
56
57
58
59
60 GeneratableBean() {
61 }
62
63
64
65
66
67 public SortedSet<String> getCurrentImports() {
68 return currentImports;
69 }
70
71
72
73
74
75 public SortedSet<String> getNewImports() {
76 return newImports;
77 }
78
79
80
81
82
83 public void ensureImport(Class<?> cls) {
84 if (currentImports.contains(cls.getName()) == false) {
85 newImports.add(cls.getName());
86 }
87 }
88
89
90
91
92
93 public int getImportInsertLocation() {
94 return lastImportLine;
95 }
96
97
98
99
100
101 public void setImportInsertLocation(int location) {
102 lastImportLine = location;
103 }
104
105
106
107
108
109 public boolean isConstructable() {
110 return constructable;
111 }
112
113
114
115
116
117 public void setConstructable(boolean constructable) {
118 this.constructable = constructable;
119 }
120
121
122
123
124
125 public boolean isManualEqualsHashCode() {
126 return manualEqualsHashCode;
127 }
128
129
130
131
132
133 public void setManualEqualsHashCode(boolean manualEqualsHashCode) {
134 this.manualEqualsHashCode = manualEqualsHashCode;
135 }
136
137
138
139
140
141 public void setTypeParts(String[] parts) {
142 this.typeFull = parts[0];
143 this.typeRaw = parts[1];
144 this.typeGenericName = parts[2] != null ? parts[2] : "";
145 this.typeGenericExtends = parts[3] != null ? parts[3] : "";
146 }
147
148
149
150
151
152 public void setSuperTypeParts(String[] parts) {
153 this.superTypeFull = parts[0];
154 this.superTypeRaw = parts[1];
155 this.superTypeGeneric = parts[2] != null ? parts[2] : "";
156 }
157
158
159
160
161
162 public List<GeneratableProperty> getProperties() {
163 return properties;
164 }
165
166
167
168
169
170
171 public boolean isSubclass() {
172 return superTypeFull.equals("DirectBean") == false;
173 }
174
175
176
177
178
179
180 public boolean isTypeGeneric() {
181 return typeGenericName.length() > 0;
182 }
183
184
185
186
187
188 public String getType() {
189 return typeFull;
190 }
191
192
193
194
195
196
197 public String getTypeGeneric(boolean includeBrackets) {
198 String result = typeGenericName + typeGenericExtends;
199 return includeBrackets && result.length() > 0 ? '<' + result + '>' : result;
200 }
201
202
203
204
205
206
207 public String getTypeGenericName(boolean includeBrackets) {
208 return includeBrackets && typeGenericName.length() > 0 ? '<' + typeGenericName + '>' : typeGenericName;
209 }
210
211
212
213
214
215 public String getTypeGenericExtends() {
216 return typeGenericExtends;
217 }
218
219
220
221
222
223 public String getTypeNoExtends() {
224 return typeFull.replace(typeGenericExtends, "");
225 }
226
227
228
229
230
231 public String getTypeRaw() {
232 return typeRaw;
233 }
234
235
236
237
238
239 public String getTypeWildcard() {
240 return typeRaw + (isTypeGeneric() ? "<?>" : "");
241 }
242
243
244
245
246
247
248 public boolean isSuperTypeGeneric() {
249 return superTypeGeneric.length() > 0;
250 }
251
252
253
254
255
256 public String getSuperType() {
257 return superTypeFull;
258 }
259
260
261
262
263
264
265 public String getSuperTypeGeneric(boolean includeBrackets) {
266 return includeBrackets && superTypeGeneric.length() > 0 ? '<' + superTypeGeneric + '>' : superTypeGeneric;
267 }
268
269
270
271
272
273 public String getSuperTypeRaw() {
274 return superTypeRaw;
275 }
276
277
278
279
280
281 public boolean isValidated() {
282 for (GeneratableProperty property : properties) {
283 if (property.isValidated()) {
284 return true;
285 }
286 }
287 return false;
288 }
289
290 }