Search in sources :

Example 1 with EventAnnotationLiteral

use of io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotationLiteral in project quarkus-github-app by quarkiverse.

the class GitHubAppProcessor method generateAnnotationLiterals.

private static void generateAnnotationLiterals(ClassOutput classOutput, DispatchingConfiguration dispatchingConfiguration) {
    for (EventDispatchingConfiguration eventDispatchingConfiguration : dispatchingConfiguration.getEventConfigurations().values()) {
        for (EventAnnotationLiteral eventAnnotationLiteral : eventDispatchingConfiguration.getEventAnnotationLiterals()) {
            String literalClassName = getLiteralClassName(eventAnnotationLiteral.getName());
            String signature = String.format("Ljavax/enterprise/util/AnnotationLiteral<L%1$s;>;L%1$s;", eventAnnotationLiteral.getName().toString().replace('.', '/'));
            ClassCreator literalClassCreator = ClassCreator.builder().classOutput(classOutput).className(literalClassName).signature(signature).superClass(AnnotationLiteral.class).interfaces(eventAnnotationLiteral.getName().toString()).build();
            Class<?>[] parameterTypes = new Class<?>[eventAnnotationLiteral.getAttributes().size()];
            Arrays.fill(parameterTypes, String.class);
            MethodCreator constructorCreator = literalClassCreator.getMethodCreator("<init>", "V", (Object[]) parameterTypes);
            constructorCreator.invokeSpecialMethod(MethodDescriptor.ofConstructor(AnnotationLiteral.class), constructorCreator.getThis());
            for (int i = 0; i < eventAnnotationLiteral.getAttributes().size(); i++) {
                constructorCreator.writeInstanceField(FieldDescriptor.of(literalClassName, eventAnnotationLiteral.getAttributes().get(i), String.class), constructorCreator.getThis(), constructorCreator.getMethodParam(i));
                constructorCreator.setModifiers(Modifier.PUBLIC);
            }
            constructorCreator.returnValue(null);
            for (String attribute : eventAnnotationLiteral.getAttributes()) {
                // we only support String for now
                literalClassCreator.getFieldCreator(attribute, String.class).setModifiers(Modifier.PRIVATE);
                MethodCreator getterCreator = literalClassCreator.getMethodCreator(attribute, String.class);
                getterCreator.setModifiers(Modifier.PUBLIC);
                getterCreator.returnValue(getterCreator.readInstanceField(FieldDescriptor.of(literalClassName, attribute, String.class), getterCreator.getThis()));
            }
            literalClassCreator.close();
        }
    }
}
Also used : MethodCreator(io.quarkus.gizmo.MethodCreator) AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) EventAnnotationLiteral(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotationLiteral) EventDispatchingConfiguration(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration) EventAnnotationLiteral(io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotationLiteral) ClassCreator(io.quarkus.gizmo.ClassCreator)

Aggregations

EventAnnotationLiteral (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotationLiteral)1 EventDispatchingConfiguration (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration)1 ClassCreator (io.quarkus.gizmo.ClassCreator)1 MethodCreator (io.quarkus.gizmo.MethodCreator)1 AnnotationLiteral (javax.enterprise.util.AnnotationLiteral)1