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


Java ClassName.nestedClass方法代码示例

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


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

示例1: create

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
static OutputValue create(Value value, ClassName specOutputClass, Spec spec)
    throws ParserException {
  ClassName outputClass = specOutputClass.nestedClass(value.name());
  Iterable<TypeVariableName> typeVariables = getTypeVariables(value, spec.typeVariables());

  List<Parameter> parameters = new ArrayList<>();
  for (Parameter parameter : value.parameters()) {
    TypeName rawParamType = withoutTypeParameters(parameter.type());

    if (isDataEnumParameter(rawParamType)) {
      TypeName paramOutputType =
          withParametersFromOther(toOutputClass(rawParamType), parameter.type());
      parameters.add(new Parameter(parameter.name(), paramOutputType, parameter.canBeNull()));
    } else {
      parameters.add(parameter);
    }
  }

  return new OutputValue(outputClass, value.name(), parameters, typeVariables);
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:21,代码来源:OutputValueFactory.java

示例2: builderCopyMethodForList

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec builderCopyMethodForList() {
    TypeName keyType = typeProvider.getTypeNameForSimpleType(memberModel.getMapModel().getKeyModel()
                                                                        .getVariable().getVariableType());
    ClassName valueParameter = poetExtensions.getModelClass(memberModel.getMapModel().getValueModel().getC2jShape());
    ClassName builderForParameter = valueParameter.nestedClass("Builder");
    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Map.class), keyType, WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code =
        CodeBlock.builder()
                 .beginControlFlow("if ($N == null)", memberParamName())
                 .addStatement("return null")
                 .endControlFlow()
                 .addStatement("return $N($N.entrySet().stream().collect(toMap($T::getKey, e -> e.getValue().build())))",
                               serviceModelCopiers.copyMethodName(),
                               memberParamName(),
                               Map.Entry.class)
                 .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:27,代码来源:MemberCopierSpec.java

示例3: builderCopyMethodForMap

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec builderCopyMethodForMap() {
    ClassName listParameter = poetExtensions.getModelClass(memberModel.getListModel().getListMemberModel().getC2jShape());
    ClassName builderForParameter = listParameter.nestedClass("Builder");

    TypeName parameterType =
        ParameterizedTypeName.get(ClassName.get(Collection.class), WildcardTypeName.subtypeOf(builderForParameter));

    CodeBlock code = CodeBlock.builder()
                              .beginControlFlow("if ($N == null)", memberParamName())
                              .addStatement("return null")
                              .endControlFlow()
                              .addStatement("return $N($N.stream().map($T::$N).collect(toList()))",
                                            serviceModelCopiers.copyMethodName(),
                                            memberParamName(),
                                            builderForParameter,
                                            "build")
                              .build();

    return MethodSpec.methodBuilder(serviceModelCopiers.builderCopyMethodName())
                     .addModifiers(Modifier.STATIC)
                     .addParameter(parameterType, memberParamName())
                     .returns(typeProvider.fieldType(memberModel))
                     .addCode(code)
                     .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:26,代码来源:MemberCopierSpec.java

示例4: fluentConsumerFluentSetter

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec fluentConsumerFluentSetter(TypeName returnType) {
    ClassName memberClass = poetExtensions.getModelClass(memberModel().getShape().getC2jName());
    ClassName builderClass = memberClass.nestedClass("Builder");
    return fluentDefaultSetterDeclaration(builderConsumerParam(builderClass), returnType)
        .addModifiers(Modifier.DEFAULT)
        .addStatement("return $N($T.builder().apply($N).build())",
                      memberModel().getFluentSetterMethodName(),
                      memberClass,
                      fieldName())
        .addJavadoc("$L", memberModel().getDefaultConsumerFluentSetterDocumentation())
        .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:13,代码来源:NonCollectionSetters.java

示例5: builderConsumerMethod

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
/**
 * Creates a method that thats a Consumer of Request.Builder
 */
private MethodSpec.Builder builderConsumerMethod(OperationModel opModel) {
    ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getInput().getVariableType());
    ClassName builder = requestType.nestedClass("Builder");
    TypeName consumer = ParameterizedTypeName.get(ClassName.get(Consumer.class), builder);

    return interfaceMethodSignature(opModel)
        .addParameter(consumer, opModel.getInput().getVariableName())
        .addJavadoc(opModel.getDocs(model, ClientType.ASYNC, SimpleMethodOverload.CONSUMER_BUILDER))
        .addStatement("return $N($T.builder().apply($N).build())",
                      opModel.getMethodName(),
                      requestType,
                      opModel.getInput().getVariableName());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:18,代码来源:AsyncClientInterface.java

示例6: operationBuilderConsumer

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec operationBuilderConsumer(IntermediateModel model,
                                            OperationModel opModel) {
    ClassName requestType = ClassName.get(model.getMetadata().getFullModelPackageName(),
                                          opModel.getInput().getVariableType());
    ClassName builder = requestType.nestedClass("Builder");
    TypeName consumer = ParameterizedTypeName.get(ClassName.get(Consumer.class), builder);

    return operationBaseSignature(model, opModel, b -> b.addParameter(consumer, opModel.getInput().getVariableName()))
        .addModifiers(Modifier.DEFAULT)
        .addStatement("return $L($T.builder().apply($L).build())",
                      opModel.getMethodName(),
                      requestType,
                      opModel.getInput().getVariableName())
        .build();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:SyncClientInterface.java

示例7: computeSubstitution

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private final TypeName computeSubstitution(final ClassName input) {
	// If the FQ name for this type starts with the root class FQ name,
	// then it's a nested type and so the substitution will be in the
	// same relative place in the output class. Otherwise, this is
	// a supertype/superinterface.
	if (input.toString().startsWith(rootClassName.toString())) { // Nested type (or the root type itself)

		// Stack the simple names of the nested types starting at the
		// end (most deeply nested) back until we hit the root
		final Deque<String> stack = new ArrayDeque<>();
		for (ClassName iterator = input;
				!iterator.equals(rootClassName);
				iterator = iterator.enclosingClassName()) {
			stack.push(iterator.simpleName());
		}

		// Now, append the simple names to the output class
		// as nested classes
		ClassName result = outputClassName;
		while (!stack.isEmpty()) {
			result = result.nestedClass(stack.pop());
		}

		return result;
	} else { // Supertype/superinterface
		return outputClassName;
	}
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:29,代码来源:Inventory.java


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