All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.longdt.vertxservice.processor.NoParamMethodProxyHandlerWriter Maven / Gradle / Ivy

Go to download

A lightweight replacement for vertx-service-proxy. This library is highly optimized for vertx java

There is a newer version: 1.1.1
Show newest version
package com.github.longdt.vertxservice.processor;

import com.squareup.javapoet.CodeBlock;
import io.vertx.serviceproxy.HelperUtils;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.util.Types;

public class NoParamMethodProxyHandlerWriter extends MethodProxyHandlerWriter {
    protected NoParamMethodProxyHandlerWriter(Types types) {
        super(types);
    }

    @Override
    public void writeInvocation(CodeBlock.Builder codeBlockBuilder, ExecutableElement element) {
        codeBlockBuilder.beginControlFlow("case $S:", element.getSimpleName().toString());
        codeBlockBuilder.add("$L.$L()\n", Constant.SERVICE_VARIABLE, element.getSimpleName().toString());
        codeBlockBuilder.indent().indent()
                .beginControlFlow(".onComplete(res ->")
                .beginControlFlow("if (res.failed())")
                .addStatement("$T.manageFailure($L, res.cause(), $L)", HelperUtils.class, Constant.MESSAGE_VARIABLE, Constant.INCLUDE_DEBUG_INFO_VARIABLE)
                .nextControlFlow("else");

        var resultType = ((DeclaredType) element.getReturnType()).getTypeArguments().get(0);
        addReplyHandler(codeBlockBuilder, resultType);

        codeBlockBuilder.endControlFlow()
                .unindent().add("});\n")
                .unindent().unindent();
        codeBlockBuilder.addStatement("break");
        codeBlockBuilder.endControlFlow();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy