本文整理汇总了Java中com.squareup.javapoet.TypeSpec.Builder.addField方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.addField方法的具体用法?Java Builder.addField怎么用?Java Builder.addField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.TypeSpec.Builder
的用法示例。
在下文中一共展示了Builder.addField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addInstanceFields
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void addInstanceFields(Builder classBuilder) {
for (InstanceField instanceField : this.instanceFields) {
FieldSpec field;
if (instanceField.isRegistryCodec()) {
field = FieldSpec
.builder(
ParameterizedTypeName.get(ClassName.get(Codec.class),
instanceField.codecForClass()),
instanceField.name())
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build();
}
else {
field = FieldSpec.builder(instanceField.type(), instanceField.name())
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build();
}
classBuilder.addField(field);
}
}
示例2: generate
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
public void generate(Appendable appendable) throws IOException {
Builder classBuilder = TypeSpec.classBuilder(this.className);
classBuilder.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
for (Constant constant : collectFields()) {
FieldSpec fieldSpec = FieldSpec.builder(String.class, constant.getName())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC)
.initializer("$S", constant.getValue()).build();
classBuilder.addField(fieldSpec);
}
JavaFile javaFile = JavaFile.builder(this.packageName, classBuilder.build())
.build();
javaFile.writeTo(appendable);
}
示例3: createCreatedHook
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Create the "created" hook method. This method will be called on each Component when it's
* created.
* It will inject dependencies if any, and call the {@link ComponentJavaConstructor} on the
* newly created instance.
* @param component {@link VueComponent} to process
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
* {@link VueComponentOptions}
* @param componentJsTypeBuilder Builder for the JsType class
* @param dependenciesBuilder Builder for our component dependencies, needed here to inject the
* dependencies in the instance
*/
private void createCreatedHook(TypeElement component, MethodSpec.Builder optionsBuilder,
Builder componentJsTypeBuilder, ComponentInjectedDependenciesBuilder dependenciesBuilder)
{
String hasRunCreatedFlagName = "vuegwt$hrc_" + getSuperComponentCount(component);
componentJsTypeBuilder.addField(boolean.class, hasRunCreatedFlagName, Modifier.PUBLIC);
MethodSpec.Builder createdMethodBuilder =
MethodSpec.methodBuilder("vuegwt$created").addModifiers(Modifier.PUBLIC);
// Avoid infinite recursion in case calling the Java constructor calls Vue.js constructor
// This can happen when extending an existing JS component
createdMethodBuilder.addStatement("if ($L) return", hasRunCreatedFlagName);
createdMethodBuilder.addStatement("$L = true", hasRunCreatedFlagName);
injectDependencies(component, dependenciesBuilder, createdMethodBuilder);
callConstructor(component, createdMethodBuilder);
if (hasInterface(processingEnv, component.asType(), HasCreated.class))
{
createdMethodBuilder.addStatement("super.created()");
}
componentJsTypeBuilder.addMethod(createdMethodBuilder.build());
// Register the hook
optionsBuilder.addStatement("options.addHookMethod($S, $S)", "created", "vuegwt$created");
}
示例4: createProperties
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Create the static properties used in our {@link VueFactory}.
* @param vueFactoryType The generated type name for our {@link VueFactory}
* @param vueFactoryBuilder The builder to create our {@link VueFactory} class
*/
private void createProperties(ClassName vueFactoryType, Builder vueFactoryBuilder)
{
vueFactoryBuilder.addField(FieldSpec
.builder(vueFactoryType, INSTANCE_PROP, Modifier.PRIVATE, Modifier.STATIC)
.build());
}
示例5: generateGwtBundle
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
public static void generateGwtBundle(TypeElement sourceType, ClassName bundleClassName,
String bundleMethodName, TypeName resourceType, String resourceExtension, Filer filer)
{
Builder bundleClassBuilder = TypeSpec
.interfaceBuilder(bundleClassName)
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(ClientBundle.class);
bundleClassBuilder.addField(FieldSpec
.builder(bundleClassName, "INSTANCE", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(CodeBlock.of("$T.create($T.class)", GWT.class, bundleClassName))
.build());
String typeElementName = sourceType.getQualifiedName().toString();
String resourcePath = typeElementName.replaceAll("\\.", "/") + "." + resourceExtension;
AnnotationSpec annotationSpec = AnnotationSpec
.builder(Source.class)
.addMember("value", CodeBlock.of("$S", resourcePath))
.build();
bundleClassBuilder.addMethod(MethodSpec
.methodBuilder(bundleMethodName)
.addAnnotation(annotationSpec)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(resourceType)
.build());
GenerationUtil.toJavaFile(filer, bundleClassBuilder, bundleClassName, sourceType);
}
示例6: addFunction
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void addFunction(
final Builder builder, final TypeElement typeElement,
final Element element, final JFunction annotation
) {
final JFunctionType functionType = annotation.type();
final String packageName = getFunctionPackageName(functionType);
final String caller = ModelUtils.getCaller(element);
final TypeName typeName = TypeUtils.getTypeName(element, true);
final boolean nullable = annotation.nullable();
final String operation = nullable ? "(input != null) ? input.$L : null" : "input.$L";
final ParameterizedTypeName fieldTypeName = ParameterizedTypeName.get(
ClassName.get(packageName, CLASS_NAME),
TypeUtils.getTypeName(typeElement),
typeName
);
builder.addField(
FieldSpec.builder(
fieldTypeName,
SourceCodeUtils.normalizeName(TypeUtils.getName(element)),
Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC
)
.initializer(
SourceTextUtils.lines(
"new $T() {",
"@Override",
"public $T apply(final $T input) {",
"return " + operation + ";",
"}",
"}"
),
fieldTypeName,
typeName, typeElement,
caller
)
.build()
);
}
示例7: addInstanceFields
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void addInstanceFields(Builder classBuilder) {
for (InstanceField instanceField : this.instanceFields) {
FieldSpec field = FieldSpec
.builder(instanceField.type(), instanceField.name())
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build();
classBuilder.addField(field);
}
}
示例8: generateJavaFile
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
public JavaFile generateJavaFile(
String packageName,
String classToInvoke,
String newClassName,
ClassMethod classMethod,
BuilderStyle builderStyle) {
final ClassName instanceClassName = ClassName.get(packageName, classToInvoke);
final ParameterSpec instanceParameter =
builder(instanceClassName, "instance", FINAL) //
.build();
final MethodSpec.Builder constructor = getConstructor(builderStyle, instanceParameter);
setDefaltParameters(classMethod.getParameters(), constructor);
final Builder javaFile =
classBuilder(newClassName) //
.addModifiers(PUBLIC, FINAL) //
.addMethod(
constructor //
.build());
final ClassName self = ClassName.get(packageName, newClassName);
addParameters(classMethod, javaFile, self);
if (builderStyle == SUPPLY_INSTANCE_WITH_ON_METHOD
|| builderStyle == SUPPLY_INSTANCE_IN_CONSTRUCTOR) {
javaFile.addField(instanceClassName, "instance", PRIVATE);
}
if (builderStyle == SUPPLY_INSTANCE_WITH_ON_METHOD) {
addOnMethod(instanceParameter, javaFile, self);
}
final Iterable<MethodSpec> invokeMethodSpec =
getInvokeMethod(packageName, classToInvoke, classMethod, builderStyle);
final MethodSpec staticConstructorMethod =
getStaticConstructorMethod(
newClassName, classMethod, self, builderStyle, instanceParameter);
final TypeSpec typeSpec =
javaFile //
.addMethod(staticConstructorMethod) //
.addMethods(invokeMethodSpec) //
.build();
return builder(packageName, typeSpec) //
.build();
}
示例9: generateField
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void generateField(Builder componentSpecBuilder, NewBindingKey key) {
FieldSpec.Builder builder =
FieldSpec.builder(key.getTypeName().box(), getFieldName(key), Modifier.PRIVATE);
componentSpecBuilder.addField(builder.build());
}