use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableClassRendererV2 method renderNamedGetRangeStartEnd.
private MethodSpec renderNamedGetRangeStartEnd(NamedColumnDescription col) {
Preconditions.checkArgument(tableMetadata.getRowMetadata().getRowParts().size() == 1);
NameComponentDescription rowComponent = tableMetadata.getRowMetadata().getRowParts().get(0);
MethodSpec.Builder getterBuilder = MethodSpec.methodBuilder("getSmallRowRange" + VarName(col)).addModifiers(Modifier.PUBLIC).addJavadoc("Returns a mapping from all the row keys in a range to their value at column $L\n" + "(if that column exists for the row-key). As the $L values are all loaded in memory,\n" + "do not use for large amounts of data. The order of results is preserved in the map.", VarName(col), VarName(col)).addParameter(rowComponent.getType().getJavaClass(), "startInclusive").addParameter(rowComponent.getType().getJavaClass(), "endExclusive").returns(ParameterizedTypeName.get(ClassName.get(LinkedHashMap.class), ClassName.get(rowComponent.getType().getJavaClass()), ClassName.get(getColumnClassForGenericTypeParameter(col))));
getterBuilder.addStatement("$T rangeRequest = $T.builder()\n" + ".startRowInclusive($T.of(startInclusive).persistToBytes())\n" + ".endRowExclusive($T.of(endExclusive).persistToBytes())\n" + ".build()", RangeRequest.class, RangeRequest.class, rowType, rowType).addStatement("return getSmallRowRange$L(rangeRequest)", VarName(col));
return getterBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableClassRendererV2 method renderNamedGetRangeColumn.
private MethodSpec renderNamedGetRangeColumn(NamedColumnDescription col) {
Preconditions.checkArgument(tableMetadata.getRowMetadata().getRowParts().size() == 1);
NameComponentDescription rowComponent = tableMetadata.getRowMetadata().getRowParts().get(0);
MethodSpec.Builder getterBuilder = MethodSpec.methodBuilder("getSmallRowRange" + VarName(col)).addModifiers(Modifier.PUBLIC).addJavadoc("Returns a mapping from all the row keys in a rangeRequest to their value at column $L\n" + "(if that column exists for the row-key). As the $L values are all loaded in memory,\n" + "do not use for large amounts of data. The order of results is preserved in the map.", VarName(col), VarName(col)).addParameter(RangeRequest.class, "rangeRequest").returns(ParameterizedTypeName.get(ClassName.get(LinkedHashMap.class), ClassName.get(rowComponent.getType().getJavaClass()), ClassName.get(getColumnClassForGenericTypeParameter(col))));
getterBuilder.addStatement("$T colSelection =\n" + "$T.create($T.of($T.toCachedBytes($L)))", ColumnSelection.class, ColumnSelection.class, ImmutableList.class, PtBytes.class, ColumnRenderers.short_name(col)).addStatement("rangeRequest = rangeRequest.getBuilder().retainColumns(colSelection).build()").addStatement("$T.checkArgument(rangeRequest.getColumnNames().size() <= 1,\n$S)", Preconditions.class, "Must not request columns other than " + VarName(col) + ".").addCode("\n").addStatement("$T<$T, $T> resultsMap = new $T<>()", LinkedHashMap.class, rowComponent.getType().getJavaClass(), getColumnClassForGenericTypeParameter(col), LinkedHashMap.class).addStatement("$T.of(t.getRange(tableRef, rangeRequest))\n" + ".immutableCopy().forEach(entry -> {\n" + " $T resultEntry =\n " + " $T.of(entry);\n" + " resultsMap.put(resultEntry.getRowName().get$L(), resultEntry.get$L());\n" + "})", BatchingVisitableView.class, rowResultType, rowResultType, CamelCase(rowComponent.getComponentName()), VarName(col)).addStatement("return resultsMap");
return getterBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project mvp4g2 by mvp4g.
the class ApplicationGenerator method generate.
public void generate(ApplicationMetaModel metaModel) throws ProcessorException {
// check if element is existing (to avoid generating code for deleted items)
if (!this.processorUtils.doesExist(metaModel.getApplication())) {
return;
}
// generate code
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(metaModel.getApplication().getSimpleName() + ApplicationGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(ClassName.get(AbstractApplication.class), metaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(metaModel.getApplication().getTypeName());
// constructor ...
MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super()").addStatement("super.eventBus = new $N.$N()", metaModel.getEventBus().getPackage(), metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME).addStatement("super.historyOnStart = $L", metaModel.getHistoryOnStart()).build();
typeSpec.addMethod(constructor);
// method "getApplicaitonLoader"
MethodSpec getApplicaitonLaoderMethod = MethodSpec.methodBuilder("getApplicationLoader").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(IsApplicationLoader.class).addStatement("return new $T()", metaModel.getLoader().getTypeName()).build();
typeSpec.addMethod(getApplicaitonLaoderMethod);
JavaFile javaFile = JavaFile.builder(metaModel.getEventBus().getPackage(), typeSpec.build()).build();
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
}
}
use of com.squareup.javapoet.MethodSpec in project mvp4g2 by mvp4g.
the class EventBusGenerator method generate.
public void generate(EventBusMetaModel eventBusMetaMetaModel, HandlerMetaModel handlerMetaModel, PresenterMetaModel presenterMetaModel, HistoryMetaModel historyMetaModel) throws ProcessorException {
// check if element is existing (to avoid generating code for deleted items)
if (!this.processorUtils.doesExist(eventBusMetaMetaModel.getEventBus())) {
return;
}
ClassName abstractEventBusClassName = ClassName.get(AbstractEventBus.class);
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(abstractEventBusClassName, eventBusMetaMetaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(eventBusMetaMetaModel.getEventBus().getTypeName());
MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S)", eventBusMetaMetaModel.getShell().getClassName()).build();
typeSpec.addMethod(constructor);
DebugGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
FilterGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
EventLoadMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
EventMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).build().generate();
EventHandlingMethodGenerator.builder().processorUtils(this.processorUtils).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).historyMetaModel(historyMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
AddPresenterGenerator.builder().typeSpec(typeSpec).processingEnvironment(this.processingEnvironment).presenterMetaModel(presenterMetaModel).build().generate();
HandlerAndPresenterRegristrationGenerator.builder().processingEnvironment(this.processingEnvironment).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
JavaFile javaFile = JavaFile.builder(eventBusMetaMetaModel.getEventBus().getPackage(), typeSpec.build()).build();
// System.out.println(javaFile.toString());
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
}
}
use of com.squareup.javapoet.MethodSpec 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