|
19 | 19 | import static com.sun.codemodel.JExpr.*;
|
20 | 20 | import static com.sun.codemodel.JMod.*;
|
21 | 21 |
|
22 |
| -import java.util.Iterator; |
23 |
| -import java.util.Map; |
24 |
| - |
25 | 22 | import org.jsonschema2pojo.Schema;
|
26 |
| -import org.jsonschema2pojo.util.LanguageFeatures; |
27 | 23 | import org.jsonschema2pojo.util.Models;
|
28 | 24 |
|
29 | 25 | import com.fasterxml.jackson.databind.JsonNode;
|
|
40 | 36 | import com.sun.codemodel.JType;
|
41 | 37 | import com.sun.codemodel.JTypeVar;
|
42 | 38 | import com.sun.codemodel.JVar;
|
| 39 | +import java.util.Iterator; |
| 40 | +import java.util.Map; |
43 | 41 |
|
44 | 42 | /**
|
45 | 43 | * Adds methods for dynamically getting, setting, and building properties.
|
@@ -105,20 +103,11 @@ public JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDef
|
105 | 103 | boolean isGenerateBuilders = ruleFactory.getGenerationConfig().isGenerateBuilders();
|
106 | 104 |
|
107 | 105 | if (isIncludeGetters || isIncludeSetters || isGenerateBuilders) {
|
108 |
| - if (LanguageFeatures.canUseJava7(ruleFactory.getGenerationConfig())) { |
109 |
| - if (isIncludeSetters) { |
110 |
| - addInternalSetMethodJava7(jclass, node); |
111 |
| - } |
112 |
| - if (isIncludeGetters) { |
113 |
| - addInternalGetMethodJava7(jclass, node); |
114 |
| - } |
115 |
| - } else { |
116 |
| - if (isIncludeSetters) { |
117 |
| - addInternalSetMethodJava6(jclass, node); |
118 |
| - } |
119 |
| - if (isIncludeGetters) { |
120 |
| - addInternalGetMethodJava6(jclass, node); |
121 |
| - } |
| 106 | + if (isIncludeSetters) { |
| 107 | + addInternalSetMethodJava6(jclass, node); |
| 108 | + } |
| 109 | + if (isIncludeGetters) { |
| 110 | + addInternalGetMethodJava6(jclass, node); |
122 | 111 | }
|
123 | 112 | }
|
124 | 113 |
|
@@ -172,38 +161,6 @@ private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMeth
|
172 | 161 | return method;
|
173 | 162 | }
|
174 | 163 |
|
175 |
| - private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { |
176 |
| - JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME); |
177 |
| - JVar nameParam = method.param(String.class, "name"); |
178 |
| - JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue"); |
179 |
| - JBlock body = method.body(); |
180 |
| - JSwitch propertySwitch = body._switch(nameParam); |
181 |
| - if (propertiesNode != null) { |
182 |
| - for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { |
183 |
| - Map.Entry<String, JsonNode> property = properties.next(); |
184 |
| - String propertyName = property.getKey(); |
185 |
| - JsonNode node = property.getValue(); |
186 |
| - String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); |
187 |
| - JType propertyType = jclass.fields().get(fieldName).type(); |
188 |
| - |
189 |
| - addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node); |
190 |
| - } |
191 |
| - } |
192 |
| - JClass extendsType = jclass._extends(); |
193 |
| - if (extendsType != null && extendsType instanceof JDefinedClass) { |
194 |
| - JDefinedClass parentClass = (JDefinedClass) extendsType; |
195 |
| - JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME, |
196 |
| - new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); |
197 |
| - propertySwitch._default().body() |
198 |
| - ._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam)); |
199 |
| - } else { |
200 |
| - propertySwitch._default().body() |
201 |
| - ._return(notFoundParam); |
202 |
| - } |
203 |
| - |
204 |
| - return method; |
205 |
| - } |
206 |
| - |
207 | 164 | private JMethod addInternalGetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
|
208 | 165 | JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
|
209 | 166 | JVar nameParam = method.param(String.class, "name");
|
@@ -305,36 +262,6 @@ private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMet
|
305 | 262 | return method;
|
306 | 263 | }
|
307 | 264 |
|
308 |
| - private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { |
309 |
| - JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME); |
310 |
| - JVar nameParam = method.param(String.class, "name"); |
311 |
| - JVar valueParam = method.param(Object.class, "value"); |
312 |
| - JBlock body = method.body(); |
313 |
| - JSwitch propertySwitch = body._switch(nameParam); |
314 |
| - if (propertiesNode != null) { |
315 |
| - for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { |
316 |
| - Map.Entry<String, JsonNode> property = properties.next(); |
317 |
| - String propertyName = property.getKey(); |
318 |
| - JsonNode node = property.getValue(); |
319 |
| - String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); |
320 |
| - JType propertyType = jclass.fields().get(fieldName).type(); |
321 |
| - |
322 |
| - addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node); |
323 |
| - } |
324 |
| - } |
325 |
| - JBlock defaultBlock = propertySwitch._default().body(); |
326 |
| - JClass extendsType = jclass._extends(); |
327 |
| - if (extendsType != null && extendsType instanceof JDefinedClass) { |
328 |
| - JDefinedClass parentClass = (JDefinedClass) extendsType; |
329 |
| - JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME, |
330 |
| - new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); |
331 |
| - defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam)); |
332 |
| - } else { |
333 |
| - defaultBlock._return(FALSE); |
334 |
| - } |
335 |
| - return method; |
336 |
| - } |
337 |
| - |
338 | 265 | private JMethod addInternalSetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
|
339 | 266 | JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
|
340 | 267 | JVar nameParam = method.param(String.class, "name");
|
|
0 commit comments