當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。