本文整理汇总了Java中com.squareup.javawriter.JavaWriter.beginControlFlow方法的典型用法代码示例。如果您正苦于以下问题:Java JavaWriter.beginControlFlow方法的具体用法?Java JavaWriter.beginControlFlow怎么用?Java JavaWriter.beginControlFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javawriter.JavaWriter
的用法示例。
在下文中一共展示了JavaWriter.beginControlFlow方法的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: writeFieldReadStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFieldReadStatement(VariableElement field,
Collection<ExecutableElement> postCreateChildMethods,
JavaWriter writer) throws IOException {
DeclaredType type = (DeclaredType) field.asType();
TypeMirror itemType = type.getTypeArguments().get(0);
TypeMirror itemTypeErasure = processingEnv.getTypeUtils().erasure(itemType);
String collectionInitializer;
try {
collectionInitializer = initializers.findCollectionInitializer(type);
} catch (InvalidTypeException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), field);
collectionInitializer = "null";
}
writer.beginControlFlow("if (bundle.containsKey(\"%s\"))", field.getSimpleName());
writer.emitStatement("object.%s = %s", field.getSimpleName(), collectionInitializer);
writer.emitStatement(
"%1$s.readCollectionFromBundle(object.%2$s, bundle, %3$s.class, \"%2$s\")",
CollectionBundler.class.getCanonicalName(),
field.getSimpleName(),
itemTypeErasure);
writePostCreateChildMethodCalls(field, itemType, postCreateChildMethods, writer);
writer.endControlFlow();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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)");
}
示例6: emitCodeForUnderConstruction
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void emitCodeForUnderConstruction(JavaWriter writer, boolean isPrimaryKey,
CodeEmitter defaultValueCodeEmitter) throws IOException {
writer.beginControlFlow("if (proxyState.isUnderConstruction())");
if (isPrimaryKey) {
writer.emitSingleLineComment("default value of the primary key is always ignored.")
.emitStatement("return");
} else {
writer.beginControlFlow("if (!proxyState.getAcceptDefaultValue$realm())")
.emitStatement("return")
.endControlFlow();
defaultValueCodeEmitter.emit(writer);
}
writer.endControlFlow()
.emitEmptyLine();
}
示例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: writeSingletonChildIfStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private boolean writeSingletonChildIfStatement(Element element,
JavaWriter writer,
boolean first)
throws IOException {
String typeName = extractChildTypeName(element, writer, false);
String assignmentStatement;
String singletonValidationStatement;
if (element instanceof ExecutableElement) {
assignmentStatement =
String.format("%sValue = (%s) child", element.getSimpleName(), typeName);
singletonValidationStatement =
String.format("%sValue == null", element.getSimpleName());
} else {
assignmentStatement =
String.format("object.%s = (%s) child", element.getSimpleName(), typeName);
singletonValidationStatement =
String.format("object.%s == null", element.getSimpleName());
}
String ifStatement;
ifStatement = String.format("if (child instanceof %s)", typeName);
if (first) {
first = false;
writer.beginControlFlow(ifStatement);
} else {
writer.nextControlFlow("else " + ifStatement);
}
String errorMessage =
String.format(
"Expected only one child of type %s for parent type %s, but found multiple",
typeName,
classElement.getSimpleName());
writer.emitStatement("Preconditions.checkState(%s, \"%s\")",
singletonValidationStatement,
errorMessage);
writer.emitStatement(assignmentStatement);
return first;
}
示例9: writeCollectionChildIfStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private boolean writeCollectionChildIfStatement(Element element,
JavaWriter writer,
boolean first)
throws IOException {
String parameterTypeName = extractChildTypeName(element, writer, true);
String addStatement;
if (element instanceof ExecutableElement) {
addStatement = String.format("%sValue.add((%s) child)",
element.getSimpleName(),
parameterTypeName);
} else {
addStatement = String.format("object.%s.add((%s) child)",
element.getSimpleName(),
parameterTypeName);
}
String ifStatement = String.format("if (child instanceof %s)", parameterTypeName);
if (first) {
first = false;
writer.beginControlFlow(ifStatement);
} else {
writer.nextControlFlow("else " + ifStatement);
}
writer.emitStatement(addStatement);
return first;
}
示例10: 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();
}
示例11: 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();
}
示例12: writeFieldReadStatement
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
@Override
public void writeFieldReadStatement(VariableElement field,
Collection<ExecutableElement> postCreateChildMethods,
JavaWriter writer)
throws IOException {
String enumType = field.asType().toString();
Name fieldName = field.getSimpleName();
String fieldNameVariable = fieldName + "Name";
writer.emitStatement("String %s = bundle.getString(\"%s\")", fieldNameVariable, fieldName);
writer.beginControlFlow(String.format("if (%s != null)", fieldNameVariable));
writer.emitStatement("object.%s = %s.valueOf(%s)", fieldName, enumType, fieldNameVariable);
writer.endControlFlow();
}
示例13: writeUpdateSelfValuesBlock
import com.squareup.javawriter.JavaWriter; //导入方法依赖的package包/类
private void writeUpdateSelfValuesBlock(final JavaWriter writer) throws IOException {
if (selfValueAssignmentInfo.convertJsonTypes) {
ErrorWriter.surroundWithIoTryCatch(writer, new ErrorWriter.ContentWriter() {
@Override
public void writeContent() throws IOException {
writer.emitStatement("map = JsonParserUtils.convertMapValues(map, context)");
}
});
}
if (selfValueAssignmentInfo.member instanceof ExecutableElement) {
writer.emitStatement(selfValueAssignmentInfo.assignmentPattern, "instance", "map");
} else {
Name fieldName = selfValueAssignmentInfo.member.getSimpleName();
writer.beginControlFlow("if (instance.%s == null)", fieldName);
String mapInitializer = null;
try {
mapInitializer = initializers.findMapInitializer(
(DeclaredType) selfValueAssignmentInfo.member.asType());
} catch (InvalidTypeException e) {
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.ERROR, e.getMessage(), selfValueAssignmentInfo.member);
}
writer.emitStatement("instance.%s = %s", fieldName, mapInitializer);
writer.endControlFlow();
writer.emitStatement("instance.%s.putAll(map)", fieldName);
}
}
示例14: 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();
}
示例15: 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();
}