Search in sources :

Example 1 with Builder

use of com.squareup.javapoet.TypeSpec.Builder in project Rocket by mozilla-tw.

the class AppModuleGenerator method generate.

TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClassNames) {
    ClassName appGlideModuleClassName = ClassName.get(appGlideModule);
    Set<String> excludedGlideModuleClassNames = getExcludedGlideModuleClassNames(appGlideModule);
    MethodSpec constructor = generateConstructor(appGlideModuleClassName, libraryGlideModuleClassNames, excludedGlideModuleClassNames);
    MethodSpec registerComponents = generateRegisterComponents(libraryGlideModuleClassNames, excludedGlideModuleClassNames);
    MethodSpec getExcludedModuleClasses = generateGetExcludedModuleClasses(excludedGlideModuleClassNames);
    MethodSpec applyOptions = MethodSpec.methodBuilder("applyOptions").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(ClassName.get("android.content", "Context"), "context").addParameter(ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder").addStatement("appGlideModule.applyOptions(context, builder)", appGlideModule).build();
    MethodSpec isManifestParsingEnabled = MethodSpec.methodBuilder("isManifestParsingEnabled").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(boolean.class).addStatement("return appGlideModule.isManifestParsingEnabled()", appGlideModule).build();
    Builder builder = TypeSpec.classBuilder(GENERATED_APP_MODULE_IMPL_SIMPLE_NAME).addModifiers(Modifier.FINAL).addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "deprecation").build()).superclass(ClassName.get(GENERATED_ROOT_MODULE_PACKAGE_NAME, GENERATED_ROOT_MODULE_SIMPLE_NAME)).addField(appGlideModuleClassName, "appGlideModule", Modifier.PRIVATE, Modifier.FINAL).addMethod(constructor).addMethod(applyOptions).addMethod(registerComponents).addMethod(isManifestParsingEnabled).addMethod(getExcludedModuleClasses);
    ClassName generatedRequestManagerFactoryClassName = ClassName.get(RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_PACKAGE_NAME, RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_SIMPLE_NAME);
    builder.addMethod(MethodSpec.methodBuilder("getRequestManagerFactory").addAnnotation(Override.class).returns(generatedRequestManagerFactoryClassName).addStatement("return new $T()", generatedRequestManagerFactoryClassName).build());
    return builder.build();
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) Builder(com.squareup.javapoet.TypeSpec.Builder) ClassName(com.squareup.javapoet.ClassName)

Example 2 with Builder

use of com.squareup.javapoet.TypeSpec.Builder in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method generate.

public void generate(TypeElement component, ComponentInjectedDependenciesBuilder dependenciesBuilder) {
    // Template resource abstract class
    ClassName componentWithSuffixClassName = componentJsTypeName(component);
    Builder componentJsTypeBuilder = getComponentJsTypeBuilder(component, componentWithSuffixClassName);
    // Initialize Options getter builder
    MethodSpec.Builder optionsBuilder = getOptionsMethodBuilder(component);
    Set<ExecutableElement> hookMethodsFromInterfaces = getHookMethodsFromInterfaces(component);
    processData(component, optionsBuilder);
    processProps(component, optionsBuilder);
    processComputed(component, optionsBuilder, componentJsTypeBuilder);
    processWatchers(component, optionsBuilder, componentJsTypeBuilder);
    processPropValidators(component, optionsBuilder, componentJsTypeBuilder);
    processPropDefaultValues(component, optionsBuilder, componentJsTypeBuilder);
    processHooks(component, optionsBuilder, hookMethodsFromInterfaces);
    processTemplateMethods(component, optionsBuilder, componentJsTypeBuilder, hookMethodsFromInterfaces);
    processInvalidEmitMethods(component);
    processRenderFunction(component, optionsBuilder, componentJsTypeBuilder);
    createCreatedHook(component, optionsBuilder, componentJsTypeBuilder, dependenciesBuilder);
    // Process the HTML template if there is one
    if (hasTemplate(processingEnv, component)) {
        componentTemplateProcessor.processComponentTemplate(component, componentJsTypeBuilder);
        optionsBuilder.addStatement("options.initRenderFunctions(getRenderFunction(), getStaticRenderFunctions())");
    }
    // Finish building Options getter
    optionsBuilder.addStatement("return options");
    componentJsTypeBuilder.addMethod(optionsBuilder.build());
    // And generate our Java Class
    GeneratorsUtil.toJavaFile(filer, componentJsTypeBuilder, componentWithSuffixClassName, component);
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) VNodeBuilder(com.axellience.vuegwt.core.client.vnode.builder.VNodeBuilder) Builder(com.squareup.javapoet.TypeSpec.Builder) ExecutableElement(javax.lang.model.element.ExecutableElement) ClassName(com.squareup.javapoet.ClassName)

Example 3 with Builder

use of com.squareup.javapoet.TypeSpec.Builder in project vue-gwt by Axellience.

the class AbstractVueComponentFactoryGenerator method generate.

/**
 * Generate our {@link VueFactory} class.
 * @param component The {@link VueComponent} class to generate {@link VueComponentOptions} from
 */
public void generate(TypeElement component) {
    ClassName vueFactoryClassName = componentFactoryName(component);
    Builder vueFactoryBuilder = createFactoryBuilderClass(component, vueFactoryClassName);
    createProperties(vueFactoryClassName, vueFactoryBuilder);
    List<CodeBlock> staticInitParameters = createInitMethod(component, vueFactoryBuilder);
    createStaticGetMethod(vueFactoryClassName, vueFactoryBuilder, staticInitParameters);
    vueFactoryBuilder.addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addAnnotation(Inject.class).build());
    // Build the ComponentOptions class
    GeneratorsUtil.toJavaFile(filer, vueFactoryBuilder, vueFactoryClassName, component);
}
Also used : Builder(com.squareup.javapoet.TypeSpec.Builder) ClassName(com.squareup.javapoet.ClassName) CodeBlock(com.squareup.javapoet.CodeBlock)

Example 4 with Builder

use of com.squareup.javapoet.TypeSpec.Builder in project vue-gwt by Axellience.

the class VueDirectiveOptionsGenerator method generate.

/**
 * Generate and save the Java file for the typeElement passed to the constructor
 * @param directiveTypeElement The {@link VueDirective} class to
 * generate {@link VueDirectiveOptions} from
 */
public void generate(TypeElement directiveTypeElement) {
    ClassName optionsClassName = GeneratorsNameUtil.directiveOptionsName(directiveTypeElement);
    Builder componentClassBuilder = TypeSpec.classBuilder(optionsClassName).addModifiers(Modifier.PUBLIC, Modifier.FINAL).superclass(VueDirectiveOptions.class).addAnnotation(JsType.class).addJavadoc("VueComponent Directive Options for directive {@link $S}", directiveTypeElement.getQualifiedName().toString());
    // Initialize constructor
    MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);
    // Add the Java Component Instance initialization
    constructorBuilder.addStatement("this.$L = new $T()", "vuegwt$javaDirectiveInstance", TypeName.get(directiveTypeElement.asType()));
    // Call the method to copy hooks functions
    constructorBuilder.addStatement("this.copyHooks()");
    // Finish building the constructor
    componentClassBuilder.addMethod(constructorBuilder.build());
    // Build the DirectiveOptions class
    GeneratorsUtil.toJavaFile(filer, componentClassBuilder, optionsClassName, directiveTypeElement);
}
Also used : JsType(jsinterop.annotations.JsType) MethodSpec(com.squareup.javapoet.MethodSpec) Builder(com.squareup.javapoet.TypeSpec.Builder) ClassName(com.squareup.javapoet.ClassName)

Example 5 with Builder

use of com.squareup.javapoet.TypeSpec.Builder in project glide by bumptech.

the class AppModuleGenerator method generate.

TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClassNames) {
    ClassName appGlideModuleClassName = ClassName.get(appGlideModule);
    List<String> excludedGlideModuleClassNames = getExcludedGlideModuleClassNames(appGlideModule);
    List<String> orderedLibraryGlideModuleClassNames = new ArrayList<>(libraryGlideModuleClassNames);
    Collections.sort(orderedLibraryGlideModuleClassNames);
    MethodSpec constructor = generateConstructor(appGlideModuleClassName, orderedLibraryGlideModuleClassNames, excludedGlideModuleClassNames);
    MethodSpec registerComponents = generateRegisterComponents(orderedLibraryGlideModuleClassNames, excludedGlideModuleClassNames);
    MethodSpec getExcludedModuleClasses = generateGetExcludedModuleClasses(excludedGlideModuleClassNames);
    MethodSpec applyOptions = MethodSpec.methodBuilder("applyOptions").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(ParameterSpec.builder(ClassName.get("android.content", "Context"), "context").addAnnotation(nonNull()).build()).addParameter(ParameterSpec.builder(ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder").addAnnotation(nonNull()).build()).addStatement("appGlideModule.applyOptions(context, builder)", appGlideModule).build();
    MethodSpec isManifestParsingEnabled = MethodSpec.methodBuilder("isManifestParsingEnabled").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(boolean.class).addStatement("return appGlideModule.isManifestParsingEnabled()", appGlideModule).build();
    Builder builder = TypeSpec.classBuilder(GENERATED_APP_MODULE_IMPL_SIMPLE_NAME).addModifiers(Modifier.FINAL).addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "deprecation").build()).superclass(ClassName.get(GENERATED_ROOT_MODULE_PACKAGE_NAME, GENERATED_ROOT_MODULE_SIMPLE_NAME)).addField(appGlideModuleClassName, "appGlideModule", Modifier.PRIVATE, Modifier.FINAL).addMethod(constructor).addMethod(applyOptions).addMethod(registerComponents).addMethod(isManifestParsingEnabled).addMethod(getExcludedModuleClasses);
    ClassName generatedRequestManagerFactoryClassName = ClassName.get(RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_PACKAGE_NAME, RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_SIMPLE_NAME);
    builder.addMethod(MethodSpec.methodBuilder("getRequestManagerFactory").addAnnotation(Override.class).addAnnotation(nonNull()).returns(generatedRequestManagerFactoryClassName).addStatement("return new $T()", generatedRequestManagerFactoryClassName).build());
    return builder.build();
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) Builder(com.squareup.javapoet.TypeSpec.Builder) ClassName(com.squareup.javapoet.ClassName) ArrayList(java.util.ArrayList)

Aggregations

Builder (com.squareup.javapoet.TypeSpec.Builder)36 ClassName (com.squareup.javapoet.ClassName)25 MethodSpec (com.squareup.javapoet.MethodSpec)24 TypeSpec (com.squareup.javapoet.TypeSpec)15 TypeElement (javax.lang.model.element.TypeElement)15 TypeName (com.squareup.javapoet.TypeName)12 ExecutableElement (javax.lang.model.element.ExecutableElement)12 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)11 PackageElement (javax.lang.model.element.PackageElement)6 VariableElement (javax.lang.model.element.VariableElement)6 TypeMirror (javax.lang.model.type.TypeMirror)6 JavaFile (com.squareup.javapoet.JavaFile)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Element (javax.lang.model.element.Element)5 DeclaredType (javax.lang.model.type.DeclaredType)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutableType (javax.lang.model.type.ExecutableType)3