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


Java JavaWriter.emitAnnotation方法代码示例

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


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

示例1: emitGetExpectedObjectSchemaInfoMap

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetExpectedObjectSchemaInfoMap(JavaWriter writer) throws IOException {
    writer.emitAnnotation("Override");
    writer.beginMethod(
            "Map<Class<? extends RealmModel>, OsObjectSchemaInfo>",
            "getExpectedObjectSchemaInfoMap",
            EnumSet.of(Modifier.PUBLIC));

    writer.emitStatement(
            "Map<Class<? extends RealmModel>, OsObjectSchemaInfo> infoMap = " +
                    "new HashMap<Class<? extends RealmModel>, OsObjectSchemaInfo>(%s)", qualifiedProxyClasses.size());
    for (int i = 0; i < qualifiedProxyClasses.size(); i++) {
        writer.emitStatement("infoMap.put(%s.class, %s.getExpectedObjectSchemaInfo())",
                qualifiedModelClasses.get(i), qualifiedProxyClasses.get(i));
    }
    writer.emitStatement("return infoMap");

    writer.endMethod();
    writer.emitEmptyLine();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:RealmProxyMediatorGenerator.java

示例2: emitInjectContextMethod

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitInjectContextMethod(JavaWriter writer) throws IOException {
    writer.emitAnnotation("Override");
    writer.beginMethod(
            "void", // Return type
            "realm$injectObjectContext", // Method name
            EnumSet.of(Modifier.PUBLIC) // Modifiers
    ); // Argument type & argument name

    writer.beginControlFlow("if (this.proxyState != null)")
            .emitStatement("return")
            .endControlFlow()
            .emitStatement("final BaseRealm.RealmObjectContext context = BaseRealm.objectContext.get()")
            .emitStatement("this.columnInfo = (%1$s) context.getColumnInfo()", columnInfoClassName())
            .emitStatement("this.proxyState = new ProxyState<%1$s>(this)", qualifiedClassName)
            .emitStatement("proxyState.setRealm$realm(context.getRealm())")
            .emitStatement("proxyState.setRow$realm(context.getRow())")
            .emitStatement("proxyState.setAcceptDefaultValue$realm(context.getAcceptDefaultValue())")
            .emitStatement("proxyState.setExcludeFields$realm(context.getExcludeFields())")
            .endMethod()
            .emitEmptyLine();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RealmProxyClassGenerator.java

示例3: emitBacklinkFieldAccessors

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitBacklinkFieldAccessors(JavaWriter writer) throws IOException {
    for (Backlink backlink : metadata.getBacklinkFields()) {
        String cacheFieldName = backlink.getTargetField() + BACKLINKS_FIELD_EXTENSION;
        String realmResultsType = "RealmResults<" + backlink.getSourceClass() + ">";

        // Getter, no setter
        writer.emitAnnotation("Override");
        writer.beginMethod(realmResultsType, metadata.getInternalGetter(backlink.getTargetField()), EnumSet.of(Modifier.PUBLIC))
                .emitStatement("BaseRealm realm = proxyState.getRealm$realm()")
                .emitStatement("realm.checkIfValid()")
                .emitStatement("proxyState.getRow$realm().checkIfAttached()")
                .beginControlFlow("if (" + cacheFieldName + " == null)")
                .emitStatement(cacheFieldName + " = RealmResults.createBacklinkResults(realm, proxyState.getRow$realm(), %s.class, \"%s\")",
                        backlink.getSourceClass(), backlink.getSourceField())
                .endControlFlow()
                .emitStatement("return " + cacheFieldName)
                .endMethod()
                .emitEmptyLine();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RealmProxyClassGenerator.java

示例4: 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

示例5: writeWriteToParcelMethod

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeWriteToParcelMethod(JavaWriter writer) throws IOException {
    List<String> parameters = new ArrayList<>(4);
    parameters.add(elementCompressedName);
    parameters.add("object");
    parameters.add("Parcel");
    parameters.add("dest");

    writer.emitAnnotation(Override.class);
    writer.beginMethod("void", "writeToParcel", Modifiers.PUBLIC, parameters, null);
    writer.emitStatement("Bundle bundle = new Bundle()");

    for (VariableElement field : parceledFields) {
        getSaveStatementWriter(field).writeFieldWriteStatement(field, writer);
    }

    writer.emitStatement("dest.writeBundle(bundle)");
    writer.endMethod();
}
 
开发者ID:Workday,项目名称:postman,代码行数:19,代码来源:ParcelerGenerator.java

示例6: writeReadFromParcelMethod

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeReadFromParcelMethod(JavaWriter writer) throws IOException {
    writer.emitAnnotation(Override.class);
    writer.beginMethod(elementCompressedName, "readFromParcel", Modifiers.PUBLIC, "Parcel",
                       "parcel");

    writer.emitStatement("%s object = new %s()", elementCompressedName, elementCompressedName);
    writer.emitStatement("Bundle bundle = parcel.readBundle()");
    writer.emitStatement("bundle.setClassLoader(%s.class.getClassLoader())",
                         elementCompressedName);
    for (VariableElement field : parceledFields) {
        getSaveStatementWriter(field).writeFieldReadStatement(field,
                                                              postCreateChildMethods,
                                                              writer);
    }
    writer.emitStatement("return object");
    writer.endMethod();
}
 
开发者ID:Workday,项目名称:postman,代码行数:18,代码来源:ParcelerGenerator.java

示例7: emitGetClassModelList

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetClassModelList(JavaWriter writer) throws IOException {
    writer.emitAnnotation("Override");
    writer.beginMethod("Set<Class<? extends RealmModel>>", "getModelClasses", EnumSet.of(Modifier.PUBLIC));
    writer.emitStatement("return MODEL_CLASSES");
    writer.endMethod();
    writer.emitEmptyLine();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:RealmProxyMediatorGenerator.java

示例8: generateField

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void generateField(JavaWriter writer, Field field) throws IOException {
     if (field.name == null) { throw new IllegalArgumentException("A field must have a name"); }
     if (field.type == null) { throw new IllegalArgumentException("A field must have a type"); }

     // Declaration of field
     for (String annotation : field.annotations) { writer.emitAnnotation(annotation); }
     writer.emitField(field.type, field.name, field.modifiers, field.initializer);

     if (field.hasSetter) { emitSetter(writer, field); }
     if (field.hasGetter) { emitGetter(writer, field); }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:RealmSyntheticTestClass.java

示例9: emitClassField

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private static void emitClassField(JavaWriter writer, ClassField field) throws IOException {
    String documentation = field.getDocumentation();
    if (!documentation.isEmpty()) {
        writer.emitJavadoc(documentation);
    }
    for (String annotation : field.getAnnotations()) {
        writer.emitAnnotation(annotation);
    }
    writer.emitField(
            field.getType(),
            field.getName(),
            PUBLIC_STATIC_FINAL,
            field.getValue());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:BuildConfigGenerator.java

示例10: writeGetter

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeGetter(JavaWriter writer) throws IOException {

        writer.emitAnnotation(Override.class);
        writer.beginMethod(JavaWriter.type(XmlElementParser.class, "?"),
                           "get",
                           EnumSet.of(Modifier.PUBLIC),
                           "String",
                           "name");
        writer.emitStatement("return MAP.get(name)");
        writer.endMethod();
    }
 
开发者ID:Workday,项目名称:autoparse-xml,代码行数:12,代码来源:ParserMapGenerator.java

示例11: writeKeySet

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeKeySet(JavaWriter writer) throws IOException {

        writer.emitAnnotation(Override.class);
        writer.beginMethod(JavaWriter.type(Set.class, "String"), "keySet", Modifiers.PUBLIC);
        writer.emitStatement("return MAP.keySet()");
        writer.endMethod();
    }
 
开发者ID:Workday,项目名称:autoparse-xml,代码行数:8,代码来源:ParserMapGenerator.java

示例12: writeGetter

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeGetter(JavaWriter writer) throws IOException {
    writer.emitAnnotation(Override.class);
    writer.beginMethod(JavaWriter.type(JsonObjectParser.class, "?"),
                       "get",
                       Modifiers.PUBLIC,
                       "String",
                       "discriminationValue");
    writer.emitStatement("return MAP.get(discriminationValue)");
    writer.endMethod();
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:11,代码来源:JsonObjectParserTableGenerator.java

示例13: writeUpdateFromMapMethod

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeUpdateFromMapMethod(JavaWriter writer) throws IOException {
    writer.emitAnnotation(Override.class);
    writer.emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("rawtypes"));
    List<String> parameters = CollectionUtils.newArrayList(parsedClassName, "instance",
                                                           JavaWriter.type(Map.class, "String", "Object"), "map",
                                                           JsonParserContext.class.getSimpleName(), "context");

    writer.beginMethod("void", "updateInstanceFromMap", Modifiers.PUBLIC, parameters, null);

    writeUpdateAssignmentsBlock(writer);
    if (selfValueAssignmentInfo != null) {
        writeUpdateSelfValuesBlock(writer);
    }
    writer.endMethod();
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:16,代码来源:JsonObjectParserGenerator.java

示例14: writeInitializeAndGetFieldMethod

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeInitializeAndGetFieldMethod(JavaWriter writer) throws IOException {
    writer.emitAnnotation(Override.class);
    writer.beginMethod("Object", "initializeAndGetField", Modifiers.PUBLIC, parsedClassName, "instance", "String",
                       "name");
    writer.emitStatement("return doInitializeAndGetField(instance, name, true)");
    writer.endMethod();
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:8,代码来源:JsonObjectParserGenerator.java

示例15: writeFromMapAssignment

import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFromMapAssignment(final JavaWriter writer, String objectName, String mapName, final String key)
        throws IOException {

    // Instantiate the new map.
    writer.emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("unchecked"));
    writer.emitStatement(state.mapDeclarationPattern, "value");

    // Switch based on the type of the actual object in the map.
    writer.emitStatement("Object o = map.get(\"%s\")", key);
    writer.beginControlFlow("if (o instanceof Map)");
    writer.emitStatement("value.putAll((Map) o)");
    writer.nextControlFlow("else if (o instanceof JSONObject)");
    ErrorWriter.surroundWithIoTryCatch(writer, new ErrorWriter.ContentWriter() {
        @Override
        public void writeContent() throws IOException {
            writer.emitStatement(
                    "JsonParserUtils.convertJsonObjectToMap((JSONObject) o, value, %s.class, " + "%s, \"%s\", "
                            + "context)", state.valueParameterTypeErasure, state.parserInstance, key);
        }
    });
    writer.nextControlFlow("else");
    ErrorWriter.writeConversionException(writer, state.mapType, "o");
    writer.endControlFlow();

    // Assign the new collection the instance's field.
    writer.emitStatement(state.assignmentPattern, objectName, "value");
    state.postCreateChildBlockWriter.writePostCreateMapBlock(writer, objectName, "value");
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:30,代码来源:MapValueAssigner.java


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