当前位置: 首页>>代码示例>>Java>>正文


Java FieldSpec类代码示例

本文整理汇总了Java中com.squareup.javapoet.FieldSpec的典型用法代码示例。如果您正苦于以下问题:Java FieldSpec类的具体用法?Java FieldSpec怎么用?Java FieldSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FieldSpec类属于com.squareup.javapoet包,在下文中一共展示了FieldSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: builderBuild

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
public static MethodSpec builderBuild(ClassName className, List<MethodSpec> methodSpecList, List<FieldSpec> fieldSpecList) {
    String name = className.simpleName();
    CodeBlock.Builder codeBlock = CodeBlock.builder();

    for (int i = 0; i < methodSpecList.size(); i++) {
        codeBlock.add("$N.$N(this.$N);\n", name.toLowerCase(), methodSpecList.get(i).name, fieldSpecList.get(i).name);
    }

    return MethodSpec
            .methodBuilder("build")
            .addModifiers(Modifier.PUBLIC)
            .addStatement("$N $N = new $N()", name, name.toLowerCase(), name)
            .addCode(codeBlock.build())
            .returns(className)
            .addStatement("return $N", name.toLowerCase())
            .build();
}
 
开发者ID:daisuke-nomura,项目名称:KiiAnnotation,代码行数:18,代码来源:BuilderGenerator.java

示例2: build

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
public TypeSpec.Builder build() {
    TypeSpec.Builder tsb = TypeSpec.classBuilder(name);
    for (Map.Entry<String, Class<?>> entry : nameTypeMap.entrySet()) {
        FieldSpec field = FieldSpec.builder(
                ClassName.get(entry.getValue()), entry.getKey(), Modifier.PRIVATE)
                .build();
        tsb.addField(field);
    }
    if (getter) {
        tsb = GetterSpec.forType(tsb).build();
    }
    if (setter) {
        tsb = SetterSpec.forType(tsb).build();
    }
    if (builder) {
        tsb = BuilderSpec.forType(packageName, tsb).build();
    }
    return tsb;
}
 
开发者ID:harmanpa,项目名称:javabard,代码行数:20,代码来源:ValueClassSpec.java

示例3: addUsedTypeConverterMethods

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private void addUsedTypeConverterMethods(TypeSpec.Builder builder) {
    Set<TypeName> usedTypeConverters = new HashSet<>();

    for (JsonFieldHolder holder : mJsonObjectHolder.fieldMap.values()) {
        usedTypeConverters.addAll(holder.type.getUsedTypeConverters());
    }

    for (TypeName usedTypeConverter : usedTypeConverters) {
        final String variableName = getTypeConverterVariableName(usedTypeConverter);
        builder.addField(FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(TypeConverter.class), usedTypeConverter), variableName)
                .addModifiers(Modifier.PRIVATE, Modifier.STATIC)
                .build()
        );

        builder.addMethod(MethodSpec.methodBuilder(getTypeConverterGetter(usedTypeConverter))
                .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
                .returns(ParameterizedTypeName.get(ClassName.get(TypeConverter.class), usedTypeConverter))
                .beginControlFlow("if ($L == null)", variableName)
                .addStatement("$L = $T.typeConverterFor($T.class)", variableName, LoganSquare.class, usedTypeConverter)
                .endControlFlow()
                .addStatement("return $L", variableName)
                .build()
        );
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ObjectMapperInjector.java

示例4: generateGlobalConstant

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private static JavaFile generateGlobalConstant(String packageName, Constant[] globalConstants) {
    TypeSpec.Builder javaClass = TypeSpec.classBuilder(CONSTANT_CLASS_NAME);
    javaClass.addModifiers(PUBLIC, FINAL);
    for (Constant constant : globalConstants) {
        String value = constant.value();
        if (constant.type().equals("Task") && value != null) {
            value = "greycat.Tasks.newTask().parse(\"" + value.replaceAll("\"", "'").trim() + "\",null);";
        } else if (constant.type().equals("String") && value != null) {
            value = "\""+value+"\"";
        }
        FieldSpec.Builder field = FieldSpec.builder(clazz(constant.type()), constant.name())
                .addModifiers(PUBLIC, STATIC);
        if (value != null) {
            field.addModifiers(FINAL).initializer(value);
        }
        javaClass.addField(field.build());
    }
    return JavaFile.builder(packageName, javaClass.build()).build();
}
 
开发者ID:datathings,项目名称:greycat,代码行数:20,代码来源:ConstantGenerator.java

示例5: getTypeAdapters

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(List<JsonProperty> properties,
    NameAllocator nameAllocator) {
  Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
  for (JsonProperty property : properties) {
    if (property.typeAdapter != null && !typeAdapters.containsKey(property.typeAdapter)) {
      ClassName typeName = (ClassName) TypeName.get(property.typeAdapter);
      String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, typeName.simpleName());
      name = nameAllocator.newName(name, typeName);

      typeAdapters.put(property.typeAdapter,
          FieldSpec.builder(typeName, NameAllocator.toJavaIdentifier(name), PRIVATE, STATIC,
              FINAL).initializer("new $T()", typeName).build());
    }
  }

  return ImmutableMap.copyOf(typeAdapters);
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:18,代码来源:AutoValueJsonExtension.java

示例6: process

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
    parser.scan(roundEnvironment);
    TypeSpec.Builder builder = TypeSpec.classBuilder("Testing")
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL);
    for (Element element : roundEnvironment.getElementsAnnotatedWith(Parse.class))
        builder.addField(FieldSpec.builder(String.class, element.getSimpleName().toString())
                .addModifiers(Modifier.PRIVATE, Modifier.FINAL)
                .initializer("$S", parser.parse("com.example.rparser", element.getAnnotation(Parse.class).value()))
                .build());
    JavaFile javaFile = JavaFile.builder("com.example.rparser", builder.build())
            .build();
    try {
        javaFile.writeTo(filer);
    } catch (IOException ignored) {
    }
    return false;
}
 
开发者ID:hendraanggrian,项目名称:r-parser,代码行数:19,代码来源:ExampleProcessor.java

示例7: buildFields

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
@Nonnull
@Override
protected List<FieldSpec> buildFields() {
    return getProperties().entrySet()
            .stream()
            .map(property -> {
                final String name = property.getKey();
                final TypeName type = property.getValue();

                final String fieldName = fieldNamePolicy.convert(name, type);
                return FieldSpec.builder(type, fieldName)
                        .addModifiers(Modifier.PRIVATE, Modifier.FINAL)
                        .build();
            })
            .collect(Collectors.toList());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:17,代码来源:JacksonClassBuilder.java

示例8: buildFields

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
@Nonnull
@Override
protected List<FieldSpec> buildFields() {
    return getProperties()
            .entrySet()
            .stream()
            .map(property -> {
                final String name = property.getKey();
                final TypeName type = property.getValue();
                final String fieldName = fieldNamePolicy.convert(name, type);
                return FieldSpec.builder(type, fieldName)
                        .addModifiers(Modifier.PRIVATE, Modifier.FINAL)
                        .build();
            })
            .collect(Collectors.toList());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:17,代码来源:ModelClassBuilder.java

示例9: getTypeAdapters

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(ImmutableList<Property> properties) {
    Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
    NameAllocator nameAllocator = new NameAllocator();
    nameAllocator.newName("CREATOR");
    for (Property property : properties) {
        if (property.typeAdapter != null && !typeAdapters.containsKey(property.typeAdapter)) {
            ClassName typeName = (ClassName) TypeName.get(property.typeAdapter);
            String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, typeName.simpleName());
            name = nameAllocator.newName(name, typeName);

            typeAdapters.put(property.typeAdapter, FieldSpec.builder(
                    typeName, NameAllocator.toJavaIdentifier(name), PRIVATE, STATIC, FINAL)
                    .initializer("new $T()", typeName).build());
        }
    }
    return ImmutableMap.copyOf(typeAdapters);
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:18,代码来源:AutoMappperProcessor.java

示例10: builderGroupBuild

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
public static MethodSpec builderGroupBuild(ClassName className, List<MethodSpec> methodSpecList, List<FieldSpec> fieldSpecList) {
    String name = className.simpleName();
    CodeBlock.Builder codeBlock = CodeBlock.builder();

    for (int i = 0; i < methodSpecList.size(); i++) {
        codeBlock.add("$N.$N(this.$N);\n", name.toLowerCase(), methodSpecList.get(i).name, fieldSpecList.get(i).name);
    }

    return MethodSpec
            .methodBuilder("build")
            .addModifiers(Modifier.PUBLIC)
            .addStatement("$N $N = new $N($N)", name, name.toLowerCase(), name, "this.kiiGroup")
            .addCode(codeBlock.build())
            .returns(className)
            .addStatement("return $N", name.toLowerCase())
            .build();
}
 
开发者ID:daisuke-nomura,项目名称:KiiAnnotation,代码行数:18,代码来源:BuilderGenerator.java

示例11: checkCompiles

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private void checkCompiles(final TypeSpec anonymousTypeSpec) {
	// Anonymous class cannot be top level class, so nest the anonymous class as a field
	final TypeSpec wrapperTypeSpec = TypeSpec
			.classBuilder("Wrapper")
			.addField(FieldSpec.builder(ClassName.get(Data.class), "target").build())
			.addField(FieldSpec.builder(AndroidClassNames.CONTEXT, "context").build())
			.addField(FieldSpec.builder(AndroidClassNames.TYPED_ARRAY, "attrs").build())
			.addField(FieldSpec
					.builder(TypeName.OBJECT, "o")
					.initializer("$L", anonymousTypeSpec)
					.build())
			.build();

	final JavaFile wrapperJavaFile = JavaFile
			.builder("", wrapperTypeSpec)
			.build();

	final Set<JavaFile> filesToCompile = new HashSet<>();

	filesToCompile.add(wrapperJavaFile);
	filesToCompile.add(CallerDef.SRC_FILE);

	CompileChecker.checkCompiles(filesToCompile);
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:25,代码来源:TestCallerGenerator.java

示例12: createGlobalInterface

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private TypeSpec createGlobalInterface() {
    return TypeSpec.classBuilder("Global")
            .addModifiers(Modifier.STATIC, Modifier.FINAL)
            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSTYPE)
                    .addMember("isNative", "true")
                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                    .build())
            .addFields(Stream.of(Object.class,
                    Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE,
                    Float.TYPE, Integer.TYPE, Long.TYPE, Short.TYPE)
                    .map(type -> FieldSpec.builder(type, "UNDEFINED_" + type.getSimpleName().toUpperCase())
                            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                            .addAnnotation(AnnotationSpec.builder(ClassNames.JSINTEROP_JSPROPERTY)
                                    .addMember("namespace", "$T.GLOBAL", ClassNames.JSINTEROP_JSPACKAGE)
                                    .addMember("name", "$S", "undefined")
                                    .build())
                            .build())
                .collect(Collectors.toList()))
            .build();
}
 
开发者ID:codegen-io,项目名称:jso-builder,代码行数:21,代码来源:JSOBuilderProcessor.java

示例13: generateMappingTable

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
public void generateMappingTable(Filer filer) throws IOException {
    if (routerTable.isEmpty()) {
        return;
    }
    FieldSpec tableFieldSpec = FieldSpec.builder(Map.class, "routerTable")
            .addModifiers(Modifier.PRIVATE)
            .build();
    MethodSpec initTableMethodSpec = getInitTableMethodSpec();
    MethodSpec queryTableMethodSpec = getqueryTableMethodSpec();
    MethodSpec constructorMethodSpec = getconstructorMethodSpec(tableFieldSpec, initTableMethodSpec);
    MethodSpec addRouterMethodSpec = getAddRouterMethodSpec();
    TypeSpec routerTableClassTypeSpec = getRouterTableClassTypeSpec(tableFieldSpec, initTableMethodSpec, queryTableMethodSpec, constructorMethodSpec, addRouterMethodSpec);
    String packageName = Constants.GENERATED_PACKAGE_NAME;
    JavaFile javaFile = JavaFile.builder(packageName, routerTableClassTypeSpec).build();
    javaFile.writeTo(filer);
}
 
开发者ID:bboylin,项目名称:D-Router,代码行数:17,代码来源:RouterTableGenerator.java

示例14: writeValueWithTypeAdapter

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
public static CodeBlock writeValueWithTypeAdapter(FieldSpec adapter, AutoMappperProcessor.Property p, ParameterSpec out) {
    CodeBlock.Builder block = CodeBlock.builder();

    if (p.isNullable()) {
        block.beginControlFlow("if ($N == null)", p.fieldName);
        block.addStatement("$N.writeInt(1)", out);
        block.nextControlFlow("else");
        block.addStatement("$N.writeInt(0)", out);
    }

    block.addStatement("$N.toParcel($N, $N)", adapter, p.fieldName, out);

    if (p.isNullable()) {
        block.endControlFlow();
    }

    return block.build();
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:19,代码来源:Parcelables.java

示例15: addFields

import com.squareup.javapoet.FieldSpec; //导入依赖的package包/类
private void addFields(final TypeSpec.Builder classBuilder) {
    FieldSpec.Builder viewIdsField = FieldSpec.builder(int[].class, "viewIds", Modifier.PRIVATE, Modifier.STATIC,
            Modifier.FINAL);
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    for (Integer id : viewIds) {
        sb.append(id).append(",");
    }

    if (viewIds.size() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }

    sb.append("}");
    viewIdsField.initializer(CodeBlock.of(sb.toString()));
    classBuilder.addField(viewIdsField.build());

}
 
开发者ID:renard314,项目名称:auto-adapter,代码行数:19,代码来源:ViewHolderFactoryGenerator.java


注:本文中的com.squareup.javapoet.FieldSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。