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


Java Builder.beginControlFlow方法代码示例

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


在下文中一共展示了Builder.beginControlFlow方法的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: createBindMethod

import com.squareup.javapoet.MethodSpec.Builder; //导入方法依赖的package包/类
/**
 * Create the bind method for our generated class.
 *
 * @param targetParameter The target class that has annotated methods.
 * @param annotatedMethodsPerClass The annotated methods that are in a given class.
 * @return {@link MethodSpec} of the generated class bind method.
 */
@NonNull
private static MethodSpec createBindMethod(@NonNull ParameterSpec targetParameter,
    @NonNull AnnotatedMethodsPerClass annotatedMethodsPerClass) throws ProcessingException {
    Map<Integer, Map<Class, AnnotatedMethod>> itemsMap = annotatedMethodsPerClass.getItemsMap();

    Builder bindMethodBuilder = getBaseMethodBuilder("bind").addParameter(targetParameter)
        .addStatement("int sensorType")
        .addStatement("$T sensor", SENSOR)
        .beginControlFlow("for ($T wrapper : $N)", LISTENER_WRAPPER, LISTENER_WRAPPERS_FIELD)
        .addStatement("sensorType = wrapper.getSensorType()")
        .addStatement("sensor = wrapper.getSensor($N)", SENSOR_MANAGER_FIELD);

    if (annotatedMethodsPerClass.hasAnnotationsOfType(OnSensorNotAvailable.class)) {
        bindMethodBuilder.beginControlFlow("if (sensor == null)");

        // Iterate through our map of sensor types and check whether an OnSensorNotAvailable
        // annotation exists, if so and the sensor is unavailable call the method.
        List<Integer> sensorTypes = new ArrayList<>();
        sensorTypes.addAll(itemsMap.keySet());
        for (int i = 0; i < sensorTypes.size(); i++) {
            Integer sensorType = sensorTypes.get(i);
            Map<Class, AnnotatedMethod> annotationMap = itemsMap.get(sensorType);
            AnnotatedMethod annotatedMethod = annotationMap.get(OnSensorNotAvailable.class);

            if (annotatedMethod != null) {
                checkAnnotatedMethodForErrors(annotatedMethod.getExecutableElement(),
                    OnSensorNotAvailable.class);

                if (i == 0) {
                    bindMethodBuilder.beginControlFlow("if (sensorType == $L)", sensorType);
                } else {
                    bindMethodBuilder.nextControlFlow("else if (sensorType == $L)", sensorType);
                }

                bindMethodBuilder.addStatement("$N.$L()", targetParameter,
                    annotatedMethod.getExecutableElement().getSimpleName());
            }
        }

        bindMethodBuilder.endControlFlow().addStatement("continue").endControlFlow();
    }

    return bindMethodBuilder.addStatement("wrapper.registerListener($N)", SENSOR_MANAGER_FIELD)
        .endControlFlow()
        .build();
}
 
开发者ID:dvoiss,项目名称:SensorAnnotations,代码行数:54,代码来源:SensorAnnotationsFileBuilder.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();
	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

示例15: addDecodeStatements

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

	CodeGeneratorContext childCtx = ctx.createDecodeChildContext(lv + ".add(%s)");

	if (!field.disableDecodeNullCheck() && !hasParent()) {
		builder.beginControlFlow("if (bsonType != $T.NULL)", BsonType.class);
	}

	builder.addStatement("reader.readStartArray()");

	TypeMirror childType = this.getChildCodeGen().getType();
	if (Util.isSameType(getType(), EnumSet.class)) {
		builder.addStatement("$T $L = $T.noneOf($T.class)", getType(), lv,
				EnumSet.class, childType);
	}
	else {
		builder.addStatement("$T $L = new $T<>()", getType(), lv,
				this.getImplementationType());
	}

	builder.beginControlFlow(
			"while ((bsonType = reader.readBsonType()) != $T.END_OF_DOCUMENT)",
			BsonType.class);

	boolean permittNullElements = permitNullElements();
	if (permittNullElements) {
		builder.beginControlFlow("if (bsonType != $T.NULL)", BsonType.class);
	}

	this.getChildCodeGen().addDecodeStatements(childCtx);

	if (permittNullElements) {
		builder.nextControlFlow("else").addStatement("reader.readNull()");
		builder.addStatement(lv + ".add(null)");
		builder.endControlFlow();
	}

	builder.endControlFlow().addStatement("reader.readEndArray()");

	builder.addStatement(ctx.setter("$L"), lv);

	if (!field.disableDecodeNullCheck() && !hasParent()) {
		builder.nextControlFlow("else").addStatement("reader.readNull()");
		if (!ctx.field().disableSetNullStatement()) {
			this.getChildCodeGen().addSetNullStatements(ctx);
		}
		builder.endControlFlow();
	}

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


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