本文整理汇总了Java中com.squareup.javapoet.JavaFile.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFile.toString方法的具体用法?Java JavaFile.toString怎么用?Java JavaFile.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.JavaFile
的用法示例。
在下文中一共展示了JavaFile.toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateClass
import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
@Override
public String generateClass(Context context, String className, String classToExtend, boolean isFinal) {
String packageName = context.packageName();
Map<String, TypeName> types = convertPropertiesToTypes(context.properties());
TypeSpec subclass = TypeSpec.classBuilder(className)
.addModifiers(isFinal ? FINAL : ABSTRACT)
.superclass(ClassName.get(context.packageName(), classToExtend))
.addMethod(generateConstructor(types))
.addMethod(generateUnbundleMethod(context))
.addMethod(generateUnboxMethod(ClassName.get("java.lang", "Byte"), TypeName.BYTE, "byte"))
.addMethod(generateUnboxMethod(ClassName.get("java.lang", "Short"), TypeName.SHORT, "short"))
.addMethod(generateUnboxMethod(ClassName.get("java.lang", "Float"), TypeName.FLOAT, "float"))
.addMethod(generateUnboxMethod(ClassName.get("java.lang", "Character"), TypeName.CHAR, "char"))
.build();
JavaFile javaFile = JavaFile.builder(packageName, subclass).build();
return javaFile.toString();
}
示例2: getBundlerClassSource
import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
/**
* Process the BundlerClass and return the source of a generated Bundler class, as a String.
* The output of this method is intended for writing to a ".java" file.
*/
public String getBundlerClassSource() {
// Create class named {FooObject}Bundler
TypeSpec bundlerType = TypeSpec.classBuilder(getBundlerClassName())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addMethod(createToBundleMethod())
.addMethod(createFromBundleMethod())
.build();
JavaFile javaFile = JavaFile.builder(info.className.packageName(), bundlerType)
.build();
return javaFile.toString();
}