当前位置: 首页>>代码示例>>Java>>正文


Java Builder.endControlFlow方法代码示例

本文整理汇总了Java中com.squareup.javapoet.MethodSpec.Builder.endControlFlow方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.endControlFlow方法的具体用法?Java Builder.endControlFlow怎么用?Java Builder.endControlFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javapoet.MethodSpec.Builder的用法示例。


在下文中一共展示了Builder.endControlFlow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    if (isObjectProperty) {
        builder.addStatement("$L.writeStringField($S, $L)", JSON_GENERATOR_VARIABLE_NAME, fieldName, getter);
    } else {
        builder.addStatement("$L.writeString($L)", JSON_GENERATOR_VARIABLE_NAME, getter);
    }

    if (checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }

        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:StringFieldType.java

示例2: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    if (isObjectProperty) {
        builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
    }
    builder.addStatement("$L.serialize($L, $L, true)", mJsonMapperVariableName, getter, JSON_GENERATOR_VARIABLE_NAME);

    if (checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }
        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ParameterizedTypeField.java

示例3: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (!isPrimitive && checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    if (isObjectProperty) {
        builder.addStatement("$L.writeBooleanField($S, $L)", JSON_GENERATOR_VARIABLE_NAME, fieldName, getter);
    } else {
        builder.addStatement("$L.writeBoolean($L)", JSON_GENERATOR_VARIABLE_NAME, getter);
    }

    if (!isPrimitive && checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }

        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:BooleanFieldType.java

示例4: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (!isPrimitive && checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    if (isObjectProperty) {
        builder.addStatement("$L.writeNumberField($S, $L)", JSON_GENERATOR_VARIABLE_NAME, fieldName, getter);
    } else {
        builder.addStatement("$L.writeNumber($L)", JSON_GENERATOR_VARIABLE_NAME, getter);
    }

    if (!isPrimitive && checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }

        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:NumberFieldType.java

示例5: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {

    if (checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    if (isObjectProperty) {
        builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
    }

    builder.addStatement("$L.serialize($L, $L, true)", mMapperVariableName, getter, JSON_GENERATOR_VARIABLE_NAME);

    if (checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }

        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:JsonFieldType.java

示例6: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (!mTypeName.isPrimitive() && checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    builder.addStatement("$T.typeConverterFor($T.class).serialize($L, $S, $L, $L)", LoganSquare.class, mTypeName, getter, isObjectProperty
            ? fieldName : null, isObjectProperty, JSON_GENERATOR_VARIABLE_NAME);

    if (!mTypeName.isPrimitive() && checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }
        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:DynamicFieldType.java

示例7: serialize

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void serialize(Builder builder, int depth, String fieldName, List<String> processedFieldNames, String getter, boolean isObjectProperty, boolean checkIfNull, boolean writeIfNull, boolean writeCollectionElementIfNull) {
    if (checkIfNull) {
        builder.beginControlFlow("if ($L != null)", getter);
    }

    builder.addStatement("$L.serialize($L, $L, $L)", ObjectMapperInjector.getMapperVariableName(ObjectMapper.class), getter, JSON_GENERATOR_VARIABLE_NAME, isObjectProperty);

    if (checkIfNull) {
        if (writeIfNull) {
            builder.nextControlFlow("else");

            if (isObjectProperty) {
                builder.addStatement("$L.writeFieldName($S)", JSON_GENERATOR_VARIABLE_NAME, fieldName);
            }
            builder.addStatement("$L.writeNull()", JSON_GENERATOR_VARIABLE_NAME);
        }

        builder.endControlFlow();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:UnknownFieldType.java

示例8: addGetCodecMethod

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
private void addGetCodecMethod(com.squareup.javapoet.TypeSpec.Builder codecProviderBuilder) {
	TypeVariableName typeVariableName = TypeVariableName.get("T");
	TypeName clazzName = ParameterizedTypeName.get(ClassName.get(Class.class), typeVariableName);
	TypeName codecName = ParameterizedTypeName.get((ClassName) CodeUtil.bsonCodecTypeName(), typeVariableName);

	Builder methodSpec = MethodSpec.methodBuilder("get")
			.addAnnotation(Override.class)
			.addAnnotation(Util.suppressWarningsAnnotation(true, false))
			.addModifiers(Modifier.PUBLIC)
			.addParameter(ParameterSpec.builder(clazzName, "clazz", Modifier.FINAL).build())
			.addParameter(CodeUtil.bsonRegistryParameter())
			.addTypeVariable(typeVariableName)
			.returns(codecName)
			.addJavadoc("{@inhericDoc}\n");

	for (ClassName entityClassName : generated) {
		ClassName bsoneerCodecClassName = Util.bsoneeName(entityClassName, GeneratedClasses.BSONEE_CODEC_SUFFIX);
		methodSpec.beginControlFlow("if (clazz == $T.class)", entityClassName);
		methodSpec.addStatement("return (Codec<T>) new $T(registry)", bsoneerCodecClassName);
		methodSpec.endControlFlow();
	}

	methodSpec.addStatement("return null");
	codecProviderBuilder.addMethod(methodSpec.build());
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:26,代码来源:BsoneeCodecProviderGenerator.java

示例9: addBodyToMethod

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
private void addBodyToMethod(Builder toBsonDocumentMethod) {
	toBsonDocumentMethod.addStatement("$T<T> codec = registry.get(wrappedClazz)",
			CodeUtil.bsonCodecTypeName());
	toBsonDocumentMethod.beginControlFlow("if (codec == null)");
	toBsonDocumentMethod.addStatement("codec = bcp.get(wrappedClazz, registry)");
	toBsonDocumentMethod.endControlFlow();
	toBsonDocumentMethod.addStatement("return new $T(wrapped, codec)",
			ClassName.bestGuess("org.bson.RawBsonDocument"));
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:10,代码来源:BsoneeBsonGenerator.java

示例10: addEncodeStatements

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void addEncodeStatements(CodeGeneratorContext ctx) {
	FieldModel field = ctx.field();
	Builder builder = ctx.builder();

	if (!this.hasParent()) {
		if (!field.disableEncodeNullCheck()) {
			builder.beginControlFlow("if ($L != null)", ctx.getter());
		}

		IdModel idModel = field.idModel();
		if (idModel != null && idModel.generatorName() != null) {
			builder.beginControlFlow("if ($L == null)", ctx.getter())
					.addStatement(ctx.setter("($T)this.$N.generate()"), getType(),
							idModel.generatorName())
					.endControlFlow();
		}

		builder.addStatement("writer.writeName($S)", field.name());
	}

	this.delegate.addEncodeStatements(getType(), ctx);

	if (!this.hasParent()) {
		if (!field.disableEncodeNullCheck()) {
			if (field.storeNullValue()) {
				builder.nextControlFlow("else").addStatement("writer.writeNull($S)",
						field.name());
			}
			builder.endControlFlow();
		}
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:34,代码来源:ScalarCodeGen.java

示例11: addDecodeStatements

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void addDecodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	Builder builder = ctx.builder();
	switch (type.getKind()) {
	case BOOLEAN:
		builder.addStatement(ctx.setter("reader.readBoolean()"));
		break;
	case BYTE:
		builder.addStatement(ctx.setter("(byte)reader.readInt32()"));
		break;
	case SHORT:
		builder.addStatement(ctx.setter("(short)reader.readInt32()"));
		break;
	case INT:
		builder.addStatement(ctx.setter("reader.readInt32()"));
		break;
	case LONG:
		builder.addStatement(ctx.setter("reader.readInt64()"));
		break;
	case CHAR:
		builder.addStatement("String string = reader.readString()");
		builder.beginControlFlow("if (string.length() != 1)");
		builder.addStatement(
				"throw new $T(String.format(\"Attempting to builder the string '%s' to a character, but its length is not equal to one\", string))",
				BsonInvalidOperationException.class);
		builder.endControlFlow();
		builder.addStatement(ctx.setter("string.charAt(0)"));
		break;
	case FLOAT:
		builder.addStatement(ctx.setter("(float)reader.readDouble()"));
		break;
	case DOUBLE:
		builder.addStatement(ctx.setter("reader.readDouble()"));
		break;
	default:
		break;
	}

}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:40,代码来源:PrimitiveDelegate.java

示例12: parse

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void parse(Builder builder, int depth, String setter, Object... setterFormatArgs) {
    TypeName fieldType = arrayType.getTypeName();
    final String collectionVarName = "collection" + depth;

    final String instanceCreator = String.format("$T<%s> $L = new $T<%s>()", arrayType.getParameterizedTypeString(), arrayType.getParameterizedTypeString());
    final Object[] instanceCreatorArgs = expandStringArgs(List.class, arrayType.getParameterizedTypeStringArgs(), collectionVarName, ArrayList.class, arrayType.getParameterizedTypeStringArgs());

    builder.beginControlFlow("if ($L.getCurrentToken() == $T.START_ARRAY)", JSON_PARSER_VARIABLE_NAME, JsonToken.class)
            .addStatement(instanceCreator, instanceCreatorArgs)
            .beginControlFlow("while ($L.nextToken() != $T.END_ARRAY)", JSON_PARSER_VARIABLE_NAME, JsonToken.class);

    if (!fieldType.isPrimitive()) {
        final String valueVarName = "value" + depth;

        builder.addStatement("$T $L", arrayType.getTypeName(), valueVarName);
        arrayType.parse(builder, depth + 1, "$L = $L", valueVarName);

        builder.addStatement("$L.add($L)", collectionVarName, valueVarName);
    } else {
        arrayType.parse(builder, depth + 1, "$L.add($L)", collectionVarName);
    }

    builder.endControlFlow();

    if (fieldType.isPrimitive()) {
        builder
                .addStatement("$T[] array = new $T[$L.size()]", fieldType, fieldType, collectionVarName)
                .addStatement("int i = 0")
                .beginControlFlow("for ($T value : $L)", fieldType, collectionVarName)
                .addStatement("array[i++] = value")
                .endControlFlow();
    } else {
        builder.addStatement("$T[] array = $L.toArray(new $T[$L.size()])", fieldType, collectionVarName, fieldType, collectionVarName);
    }

    builder
            .addStatement(setter, expandStringArgs(setterFormatArgs, "array"))
            .nextControlFlow("else")
            .addStatement(setter, expandStringArgs(setterFormatArgs, "null"))
            .endControlFlow();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:ArrayCollectionType.java

示例13: writeCheckingForNull

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
public void writeCheckingForNull(Builder p, String tn, CodeBlock cb) {
	p.beginControlFlow("if (value.$L != null)", tn);
	p.addCode(cb);
	p.endControlFlow();
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:6,代码来源:GetterGenerator.java

示例14: addEncodeStatements

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void addEncodeStatements(CodeGeneratorContext ctx) {
	FieldModel field = ctx.field();
	IdModel idModel = field.idModel();
	Builder builder = ctx.builder();

	if (idModel != null && idModel.generatorName() != null) {
		builder.addStatement("$T id", UUID.class)
				.beginControlFlow("if ($L == null)", ctx.getter())
				.addStatement("id = ($T)this.$N.generate()", UUID.class,
						idModel.generatorName());

		if (idModel.conversion() == IdConversion.HEX_UUID) {
			builder.addStatement(ctx.setter("id.toString()"));
		}
		else if (idModel.conversion() == IdConversion.BASE64_UUID) {
			builder.addStatement("$T bb = $T.wrap(new byte[16])", ByteBuffer.class,
					ByteBuffer.class);
			builder.addStatement("bb.putLong(id.getMostSignificantBits())");
			builder.addStatement("bb.putLong(id.getLeastSignificantBits())");
			builder.addStatement(
					ctx.setter("$T.getUrlEncoder().encodeToString(bb.array())"),
					Base64.class);
		}
		builder.nextControlFlow("else");

		if (idModel.conversion() == IdConversion.HEX_UUID) {
			builder.addStatement("id = $T.fromString($L)", UUID.class, ctx.getter());
		}
		else if (idModel.conversion() == IdConversion.BASE64_UUID) {
			builder.addStatement("$T bb = $T.wrap($T.getUrlDecoder().decode($L))",
					ByteBuffer.class, ByteBuffer.class, Base64.class, ctx.getter());
			builder.addStatement("id = new $T(bb.getLong(), bb.getLong())",
					UUID.class);
		}
		builder.endControlFlow();
	}
	else {
		if (idModel != null) {
			if (idModel.conversion() == IdConversion.HEX_UUID) {
				builder.addStatement("$T id = $T.fromString($L)", UUID.class,
						UUID.class, ctx.getter());
			}
			else if (idModel.conversion() == IdConversion.BASE64_UUID) {
				builder.addStatement("$T bb = $T.wrap($T.getUrlDecoder().decode($L))",
						ByteBuffer.class, ByteBuffer.class, Base64.class,
						ctx.getter());
				builder.addStatement("$T id = new $T(bb.getLong(), bb.getLong())",
						UUID.class, UUID.class);
			}
		}
	}

	ctx.builder().addStatement("writer.writeName($S)", field.name())
			.addStatement("this.uUIDCodec.encode(writer, id, encoderContext)");

	ctx.instanceFields()
			.add(ImmutableInstanceField.builder().type(ClassName.get(Codec.class))
					.name("uUIDCodec").codecForClass(ClassName.get(UUID.class))
					.build());
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:62,代码来源:ConversionUUIDCodeGen.java

示例15: addEncodeStatements

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
@Override
public void addEncodeStatements(CodeGeneratorContext ctx) {
	FieldModel field = ctx.field();
	Builder builder = ctx.builder();

	if (!field.disableEncodeNullCheck() && !hasParent()) {
		builder.beginControlFlow("if ($L != null)", ctx.getter());
	}

	if (!field.storeEmptyCollection()) {
		builder.beginControlFlow("if (!$L.isEmpty())", ctx.getter());
	}

	if (!hasParent()) {
		builder.addStatement("writer.writeName($S)", field.name());
	}

	TypeMirror childType = this.getChildCodeGen().getType();
	builder.addStatement("writer.writeStartArray()").beginControlFlow(
			"for ($T $L : $L)", childType, ctx.getLoopVar(), ctx.getter());

	boolean permittNullElements = permitNullElements();
	if (!field.disableEncodeNullCheck() && permittNullElements) {
		builder.beginControlFlow("if ($L != null)", ctx.getLoopVar());
	}

	this.getChildCodeGen().addEncodeStatements(
			ctx.createEncodeChildContext(String.valueOf(ctx.getLoopVar())));

	if (!field.disableEncodeNullCheck() && permittNullElements) {
		builder.nextControlFlow("else").addStatement("writer.writeNull()");
		builder.endControlFlow();
	}

	builder.endControlFlow().addStatement("writer.writeEndArray()");

	if (!field.storeEmptyCollection()) {
		builder.endControlFlow();
	}

	if (!field.disableEncodeNullCheck() && !hasParent()) {
		if (field.storeNullValue()) {
			builder.nextControlFlow("else").addStatement("writer.writeNull($S)",
					field.name());
		}
		builder.endControlFlow();
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:49,代码来源:CollectionCodeGen.java


注:本文中的com.squareup.javapoet.MethodSpec.Builder.endControlFlow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。