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


Java JavaWriter.setIndent方法代码示例

本文整理汇总了Java中com.squareup.javawriter.JavaWriter.setIndent方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.setIndent方法的具体用法?Java JavaWriter.setIndent怎么用?Java JavaWriter.setIndent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javawriter.JavaWriter的用法示例。


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

示例1: generate

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
    String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%s", Constants.REALM_PACKAGE_NAME, Constants.DEFAULT_MODULE_CLASS_NAME);
    JavaFileObject sourceFile = env.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
    writer.setIndent("    ");

    writer.emitPackage(Constants.REALM_PACKAGE_NAME);
    writer.emitEmptyLine();

    Map<String, Boolean> attributes = new HashMap<String, Boolean>();
    attributes.put("allClasses", Boolean.TRUE);
    writer.emitAnnotation(RealmModule.class, attributes);
    writer.beginType(
            qualifiedGeneratedClassName,        // full qualified name of the item to generate
            "class",                            // the type of the item
            Collections.<Modifier>emptySet(),   // modifiers to apply
            null);                              // class to extend
    writer.emitEmptyLine();

    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DefaultModuleGenerator.java

示例2: generate

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
    String qualifiedGeneratedClassName = String.format(Locale.US, "%s.%sMediator", REALM_PACKAGE_NAME, className);
    JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));
    writer.setIndent("    ");

    writer.emitPackage(REALM_PACKAGE_NAME);
    writer.emitEmptyLine();

    writer.emitImports(
            "android.util.JsonReader",
            "java.io.IOException",
            "java.util.Collections",
            "java.util.HashSet",
            "java.util.List",
            "java.util.Map",
            "java.util.HashMap",
            "java.util.Set",
            "java.util.Iterator",
            "java.util.Collection",
            "io.realm.internal.ColumnInfo",
            "io.realm.internal.RealmObjectProxy",
            "io.realm.internal.RealmProxyMediator",
            "io.realm.internal.Row",
            "io.realm.internal.OsSchemaInfo",
            "io.realm.internal.OsObjectSchemaInfo",
            "org.json.JSONException",
            "org.json.JSONObject"
    );

    writer.emitEmptyLine();

    writer.emitAnnotation(RealmModule.class);
    writer.beginType(
            qualifiedGeneratedClassName,        // full qualified name of the item to generate
            "class",                            // the type of the item
            Collections.<Modifier>emptySet(),   // modifiers to apply
            "RealmProxyMediator");              // class to extend
    writer.emitEmptyLine();

    emitFields(writer);
    emitGetExpectedObjectSchemaInfoMap(writer);
    emitCreateColumnInfoMethod(writer);
    emitGetFieldNamesMethod(writer);
    emitGetSimpleClassNameMethod(writer);
    emitNewInstanceMethod(writer);
    emitGetClassModelList(writer);
    emitCopyToRealmMethod(writer);
    emitInsertObjectToRealmMethod(writer);
    emitInsertListToRealmMethod(writer);
    emitInsertOrUpdateObjectToRealmMethod(writer);
    emitInsertOrUpdateListToRealmMethod(writer);
    emitCreteOrUpdateUsingJsonObject(writer);
    emitCreateUsingJsonStream(writer);
    emitCreateDetachedCopyMethod(writer);
    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:59,代码来源:RealmProxyMediatorGenerator.java

示例3: generate

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException, UnsupportedOperationException {
    JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedClassName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));

    // Set source code indent
    writer.setIndent(Constants.INDENT);

    writer.emitPackage(Constants.REALM_PACKAGE_NAME)
            .emitEmptyLine();

    List<String> imports = new ArrayList<String>(IMPORTS);
    if (!metadata.getBacklinkFields().isEmpty()) {
        imports.add("io.realm.internal.UncheckedRow");
    }
    writer.emitImports(imports)
            .emitEmptyLine();

    // Begin the class definition
    if (suppressWarnings) {
        writer.emitAnnotation("SuppressWarnings(\"all\")");
    }
    writer
            .beginType(
            qualifiedGeneratedClassName, // full qualified name of the item to generate
            "class",                     // the type of the item
            EnumSet.of(Modifier.PUBLIC), // modifiers to apply
            qualifiedClassName,          // class to extend
            "RealmObjectProxy",          // interfaces to implement
            interfaceName)
            .emitEmptyLine();

    emitColumnInfoClass(writer);

    emitClassFields(writer);

    emitInstanceFields(writer);
    emitConstructor(writer);

    emitInjectContextMethod(writer);
    emitPersistedFieldAccessors(writer);
    emitBacklinkFieldAccessors(writer);
    emitCreateExpectedObjectSchemaInfo(writer);
    emitGetExpectedObjectSchemaInfo(writer);
    emitCreateColumnInfoMethod(writer);
    emitGetSimpleClassNameMethod(writer);
    emitGetFieldNamesMethod(writer);
    emitCreateOrUpdateUsingJsonObject(writer);
    emitCreateUsingJsonStream(writer);
    emitCopyOrUpdateMethod(writer);
    emitCopyMethod(writer);
    emitInsertMethod(writer);
    emitInsertListMethod(writer);
    emitInsertOrUpdateMethod(writer);
    emitInsertOrUpdateListMethod(writer);
    emitCreateDetachedCopyMethod(writer);
    emitUpdateMethod(writer);
    emitToStringMethod(writer);
    emitRealmObjectProxyImplementation(writer);
    emitHashcodeMethod(writer);
    emitEqualsMethod(writer);

    // End the class definition
    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:66,代码来源:RealmProxyClassGenerator.java

示例4: generate

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generate() throws IOException {
    String qualifiedGeneratedInterfaceName =
            String.format(Locale.US, "%s.%s", Constants.REALM_PACKAGE_NAME, Utils.getProxyInterfaceName(className));
    JavaFileObject sourceFile = processingEnvironment.getFiler().createSourceFile(qualifiedGeneratedInterfaceName);
    JavaWriter writer = new JavaWriter(new BufferedWriter(sourceFile.openWriter()));

    writer.setIndent(Constants.INDENT);

    writer
            .emitPackage(Constants.REALM_PACKAGE_NAME)
            .emitEmptyLine()
            .beginType(qualifiedGeneratedInterfaceName, "interface", EnumSet.of(Modifier.PUBLIC));
    for (VariableElement field : metaData.getFields()) {
        if (field.getModifiers().contains(Modifier.STATIC) || (field.getAnnotation(Ignore.class) != null)) {
            continue;
        }
        // The field is neither static nor ignored
        String fieldName = field.getSimpleName().toString();
        String fieldTypeCanonicalName = field.asType().toString();
        writer
                .beginMethod(
                        fieldTypeCanonicalName,
                        metaData.getInternalGetter(fieldName),
                        EnumSet.of(Modifier.PUBLIC))
                .endMethod();

        // MutableRealmIntegers do not have setters.
        if (Utils.isMutableRealmInteger(field)) { continue; }
        writer
                .beginMethod(
                        "void",
                        metaData.getInternalSetter(fieldName),
                        EnumSet.of(Modifier.PUBLIC),
                        fieldTypeCanonicalName,
                        "value")
                .endMethod();
    }

    // backlinks are final and have only a getter.
    for (Backlink backlink : metaData.getBacklinkFields()) {
        writer
                .beginMethod(
                        backlink.getTargetFieldType(),
                        metaData.getInternalGetter(backlink.getTargetField()),
                        EnumSet.of(Modifier.PUBLIC))
                .endMethod();
    }

    writer.endType();
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:52,代码来源:RealmProxyInterfaceGenerator.java

示例5: generateParser

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParser() throws IOException {
    String parserName = MetaTypeNames.constructTypeName(classElement, GeneratedClassNames.PARSER_SUFFIX);

    JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parserName);

    JavaWriter writer = new JavaWriter(sourceFile.openWriter());
    writer.setIndent("    ");
    writer.emitPackage(processingEnv.getElementUtils().getPackageOf(classElement).getQualifiedName().toString());
    writer.emitImports(getStandardImports());
    writer.emitEmptyLine();

    parsedClassName = writer.compressType(classElement.getQualifiedName().toString());
    String jsonObjectParserInterfaceName = JavaWriter.type(JsonObjectParser.class, parsedClassName);
    String fromMapUpdaterInterfaceName = JavaWriter.type(InstanceUpdater.class, parsedClassName);
    writer.beginType(parserName, "class", EnumSet.of(Modifier.PUBLIC, Modifier.FINAL), null,
                     jsonObjectParserInterfaceName, fromMapUpdaterInterfaceName);
    writer.emitEmptyLine();

    writer.emitField(parserName, "INSTANCE", Modifiers.PUBLIC_CONSTANT,
                     String.format("new %s()", writer.compressType(parserName)));
    writer.emitEmptyLine();

    // Constructor
    writer.beginMethod(null, parserName, Modifiers.PRIVATE);
    writer.endMethod();
    writer.emitEmptyLine();

    initializeAssignments(writer);

    writePublicParseJsonObjectMethod(writer);
    writer.emitEmptyLine();
    writeParseFromJsonObjectMethod(writer);
    writer.emitEmptyLine();
    writeParseFromReaderMethod(writer);
    writer.emitEmptyLine();
    writeUpdateFromMapMethod(writer);
    writer.emitEmptyLine();
    writeGetFieldMethod(writer);
    writer.emitEmptyLine();
    writeInitializeAndGetFieldMethod(writer);
    writer.emitEmptyLine();
    writeDoInitializeAndGetFieldMethod(writer);

    if (!postCreateChildMethods.isEmpty()) {
        // TODO: Only write the methods that we need.
        // TODO: Tell block writer whether to write the map or collection parts.
        writer.emitEmptyLine();
        postCreateChildBlockWriter.writePostCreateChildMethod(writer);
        writer.emitEmptyLine();
        postCreateChildBlockWriter.writePostCreateCollectionMethod(writer);
        writer.emitEmptyLine();
        postCreateChildBlockWriter.writePostCreateMapMethod(writer);
    }

    writer.endType();
    writer.close();
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:58,代码来源:JsonObjectParserGenerator.java


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