本文整理汇总了Java中com.squareup.javapoet.TypeSpec.Builder.build方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.build方法的具体用法?Java Builder.build怎么用?Java Builder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.TypeSpec.Builder
的用法示例。
在下文中一共展示了Builder.build方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: poetSpec
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
@Override
public TypeSpec poetSpec() {
Builder enumBuilder = createEnumBuilder(className)
.addField(String.class, VALUE, Modifier.PRIVATE, Modifier.FINAL)
.addMethod(toStringBuilder().addStatement("return $T.valueOf($N)", String.class, VALUE).build())
.addMethod(fromValueSpec())
.addMethod(knownValuesSpec())
.addMethod(createConstructor());
addDeprecated(enumBuilder::addAnnotation, shape);
addJavadoc(enumBuilder::addJavadoc, shape);
shape.getEnums().forEach(
e -> enumBuilder.addEnumConstant(e.getName(), TypeSpec.anonymousClassBuilder("$S", e.getValue()).build())
);
enumBuilder.addEnumConstant(UNKNOWN_TO_SDK_VERSION, TypeSpec.anonymousClassBuilder("null").build());
return enumBuilder.build();
}
示例2: getTypeSpec
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* genera classe di test per clazz
*
* @param clazz
* @param prop
* @param mongo
* @return
*/
@Override
public TypeSpec getTypeSpec(Class<?> clazz) {
Builder classTestBuilder = TypeSpec.classBuilder(clazz.getSimpleName() + TEST);
ClassName superClass = ClassName.get(
PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_PACKAGE),
PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_CLASS));
classTestBuilder.superclass(superClass);
classTestBuilder.addJavadoc("@author \n");
classTestBuilder.addModifiers(Modifier.PUBLIC);
AnnotationSpec.Builder annSpecBuilder = AnnotationSpec.builder(Generated.class);
annSpecBuilder.addMember("value", "\"it.fratta.jerkoff.Generator\"");
annSpecBuilder.addMember("date", "\"" + Calendar.getInstance().getTime().toString() + "\"");
AnnotationSpec annGenSpec = annSpecBuilder.build();
classTestBuilder.addAnnotation(annGenSpec);
/*
* for spring test
*/
// FieldSpec.Builder spec = FieldSpec.builder(clazz,
// getNewInstanceOfNoParameters(clazz), Modifier.PRIVATE);
// spec.addAnnotation(Autowired.class);
// classTestBuilder.addField(spec.build());
addClassMethodsToBuilder(classTestBuilder, clazz);
return classTestBuilder.build();
}
示例3: buildTemplateImpl
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Create the template resource implementation based on the result of the template parser.
* @param componentTypeName The name of our Template class
* @param templateParserResult The result of the HTML template parsed by {@link TemplateParser}
* render function
* @param templateCompilerResourceFolder Folder holding res
* @return The built Java class representing our template
*/
public TypeSpec buildTemplateImpl(ClassName componentTypeName,
TemplateParserResult templateParserResult, Folder templateCompilerResourceFolder)
{
Builder templateImplBuilder = TypeSpec
.classBuilder(componentTemplateImplName(componentTypeName))
.addModifiers(Modifier.PUBLIC)
.superclass(componentJsTypeName(componentTypeName))
.addSuperinterface(componentTemplateName(componentTypeName));
// Compile the resulting HTML template String
compileTemplateString(templateImplBuilder,
templateParserResult.getProcessedTemplate(),
templateCompilerResourceFolder);
// Process the java expressions from the template
processTemplateExpressions(templateImplBuilder, templateParserResult);
return templateImplBuilder.build();
}
示例4: poetSpec
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
@Override
public TypeSpec poetSpec() {
ClassName interfaceClass = poetExtensions.getClientClass(model.getMetadata().getSyncInterface());
Builder classBuilder = PoetUtils.createClassBuilder(className)
.addAnnotation(SdkInternalApi.class)
.addModifiers(FINAL)
.addSuperinterface(interfaceClass)
.addJavadoc("Internal implementation of {@link $1T}.\n\[email protected] $1T#builder()",
interfaceClass)
.addField(ClientHandler.class, "clientHandler", PRIVATE, FINAL)
.addField(protocolSpec.protocolFactory(model))
.addField(ClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL)
.addMethods(operations());
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
classBuilder.addMethod(constructorWithAdvancedConfiguration());
} else {
classBuilder.addMethod(constructor());
}
protocolSpec.createErrorResponseHandler().ifPresent(classBuilder::addMethod);
classBuilder.addMethod(protocolSpec.initProtocolFactory(model));
classBuilder.addMethod(closeMethod());
classBuilder.addMethods(protocolSpec.additionalMethods());
return classBuilder.build();
}
示例5: generate
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClassNames) {
ClassName appGlideModuleClassName = ClassName.get(appGlideModule);
Set<String> excludedGlideModuleClassNames =
getExcludedGlideModuleClassNames(appGlideModule);
MethodSpec constructor =
generateConstructor(
appGlideModuleClassName, libraryGlideModuleClassNames, excludedGlideModuleClassNames);
MethodSpec registerComponents =
generateRegisterComponents(libraryGlideModuleClassNames, excludedGlideModuleClassNames);
MethodSpec getExcludedModuleClasses =
generateGetExcludedModuleClasses(excludedGlideModuleClassNames);
MethodSpec applyOptions =
MethodSpec.methodBuilder("applyOptions")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addParameter(ClassName.get("android.content", "Context"), "context")
.addParameter(ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder")
.addStatement("appGlideModule.applyOptions(context, builder)", appGlideModule)
.build();
MethodSpec isManifestParsingEnabled =
MethodSpec.methodBuilder("isManifestParsingEnabled")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(boolean.class)
.addStatement("return appGlideModule.isManifestParsingEnabled()", appGlideModule)
.build();
Builder builder = TypeSpec.classBuilder(GENERATED_APP_MODULE_IMPL_SIMPLE_NAME)
.addModifiers(Modifier.FINAL)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build()
)
.superclass(
ClassName.get(GENERATED_ROOT_MODULE_PACKAGE_NAME, GENERATED_ROOT_MODULE_SIMPLE_NAME))
.addField(appGlideModuleClassName, "appGlideModule", Modifier.PRIVATE, Modifier.FINAL)
.addMethod(constructor)
.addMethod(applyOptions)
.addMethod(registerComponents)
.addMethod(isManifestParsingEnabled)
.addMethod(getExcludedModuleClasses);
ClassName generatedRequestManagerFactoryClassName =
ClassName.get(
RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_PACKAGE_NAME,
RequestManagerFactoryGenerator.GENERATED_REQUEST_MANAGER_FACTORY_SIMPLE_NAME);
builder.addMethod(
MethodSpec.methodBuilder("getRequestManagerFactory")
.addAnnotation(Override.class)
.returns(generatedRequestManagerFactoryClassName)
.addStatement("return new $T()", generatedRequestManagerFactoryClassName)
.build());
return builder.build();
}