use of com.sun.codemodel.JAnnotationArrayMember in project jsonschema2pojo by joelittlejohn.
the class ConstructorRule method generateFieldsConstructor.
private JMethod generateFieldsConstructor(JDefinedClass jclass, Set<String> classProperties, Set<String> combinedSuperProperties) {
// add the public constructor with property parameters
JMethod fieldsConstructor = jclass.constructor(JMod.PUBLIC);
GenerationConfig generationConfig = ruleFactory.getGenerationConfig();
JAnnotationArrayMember constructorPropertiesAnnotation;
if (generationConfig.isIncludeConstructorPropertiesAnnotation()) {
constructorPropertiesAnnotation = fieldsConstructor.annotate(ConstructorProperties.class).paramArray("value");
} else {
constructorPropertiesAnnotation = null;
}
JBlock constructorBody = fieldsConstructor.body();
JInvocation superInvocation = constructorBody.invoke("super");
Map<String, JFieldVar> fields = jclass.fields();
Map<String, JVar> classFieldParams = new HashMap<>();
for (String property : classProperties) {
JFieldVar field = fields.get(property);
if (field == null) {
throw new IllegalStateException("Property " + property + " hasn't been added to JDefinedClass before calling addConstructors");
}
fieldsConstructor.javadoc().addParam(property);
if (generationConfig.isIncludeConstructorPropertiesAnnotation() && constructorPropertiesAnnotation != null) {
constructorPropertiesAnnotation.param(field.name());
}
JVar param = fieldsConstructor.param(field.type(), field.name());
constructorBody.assign(JExpr._this().ref(field), param);
classFieldParams.put(property, param);
}
List<JVar> superConstructorParams = new ArrayList<>();
for (String property : combinedSuperProperties) {
JFieldVar field = reflectionHelper.searchSuperClassesForField(property, jclass);
if (field == null) {
throw new IllegalStateException("Property " + property + " hasn't been added to JDefinedClass before calling addConstructors");
}
JVar param = classFieldParams.get(property);
if (param == null) {
param = fieldsConstructor.param(field.type(), field.name());
}
fieldsConstructor.javadoc().addParam(property);
if (generationConfig.isIncludeConstructorPropertiesAnnotation() && constructorPropertiesAnnotation != null) {
constructorPropertiesAnnotation.param(param.name());
}
superConstructorParams.add(param);
}
for (JVar param : superConstructorParams) {
superInvocation.arg(param);
}
return fieldsConstructor;
}
use of com.sun.codemodel.JAnnotationArrayMember in project jsonschema2pojo by joelittlejohn.
the class Models method suppressWarnings.
public static void suppressWarnings(JMethod method, String... values) {
JAnnotationUse annotation = method.annotate(SuppressWarnings.class);
JAnnotationArrayMember member = annotation.paramArray("value");
for (String value : values) {
member.param(value);
}
}
Aggregations