本文整理汇总了Java中com.squareup.javawriter.JavaWriter.endControlFlow方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.endControlFlow方法的具体用法?Java JavaWriter.endControlFlow怎么用?Java JavaWriter.endControlFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.endControlFlow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: writeFieldWriteStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFieldWriteStatement(VariableElement field, JavaWriter writer)
throws IOException {
DeclaredType type = (DeclaredType) field.asType();
List<? extends TypeMirror> typeArguments = type.getTypeArguments();
TypeMirror keyType = typeArguments.get(0);
TypeMirror valueType = typeArguments.get(1);
writer.beginControlFlow("if (object.%s != null)", field.getSimpleName());
writer.emitStatement(
"%1$s.writeMapToBundle(object.%2$s, bundle, %3$s.class, %4$s.class, \"%2$s\")",
MapBundler.class.getCanonicalName(),
field.getSimpleName(),
keyType,
valueType);
writer.endControlFlow();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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)");
}
示例7: generateCode
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public void generateCode(Elements elementUtils, Filer filer) throws IOException {
TypeElement superClassName = elementUtils.getTypeElement(qualifiedClassName);
String factoryClassName = superClassName.getSimpleName() + SUFFIX;
JavaFileObject jfo = filer.createSourceFile(qualifiedClassName + SUFFIX);
Writer writer = jfo.openWriter();
JavaWriter jw = new JavaWriter(writer);
// 写包名
PackageElement pkg = elementUtils.getPackageOf(superClassName);
if (!pkg.isUnnamed()) {
jw.emitPackage(pkg.getQualifiedName().toString());
jw.emitEmptyLine();
} else {
jw.emitPackage("");
}
jw.beginType(factoryClassName, "class", EnumSet.of(Modifier.PUBLIC));
jw.emitEmptyLine();
jw.beginMethod(qualifiedClassName, "create", EnumSet.of(Modifier.PUBLIC), "String", "id");
jw.beginControlFlow("if (id == null)");
jw.emitStatement("throw new IllegalArgumentException(\"id is null!\")");
jw.endControlFlow();
for (FactoryAnnotatedClass item : itemsMap.values()) {
jw.beginControlFlow(String.format("if (\"%s\".equals(id))", item.getId()));
jw.emitStatement("return new %s()", item.getTypeElement().getQualifiedName().toString());
jw.endControlFlow();
jw.emitEmptyLine();
}
jw.emitStatement("throw new IllegalArgumentException(\"Unknown id = \" + id)");
jw.endMethod();
jw.endType();
jw.close();
}
示例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: writeAttributeAssignment
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeAttributeAssignment(List<String> names,
Element attributeElement,
JavaWriter writer)
throws IOException {
String ifPattern = "if (attributes.hasAttribute(\"%s\"))";
String initializationPattern = getAttributeInitializationPattern(attributeElement);
String assignmentPattern;
if (attributeElement instanceof ExecutableElement) {
assignmentPattern = String.format(Locale.US,
"object.%s(%s)",
attributeElement.getSimpleName(),
initializationPattern);
} else {
assignmentPattern = String.format(Locale.US,
"object.%s = %s",
attributeElement.getSimpleName(),
initializationPattern);
}
String name = names.get(0);
writer.beginControlFlow(String.format(ifPattern, name));
writer.emitStatement(assignmentPattern, name);
for (int i = 1; i < names.size(); i++) {
name = names.get(i);
writer.nextControlFlow(String.format("else " + ifPattern, name));
writer.emitStatement(assignmentPattern, name);
}
writer.endControlFlow();
}
示例10: writeFieldWriteStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFieldWriteStatement(VariableElement field, JavaWriter writer)
throws IOException {
Name fieldName = field.getSimpleName();
writer.beginControlFlow(String.format("if (object.%s != null)", fieldName));
writer.emitStatement("bundle.putString(\"%s\", object.%s.name())", fieldName, fieldName);
writer.endControlFlow();
}
示例11: 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(readerAssignmentPattern, objectName, readerName, key);
writer.endControlFlow();
}
示例12: writePostCreateChildMethodCalls
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writePostCreateChildMethodCalls(VariableElement field,
TypeMirror itemType,
Collection<ExecutableElement>
postCreateChildMethods,
JavaWriter writer) throws IOException {
if (!postCreateChildMethods.isEmpty() && metaTypes.isSubtype(itemType, Names.PARCELABLE)) {
writer.beginControlFlow("for (Object child : object.%s)", field.getSimpleName());
for (ExecutableElement method : postCreateChildMethods) {
writer.emitStatement("object.%s(child)", method.getSimpleName());
}
writer.endControlFlow();
}
}
示例13: writeDoInitializeAndGetFieldMethod
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeDoInitializeAndGetFieldMethod(JavaWriter writer) throws IOException {
writer.beginMethod("Object", "doInitializeAndGetField", Modifiers.PRIVATE, parsedClassName, "instance",
"String", "name", "boolean", "initializeCollections");
writer.beginControlFlow("switch (name)");
for (AssignmentInfo assignmentInfo : assignments) {
if (assignmentInfo.member instanceof VariableElement) {
writeInitializeAndGetBlock(writer, (VariableElement) assignmentInfo.member, assignmentInfo.name);
}
}
writer.beginControlFlow("default:");
writer.emitStatement("return null");
writer.endControlFlow();
writer.endControlFlow();
writer.endMethod();
}
示例14: writeInitializeAndGetBlock
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeInitializeAndGetBlock(JavaWriter writer, VariableElement field, String name) throws IOException {
writer.beginControlFlow("case (\"%s\"):", name);
if (metaTypes.isSubtypeErasure(field.asType(), Collection.class) || metaTypes.isSubtypeErasure(field.asType(),
Map.class)) {
writer.beginControlFlow("if (initializeCollections && instance.%s == null)", field.getSimpleName());
writeInitializeField(writer, field);
writer.endControlFlow();
}
writer.emitStatement("return instance.%s", field.getSimpleName());
writer.endControlFlow();
}
示例15: surroundWithIoTryCatch
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
public static void surroundWithIoTryCatch(JavaWriter writer, ContentWriter contentWriter)
throws IOException {
writer.beginControlFlow("try");
contentWriter.writeContent();
writer.nextControlFlow("catch (IOException e)");
writer.emitStatement("throw new RuntimeException(e)");
writer.endControlFlow();
}