Search in sources :

Example 1 with EventAnnotationLiteral

use of io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotationLiteral in project quarkus-github-action by quarkiverse.

the class GitHubActionProcessor method generateAnnotationLiterals.

private static void generateAnnotationLiterals(ClassOutput classOutput, DispatchingConfiguration dispatchingConfiguration) {
    for (ActionDispatchingConfiguration eventDispatchingConfiguration : dispatchingConfiguration.getActionDispatchingConfigurations()) {
        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.githubaction.deployment.DispatchingConfiguration.EventAnnotationLiteral) ActionDispatchingConfiguration(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.ActionDispatchingConfiguration) EventAnnotationLiteral(io.quarkiverse.githubaction.deployment.DispatchingConfiguration.EventAnnotationLiteral) ClassCreator(io.quarkus.gizmo.ClassCreator)

Aggregations

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