本文整理汇总了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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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); }
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}