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


Java Builder.nextControlFlow方法代码示例

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


在下文中一共展示了Builder.nextControlFlow方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: addEncodeStatements

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

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

		if (idModel.conversion() == IdConversion.HEX_OBJECTID) {
			builder.addStatement(ctx.setter("id.toHexString()"));
		}
		else if (idModel.conversion() == IdConversion.BASE64_OBJECTID) {
			builder.addStatement(
					ctx.setter("$T.getUrlEncoder().encodeToString(id.toByteArray())"),
					Base64.class);
		}

		builder.nextControlFlow("else");

		if (idModel.conversion() == IdConversion.HEX_OBJECTID) {
			builder.addStatement("id = new $T($L)", ObjectId.class, ctx.getter());
		}
		else if (idModel.conversion() == IdConversion.BASE64_OBJECTID) {
			builder.addStatement("id = new $T($T.getUrlDecoder().decode($L))",
					ObjectId.class, Base64.class, ctx.getter());
		}
		builder.endControlFlow().addStatement("writer.writeObjectId($S, id)",
				ctx.field().name());
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:34,代码来源:ConversionObjectIdCodeGen.java

示例9: 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

示例10: 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


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