本文整理匯總了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();
}