Search in sources :

Example 1 with ComponentJsTypeGenerator

use of com.axellience.vuegwt.processors.component.ComponentJsTypeGenerator in project vue-gwt by Axellience.

the class VueGwtProcessor method processComponentAnnotations.

private void processComponentAnnotations(RoundEnvironment roundEnv) {
    Set<? extends Element> componentElements = roundEnv.getElementsAnnotatedWith(Component.class);
    ComponentJsTypeGenerator componentJsTypeGenerator = new ComponentJsTypeGenerator(processingEnv);
    VueComponentFactoryGenerator vueFactoryGenerator = new VueComponentFactoryGenerator(processingEnv);
    for (TypeElement componentType : ElementFilter.typesIn(componentElements)) {
        ComponentInjectedDependenciesBuilder dependenciesBuilder = new ComponentInjectedDependenciesBuilder(processingEnv, componentType);
        vueFactoryGenerator.generate(componentType, dependenciesBuilder.hasInjectedDependencies());
        componentJsTypeGenerator.generate(componentType, dependenciesBuilder);
    }
}
Also used : ComponentJsTypeGenerator(com.axellience.vuegwt.processors.component.ComponentJsTypeGenerator) TypeElement(javax.lang.model.element.TypeElement) ComponentInjectedDependenciesBuilder(com.axellience.vuegwt.processors.component.ComponentInjectedDependenciesBuilder) VueComponentFactoryGenerator(com.axellience.vuegwt.processors.component.factory.VueComponentFactoryGenerator)

Example 2 with ComponentJsTypeGenerator

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

Aggregations

ComponentJsTypeGenerator (com.axellience.vuegwt.processors.component.ComponentJsTypeGenerator)2 TypeElement (javax.lang.model.element.TypeElement)2 Component (com.axellience.vuegwt.core.annotations.component.Component)1 Computed (com.axellience.vuegwt.core.annotations.component.Computed)1 Prop (com.axellience.vuegwt.core.annotations.component.Prop)1 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)1 ComponentInjectedDependenciesBuilder (com.axellience.vuegwt.processors.component.ComponentInjectedDependenciesBuilder)1 VueComponentFactoryGenerator (com.axellience.vuegwt.processors.component.factory.VueComponentFactoryGenerator)1 TemplateMethodsBuilder (com.axellience.vuegwt.processors.component.template.builder.TemplateMethodsBuilder)1 TemplateParser (com.axellience.vuegwt.processors.component.template.parser.TemplateParser)1 TemplateParserContext (com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext)1 LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)1 LocalComponents (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponents)1 TemplateParserResult (com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult)1 ComponentGeneratorsUtil (com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil)1 ComponentGeneratorsUtil.getComponentLocalComponents (com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getComponentLocalComponents)1 ComponentGeneratorsUtil.getSuperComponentType (com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getSuperComponentType)1 GeneratorsNameUtil.componentToTagName (com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentToTagName)1 GeneratorsUtil.getComputedPropertyName (com.axellience.vuegwt.processors.utils.GeneratorsUtil.getComputedPropertyName)1 GeneratorsUtil.hasAnnotation (com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation)1