本文整理汇总了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);
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
示例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();
}
示例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;
}
}