Search in sources :

Example 1 with VueComponent

use of com.axellience.vuegwt.core.client.component.VueComponent in project vue-gwt by Axellience.

the class VueGwtExamplesService method initExamples.

public static void initExamples() {
    if (DomGlobal.document.getElementById("fullJsComponent") != null) {
        VueJsConstructor<VueComponent> vueClass = (VueJsConstructor<VueComponent>) ((JsPropertyMap) DomGlobal.window).get("FullJsComponent");
        VueComponent myComponent = vueClass.instantiate();
        myComponent.$mount("#fullJsComponent");
    }
    ExampleInjector exampleInjector = DaggerExampleInjector.builder().build();
    addExample("simpleLinkComponent", SimpleLinkComponent.class);
    addExample("emitAnnotation", ParentEmitAnnotationComponent.class);
    addExample("linkComponent", LinkComponent.class);
    addExample("canHideComponent", CanHideComponent.class);
    addExample("simpleTodoListComponent", SimpleTodoListComponent.class);
    addExample("exclamationComponent", ExclamationComponent.class);
    addExample("messageComponent", MessageComponent.class);
    addExample("parentComponent", ParentComponent.class);
    addExample("todoListComponent", TodoListComponent.class);
    addExample("melisandreComponent", MelisandreComponent.class);
    addExample("kittenComponent", KittenComponent.class);
    addExample("reverseComponent", ReverseComponent.class);
    addExample("vForWithIndexComponent", VForWithIndexComponent.class);
    addExample("vForWithRangeComponent", VForWithRangeComponent.class);
    addExample("vForOnObjectComponent", VForOnObjectComponent.class);
    addExample("vForOnObjectWithKeyComponent", VForOnObjectWithKeyComponent.class);
    addExample("vForOnObjectWithKeyAndIndexComponent", VForOnObjectWithKeyAndIndexComponent.class);
    addExample("evenNumbersComponent", EvenNumbersComponent.class);
    addExample("bindInlineStyleComponent", BindInlineStyleComponent.class);
    addExample("buttonPlusOneComponent", ButtonPlusOneComponent.class);
    addExample("greetComponent", GreetComponent.class);
    addExample("hiWhatComponent", HiWhatComponent.class);
    addExample("vOnWithDOMEventComponent", VOnWithDOMEventComponent.class);
    addExample("todoTextComponent", TodoTextComponent.class);
    addExample("todoTextComputedComponent", TodoTextComputedComponent.class);
    addExample("sharedDataModelComponent1", SharedDataModelComponent.class);
    addExample("sharedDataModelComponent2", SharedDataModelComponent.class);
    addExample("sharedDataModelComponent3", SharedDataModelComponent.class);
    addExample("counterWithEventComponent", CounterWithEventComponent.class);
    addExample("treeComponent", TreeComponent.class);
    addExample("recursiveComponent", RecursiveComponent.class);
    addExample("focusDirectiveComponent", FocusDirectiveComponent.class);
    addExample("renderAppComponent", RenderAppComponent.class);
    addExample("extendJavaComponent", ChildComponent.class);
    addExample("fullJsWithMethodsComponent", FullJsWithMethodsComponentFactory.get());
    addExample("propDefaultValueComponent", ParentPropDefaultValueComponent.class);
    addExample("gotQuotesComponent", exampleInjector.gotQuoteComponentFactory());
    addExample("errorBoundary", ErrorBoundaryComponent.class);
    addExample("extendJsComponent", ChildJavaComponent.class);
    addExample("passValues", ParentPassValuesComponent.class);
}
Also used : VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) VueJsConstructor(com.axellience.vuegwt.core.client.vue.VueJsConstructor)

Example 2 with VueComponent

use of com.axellience.vuegwt.core.client.component.VueComponent in project vue-gwt by Axellience.

the class VueGwtExamplesService method addExample.

private static void addExample(String exampleId, VueFactory exampleVueFactory) {
    // If we find the containing div for this example, we instantiate it
    if (DomGlobal.document.getElementById(exampleId) != null) {
        VueComponent exampleInstance = Vue.attach("#" + exampleId, exampleVueFactory);
        ((JsPropertyMap) DomGlobal.window).set(exampleId, exampleInstance);
    }
}
Also used : VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) JsPropertyMap(jsinterop.base.JsPropertyMap)

Example 3 with VueComponent

use of com.axellience.vuegwt.core.client.component.VueComponent in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method getOptionsMethodBuilder.

/**
 * Create and return the builder for the method that creating the {@link VueComponentOptions}
 * for this {@link VueComponent}.
 * @param component The {@link VueComponent} we are generating for
 * @return A {@link MethodSpec.Builder} for the method that creates the {@link VueComponentOptions}
 */
private MethodSpec.Builder getOptionsMethodBuilder(TypeElement component) {
    TypeName optionsTypeName = ParameterizedTypeName.get(ClassName.get(VueComponentOptions.class), ClassName.get(component));
    MethodSpec.Builder optionsMethodBuilder = MethodSpec.methodBuilder("getOptions").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(optionsTypeName).addStatement("$T options = new $T()", optionsTypeName, optionsTypeName);
    Component annotation = component.getAnnotation(Component.class);
    if (!"".equals(annotation.name()))
        optionsMethodBuilder.addStatement("options.setName($S)", annotation.name());
    optionsMethodBuilder.addStatement("options.setComponentJavaPrototype($T.getJavaConstructor($T.class).prototype)", VueGWT.class, componentJsTypeName(component));
    return optionsMethodBuilder;
}
Also used : TypeName(com.squareup.javapoet.TypeName) GeneratorsNameUtil.componentJsTypeName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentJsTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) VueComponentOptions(com.axellience.vuegwt.core.client.component.options.VueComponentOptions) MethodSpec(com.squareup.javapoet.MethodSpec) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Component(com.axellience.vuegwt.core.annotations.component.Component)

Example 4 with VueComponent

use of com.axellience.vuegwt.core.client.component.VueComponent in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method processData.

/**
 * Process data fields from the {@link VueComponent} Class.
 * @param component {@link VueComponent} to process
 * @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
 * {@link VueComponentOptions}
 */
private void processData(TypeElement component, MethodSpec.Builder optionsBuilder) {
    Component annotation = component.getAnnotation(Component.class);
    List<String> fieldsName = ElementFilter.fieldsIn(component.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isFieldVisibleInJS).filter(field -> field.getAnnotation(Prop.class) == null).map(field -> field.getSimpleName().toString()).collect(Collectors.toList());
    if (fieldsName.isEmpty())
        return;
    // Declare data fields
    String fieldNamesParameters = fieldsName.stream().map(fieldName -> "\"" + fieldName + "\"").collect(Collectors.joining(", "));
    optionsBuilder.addStatement("options.initData($L, $L)", annotation.useFactory(), fieldNamesParameters);
}
Also used : GeneratorsUtil(com.axellience.vuegwt.processors.utils.GeneratorsUtil) HasRender(com.axellience.vuegwt.core.client.component.hooks.HasRender) Modifier(javax.lang.model.element.Modifier) Function(elemental2.core.Function) ClassName(com.squareup.javapoet.ClassName) GeneratorsUtil.hasAnnotation(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation) TypeElement(javax.lang.model.element.TypeElement) Watch(com.axellience.vuegwt.core.annotations.component.Watch) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) HasCreated(com.axellience.vuegwt.core.client.component.hooks.HasCreated) VueComponentOptions(com.axellience.vuegwt.core.client.component.options.VueComponentOptions) Elements(javax.lang.model.util.Elements) ComputedKind(com.axellience.vuegwt.core.client.component.options.computed.ComputedKind) ComponentGeneratorsUtil(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil) Computed(com.axellience.vuegwt.core.annotations.component.Computed) PropDefault(com.axellience.vuegwt.core.annotations.component.PropDefault) Messager(javax.annotation.processing.Messager) GeneratorsUtil.hasInterface(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasInterface) HookMethod(com.axellience.vuegwt.core.annotations.component.HookMethod) GeneratorsNameUtil.componentFactoryName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentFactoryName) VueGWT(com.axellience.vuegwt.core.client.VueGWT) ComponentTemplateProcessor(com.axellience.vuegwt.processors.component.template.ComponentTemplateProcessor) Set(java.util.Set) VNodeBuilder(com.axellience.vuegwt.core.client.vnode.builder.VNodeBuilder) Collectors(java.util.stream.Collectors) JsArray(elemental2.core.JsArray) PropValidator(com.axellience.vuegwt.core.annotations.component.PropValidator) List(java.util.List) Stream(java.util.stream.Stream) Filer(javax.annotation.processing.Filer) GeneratorsNameUtil.componentInjectedDependenciesName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentInjectedDependenciesName) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) TypeName(com.squareup.javapoet.TypeName) GeneratorsNameUtil.methodToEventName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.methodToEventName) CreateElementFunction(com.axellience.vuegwt.core.client.vnode.builder.CreateElementFunction) Builder(com.squareup.javapoet.TypeSpec.Builder) VueJsConstructor(com.axellience.vuegwt.core.client.vue.VueJsConstructor) ComponentJavaConstructor(com.axellience.vuegwt.core.client.component.ComponentJavaConstructor) JsMethod(jsinterop.annotations.JsMethod) HashSet(java.util.HashSet) Kind(javax.tools.Diagnostic.Kind) DeclaredType(javax.lang.model.type.DeclaredType) Prop(com.axellience.vuegwt.core.annotations.component.Prop) ElementFilter(javax.lang.model.util.ElementFilter) JsType(jsinterop.annotations.JsType) GeneratorsNameUtil.componentJsTypeName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentJsTypeName) CodeBlock(com.squareup.javapoet.CodeBlock) Component(com.axellience.vuegwt.core.annotations.component.Component) VNode(com.axellience.vuegwt.core.client.vnode.VNode) MethodSpec(com.squareup.javapoet.MethodSpec) ExecutableElement(javax.lang.model.element.ExecutableElement) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) TypeMirror(javax.lang.model.type.TypeMirror) Emit(com.axellience.vuegwt.core.annotations.component.Emit) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Component(com.axellience.vuegwt.core.annotations.component.Component)

Example 5 with VueComponent

use of com.axellience.vuegwt.core.client.component.VueComponent in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method processProps.

/**
 * Process Vue Props from the {@link VueComponent} Class.
 * @param component {@link VueComponent} to process
 * @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
 * {@link VueComponentOptions}
 */
private void processProps(TypeElement component, MethodSpec.Builder optionsBuilder) {
    ElementFilter.fieldsIn(component.getEnclosedElements()).stream().filter(field -> hasAnnotation(field, Prop.class)).forEach(field -> {
        String fieldName = field.getSimpleName().toString();
        Prop prop = field.getAnnotation(Prop.class);
        if (!isFieldVisibleInJS(field)) {
            printError("The field \"" + fieldName + "\" annotated with @Prop must also be annotated with @JsProperty.", component);
        }
        optionsBuilder.addStatement("options.addJavaProp($S, $L, $S)", fieldName, prop.required(), prop.checkType() ? getNativeNameForJavaType(field.asType()) : null);
    });
}
Also used : GeneratorsUtil(com.axellience.vuegwt.processors.utils.GeneratorsUtil) HasRender(com.axellience.vuegwt.core.client.component.hooks.HasRender) Modifier(javax.lang.model.element.Modifier) Function(elemental2.core.Function) ClassName(com.squareup.javapoet.ClassName) GeneratorsUtil.hasAnnotation(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation) TypeElement(javax.lang.model.element.TypeElement) Watch(com.axellience.vuegwt.core.annotations.component.Watch) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) HasCreated(com.axellience.vuegwt.core.client.component.hooks.HasCreated) VueComponentOptions(com.axellience.vuegwt.core.client.component.options.VueComponentOptions) Elements(javax.lang.model.util.Elements) ComputedKind(com.axellience.vuegwt.core.client.component.options.computed.ComputedKind) ComponentGeneratorsUtil(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil) Computed(com.axellience.vuegwt.core.annotations.component.Computed) PropDefault(com.axellience.vuegwt.core.annotations.component.PropDefault) Messager(javax.annotation.processing.Messager) GeneratorsUtil.hasInterface(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasInterface) HookMethod(com.axellience.vuegwt.core.annotations.component.HookMethod) GeneratorsNameUtil.componentFactoryName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentFactoryName) VueGWT(com.axellience.vuegwt.core.client.VueGWT) ComponentTemplateProcessor(com.axellience.vuegwt.processors.component.template.ComponentTemplateProcessor) Set(java.util.Set) VNodeBuilder(com.axellience.vuegwt.core.client.vnode.builder.VNodeBuilder) Collectors(java.util.stream.Collectors) JsArray(elemental2.core.JsArray) PropValidator(com.axellience.vuegwt.core.annotations.component.PropValidator) List(java.util.List) Stream(java.util.stream.Stream) Filer(javax.annotation.processing.Filer) GeneratorsNameUtil.componentInjectedDependenciesName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentInjectedDependenciesName) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) TypeName(com.squareup.javapoet.TypeName) GeneratorsNameUtil.methodToEventName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.methodToEventName) CreateElementFunction(com.axellience.vuegwt.core.client.vnode.builder.CreateElementFunction) Builder(com.squareup.javapoet.TypeSpec.Builder) VueJsConstructor(com.axellience.vuegwt.core.client.vue.VueJsConstructor) ComponentJavaConstructor(com.axellience.vuegwt.core.client.component.ComponentJavaConstructor) JsMethod(jsinterop.annotations.JsMethod) HashSet(java.util.HashSet) Kind(javax.tools.Diagnostic.Kind) DeclaredType(javax.lang.model.type.DeclaredType) Prop(com.axellience.vuegwt.core.annotations.component.Prop) ElementFilter(javax.lang.model.util.ElementFilter) JsType(jsinterop.annotations.JsType) GeneratorsNameUtil.componentJsTypeName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentJsTypeName) CodeBlock(com.squareup.javapoet.CodeBlock) Component(com.axellience.vuegwt.core.annotations.component.Component) VNode(com.axellience.vuegwt.core.client.vnode.VNode) MethodSpec(com.squareup.javapoet.MethodSpec) ExecutableElement(javax.lang.model.element.ExecutableElement) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) TypeMirror(javax.lang.model.type.TypeMirror) Emit(com.axellience.vuegwt.core.annotations.component.Emit) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Prop(com.axellience.vuegwt.core.annotations.component.Prop)

Aggregations

VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)5 Component (com.axellience.vuegwt.core.annotations.component.Component)3 VueComponentOptions (com.axellience.vuegwt.core.client.component.options.VueComponentOptions)3 VueJsConstructor (com.axellience.vuegwt.core.client.vue.VueJsConstructor)3 GeneratorsNameUtil.componentJsTypeName (com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentJsTypeName)3 MethodSpec (com.squareup.javapoet.MethodSpec)3 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)3 TypeName (com.squareup.javapoet.TypeName)3 Computed (com.axellience.vuegwt.core.annotations.component.Computed)2 Emit (com.axellience.vuegwt.core.annotations.component.Emit)2 HookMethod (com.axellience.vuegwt.core.annotations.component.HookMethod)2 Prop (com.axellience.vuegwt.core.annotations.component.Prop)2 PropDefault (com.axellience.vuegwt.core.annotations.component.PropDefault)2 PropValidator (com.axellience.vuegwt.core.annotations.component.PropValidator)2 Watch (com.axellience.vuegwt.core.annotations.component.Watch)2 VueGWT (com.axellience.vuegwt.core.client.VueGWT)2 ComponentJavaConstructor (com.axellience.vuegwt.core.client.component.ComponentJavaConstructor)2 HasCreated (com.axellience.vuegwt.core.client.component.hooks.HasCreated)2 HasRender (com.axellience.vuegwt.core.client.component.hooks.HasRender)2 ComputedKind (com.axellience.vuegwt.core.client.component.options.computed.ComputedKind)2