本文整理汇总了Java中com.squareup.javapoet.ClassName.peerClass方法的典型用法代码示例。如果您正苦于以下问题:Java ClassName.peerClass方法的具体用法?Java ClassName.peerClass怎么用?Java ClassName.peerClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.ClassName
的用法示例。
在下文中一共展示了ClassName.peerClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBuilder
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private void generateBuilder(TypeElement element) {
if (!isJsObject(element)) {
emitError("Type isn't a pure JsType JavaScript object", element);
return;
}
ClassName className = ClassName.get(element);
ClassName builderName = className.peerClass(className.simpleName() + "JSOBuilder");
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(builderName)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT);
// Create object field
typeSpec.addField(createObjectField(className));
typeSpec.addMethods(getPropertyFields(element)
.map(this::createPropertyMethod)
.collect(Collectors.toList()));
// Create build method
typeSpec.addMethod(createBuildMethod(className, element));
// Create toJSON method
typeSpec.addMethod(createToJSONMethod(className));
// Create JsArray type
typeSpec.addType(createJsArrayInterface());
// Create JSON type
typeSpec.addType(createJsonInterface());
// Create Global type
typeSpec.addType(createGlobalInterface());
// Create Serializer type
typeSpec.addType(createSerializer(builderName));
// Create JSON serializer
typeSpec.addType(new SerializerGenerator().createSerializer(builderName.nestedClass("JreSerializer")));
JavaFile javaFile = JavaFile.builder(builderName.packageName(), typeSpec.build())
.skipJavaLangImports(true)
.build();
try {
javaFile.writeTo(this.processingEnv.getFiler());
} catch (IOException e) {
emitError("Unable to write file: " + e.getMessage(), element);
}
}
示例2: getBuilderName
import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private ClassName getBuilderName(Element element) {
ClassName className = ClassName.get(TypeMapper.asType(element));
return className.peerClass(className.simpleName() + "JSOBuilder");
}