Search in sources :

Example 1 with Prop

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

the class ComponentTemplateProcessor method processLocalComponentClass.

/**
 * Register the local component and all of its {@link Prop}.
 * This will be used for type validation.
 * @param localComponents The {@link LocalComponents} object where we should register our {@link LocalComponent}
 * @param localComponentType The class to process
 */
private void processLocalComponentClass(LocalComponents localComponents, TypeElement localComponentType) {
    Component componentAnnotation = localComponentType.getAnnotation(Component.class);
    String localComponentTagName = componentToTagName(localComponentType.getSimpleName().toString(), componentAnnotation);
    if (localComponents.hasLocalComponent(localComponentTagName))
        return;
    LocalComponent localComponent = localComponents.addLocalComponent(localComponentTagName);
    ElementFilter.fieldsIn(localComponentType.getEnclosedElements()).forEach(field -> {
        Prop propAnnotation = field.getAnnotation(Prop.class);
        if (propAnnotation != null) {
            localComponent.addProp(field.getSimpleName().toString(), TypeName.get(field.asType()), propAnnotation.required());
        }
    });
}
Also used : Prop(com.axellience.vuegwt.core.annotations.component.Prop) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Component(com.axellience.vuegwt.core.annotations.component.Component) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)

Example 2 with Prop

use of com.axellience.vuegwt.core.annotations.component.Prop 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

Component (com.axellience.vuegwt.core.annotations.component.Component)2 Prop (com.axellience.vuegwt.core.annotations.component.Prop)2 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)2 Computed (com.axellience.vuegwt.core.annotations.component.Computed)1 Emit (com.axellience.vuegwt.core.annotations.component.Emit)1 HookMethod (com.axellience.vuegwt.core.annotations.component.HookMethod)1 PropDefault (com.axellience.vuegwt.core.annotations.component.PropDefault)1 PropValidator (com.axellience.vuegwt.core.annotations.component.PropValidator)1 Watch (com.axellience.vuegwt.core.annotations.component.Watch)1 VueGWT (com.axellience.vuegwt.core.client.VueGWT)1 ComponentJavaConstructor (com.axellience.vuegwt.core.client.component.ComponentJavaConstructor)1 HasCreated (com.axellience.vuegwt.core.client.component.hooks.HasCreated)1 HasRender (com.axellience.vuegwt.core.client.component.hooks.HasRender)1 VueComponentOptions (com.axellience.vuegwt.core.client.component.options.VueComponentOptions)1 ComputedKind (com.axellience.vuegwt.core.client.component.options.computed.ComputedKind)1 VNode (com.axellience.vuegwt.core.client.vnode.VNode)1 CreateElementFunction (com.axellience.vuegwt.core.client.vnode.builder.CreateElementFunction)1 VNodeBuilder (com.axellience.vuegwt.core.client.vnode.builder.VNodeBuilder)1 VueJsConstructor (com.axellience.vuegwt.core.client.vue.VueJsConstructor)1 ComponentTemplateProcessor (com.axellience.vuegwt.processors.component.template.ComponentTemplateProcessor)1