本文整理汇总了Java中com.squareup.javawriter.JavaWriter.emitStatement方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.emitStatement方法的具体用法?Java JavaWriter.emitStatement怎么用?Java JavaWriter.emitStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.emitStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitStreamTypeConversion
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void emitStreamTypeConversion(
String varName, String setter, String fieldName, String fieldType, JavaWriter writer, boolean isPrimaryKey)
throws IOException {
// Only throw exception for primitive types.
// For boxed types and String, exception will be thrown in the setter.
String statementSetNullOrThrow = (Utils.isPrimitiveType(fieldType)) ?
String.format(Locale.US, Constants.STATEMENT_EXCEPTION_ILLEGAL_NULL_VALUE, fieldName) :
String.format(Locale.US, "%s.%s(null)", varName, setter);
// @formatter:off
writer
.beginControlFlow("if (reader.peek() != JsonToken.NULL)")
.emitStatement("%s.%s((%s) reader.next%s())", varName, setter, castType, jsonType)
.nextControlFlow("else")
.emitStatement("reader.skipValue()")
.emitStatement(statementSetNullOrThrow)
.endControlFlow();
// @formatter:on
if (isPrimaryKey) {
writer.emitStatement("jsonHasPrimaryKey = true");
}
}
示例2: 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();
}
示例3: emitMediatorSwitch
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitMediatorSwitch(ProxySwitchStatement statement, JavaWriter writer, boolean nullPointerCheck)
throws IOException {
if (nullPointerCheck) {
writer.emitStatement("checkClass(clazz)");
writer.emitEmptyLine();
}
if (qualifiedModelClasses.size() == 0) {
writer.emitStatement("throw getMissingProxyClassException(clazz)");
} else {
writer.beginControlFlow("if (clazz.equals(%s.class))", qualifiedModelClasses.get(0));
statement.emitStatement(0, writer);
for (int i = 1; i < qualifiedModelClasses.size(); i++) {
writer.nextControlFlow("else if (clazz.equals(%s.class))", qualifiedModelClasses.get(i));
statement.emitStatement(i, writer);
}
writer.nextControlFlow("else");
writer.emitStatement("throw getMissingProxyClassException(clazz)");
writer.endControlFlow();
}
}
示例4: emitSetter
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitSetter(JavaWriter writer, Field field) throws IOException {
// Setter
writer.beginMethod(
"void", // Return type
"set" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC), field.type, field.name); // Modifiers
writer.emitStatement("realmSet$" + field.name + "(" + field.name + ")");
writer.endMethod();
// Realm Setter
writer.beginMethod(
"void", // Return type
"realmSet$" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC), field.type, field.name); // Modifiers
writer.emitStatement("this." + field.name + "=" + field.name);
writer.endMethod();
}
示例5: emitGetter
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitGetter(JavaWriter writer, Field field) throws IOException {
// Getter
writer.beginMethod(
field.type, // Return type
"get" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC)); // Modifiers
writer.emitStatement("return realmGet$" + field.name + "()");
writer.endMethod();
// Realm Getter
writer.beginMethod(
field.type, // Return type
"realmGet$" + field.name, // Method name
EnumSet.of(Modifier.PUBLIC)); // Modifiers
writer.emitStatement("return " + field.name);
writer.endMethod();
}
示例6: writeInitializeField
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeInitializeField(JavaWriter writer, VariableElement field) throws IOException {
String initialization = null;
DeclaredType type = (DeclaredType) field.asType();
try {
if (metaTypes.isSubtypeErasure(type, Collection.class)) {
initialization = initializers.findCollectionInitializer(type);
} else if (metaTypes.isSubtypeErasure(type, Map.class)) {
initialization = initializers.findMapInitializer(type);
} else {
throw new IllegalArgumentException("Expected field to be of type Collection or Map, but found " + type);
}
} catch (InvalidTypeException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), field);
}
writer.emitStatement("instance.%s = %s", field.getSimpleName(), initialization);
}
示例7: writeFromReaderAssignment
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFromReaderAssignment(JavaWriter writer,
String objectName,
String readerName,
String key)
throws IOException {
writer.beginControlFlow("if (!JsonParserUtils.handleNull(%s))", readerName);
writer.emitStatement(state.collectionDeclarationPattern, "collection");
writeParameterList(writer);
writer.emitStatement(
"JsonParserUtils.parseJsonArray(%1$s, collection, %2$s, %3$s.class, "
+ "parameterList, \"%4$s\")",
readerName,
state.parser,
writer.compressType(state.itemType),
key);
writer.emitStatement(state.assignmentPattern, objectName, "collection");
state.postCreateChildBlockWriter.writePostCreateCollectionBlock(writer,
objectName,
"collection");
writer.endControlFlow();
}
示例8: writeFromJsonObjectAssignment
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFromJsonObjectAssignment(JavaWriter writer,
String objectName,
String jsonObjectName,
String name)
throws IOException {
writer.emitStatement(state.collectionDeclarationPattern, "collection");
writeParameterList(writer);
writer.emitStatement(
"JsonParserUtils.convertJsonArrayToCollection(%s.optJSONArray(\"%s\"), "
+ "collection, %s, %s.class, parameterList, \"%s\")",
jsonObjectName,
name,
state.parser,
writer.compressType(state.itemType),
name);
writer.emitStatement(state.assignmentPattern, objectName, "collection");
state.postCreateChildBlockWriter.writePostCreateCollectionBlock(writer,
objectName,
"collection");
}
示例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<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();
}
示例10: writeFieldReadStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFieldReadStatement(VariableElement field,
Collection<ExecutableElement> postCreateChildMethods,
JavaWriter writer)
throws IOException {
writer.emitStatement("object.%s = bundle.getParcelable(\"%s\")",
field.getSimpleName(),
field.getSimpleName());
for (ExecutableElement method : postCreateChildMethods) {
writer.emitStatement("object.%s(object.%s)",
method.getSimpleName(),
field.getSimpleName());
}
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
示例14: 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();
}
示例15: emitMediatorShortCircuitSwitch
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitMediatorShortCircuitSwitch(ProxySwitchStatement statement, JavaWriter writer, boolean nullPointerCheck)
throws IOException {
if (nullPointerCheck) {
writer.emitStatement("checkClass(clazz)");
writer.emitEmptyLine();
}
for (int i = 0; i < qualifiedModelClasses.size(); i++) {
writer.beginControlFlow("if (clazz.equals(%s.class))", qualifiedModelClasses.get(i));
statement.emitStatement(i, writer);
writer.endControlFlow();
}
writer.emitStatement("throw getMissingProxyClassException(clazz)");
}