use of com.sun.codemodel.JAnnotationUse in project scout.rt by eclipse.
the class HandlerArtifactProcessor method createAndPersistAuthHandler.
/**
* Generates the AuthHandler.
*/
public String createAndPersistAuthHandler(final JClass portTypeEntryPoint, final EntryPointDefinition entryPointDefinition, final ProcessingEnvironment processingEnv) throws IOException, JClassAlreadyExistsException {
final JCodeModel model = new JCodeModel();
final String fullName = entryPointDefinition.getEntryPointQualifiedName() + "_" + AUTH_HANDLER_NAME;
final JDefinedClass authHandler = model._class(fullName)._extends(model.ref(AuthenticationHandler.class));
// Add 'Generated' annotation
final JAnnotationUse generatedAnnotation = authHandler.annotate(Generated.class);
generatedAnnotation.param("value", JaxWsAnnotationProcessor.class.getName());
generatedAnnotation.param("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSSZ").format(new Date()));
generatedAnnotation.param("comments", format("Authentication Handler for [method=%s, verifier=%s]", AptUtil.toSimpleName(entryPointDefinition.getAuthMethod()), AptUtil.toSimpleName(entryPointDefinition.getAuthVerifier())));
// Add default constructor with super call to provide authentication annotation.
final JMethod defaultConstructor = authHandler.constructor(JMod.PUBLIC);
final JClass entryPointDefinitionClass = model.ref(entryPointDefinition.getQualifiedName());
defaultConstructor.body().invoke("super").arg(JExpr.dotclass(entryPointDefinitionClass).invoke("getAnnotation").arg(JExpr.dotclass(model.ref(WebServiceEntryPoint.class))).invoke("authentication"));
AptUtil.addJavaDoc(authHandler, format("This class is auto-generated by APT triggered by Maven build and is based on the authentication configuration declared in {@link %s}.", entryPointDefinition.getSimpleName()));
AptUtil.buildAndPersist(model, processingEnv.getFiler());
return authHandler.fullName();
}
use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.
the class BuilderRule method generateNoArgsBaseBuilderConstructor.
private void generateNoArgsBaseBuilderConstructor(JDefinedClass instanceClass, JDefinedClass builderClass, JDefinedClass concreteBuilderClass) {
JMethod noArgsConstructor = builderClass.constructor(JMod.PUBLIC);
JAnnotationUse warningSuppression = noArgsConstructor.annotate(SuppressWarnings.class);
warningSuppression.param("value", "unchecked");
JBlock constructorBlock = noArgsConstructor.body();
JFieldVar instanceField = reflectionHelper.searchClassAndSuperClassesForField("instance", builderClass);
// Determine if we need to invoke the super() method for our parent builder
JClass parentClass = builderClass._extends();
if (!(parentClass.isPrimitive() || reflectionHelper.isFinal(parentClass) || Objects.equals(parentClass.fullName(), "java.lang.Object"))) {
constructorBlock.invoke("super");
}
// Only initialize the instance if the object being constructed is actually this class
// if it's a subtype then ignore the instance initialization since the subclass will initialize it
constructorBlock.directStatement("// Skip initialization when called from subclass");
JInvocation comparison = JExpr._this().invoke("getClass").invoke("equals").arg(JExpr.dotclass(concreteBuilderClass));
JConditional ifNotSubclass = constructorBlock._if(comparison);
ifNotSubclass._then().assign(JExpr._this().ref(instanceField), JExpr.cast(instanceField.type(), JExpr._new(instanceClass)));
}
use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.
the class MinimumMaximumRule method apply.
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) {
if (node.has("minimum")) {
final Class<? extends Annotation> decimalMinClass = ruleFactory.getGenerationConfig().isUseJakartaValidation() ? DecimalMin.class : javax.validation.constraints.DecimalMin.class;
JAnnotationUse annotation = field.annotate(decimalMinClass);
annotation.param("value", node.get("minimum").asText());
}
if (node.has("maximum")) {
final Class<? extends Annotation> decimalMaxClass = ruleFactory.getGenerationConfig().isUseJakartaValidation() ? DecimalMax.class : javax.validation.constraints.DecimalMax.class;
JAnnotationUse annotation = field.annotate(decimalMaxClass);
annotation.param("value", node.get("maximum").asText());
}
}
return field;
}
use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.
the class DigitsRule method apply.
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && node.has("integerDigits") && node.has("fractionalDigits") && isApplicableType(field)) {
final Class<? extends Annotation> digitsClass = ruleFactory.getGenerationConfig().isUseJakartaValidation() ? Digits.class : javax.validation.constraints.Digits.class;
JAnnotationUse annotation = field.annotate(digitsClass);
annotation.param("integer", node.get("integerDigits").asInt());
annotation.param("fraction", node.get("fractionalDigits").asInt());
}
return field;
}
use of com.sun.codemodel.JAnnotationUse in project jsonschema2pojo by joelittlejohn.
the class MinLengthMaxLengthRule method apply.
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && (node.has("minLength") || node.has("maxLength")) && isApplicableType(field)) {
final Class<? extends Annotation> sizeClass = ruleFactory.getGenerationConfig().isUseJakartaValidation() ? Size.class : javax.validation.constraints.Size.class;
JAnnotationUse annotation = field.annotate(sizeClass);
if (node.has("minLength")) {
annotation.param("min", node.get("minLength").asInt());
}
if (node.has("maxLength")) {
annotation.param("max", node.get("maxLength").asInt());
}
}
return field;
}
Aggregations