本文整理汇总了Java中com.squareup.javawriter.JavaWriter.emitField方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.emitField方法的具体用法?Java JavaWriter.emitField怎么用?Java JavaWriter.emitField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.emitField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitInstanceFields
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitInstanceFields(JavaWriter writer) throws IOException {
writer.emitEmptyLine()
.emitField(columnInfoClassName(), "columnInfo", EnumSet.of(Modifier.PRIVATE))
.emitField("ProxyState<" + qualifiedClassName + ">", "proxyState", EnumSet.of(Modifier.PRIVATE));
for (VariableElement variableElement : metadata.getFields()) {
if (Utils.isMutableRealmInteger(variableElement)) {
emitMutableRealmIntegerField(writer, variableElement);
} else if (Utils.isRealmList(variableElement)) {
String genericType = Utils.getGenericTypeQualifiedName(variableElement);
writer.emitField("RealmList<" + genericType + ">", variableElement.getSimpleName().toString() + "RealmList", EnumSet.of(Modifier.PRIVATE));
}
}
for (Backlink backlink : metadata.getBacklinkFields()) {
writer.emitField(backlink.getTargetFieldType(), backlink.getTargetField() + BACKLINKS_FIELD_EXTENSION,
EnumSet.of(Modifier.PRIVATE));
}
}
示例2: writeMapField
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeMapField(JavaWriter writer) throws IOException {
writer.emitField(MAP_TYPE, "MAP", Modifiers.PRIVATE_CONSTANT,
String.format("new HashMap<Class<?>, %s<?>>()",
InstanceUpdater.class.getSimpleName()));
writer.beginInitializer(true);
for (Map.Entry<String, String> entry : classNameToParserNameMap.entrySet()) {
String className = entry.getKey();
String parserQualifiedName = entry.getValue();
TypeElement parserType =
processingEnv.getElementUtils().getTypeElement(parserQualifiedName);
if (parserType == null
|| metaTypes.isSubtypeErasure(parserType.asType(), InstanceUpdater.class)) {
writer.emitStatement("MAP.put(%s.class, %s.INSTANCE)",
className,
parserQualifiedName);
}
}
writer.endInitializer();
}
示例3: emitFields
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitFields(JavaWriter writer) throws IOException {
writer.emitField("Set<Class<? extends RealmModel>>", "MODEL_CLASSES", EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL));
writer.beginInitializer(true);
writer.emitStatement("Set<Class<? extends RealmModel>> modelClasses = new HashSet<Class<? extends RealmModel>>(%s)", qualifiedModelClasses.size());
for (String clazz : qualifiedModelClasses) {
writer.emitStatement("modelClasses.add(%s.class)", clazz);
}
writer.emitStatement("MODEL_CLASSES = Collections.unmodifiableSet(modelClasses)");
writer.endInitializer();
writer.emitEmptyLine();
}
示例4: emitClassFields
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitClassFields(JavaWriter writer) throws IOException {
writer.emitEmptyLine()
.emitField("OsObjectSchemaInfo", "expectedObjectSchemaInfo",
EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL), "createExpectedObjectSchemaInfo()");
writer.emitField("List<String>", "FIELD_NAMES", EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL));
writer.beginInitializer(true)
.emitStatement("List<String> fieldNames = new ArrayList<String>(%s)", metadata.getFields().size());
for (VariableElement field : metadata.getFields()) {
writer.emitStatement("fieldNames.add(\"%s\")", field.getSimpleName().toString());
}
writer.emitStatement("FIELD_NAMES = Collections.unmodifiableList(fieldNames)")
.endInitializer();
}
示例5: emitMutableRealmIntegerField
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitMutableRealmIntegerField(JavaWriter writer, VariableElement variableElement) throws IOException{
writer.emitField("MutableRealmInteger.Managed",
mutableRealmIntegerFieldName(variableElement),
EnumSet.of(Modifier.PRIVATE, Modifier.FINAL),
String.format(
"new MutableRealmInteger.Managed<%1$s>() {\n"
+ " @Override protected ProxyState<%1$s> getProxyState() { return proxyState; }\n"
+ " @Override protected long getColumnIndex() { return columnInfo.%2$s; }\n"
+ "}",
qualifiedClassName, columnIndexVarName(variableElement)));
}
示例6: 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); }
}
示例7: 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());
}
示例8: writeParseAttributesMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void writeParseAttributesMethod(TypeElement classElement,
JavaWriter writer)
throws IOException {
List<String> parameters = new ArrayList<String>(4);
parameters.add(classElement.getSimpleName().toString());
parameters.add("object");
parameters.add(XmlStreamReader.class.getSimpleName());
parameters.add("reader");
writer.beginMethod("void", "parseAttributes", EnumSet.of(Modifier.PRIVATE), parameters,
CollectionUtils.newArrayList(ParseException.class.getSimpleName()));
writer.emitStatement("Attributes attributes = new Attributes(reader)");
for (Map.Entry<List<String>, Element> entry : attributesAndElements.getAttributes()
.entrySet()) {
List<String> names = entry.getKey();
Element attributeElement = entry.getValue();
writeAttributeAssignment(names, attributeElement, writer);
}
Element textContent = attributesAndElements.getTextContentElement();
writer.emitField("String",
"contentString",
EnumSet.noneOf(Modifier.class),
"attributes.getContentString()");
writer.beginControlFlow("if (contentString != null)");
if (textContent instanceof ExecutableElement) {
writer.emitStatement("object.%s(contentString)", textContent.getSimpleName());
} else if (textContent instanceof VariableElement) {
writer.emitStatement("object.%s = contentString", textContent.getSimpleName());
}
writer.endControlFlow();
writer.endMethod();
}
示例9: writeMapField
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeMapField(JavaWriter writer) throws IOException {
writer.emitField(MAP_TYPE, "MAP", Modifiers.PRIVATE_CONSTANT,
String.format("new HashMap<String, %s<?>>()",
XmlElementParser.class.getSimpleName()));
writer.beginInitializer(true);
for (Map.Entry<String, TypeElement> entry : parseMap.entrySet()) {
writer.emitStatement("MAP.put(\"%s\", %s.INSTANCE)", entry.getKey(),
entry.getValue().getSimpleName()
+ GeneratedClassNames.PARSER_SUFFIX);
}
writer.endInitializer();
}
示例10: generateParser
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParser()
throws IOException {
String parserName =
classElement.getQualifiedName().toString() + GeneratedClassNames.PARSER_SUFFIX;
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parserName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(processingEnv.getElementUtils()
.getPackageOf(classElement)
.getQualifiedName()
.toString());
writer.emitImports(getStandardImports());
writer.emitEmptyLine();
String xmlElementParserName =
JavaWriter.type(XmlElementParser.class, classElement.getSimpleName().toString());
writer.beginType(parserName,
"class",
EnumSet.of(Modifier.PUBLIC, Modifier.FINAL),
null,
xmlElementParserName);
writer.emitEmptyLine();
writer.emitField(parserName,
"INSTANCE",
EnumSet.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL),
String.format("new %s()", writer.compressType(parserName)));
writer.emitEmptyLine();
// Constructor
writer.beginMethod(null, parserName, EnumSet.of(Modifier.PRIVATE));
writer.endMethod();
writer.emitEmptyLine();
writeParseElementMethod(writer);
writer.emitEmptyLine();
parseAttributesMethodWriter.writeParseAttributesMethod(classElement, writer);
writer.emitEmptyLine();
parseChildrenMethodWriter.writeParseChildrenMethod(classElement, writer);
writer.emitEmptyLine();
writer.endType();
writer.close();
}
示例11: 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();
}
示例12: writePublicParseJsonObjectMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writePublicParseJsonObjectMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(Override.class);
writer.beginMethod(parsedClassName, "parseJsonObject", Modifiers.PUBLIC,
CollectionUtils.newArrayList(AndroidNames.JSON_OBJECT, "jsonObject",
AndroidNames.JSON_READER, "reader", "String",
"discriminationName", "String", "discriminationValue"),
CollectionUtils.newArrayList(IOException.class.getSimpleName()));
writer.emitField(parsedClassName, "result", Modifiers.NONE, "new " + parsedClassName + "()");
if (!discriminationValueAssignmentPatterns.isEmpty()) {
writer.beginControlFlow("if (discriminationValue != null)");
for (String assignmentPattern : discriminationValueAssignmentPatterns) {
writer.emitStatement(assignmentPattern, "result", "discriminationValue");
}
writer.endControlFlow();
}
String selfValuesMapName = null;
if (selfValueAssignmentInfo != null) {
Element member = selfValueAssignmentInfo.member;
String initializer = null;
selfValuesMapName = member.getSimpleName().toString() + SELF_VALUE_NAME_SUFFIX;
try {
initializer = initializers.findMapInitializer((DeclaredType) member.asType());
} catch (InvalidTypeException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), member);
}
writer.emitField(member.asType().toString(), selfValuesMapName, Modifiers.NONE, initializer);
}
writer.beginControlFlow("if (jsonObject != null)");
if (selfValueAssignmentInfo != null) {
writer.emitStatement("parseFromJsonObject(result, jsonObject, discriminationName, %s)", selfValuesMapName);
} else {
writer.emitStatement("parseFromJsonObject(result, jsonObject, discriminationName)");
}
writer.endControlFlow();
writer.beginControlFlow("if (reader != null)");
if (selfValueAssignmentInfo != null) {
writer.emitStatement("parseFromReader(result, reader, discriminationName, %s)", selfValuesMapName);
} else {
writer.emitStatement("parseFromReader(result, reader, discriminationName)");
}
writer.endControlFlow();
if (selfValueAssignmentInfo != null) {
writer.emitStatement(selfValueAssignmentInfo.assignmentPattern, "result", selfValuesMapName);
}
writer.emitStatement("return result");
writer.endMethod();
}
示例13: writeParseFromJsonObjectMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeParseFromJsonObjectMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("rawtypes"));
List<String> parameters = CollectionUtils.newArrayList(parsedClassName, "out", AndroidNames.JSON_OBJECT,
"jsonObject", "String", "discriminationName");
if (selfValueAssignmentInfo != null) {
parameters.add("java.util.Map<String, Object>");
parameters.add("selfValuesMap");
}
writer.beginMethod("void", "parseFromJsonObject", Modifiers.PRIVATE, parameters,
CollectionUtils.newArrayList(IOException.class.getSimpleName()));
for (AssignmentInfo assignmentInfo : assignments) {
writer.beginControlFlow("if (jsonObject.has(\"%s\"))", assignmentInfo.name);
assignmentInfo.assigner.writeFromJsonObjectAssignment(writer, "out", "jsonObject", assignmentInfo.name);
writer.emitStatement("jsonObject.remove(\"%s\")", assignmentInfo.name);
writer.endControlFlow();
}
if (!discriminationValueAssignmentPatterns.isEmpty()) {
writer.beginControlFlow("if (jsonObject.has(discriminationName))");
writer.emitField("String", "discriminationValue", Modifiers.FINAL,
"jsonObject.optString(discriminationName)");
writer.emitStatement("jsonObject.remove(discriminationName)");
for (String assignmentPattern : discriminationValueAssignmentPatterns) {
writer.emitStatement(assignmentPattern, "out", "discriminationValue");
}
writer.endControlFlow();
}
if (selfValueAssignmentInfo != null) {
writer.emitAnnotation(SuppressWarnings.class, JavaWriter.stringLiteral("unchecked"));
writer.emitField(JavaWriter.type(Iterator.class, "String"), "keys", Modifiers.NONE, "jsonObject.keys()");
writer.beginControlFlow("while (keys.hasNext())");
writer.emitField("String", "key", Modifiers.NONE, "keys.next()");
if (selfValueAssignmentInfo.convertJsonTypes) {
writer.emitStatement(
"selfValuesMap.put(key, JsonParserUtils.getAndConvertValue(jsonObject, " + "key))");
} else {
writer.emitStatement("selfValuesMap.put(key, jsonObject.opt(key))");
}
writer.endControlFlow();
}
writer.endMethod();
}
示例14: writeParseFromReaderMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeParseFromReaderMethod(JavaWriter writer) throws IOException {
writer.emitAnnotation(SuppressWarnings.class, "{ \"rawtypes\", \"unchecked\"}");
ArrayList<String> parameters = CollectionUtils.newArrayList(parsedClassName, "out", AndroidNames.JSON_READER,
"reader", "String", "discriminationName");
if (selfValueAssignmentInfo != null) {
parameters.add("java.util.Map<String, Object>");
parameters.add("selfValuesMap");
}
writer.beginMethod("void", "parseFromReader", Modifiers.PRIVATE, parameters,
CollectionUtils.newArrayList(IOException.class.getSimpleName()));
writer.beginControlFlow("while (reader.hasNext())");
writer.emitField(String.class.getSimpleName(), "name", Modifiers.NONE, "reader.nextName()");
if (!discriminationValueAssignmentPatterns.isEmpty()) {
writer.beginControlFlow("if (discriminationName.equals(name) && !JsonParserUtils.handleNull(reader))");
writer.emitField("String", "discriminationValue", Modifiers.FINAL,
"JsonParserUtils.nextString(reader, discriminationName)");
for (String assignmentPattern : discriminationValueAssignmentPatterns) {
writer.emitStatement(assignmentPattern, "out", "discriminationValue");
}
writer.emitStatement("continue");
writer.endControlFlow();
}
writer.beginControlFlow("switch (name)");
for (AssignmentInfo assignmentInfo : assignments) {
writer.beginControlFlow("case \"%s\":", assignmentInfo.name);
assignmentInfo.assigner.writeFromReaderAssignment(writer, "out", "reader", assignmentInfo.name);
writer.emitStatement("break");
writer.endControlFlow();
}
writer.beginControlFlow("default:");
if (selfValueAssignmentInfo != null) {
writer.emitStatement("selfValuesMap.put(name, JsonParserUtils.parseNextValue(reader, %s))",
selfValueAssignmentInfo.convertJsonTypes);
} else {
writer.emitStatement("reader.skipValue()");
}
writer.endControlFlow();
writer.endControlFlow();
writer.endControlFlow();
writer.endMethod();
}
示例15: writeFromReaderAssignment
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFromReaderAssignment(JavaWriter writer,
String objectName,
String readerName,
String key)
throws IOException {
String value;
switch (objectTypeString) {
case AndroidNames.JSON_ARRAY_FULL:
value = String.format(Locale.US,
"JsonParserUtils.parseAsJsonArray(%s, \"%s\")",
readerName,
key);
break;
case AndroidNames.JSON_OBJECT_FULL:
value = String.format(Locale.US,
"JsonParserUtils.parseAsJsonObject(%s, \"%s\")",
readerName,
key);
break;
case "java.lang.Object":
value = String.format(Locale.US,
"JsonParserUtils.parseNextValue(%s, %s)",
readerName,
convertJsonTypes);
break;
default:
value = String.format(Locale.US,
"(%1$s) JsonParserUtils.parseJsonObject(%2$s, %3$s, "
+ "\"%4$s\", %5$s.class)",
writer.compressType(objectTypeString),
readerName,
parserInstance,
key,
writer.compressType(objectTypeErasure));
break;
}
writer.emitField(objectTypeString, "value", Modifiers.NONE, value);
writer.emitStatement(assignmentPattern, objectName, "value");
postCreateChildBlockWriter.writePostCreateChildBlock(writer, objectName, "value");
}