use of com.squareup.javapoet.MethodSpec in project web3sdk by FISCO-BCOS.
the class AbiTypesGenerator method generateBytesTypes.
private <T extends Type> void generateBytesTypes(Class<T> superclass, Path path) throws IOException {
String packageName = createPackageName(superclass);
ClassName className;
for (int byteSize = 1; byteSize <= 32; byteSize++) {
MethodSpec constructorSpec = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addParameter(byte[].class, "value").addStatement("super($L, $N)", byteSize, "value").build();
className = ClassName.get(packageName, superclass.getSimpleName() + byteSize);
FieldSpec defaultFieldSpec = FieldSpec.builder(className, DEFAULT, Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("new $T(new byte[$L])", className, byteSize).build();
TypeSpec bytesType = TypeSpec.classBuilder(className.simpleName()).addJavadoc(CODEGEN_WARNING).superclass(superclass).addModifiers(Modifier.PUBLIC).addField(defaultFieldSpec).addMethod(constructorSpec).build();
write(packageName, bytesType, path);
}
}
use of com.squareup.javapoet.MethodSpec in project web3sdk by FISCO-BCOS.
the class AbiTypesGenerator method generateIntTypes.
private <T extends Type> void generateIntTypes(Class<T> superclass, Path path) throws IOException {
String packageName = createPackageName(superclass);
ClassName className;
for (int bitSize = 8; bitSize <= Type.MAX_BIT_LENGTH; bitSize += 8) {
className = ClassName.get(packageName, superclass.getSimpleName() + bitSize);
MethodSpec constructorSpec = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addParameter(BigInteger.class, "value").addStatement("super($L, $N)", bitSize, "value").build();
MethodSpec overideConstructorSpec = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addParameter(long.class, "value").addStatement("this(BigInteger.valueOf(value))").build();
FieldSpec defaultFieldSpec = FieldSpec.builder(className, DEFAULT, Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("new $T(BigInteger.ZERO)", className).build();
TypeSpec intType = TypeSpec.classBuilder(className.simpleName()).addJavadoc(CODEGEN_WARNING).superclass(superclass).addModifiers(Modifier.PUBLIC).addField(defaultFieldSpec).addMethods(Arrays.asList(constructorSpec, overideConstructorSpec)).build();
write(packageName, intType, path);
}
}
use of com.squareup.javapoet.MethodSpec in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildEventObservableFunction.
static MethodSpec buildEventObservableFunction(String responseClassName, String functionName, List<NamedTypeName> indexedParameters, List<NamedTypeName> nonIndexedParameters) throws ClassNotFoundException {
String generatedFunctionName = Strings.lowercaseFirstLetter(functionName) + "EventObservable";
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName.get(ClassName.get(rx.Observable.class), ClassName.get("", responseClassName));
MethodSpec.Builder observableMethodBuilder = MethodSpec.methodBuilder(generatedFunctionName).addModifiers(Modifier.PUBLIC).addParameter(DefaultBlockParameter.class, START_BLOCK).addParameter(DefaultBlockParameter.class, END_BLOCK).returns(parameterizedTypeName);
buildVariableLengthEventConstructor(observableMethodBuilder, functionName, indexedParameters, nonIndexedParameters);
TypeSpec converter = TypeSpec.anonymousClassBuilder("").addSuperinterface(ParameterizedTypeName.get(ClassName.get(Func1.class), ClassName.get(Log.class), ClassName.get("", responseClassName))).addMethod(MethodSpec.methodBuilder("call").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(Log.class, "log").returns(ClassName.get("", responseClassName)).addStatement("$T eventValues = extractEventParameters(event, log)", EventValues.class).addStatement("$1T typedResponse = new $1T()", ClassName.get("", responseClassName)).addCode(buildTypedResponse("typedResponse", indexedParameters, nonIndexedParameters)).addStatement("return typedResponse").build()).build();
observableMethodBuilder.addStatement("$1T filter = new $1T($2L, $3L, " + "getContractAddress())", EthFilter.class, START_BLOCK, END_BLOCK).addStatement("filter.addSingleTopic($T.encode(event))", EventEncoder.class).addStatement("return web3j.ethLogObservable(filter).map($L)", converter);
return observableMethodBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project Rocket by mozilla-tw.
the class AppModuleGenerator method generateRegisterComponents.
private MethodSpec generateRegisterComponents(Set<String> libraryGlideModuleClassNames, Set<String> excludedGlideModuleClassNames) {
MethodSpec.Builder registerComponents = MethodSpec.methodBuilder("registerComponents").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addParameter(ClassName.get("android.content", "Context"), "context").addParameter(ClassName.get("com.bumptech.glide", "Glide"), "glide").addParameter(ClassName.get("com.bumptech.glide", "Registry"), "registry");
for (String glideModule : libraryGlideModuleClassNames) {
if (excludedGlideModuleClassNames.contains(glideModule)) {
continue;
}
ClassName moduleClassName = ClassName.bestGuess(glideModule);
registerComponents.addStatement("new $T().registerComponents(context, glide, registry)", moduleClassName);
}
// Order matters here. The AppGlideModule must be called last.
registerComponents.addStatement("appGlideModule.registerComponents(context, glide, registry)");
return registerComponents.build();
}
use of com.squareup.javapoet.MethodSpec in project Rocket by mozilla-tw.
the class AppModuleGenerator method generateConstructor.
private MethodSpec generateConstructor(ClassName appGlideModule, Set<String> libraryGlideModuleClassNames, Set<String> excludedGlideModuleClassNames) {
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
constructorBuilder.addStatement("appGlideModule = new $T()", appGlideModule);
ClassName androidLogName = ClassName.get("android.util", "Log");
// Add some log lines to indicate to developers which modules where discovered.
constructorBuilder.beginControlFlow("if ($T.isLoggable($S, $T.DEBUG))", androidLogName, GLIDE_LOG_TAG, androidLogName);
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG, "Discovered AppGlideModule from annotation: " + appGlideModule);
// Excluded GlideModule classes from the manifest are logged in Glide's singleton.
for (String glideModule : libraryGlideModuleClassNames) {
ClassName moduleClassName = ClassName.bestGuess(glideModule);
if (excludedGlideModuleClassNames.contains(glideModule)) {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG, "AppGlideModule excludes LibraryGlideModule from annotation: " + moduleClassName);
} else {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG, "Discovered LibraryGlideModule from annotation: " + moduleClassName);
}
}
constructorBuilder.endControlFlow();
return constructorBuilder.build();
}
Aggregations