本文整理汇总了Java中com.squareup.javapoet.CodeBlock.Builder.endControlFlow方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.endControlFlow方法的具体用法?Java Builder.endControlFlow怎么用?Java Builder.endControlFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.CodeBlock.Builder
的用法示例。
在下文中一共展示了Builder.endControlFlow方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putEncodeCode
import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
@Override
public void putEncodeCode(Builder cb, TypeMirror iterableTypeMirror, Collection<EncodeCodeProvider> allProviders, String varName) {
TypeMirror iterableTypeArgument = getIterableEnclosedType(iterableTypeMirror);
TypeName iterableTypeArgumentTypeName = getIterableEnclosedTypeName(iterableTypeMirror);
String instanceName = nameGenerator.instanceName(iterableTypeArgument);
cb.addStatement("writer.writeStartArray()");
cb.beginControlFlow("for ($T $L:(($T)$L))", iterableTypeArgumentTypeName, instanceName, getIterableCast(iterableTypeMirror), varName);
boolean primitive = iterableTypeArgument.getKind().isPrimitive();
if ( !primitive ){
cb.beginControlFlow("if ($L == null)", instanceName);
cb.addStatement("writer.writeNull()");
cb.nextControlFlow("else");
}
for(EncodeCodeProvider provider:allProviders){
if (provider.applies(iterableTypeArgument)){
String newVarName = nameGenerator.instanceName(iterableTypeArgument).toLowerCase();
provider.putEncodeCode(cb, iterableTypeArgument, allProviders, newVarName);
break;
}
}
if ( !primitive ){
cb.endControlFlow();
}
cb.endControlFlow();
cb.addStatement("writer.writeEndArray()");
return;
}
示例2: getDecodeCode
import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
@Override
public CodeBlock getDecodeCode(Property property, DecodeCodeProviders decodeProviders) {
Builder builder = CodeBlock.builder();
String getAccessName = property.getGetterCall();
String setAccessName = property.getSetterCall();
setAccessName += property.hasSetter() ? "($L)" : " = $L";
TypeMirror resolvedType = property.getResolvedType();
builder.addStatement("$T bsonType = reader.getCurrentBsonType()", CodeUtil.bsonTypeTypeName());
builder.beginControlFlow("if (bsonType == $T.NULL)", CodeUtil.bsonTypeTypeName());
builder.addStatement("reader.readNull()");
builder.addStatement("instance." + setAccessName, "null");
builder.addStatement("return");
builder.endControlFlow();
if ( initializeProperty() ){
TypeMirror iterableImplementationCollectionClass = getIterableImplementationType(resolvedType);
TypeMirror iterableDeclarationCollectionClass = getIterableDeclarationType(resolvedType);
builder.addStatement("$T value = instance.$L", iterableDeclarationCollectionClass, getAccessName);
builder.beginControlFlow("if (value == null)");
builder.addStatement("value = new $T()", TypeName.get(iterableImplementationCollectionClass));
builder.addStatement("instance." + setAccessName, "value");
builder.endControlFlow();
}
putDecodeCode(builder, resolvedType, decodeProviders, !initializeProperty(), "value");
if ( !initializeProperty() ){
builder.addStatement("instance." + setAccessName, "value");
}
return builder.build();
}
示例3: putDecodeCode
import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
@Override
public void putDecodeCode(Builder cb, TypeMirror tm, DecodeCodeProviders decodeProviders, String variableToUse, boolean declareVariable) {
DeclaredType entry = (DeclaredType)tm;
TypeMirror keyArgument = entry.getTypeArguments().get(0);
TypeMirror valueArgument = entry.getTypeArguments().get(1);
cb.addStatement("reader.readStartDocument()");
cb.addStatement("reader.readName(\"key\")");
cb.addStatement("$T $L = null", keyArgument, variableToUse+"0");
cb.addStatement("$T $L = null", valueArgument, variableToUse+"1");
cb.addStatement("bsonType = reader.getCurrentBsonType()", CodeUtil.bsonTypeTypeName());
cb.beginControlFlow("if (bsonType == $T.NULL)", CodeUtil.bsonTypeTypeName());
cb.addStatement("reader.readNull()");
cb.addStatement("reader.skipName()");
cb.addStatement("reader.skipValue()");
cb.nextControlFlow("else");
Builder builder = CodeBlock.builder();
decodeProviders.putDecodeCode(builder, keyArgument, variableToUse+"0", false);
boolean hasToInstantiate = decodeProviders.hasToInstantiate(keyArgument);
if ( hasToInstantiate ){
cb.add(builder.build());
}else{
cb.add("$L = ", variableToUse+"0");
cb.add(builder.build()+";\n");
}
cb.addStatement("reader.readName(\"value\")");
builder = CodeBlock.builder();
decodeProviders.putDecodeCode(builder, valueArgument, variableToUse+"1", false);
hasToInstantiate = decodeProviders.hasToInstantiate(valueArgument);
if ( hasToInstantiate ){
cb.add(builder.build());
}else{
cb.add("$L = ", variableToUse+"1");
cb.add(builder.build()+";\n");
}
cb.endControlFlow();
cb.addStatement("reader.readEndDocument()");
}
示例4: putDecodeCode
import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
protected void putDecodeCode(Builder cb, TypeMirror iterableTypeMirror, DecodeCodeProviders decodeProviders, String variableToUse, boolean instantiate, boolean declareVariable) {
String temporalVariable = variableToUse+"tmp";
super.putDecodeCode(cb, iterableTypeMirror, decodeProviders, temporalVariable, instantiate, declareVariable);
TypeMirror iterableType = getIterableType(iterableTypeMirror);
if ( !iterableType.getKind().isPrimitive() ){
cb.addStatement("$T $L = $L.toArray(new $T[]{})", iterableTypeMirror, variableToUse, temporalVariable, iterableType);
}else{
cb.addStatement("$T $L = new $T[$L.size()]", iterableTypeMirror, variableToUse, iterableType, temporalVariable);
String idxName = variableToUse+"TmpIdx";
cb.beginControlFlow("for(int $L=0; $L < $L.length; $L++)", idxName, idxName, variableToUse, idxName);
cb.addStatement("$L[$L] = $L.get($L)", variableToUse, idxName, temporalVariable, idxName);
cb.endControlFlow();
}
}
示例5: putDecodeCode
import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
protected void putDecodeCode(Builder cb, TypeMirror iterableTypeMirror, DecodeCodeProviders decodeProviders, String variableToUse, boolean instantiate, boolean declareVariable) {
TypeMirror iterableType = getIterableType(iterableTypeMirror);
String addMethod = getAddMethod();
if ( instantiate ){
TypeMirror iterableImplementationCollectionClass = getIterableImplementationType(iterableTypeMirror);
TypeMirror iterableDeclarationCollectionClass = getIterableDeclarationType(iterableTypeMirror);
if ( declareVariable ){
cb.addStatement("$T $L = new $T()", iterableDeclarationCollectionClass, variableToUse, iterableImplementationCollectionClass);
}else{
cb.addStatement("$L = new $T()", variableToUse, iterableImplementationCollectionClass);
}
}
cb.addStatement("reader.readStartArray()");
cb.beginControlFlow("while (reader.readBsonType() != $T.END_OF_DOCUMENT)", CodeUtil.bsonTypeTypeName());
cb.addStatement("bsonType = reader.getCurrentBsonType()", CodeUtil.bsonTypeTypeName());
cb.beginControlFlow("if (bsonType == $T.NULL)", CodeUtil.bsonTypeTypeName());
cb.addStatement("reader.readNull()");
if ( supportsNull(iterableType) ){
cb.addStatement("$L.$L(null)", variableToUse, addMethod);
}
cb.nextControlFlow("else");
Builder builder2 = CodeBlock.builder();
if ( decodeProviders.applies(iterableType) ){
String varName = nameGenerator.instanceName(iterableType).toLowerCase();
decodeProviders.putDecodeCode(builder2, iterableType, varName);
boolean hasToInstantiate = decodeProviders.hasToInstantiate(iterableType);
if ( hasToInstantiate ){
cb.add(builder2.build());
}
cb.add("$L.$L(",variableToUse, addMethod);
if ( hasToInstantiate ){
List<String> namesUsed = nameGenerator.generateNames(varName, decodeProviders.variablesUsed(iterableType));
cb.add(Joiner.on(',').join(namesUsed));
}else{
cb.add(builder2.build());
}
cb.add(");\n");
}
cb.endControlFlow();
cb.endControlFlow();
cb.addStatement("reader.readEndArray()");
return;
}