use of com.squareup.javapoet.MethodSpec in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildRegisterEventLogPushFunction.
private MethodSpec buildRegisterEventLogPushFunction(String eventName) throws ClassNotFoundException {
String generatedFunctionName = "register" + eventName + "EventLogFilter";
MethodSpec.Builder getEventMethodBuilder = MethodSpec.methodBuilder(generatedFunctionName).addModifiers(Modifier.PUBLIC).addParameter(String.class, FROM_BLOCK).addParameter(String.class, TO_BLOCK);
addParameter(getEventMethodBuilder, "string[]", OTHER_TOPICS).addParameter(AbiTypes.getType("EventLogPushCallback"), CALLBACK_VALUE);
getEventMethodBuilder.addStatement("String topic0 = $T.encode(" + buildEventDefinitionName(eventName) + ")", EventEncoder.class);
getEventMethodBuilder.addStatement("registerEventLogPushFilter(ABI,BINARY" + "," + "topic0" + "," + FROM_BLOCK + "," + TO_BLOCK + "," + OTHER_TOPICS + "," + CALLBACK_VALUE + ")");
return getEventMethodBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project web3sdk by FISCO-BCOS.
the class AbiTypesMapperGenerator method generate.
private void generate(String destinationDir) throws IOException {
String typesPackageName = "org.fisco.bcos.web3j.abi.datatypes";
String autoGeneratedTypesPackageName = typesPackageName + ".generated";
MethodSpec.Builder builder = MethodSpec.methodBuilder("getType").addModifiers(Modifier.PUBLIC, Modifier.STATIC).addParameter(String.class, TYPE).returns(ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class))).beginControlFlow("switch (type)");
builder = addTypes(builder, typesPackageName);
builder = addGeneratedTypes(builder, autoGeneratedTypesPackageName);
builder = builder.addStatement("default:\nthrow new $T($S\n+ $N)", UnsupportedOperationException.class, "Unsupported type encountered: ", TYPE);
builder.endControlFlow();
MethodSpec methodSpec = builder.build();
MethodSpec constructorSpec = MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).build();
TypeSpec typeSpec = TypeSpec.classBuilder("AbiTypes").addJavadoc(buildWarning(AbiTypesMapperGenerator.class)).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(constructorSpec).addMethod(methodSpec).build();
write(autoGeneratedTypesPackageName, typeSpec, destinationDir);
}
use of com.squareup.javapoet.MethodSpec in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method targetWithNextHelper.
/**
* Writes a class file {@code Deps(index).java} to the directory
* {@code projectPath/com/example/deps(index)}
*
* @param callNext if we should call the method from {@code Deps(index+1).java}
*/
static void targetWithNextHelper(int index, boolean callNext, Path projectPath) throws IOException {
ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
MethodSpec callNextMethod = MethodSpec.methodBuilder("CallNext").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(void.class).addStatement("$T.PrintSth()", nextClass).build();
TypeSpec.Builder klassBuilder = TypeSpec.classBuilder("Deps" + index).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(randomMethod);
if (callNext) {
klassBuilder.addMethod(callNextMethod);
}
TypeSpec klass = klassBuilder.build();
writeClassToDir(klass, "com.example.deps" + index, projectPath);
}
use of com.squareup.javapoet.MethodSpec in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method targetWithNextExtraHelper.
/**
* Writes a class file {@code Deps(index).java} with extra method {@code printSthElse()}
* to the directory {@code projectPath/com/example/deps(index)}
*
* @param callNext if we should call the method from {@code Deps(index+1).java}
*/
static void targetWithNextExtraHelper(int index, boolean callNext, Path projectPath) throws IOException {
ClassName nextClass = ClassName.get("com.example.deps" + (index + 1), "Deps" + (index + 1));
MethodSpec callNextMethod = MethodSpec.methodBuilder("CallNext").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(void.class).addStatement("$T.PrintSth()", nextClass).build();
TypeSpec.Builder klassBuilder = TypeSpec.classBuilder("Deps" + index).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(randomMethod).addMethod(somethingElseMethod);
if (callNext) {
klassBuilder.addMethod(callNextMethod);
}
TypeSpec klass = klassBuilder.build();
writeClassToDir(klass, "com.example.deps" + index, projectPath);
}
use of com.squareup.javapoet.MethodSpec in project glide by bumptech.
the class RootModuleGenerator method generateConstructor.
private static MethodSpec generateConstructor(ClassName rootGlideModule, Set<String> childGlideModuleClassNames, Set<String> excludedGlideModuleClassNames) {
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
constructorBuilder.addStatement("rootGlideModule = new $T()", rootGlideModule);
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 RootGlideModule from annotation: " + rootGlideModule);
// Excluded GlideModule classes from the manifest are logged in Glide's singleton.
for (String glideModule : childGlideModuleClassNames) {
ClassName moduleClassName = ClassName.bestGuess(glideModule);
if (excludedGlideModuleClassNames.contains(glideModule)) {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG, "RootGlideModule excludes ChildGlideModule from annotation: " + moduleClassName);
} else {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG, "Discovered ChildGlideModule from annotation: " + moduleClassName);
}
}
constructorBuilder.endControlFlow();
return constructorBuilder.build();
}
Aggregations