Search in sources :

Example 1 with Emit

use of com.axellience.vuegwt.core.annotations.component.Emit in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method addProxyJsTypeMethodIfNecessary.

/**
 * Generate a JsInterop proxy method for a {@link VueComponent} method.
 * This proxy will keep the same name in JS and can be therefore passed to Vue to
 * configure our {@link VueComponent}.
 * @param componentJsTypeBuilder Builder for the JsType class
 * @param originalMethod Method to proxify
 */
private void addProxyJsTypeMethodIfNecessary(Builder componentJsTypeBuilder, ExecutableElement originalMethod) {
    Emit emitAnnotation = originalMethod.getAnnotation(Emit.class);
    if (isMethodVisibleInJS(originalMethod) && emitAnnotation == null)
        return;
    MethodSpec.Builder proxyMethodBuilder = MethodSpec.methodBuilder(originalMethod.getSimpleName().toString()).addModifiers(Modifier.PUBLIC).returns(ClassName.get(originalMethod.getReturnType()));
    originalMethod.getParameters().forEach(parameter -> proxyMethodBuilder.addParameter(TypeName.get(parameter.asType()), parameter.getSimpleName().toString()));
    String methodCallParameters = getSuperMethodCallParameters(originalMethod);
    boolean hasReturnValue = !"void".equals(originalMethod.getReturnType().toString());
    if (hasReturnValue) {
        proxyMethodBuilder.addStatement("$T result = super.$L($L)", originalMethod.getReturnType(), originalMethod.getSimpleName().toString(), methodCallParameters);
    } else {
        proxyMethodBuilder.addStatement("super.$L($L)", originalMethod.getSimpleName().toString(), methodCallParameters);
    }
    if (emitAnnotation != null)
        addEmitEventCall(originalMethod, proxyMethodBuilder, methodCallParameters);
    if (hasReturnValue)
        proxyMethodBuilder.addStatement("return result");
    componentJsTypeBuilder.addMethod(proxyMethodBuilder.build());
}
Also used : Emit(com.axellience.vuegwt.core.annotations.component.Emit) MethodSpec(com.squareup.javapoet.MethodSpec)

Aggregations

Emit (com.axellience.vuegwt.core.annotations.component.Emit)1 MethodSpec (com.squareup.javapoet.MethodSpec)1