Search in sources :

Example 1 with JsType

use of jsinterop.annotations.JsType in project vue-gwt by Axellience.

the class VueJsComponentFactoryGenerator method createInitMethod.

@Override
protected List<CodeBlock> createInitMethod(TypeElement component, Builder vueFactoryBuilder) {
    JsType jsType = component.getAnnotation(JsType.class);
    if (jsType == null || !jsType.isNative()) {
        messager.printMessage(Kind.ERROR, component.asType().toString() + " @JsComponent must have a @JsType annotation with isNative to true");
        return null;
    }
    if (!JsPackage.GLOBAL.equals(jsType.namespace())) {
        messager.printMessage(Kind.ERROR, component.asType().toString() + " @JsType annotation on @JsComponent must have namespace set to JsPackage.GLOBAL");
        return null;
    }
    JsComponent jsComponent = component.getAnnotation(JsComponent.class);
    MethodSpec.Builder initBuilder = MethodSpec.methodBuilder("init").addModifiers(Modifier.PRIVATE);
    if ("Function".equals(jsType.name())) {
        initForComponentConstructor(jsComponent, initBuilder);
    } else if ("Object".equals(jsType.name())) {
        initForComponentOptions(jsComponent, initBuilder);
    } else {
        messager.printMessage(Kind.ERROR, component.asType().toString() + " @JsType annotation on @JsComponent must have name set to either Function or Object.");
    }
    vueFactoryBuilder.addMethod(initBuilder.build());
    return new LinkedList<>();
}
Also used : JsType(jsinterop.annotations.JsType) MethodSpec(com.squareup.javapoet.MethodSpec) JsComponent(com.axellience.vuegwt.core.annotations.component.JsComponent) LinkedList(java.util.LinkedList)

Aggregations

JsComponent (com.axellience.vuegwt.core.annotations.component.JsComponent)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 LinkedList (java.util.LinkedList)1 JsType (jsinterop.annotations.JsType)1