Search in sources :

Example 1 with ComponentGeneratorsUtil

use of com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil in project vue-gwt by Axellience.

the class ComponentTemplateProcessor method registerFieldsAndMethodsInContext.

/**
 * Process the ComponentJsType class to register all the fields and methods visible in
 * the context.
 * TODO: Improve this method by putting things together with {@link ComponentJsTypeGenerator}
 * @param componentTypeElement The class to process
 */
private void registerFieldsAndMethodsInContext(TemplateParserContext templateParserContext, TypeElement componentTypeElement, Set<String> alreadyDoneVariable, Set<String> alreadyDoneMethods) {
    ElementFilter.fieldsIn(componentTypeElement.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isFieldVisibleInJS).forEach(field -> {
        String name = field.getSimpleName().toString();
        if (alreadyDoneVariable.contains(name))
            return;
        alreadyDoneVariable.add(name);
        templateParserContext.addRootVariable(ClassName.get(field.asType()), name);
    });
    ElementFilter.methodsIn(componentTypeElement.getEnclosedElements()).stream().filter(method -> hasAnnotation(method, Computed.class)).filter(method -> !"void".equals(method.getReturnType().toString())).forEach(method -> {
        String name = getComputedPropertyName(method);
        if (alreadyDoneVariable.contains(name))
            return;
        alreadyDoneVariable.add(name);
        TypeMirror propertyType;
        if ("void".equals(method.getReturnType().toString()))
            propertyType = method.getParameters().get(0).asType();
        else
            propertyType = method.getReturnType();
        templateParserContext.addRootVariable(ClassName.get(propertyType), name);
    });
    ElementFilter.methodsIn(componentTypeElement.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isMethodVisibleInTemplate).map(ExecutableElement::getSimpleName).map(Object::toString).forEach(methodName -> {
        if (alreadyDoneMethods.contains(methodName))
            return;
        alreadyDoneMethods.add(methodName);
        templateParserContext.addRootMethod(methodName);
    });
    getSuperComponentType(componentTypeElement).ifPresent(superComponent -> registerFieldsAndMethodsInContext(templateParserContext, superComponent, alreadyDoneVariable, alreadyDoneMethods));
}
Also used : Builder(com.squareup.javapoet.TypeSpec.Builder) ClassName(com.squareup.javapoet.ClassName) GeneratorsUtil.hasAnnotation(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation) TypeElement(javax.lang.model.element.TypeElement) ComponentGeneratorsUtil.getSuperComponentType(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getSuperComponentType) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Elements(javax.lang.model.util.Elements) FileObject(javax.tools.FileObject) HashSet(java.util.HashSet) ComponentGeneratorsUtil.getComponentLocalComponents(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getComponentLocalComponents) Kind(javax.tools.Diagnostic.Kind) ComponentGeneratorsUtil(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil) Computed(com.axellience.vuegwt.core.annotations.component.Computed) DeclaredType(javax.lang.model.type.DeclaredType) Prop(com.axellience.vuegwt.core.annotations.component.Prop) ElementFilter(javax.lang.model.util.ElementFilter) Messager(javax.annotation.processing.Messager) TemplateMethodsBuilder(com.axellience.vuegwt.processors.component.template.builder.TemplateMethodsBuilder) StandardLocation(javax.tools.StandardLocation) Component(com.axellience.vuegwt.core.annotations.component.Component) TemplateParser(com.axellience.vuegwt.processors.component.template.parser.TemplateParser) ExecutableElement(javax.lang.model.element.ExecutableElement) ComponentJsTypeGenerator(com.axellience.vuegwt.processors.component.ComponentJsTypeGenerator) LocalComponents(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponents) TemplateParserResult(com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult) Set(java.util.Set) IOException(java.io.IOException) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) TypeMirror(javax.lang.model.type.TypeMirror) Filer(javax.annotation.processing.Filer) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) GeneratorsUtil.getComputedPropertyName(com.axellience.vuegwt.processors.utils.GeneratorsUtil.getComputedPropertyName) TemplateParserContext(com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext) GeneratorsNameUtil.componentToTagName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentToTagName) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Computed(com.axellience.vuegwt.core.annotations.component.Computed)

Example 2 with ComponentGeneratorsUtil

use of com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil 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)

Aggregations

Component (com.axellience.vuegwt.core.annotations.component.Component)2 Computed (com.axellience.vuegwt.core.annotations.component.Computed)2 Prop (com.axellience.vuegwt.core.annotations.component.Prop)2 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)2 ComponentGeneratorsUtil (com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil)2 GeneratorsUtil.hasAnnotation (com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation)2 ClassName (com.squareup.javapoet.ClassName)2 TypeName (com.squareup.javapoet.TypeName)2 Builder (com.squareup.javapoet.TypeSpec.Builder)2 HashSet (java.util.HashSet)2 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