use of com.squareup.javapoet.TypeSpec.Builder in project vue-gwt by Axellience.
the class AbstractVueComponentFactoryGenerator method generate.
/**
* Generate our {@link VueComponentFactory} class.
*
* @param component The {@link IsVueComponent} class to generate {@link VueComponentOptions} from
*/
public void generate(TypeElement component) {
ClassName vueFactoryClassName = componentFactoryName(component);
Builder vueFactoryBuilder = createFactoryBuilderClass(component, vueFactoryClassName);
createGetName(vueFactoryBuilder, component);
createProperties(vueFactoryClassName, vueFactoryBuilder);
List<CodeBlock> staticInitParameters = createInitMethod(component, vueFactoryBuilder);
createStaticGetMethod(component, vueFactoryClassName, vueFactoryBuilder, staticInitParameters);
vueFactoryBuilder.addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PROTECTED).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 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 kripton by xcesco.
the class BindDaoBuilder method visit.
/*
* (non-Javadoc)
*
* @see
* com.abubusoft.kripton.processor.sqlite.model.SQLiteModelElementVisitor#
* visit(com.abubusoft.kripton.processor.sqlite.model.SQLiteDaoDefinition)
*/
@Override
public void visit(SQLiteDaoDefinition value) throws Exception {
currentDaoDefinition = value;
// check if we need to generate or not
if (value.getElement().getAnnotation(BindDaoMany2Many.class) != null && value.getElement().getAnnotation(BindGeneratedDao.class) == null) {
return;
}
String classTableName = daoName(value);
PackageElement pkg = elementUtils.getPackageOf(value.getElement());
String packageName = pkg.isUnnamed() ? "" : pkg.getQualifiedName().toString();
AnnotationProcessorUtilis.infoOnGeneratedClasses(BindDao.class, packageName, classTableName);
builder = TypeSpec.classBuilder(classTableName).superclass(Dao.class).addSuperinterface(typeName(value.getElement())).addModifiers(Modifier.PUBLIC);
for (TypeName item : value.implementedInterface) {
builder.addSuperinterface(item);
}
BindTypeContext context = new BindTypeContext(builder, TypeUtility.typeName(packageName, classTableName), Modifier.PRIVATE, Modifier.STATIC);
String entityName = BindDataSourceSubProcessor.generateEntityName(value, value.getEntity());
// javadoc for class
builder.addJavadoc("<p>");
builder.addJavadoc("\nDAO implementation for entity <code>$L</code>, based on interface <code>$L</code>\n", entityName, value.getElement().getSimpleName().toString());
builder.addJavadoc("</p>\n\n");
JavadocUtility.generateJavadocGeneratedBy(builder);
builder.addJavadoc(" @see $T\n", TypeUtility.className(value.getEntityClassName()));
builder.addJavadoc(" @see $T\n", TypeUtility.className(value.getElement().getQualifiedName().toString()));
builder.addJavadoc(" @see $T\n", BindTableGenerator.tableClassName(value, value.getEntity()));
{
// constructor
MethodSpec.Builder methodBuilder = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addParameter(BindDaoFactoryBuilder.generateDaoFactoryClassName(value.getParent()), "daoFactory");
methodBuilder.addStatement("super(daoFactory.getContext())");
if (value.hasRelations()) {
methodBuilder.addStatement("this.daoFactory=daoFactory");
builder.addField(BindDaoFactoryBuilder.generateDaoFactoryClassName(value.getParent()), "daoFactory", Modifier.PRIVATE);
}
builder.addMethod(methodBuilder.build());
}
// define column typeName set
for (SQLiteModelMethod item : value.getCollection()) {
item.accept(this);
}
// generate live data support methods
if (value.hasLiveData()) {
// method sendEvent
{
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(METHOD_NAME_REGISTRY_EVENT).addModifiers(Modifier.PROTECTED).addParameter(Integer.TYPE, "affectedRows");
methodBuilder.beginControlFlow("if (affectedRows==0)");
methodBuilder.addStatement("return");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("if (_context.isInSession())");
methodBuilder.addStatement("_context.registrySQLEvent($T.$L)", BindDataSourceBuilder.generateDataSourceName(value.getParent()), value.daoUidName);
methodBuilder.nextControlFlow("else");
methodBuilder.addStatement("invalidateLiveData()");
methodBuilder.endControlFlow();
builder.addMethod(methodBuilder.build());
}
// method registryChange
{
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("registryChange").addModifiers(Modifier.PUBLIC);
methodBuilder.addJavadoc("<p>Allows to registry change on this DAO in a transaction, in an batch operation or in a standalone operation.</p>\n\n");
methodBuilder.addStatement("registryEvent(1)");
builder.addMethod(methodBuilder.build());
}
// field liveDatas
{
FieldSpec.Builder liveDataBuilder = FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Collection.class), ParameterizedTypeName.get(ClassName.get(WeakReference.class), // WildcardTypeName.subtypeOf(Object.class)))),
ClassName.get(LiveDataHandler.class))), "liveDatas").addModifiers(Modifier.STATIC).initializer(CodeBlock.builder().add("new $T()", ParameterizedTypeName.get(ClassName.get(CopyOnWriteArraySet.class), ParameterizedTypeName.get(ClassName.get(WeakReference.class), ClassName.get(LiveDataHandler.class)))).build());
builder.addField(liveDataBuilder.build());
}
// registryLiveData
{
// .addParameter(ParameterizedTypeName.get(ClassName.get(LiveDataHandler.class),
// WildcardTypeName.subtypeOf(Object.class)), "value");
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(METHOD_NAME_REGISTRY_LIVE_DATA).addModifiers(Modifier.PROTECTED).addParameter(ClassName.get(LiveDataHandler.class), "value");
methodBuilder.addStatement("liveDatas.add(new $T(value))", ParameterizedTypeName.get(ClassName.get(WeakReference.class), ClassName.get(LiveDataHandler.class)));
builder.addMethod(methodBuilder.build());
}
// invalidateLiveData
{
// check datasource and dao package must be the same, otherwise
// invalidate must be public
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(METHOD_NAME_INVALIDATE_LIVE_DATA).addJavadoc("<p>Invalidate livedata.</p>\n\n").addModifiers(Modifier.PUBLIC);
methodBuilder.beginControlFlow("for ($T item: liveDatas)", ParameterizedTypeName.get(ClassName.get(WeakReference.class), // WildcardTypeName.subtypeOf(Object.class))));
ClassName.get(LiveDataHandler.class)));
methodBuilder.beginControlFlow("if (item.get()!=null)");
methodBuilder.addStatement("item.get().invalidate()");
methodBuilder.endControlFlow();
methodBuilder.endControlFlow();
builder.addMethod(methodBuilder.build());
}
}
// generate serializer params
for (Entry<TypeName, String> item : currentDaoDefinition.managedParams.entrySet()) {
BindTransformer.checkIfIsInUnsupportedPackage(item.getKey());
ManagedPropertyPersistenceHelper.generateParamSerializer(context, item.getValue(), item.getKey(), PersistType.BYTE);
ManagedPropertyPersistenceHelper.generateParamParser(context, item.getValue(), item.getKey(), PersistType.BYTE);
}
// generate subject
if (currentDaoDefinition.getParent().generateRx) {
ParameterizedTypeName subjectTypeName = ParameterizedTypeName.get(ClassName.get(PublishSubject.class), ClassName.get(SQLiteEvent.class));
// subject
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("getSubject").addModifiers(Modifier.PUBLIC);
methodBuilder.addStatement("return subject").returns(subjectTypeName);
builder.addMethod(methodBuilder.build());
// subject instance
FieldSpec.Builder fieldBuilder = FieldSpec.builder(subjectTypeName, "subject", Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("$T.create()", ClassName.get(PublishSubject.class));
builder.addField(fieldBuilder.build());
}
// generate prepared statement cleaner
{
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("clearCompiledStatements").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(Void.TYPE);
if (value.preparedStatementNames.size() > 0) {
methodBuilder.beginControlFlow("try");
for (String item : value.preparedStatementNames) {
methodBuilder.beginControlFlow("if ($L!=null)", item);
methodBuilder.addStatement("$L.close()", item);
methodBuilder.addStatement("$L=null", item);
methodBuilder.endControlFlow();
}
methodBuilder.nextControlFlow("catch($T e)", IOException.class);
methodBuilder.addStatement("e.printStackTrace()");
methodBuilder.endControlFlow();
}
builder.addMethod(methodBuilder.build());
}
TypeSpec typeSpec = builder.build();
JavaWriterHelper.writeJava2File(filer, packageName, typeSpec);
}
use of com.squareup.javapoet.TypeSpec.Builder in project aws-sdk-java-v2 by aws.
the class SyncClientClass method poetSpec.
@Override
public TypeSpec poetSpec() {
ClassName interfaceClass = poetExtensions.getClientClass(model.getMetadata().getSyncInterface());
Builder classBuilder = PoetUtils.createClassBuilder(className).addAnnotation(SdkInternalApi.class).addModifiers(FINAL).addSuperinterface(interfaceClass).addJavadoc("Internal implementation of {@link $1T}.\n\n@see $1T#builder()", interfaceClass).addField(logger()).addField(SyncClientHandler.class, "clientHandler", PRIVATE, FINAL).addField(protocolSpec.protocolFactory(model)).addField(SdkClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL).addMethod(constructor()).addMethod(nameMethod()).addMethods(protocolSpec.additionalMethods()).addMethods(operations()).addMethod(resolveMetricPublishersMethod());
protocolSpec.createErrorResponseHandler().ifPresent(classBuilder::addMethod);
classBuilder.addMethod(protocolSpec.initProtocolFactory(model));
classBuilder.addMethod(closeMethod());
if (model.hasPaginators()) {
classBuilder.addMethod(applyPaginatorUserAgentMethod(poetExtensions, model));
}
if (model.containsRequestSigners()) {
classBuilder.addMethod(applySignerOverrideMethod(poetExtensions, model));
}
if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
classBuilder.addMethod(utilitiesMethod());
}
model.getEndpointOperation().ifPresent(o -> classBuilder.addField(EndpointDiscoveryRefreshCache.class, "endpointDiscoveryCache", PRIVATE));
if (model.hasWaiters()) {
classBuilder.addMethod(waiterMethod());
}
return classBuilder.build();
}
Aggregations