use of com.squareup.javapoet.JavaFile in project graylog2-server by Graylog2.
the class WithBeanGetterExtension method generateClass.
@Override
public String generateClass(Context context, String className, String classToExtend, boolean isFinal) {
final TypeSpec.Builder typeSpecBuilder = newTypeSpecBuilder(context, className, classToExtend, isFinal);
final Map<String, ExecutableElement> properties = context.properties();
for (Map.Entry<String, ExecutableElement> entry : properties.entrySet()) {
typeSpecBuilder.addMethod(generateGetterMethod(entry.getKey(), entry.getValue()));
}
final JavaFile javaFile = JavaFile.builder(context.packageName(), typeSpecBuilder.build()).build();
return javaFile.toString();
}
use of com.squareup.javapoet.JavaFile in project bazel by bazelbuild.
the class JavaCodeGeneratorHelper method writeClassToDir.
private static void writeClassToDir(TypeSpec klass, String packageName, Path path) throws IOException {
JavaFile javaFile = JavaFile.builder(packageName, klass).build();
javaFile.writeTo(path);
}
use of com.squareup.javapoet.JavaFile in project web3sdk by FISCO-BCOS.
the class AbiTypesMapperGenerator method write.
private void write(String packageName, TypeSpec typeSpec, Path destination) throws IOException {
JavaFile javaFile = JavaFile.builder(packageName, typeSpec).indent(" ").skipJavaLangImports(true).build();
javaFile.writeTo(destination);
}
use of com.squareup.javapoet.JavaFile in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method generateJavaFiles.
public void generateJavaFiles(String contractName, String bin, String abi, String destinationDirLocation, String basePackageName) throws IOException, ClassNotFoundException {
String className = Strings.capitaliseFirstLetter(contractName);
TypeSpec.Builder classBuilder = createClassBuilder(className, bin, abi);
classBuilder.addMethod(buildConstructor(Credentials.class, CREDENTIALS));
classBuilder.addMethod(buildConstructor(TransactionManager.class, TRANSACTION_MANAGER));
classBuilder.addMethod(buildConstructorWithDefaultParam(Credentials.class, CREDENTIALS));
classBuilder.addMethod(buildConstructorWithDefaultParam(TransactionManager.class, TRANSACTION_MANAGER));
classBuilder.addMethods(buildFunctionDefinitions(className, classBuilder, loadContractDefinition(abi)));
classBuilder.addMethod(buildLoad(className, Credentials.class, CREDENTIALS));
classBuilder.addMethod(buildLoad(className, TransactionManager.class, TRANSACTION_MANAGER));
classBuilder.addMethod(buildLoadByName(className, Credentials.class, CREDENTIALS));
classBuilder.addMethod(buildLoadByName(className, TransactionManager.class, TRANSACTION_MANAGER));
JavaFile javaFile = JavaFile.builder(basePackageName, classBuilder.build()).indent(" ").skipJavaLangImports(true).build();
javaFile.writeTo(new File(destinationDirLocation));
}
use of com.squareup.javapoet.JavaFile in project Bro by 2BAB.
the class CodeGenerator method generateMergeMapFile.
/**
* Step 3 :
* <p>
* Generate all map file with temp-json by other module in app-module's build path
*
* @param packageName package name for generating host file
* @param filer filer tools
* @param existFile exist file generated by processor.init()
*/
public static void generateMergeMapFile(String packageName, Map<String, Map<String, BroProperties>> exposeMaps, Filer filer, File existFile, String rootProjectPath) {
try {
TypeSpec.Builder builder = TypeSpec.classBuilder(Constants.MERGED_MAP_FILE_NAME).addModifiers(Modifier.PUBLIC).addSuperinterface(IBroMap.class);
for (Map.Entry<String, Map<String, BroProperties>> entry : exposeMaps.entrySet()) {
builder.addMethod(generateMapMethod("get" + entry.getKey() + "Map", entry.getValue()));
}
JavaFile file = JavaFile.builder(packageName, builder.build()).addFileComment("Generated by Bro.").build();
if (existFile == null) {
// standard output
file.writeTo(filer);
} else {
// hack file override exception
File folder = existFile.getParentFile();
int times = file.toJavaFileObject().toUri().toString().split("/").length;
for (int i = 1; i < times; i++) {
folder = folder.getParentFile();
}
file.writeTo(folder);
}
DocGenerator.generateDoc(rootProjectPath, exposeMaps);
} catch (Exception e) {
BroCompileLogger.e(e.getMessage());
}
}
Aggregations