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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations