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