本文整理汇总了Java中com.squareup.javawriter.JavaWriter.compressType方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.compressType方法的具体用法?Java JavaWriter.compressType怎么用?Java JavaWriter.compressType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.compressType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classJavaDoc
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
protected void classJavaDoc(JavaWriter w) throws IOException {
String operatorClassName = w.compressType(getFqcn());
ExecutableElement method = methods.get(0).method;
String operationName = method.getSimpleName().toString();
String params = invocationParams(method);
w.emitJavadoc(GenUtils.DOCS_OPERATOR_CLASS,
operationsClass.getQualifiedName().toString(),
operatorClassName,
operatorClassName,
operationName,
methods.get(0).operatorTypeSupport.listenerExample(w.compressType(getDataType(method).toString())),
operationName,
params,
capitalize(operationName),
params,
capitalize(operationName)
);
}
示例2: writePostCreateCollectionMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writePostCreateCollectionMethod(JavaWriter writer) throws IOException {
String collectionType = writer.compressType(JavaWriter.type(Collection.class, "?"));
writer.beginMethod("void",
"onPostCreateCollection",
Modifiers.PRIVATE,
parentType,
"parent",
collectionType,
"collection");
writer.beginControlFlow("for (Object o : collection)");
writeItemSwitch(writer, "parent", "o");
writer.endControlFlow();
writer.endMethod();
}
示例3: writePostCreateMapMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writePostCreateMapMethod(JavaWriter writer) throws IOException {
String mapType = writer.compressType(JavaWriter.type(Map.class, "?", "?"));
writer.beginMethod("void",
"onPostCreateMap",
Modifiers.PRIVATE,
parentType,
"parent",
mapType,
"map");
writer.beginControlFlow("for (Object o : map.values())");
writeItemSwitch(writer, "parent", "o");
writer.endControlFlow();
writer.endMethod();
}
示例4: generateParceler
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateParceler() throws IOException {
JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(parcelerName);
JavaWriter writer = new JavaWriter(sourceFile.openWriter());
writer.emitPackage(processingEnv.getElementUtils().getPackageOf(
elementToParcel).getQualifiedName().toString());
writer.emitImports(getImports());
writer.emitEmptyLine();
elementCompressedName = writer.compressType(elementToParcel.getQualifiedName().toString());
writer.beginType(parcelerName, "class", EnumSet.of(Modifier.PUBLIC, Modifier.FINAL), null,
JavaWriter.type(Parceler.class, elementCompressedName));
writer.emitEmptyLine();
writeWriteToParcelMethod(writer);
writer.emitEmptyLine();
writeReadFromParcelMethod(writer);
writer.emitEmptyLine();
writeNewArrayMethod(writer);
writer.emitEmptyLine();
writer.endType();
writer.close();
}
示例5: asyncProvider
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public String asyncProvider(final JavaWriter w, final ExecutableElement method) {
String type = w.compressType(ASYNC_PROVIDER_CLASS + "<" + getDataType(method) + ">");
return type + " provider = new " + type + "() {\n"
+ " @Override\n"
+ " public " + w.compressType(getReturnType(method)) + " provideAsync() {\n"
+ " return getOperations()." + invocation(method) + ";\n"
+ " }\n"
+ "}";
}
示例6: loaderDescriptionReturnType
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public String loaderDescriptionReturnType(JavaWriter w, ExecutableElement method,
BaseGenerator generator) {
String dataType = getDataType(method).toString();
return w.compressType(OBSERVER_BUILDER_CLASS
+ "<" + dataType + "," +
loaderDescription(generator.packageName, generator.operationsClass) + ">");
}
示例7: writeItemSwitch
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeItemSwitch(JavaWriter writer, String parent, String item) throws IOException {
String mapType = writer.compressType(JavaWriter.type(Map.class, "?", "?"));
String collectionType = writer.compressType(JavaWriter.type(Collection.class, "?"));
writer.beginControlFlow("if (%s instanceof %s)", item, JavaWriter.rawType(collectionType));
writer.emitStatement("onPostCreateCollection(%s, (%s) %s)", parent, collectionType, item);
writer.nextControlFlow("else if (%s instanceof %s)", item, JavaWriter.rawType(mapType));
writer.emitStatement("onPostCreateMap(%s, (%s) %s)", parent, mapType, item);
writer.nextControlFlow("else");
writer.emitStatement("onPostCreateChild(%s, %s)", parent, item);
writer.endControlFlow();
}
示例8: writeObjectGetterFromMap
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeObjectGetterFromMap(final JavaWriter writer, String mapName, String key)
throws IOException {
String objectTypeCompressed = writer.compressType(objectTypeString);
writer.emitStatement(("%s value"), objectTypeCompressed);
writer.emitStatement("Object o = %s.get(\"%s\")", mapName, key);
writer.beginControlFlow("if (o == null)");
writer.emitStatement("value = null");
writer.nextControlFlow("else if (o instanceof %s)", objectTypeCompressed);
writer.emitStatement("value = (%s) o", objectTypeCompressed);
if (!AndroidNames.JSON_OBJECT_FULL.equals(objectTypeString)
&& !AndroidNames.JSON_ARRAY_FULL.equals(objectTypeString)) {
writer.nextControlFlow("else if (o instanceof JSONObject)");
ErrorWriter.surroundWithIoTryCatch(writer, new ErrorWriter.ContentWriter() {
@Override
public void writeContent() throws IOException {
writer.emitStatement(
"value = JsonParserUtils.convertJsonObject((JSONObject) o, %s.class, "
+ "%s, context)",
objectTypeErasure,
parserInstance);
}
});
}
writer.nextControlFlow("else");
ErrorWriter.writeConversionException(writer, objectTypeString, "o");
writer.endControlFlow();
}
示例9: 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();
}
示例10: writeFromJsonObjectAssignment
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFromJsonObjectAssignment(JavaWriter writer,
String objectName,
String jsonObjectName,
String name)
throws IOException {
String objectTypeCompressed = writer.compressType(objectTypeString);
writer.emitField(objectTypeCompressed, "value", Modifiers.NONE, "null");
writer.emitField(Object.class.getCanonicalName(), "o", Modifiers.NONE,
String.format(Locale.US, "%1$s.opt(\"%2$s\")", jsonObjectName, name));
if (AndroidNames.JSON_OBJECT_FULL.equals(objectTypeString)
|| AndroidNames.JSON_ARRAY_FULL.equals(
objectTypeString)) {
// If the object type is a JSONObject or JSONArray, then 'o' is probably one of those
// already.
// Do the instanceof check and then assign 'o' to 'value'.
writer.beginControlFlow("if (o instanceof %s)", objectTypeCompressed);
writer.emitStatement("value = (%s) o", objectTypeCompressed);
writer.endControlFlow();
} else if ("null".equals(parserInstance)) {
if (!convertJsonTypes && Object.class.getCanonicalName().equals(objectTypeString)) {
// A wildcard that where we are not supposed to convert json types, so just
// assign 'o' to 'value'.
writer.emitStatement("value = o");
} else {
// Attempt a conversion without an explicit parser instance
writer.beginControlFlow("if (o instanceof %s)", AndroidNames.JSON_OBJECT);
writer.emitStatement(
"value = JsonParserUtils.convertJsonObject((%s) o, %s.class, null)",
AndroidNames.JSON_OBJECT,
objectTypeCompressed);
if (metaTypes.isAssignable(Collection.class, objectType)) {
writer.nextControlFlow("else if (o instanceof %s)",
AndroidNames.JSON_ARRAY_FULL);
writer.emitStatement("value = JsonParserUtils.convertArbitraryJsonArray((%s) "
+ "o)",
AndroidNames.JSON_ARRAY_FULL);
}
writer.nextControlFlow("else if (o instanceof %s)", objectTypeCompressed);
if (Object.class.getCanonicalName().equals(objectTypeString)) {
// Do not generate a redundant cast warning
writer.emitStatement("value = o");
} else {
writer.emitStatement("value = (%s) o", objectTypeCompressed);
}
writer.endControlFlow();
}
} else {
// We were given a parser instance, so use that to perform the conversion.
writer.beginControlFlow("if (o instanceof %s)", AndroidNames.JSON_OBJECT);
writer.emitStatement(
"value = %s.parseJsonObject((%s) o, null, discriminationName, null)",
parserInstance,
AndroidNames.JSON_OBJECT);
writer.endControlFlow();
}
// Check to make sure that any conversions were successful
writer.beginControlFlow("if (value == null)");
String message = String.format(Locale.US,
"\"Could not convert value at \\\"%s\\\" to %s from \" + o"
+ ".getClass().getCanonicalName() + \".\"",
name,
objectTypeString);
writer.emitStatement("throw new java.lang.RuntimeException(%s)", message);
writer.endControlFlow();
// Assign the resulting value to the parent object
writer.emitStatement(assignmentPattern, objectName, "value");
postCreateChildBlockWriter.writePostCreateChildBlock(writer, objectName, "value");
}