下面列出了io.reactivex.CompletableOnSubscribe#com.squareup.javapoet.TypeVariableName 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static MethodSpec.Builder getDeployMethodSpec(
String className, Class authType, String authName,
boolean isPayable, boolean withGasProvider) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("deploy")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(
buildRemoteCall(TypeVariableName.get(className, Type.class)))
.addParameter(Web3j.class, WEB3J)
.addParameter(authType, authName);
if (isPayable && !withGasProvider) {
return builder.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT)
.addParameter(BigInteger.class, INITIAL_VALUE);
} else if (isPayable && withGasProvider) {
return builder.addParameter(GasProvider.class, CONTRACT_GAS_PROVIDER)
.addParameter(BigInteger.class, INITIAL_VALUE);
} else if (!isPayable && withGasProvider) {
return builder.addParameter(GasProvider.class, CONTRACT_GAS_PROVIDER);
} else {
return builder.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT);
}
}
private static MethodSpec.Builder getDeployMethodSpec(
String className, Class authType, String authName, boolean isPayable) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("deploy")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(
buildRemoteCall(TypeVariableName.get(className, Type.class)))
.addParameter(Web3j.class, WEB3J)
.addParameter(authType, authName)
.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT);
if (isPayable) {
return builder.addParameter(BigInteger.class, INITIAL_VALUE);
} else {
return builder;
}
}
public static ImmutableList<TypeVariableName> getTypeVariables(PsiClass psiClass) {
PsiTypeParameter[] psiTypeParameters = psiClass.getTypeParameters();
final List<TypeVariableName> typeVariables = new ArrayList<>(psiTypeParameters.length);
for (PsiTypeParameter psiTypeParameter : psiTypeParameters) {
final PsiReferenceList extendsList = psiTypeParameter.getExtendsList();
final PsiClassType[] psiClassTypes = extendsList.getReferencedTypes();
final TypeName[] boundsTypeNames = new TypeName[psiClassTypes.length];
for (int i = 0, size = psiClassTypes.length; i < size; i++) {
boundsTypeNames[i] = PsiTypeUtils.getTypeName(psiClassTypes[i]);
}
final TypeVariableName typeVariable =
TypeVariableName.get(psiTypeParameter.getName(), boundsTypeNames);
typeVariables.add(typeVariable);
}
return ImmutableList.copyOf(typeVariables);
}
@Test
public void testGetTypeVariablesOnParameterizedTypeRecursive() {
TypeVariableName type1 = TypeVariableName.get("R");
TypeVariableName type2 = TypeVariableName.get("S");
TypeVariableName type3 = TypeVariableName.get("T");
TypeName type =
ParameterizedTypeName.get(
ClassName.bestGuess("java.lang.Object"),
type1,
type2,
ParameterizedTypeName.get(ClassName.bestGuess("java.lang.Object"), type3));
assertThat(MethodParamModelUtils.getTypeVariables(type)).hasSize(3);
assertThat(MethodParamModelUtils.getTypeVariables(type)).contains(type1);
assertThat(MethodParamModelUtils.getTypeVariables(type)).contains(type2);
assertThat(MethodParamModelUtils.getTypeVariables(type)).contains(type3);
}
private static String getStateContainerClassNameWithTypeVars(SpecModel specModel) {
if (specModel.getStateValues().isEmpty()) {
return specModel.getStateContainerClass().toString();
}
final StringBuilder stringBuilder = new StringBuilder();
final ImmutableList<TypeVariableName> typeVariables = specModel.getTypeVariables();
if (!typeVariables.isEmpty()) {
stringBuilder.append("<");
for (int i = 0, size = typeVariables.size(); i < size - 1; i++) {
stringBuilder.append(typeVariables.get(i).name).append(", ");
}
stringBuilder.append(typeVariables.get(typeVariables.size() - 1)).append(">");
}
return getStateContainerClassName(specModel) + stringBuilder;
}
public SpecMethodModel(
ImmutableList<Annotation> annotations,
ImmutableList<Modifier> modifiers,
CharSequence name,
TypeSpec returnTypeSpec,
ImmutableList<TypeVariableName> typeVariables,
ImmutableList<MethodParamModel> methodParams,
Object representedObject,
@Nullable A typeModel) {
this.annotations = annotations;
this.modifiers = modifiers;
this.name = name;
this.returnTypeSpec = returnTypeSpec;
this.returnType = returnTypeSpec != null ? returnTypeSpec.getTypeName() : null;
this.typeVariables = typeVariables;
this.methodParams = methodParams;
this.representedObject = representedObject;
this.typeModel = typeModel;
}
/** Get the type variables from the given {@link TypeElement}. */
public static List<TypeVariableName> getTypeVariables(TypeElement typeElement) {
final List<? extends TypeParameterElement> typeParameters = typeElement.getTypeParameters();
final int typeParameterCount = typeParameters.size();
final List<TypeVariableName> typeVariables = new ArrayList<>(typeParameterCount);
for (TypeParameterElement typeParameterElement : typeParameters) {
final int boundTypesCount = typeParameterElement.getBounds().size();
final TypeName[] boundsTypeNames = new TypeName[boundTypesCount];
for (int i = 0; i < boundTypesCount; i++) {
boundsTypeNames[i] = TypeName.get(typeParameterElement.getBounds().get(i));
}
final TypeVariableName typeVariable =
TypeVariableName.get(typeParameterElement.getSimpleName().toString(), boundsTypeNames);
typeVariables.add(typeVariable);
}
return typeVariables;
}
private static MethodSpec.Builder getDeployMethodSpec(
String className,
Class authType,
String authName,
boolean isPayable,
boolean withGasProvider) {
MethodSpec.Builder builder =
MethodSpec.methodBuilder("deploy")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(buildRemoteCall(TypeVariableName.get(className, Type.class)))
.addParameter(Web3j.class, WEB3J)
.addParameter(authType, authName);
if (isPayable && !withGasProvider) {
return builder.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT)
.addParameter(BigInteger.class, INITIAL_VALUE);
} else if (isPayable && withGasProvider) {
return builder.addParameter(ContractGasProvider.class, CONTRACT_GAS_PROVIDER)
.addParameter(BigInteger.class, INITIAL_VALUE);
} else if (!isPayable && withGasProvider) {
return builder.addParameter(ContractGasProvider.class, CONTRACT_GAS_PROVIDER);
} else {
return builder.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT);
}
}
private MethodSpec.Builder createFoldSignature(Iterable<TypeVariableName> availableTypeVariables)
throws ParserException {
MethodSpec.Builder builder =
MethodSpec.methodBuilder("map")
.addTypeVariable(FOLD_RETURN_TYPE)
.addModifiers(Modifier.PUBLIC)
.returns(FOLD_RETURN_TYPE);
for (OutputValue arg : values) {
TypeName visitor =
ParameterizedTypeName.get(
ClassName.get(Function.class),
TypeVariableUtils.withoutMissingTypeVariables(
arg.parameterizedOutputClass(), availableTypeVariables),
FOLD_RETURN_TYPE);
builder.addParameter(
ParameterSpec.builder(visitor, asCamelCase(arg.name()))
.addAnnotation(Nonnull.class)
.build());
}
return builder;
}
private MethodSpec.Builder createFoldVoidSignature(
Iterable<TypeVariableName> availableTypeVariables) throws ParserException {
MethodSpec.Builder builder =
MethodSpec.methodBuilder("match").addModifiers(Modifier.PUBLIC).returns(void.class);
for (OutputValue arg : values) {
TypeName visitor =
ParameterizedTypeName.get(
ClassName.get(Consumer.class),
withoutMissingTypeVariables(arg.parameterizedOutputClass(), availableTypeVariables));
builder.addParameter(
ParameterSpec.builder(visitor, asCamelCase(arg.name()))
.addAnnotation(Nonnull.class)
.build());
}
return builder;
}
private static boolean typeNeedsTypeVariable(TypeName type, TypeVariableName typeVariable) {
if (typeVariable.equals(type)) {
return true;
}
if (type instanceof ParameterizedTypeName) {
ParameterizedTypeName parameterized = ((ParameterizedTypeName) type);
for (TypeName typeArgument : parameterized.typeArguments) {
if (typeVariable.equals(typeArgument)) {
return true;
}
if (typeNeedsTypeVariable(typeArgument, typeVariable)) {
return true;
}
}
}
if (type instanceof ArrayTypeName) {
ArrayTypeName arrayType = (ArrayTypeName) type;
if (typeVariable.equals(arrayType.componentType)) {
return true;
}
}
return false;
}
private static TypeName getSuperclassForValue(OutputValue value, OutputSpec spec)
throws ParserException {
if (!spec.hasTypeVariables()) {
return spec.outputClass();
}
List<TypeName> superParameters = new ArrayList<>();
for (TypeVariableName typeVariable : spec.typeVariables()) {
if (Iterables.contains(value.typeVariables(), typeVariable)) {
superParameters.add(typeVariable);
} else {
if (typeVariable.bounds.size() == 0) {
superParameters.add(TypeName.OBJECT);
} else if (typeVariable.bounds.size() == 1) {
superParameters.add(typeVariable.bounds.get(0));
} else {
throw new ParserException("More than one generic type bound is not supported ");
}
}
}
return ParameterizedTypeName.get(
spec.outputClass(), superParameters.toArray(new TypeName[] {}));
}
private static MethodSpec createAsSpecMethod(OutputValue value, OutputSpec spec) {
List<TypeVariableName> missingTypeVariables = extractMissingTypeVariablesForValue(value, spec);
Builder builder =
MethodSpec.methodBuilder("as" + spec.outputClass().simpleName())
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.returns(spec.parameterizedOutputClass())
.addTypeVariables(missingTypeVariables)
.addStatement("return ($T) this", spec.parameterizedOutputClass());
// if there are type variables that this sub-type doesn't use, they will lead to 'unchecked
// cast'
// warnings when compiling the generated code. These warnings are safe to suppress, since this
// sub type will never use those type variables.
if (!missingTypeVariables.isEmpty()) {
builder.addAnnotation(SUPPRESS_UNCHECKED_WARNINGS);
}
return builder.build();
}
public static Spec parse(Element element, ProcessingEnvironment processingEnv) {
Messager messager = processingEnv.getMessager();
if (element.getKind() != ElementKind.INTERFACE) {
messager.printMessage(
Diagnostic.Kind.ERROR, "@DataEnum can only be used on interfaces.", element);
return null;
}
TypeElement dataEnum = (TypeElement) element;
List<TypeVariableName> typeVariableNames = new ArrayList<>();
for (TypeParameterElement typeParameterElement : dataEnum.getTypeParameters()) {
typeVariableNames.add(TypeVariableName.get(typeParameterElement));
}
List<Value> values = ValuesParser.parse(dataEnum, processingEnv);
if (values == null) {
return null;
}
ClassName enumInterface = ClassName.get(dataEnum);
return new Spec(enumInterface, typeVariableNames, values);
}
@Override
public TypeName replaceReturnType(String currentPkg, String directParentInterface, String curClassname,
List<? extends TypeMirror> superInterfaces, TypeName superClass, ExecutableElement method) {
final TypeMirror returnType = method.getReturnType();
switch (method.getSimpleName().toString()){
case TypeCopyableFiller.NAME_COPY: {
switch (returnType.getKind()) {
case TYPEVAR: //泛型
return TypeVariableName.get(directParentInterface);
default:
return TypeName.get(returnType);
}
}
default:
return TypeName.get(returnType);
}
}
@Override
public TypeSpec poetSpec() {
TypeSpec.Builder builder = PoetUtils.createInterfaceBuilder(builderInterfaceName)
.addTypeVariable(PoetUtils.createBoundedTypeVariableName("B", builderInterfaceName, "B", "C"))
.addTypeVariable(TypeVariableName.get("C"))
.addSuperinterface(PoetUtils.createParameterizedTypeName(AwsClientBuilder.class, "B", "C"))
.addJavadoc(getJavadoc());
if (model.getEndpointOperation().isPresent()) {
if (model.getCustomizationConfig().isEnableEndpointDiscoveryMethodRequired()) {
builder.addMethod(enableEndpointDiscovery());
}
builder.addMethod(endpointDiscovery());
}
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
builder.addMethod(serviceConfigurationMethod());
builder.addMethod(serviceConfigurationConsumerBuilderMethod());
}
return builder.build();
}
private TypeName getTypeName(String name) {
if (name == null || name.length() == 0) {
return null;
}
java.lang.reflect.Type type = getType(name);
if (type != null) {
return ClassName.get(type);
} else {
return TypeVariableName.get(name);
}
}
private MethodSpec serviceConfigurationMethod() {
ClassName serviceConfiguration = ClassName.get(basePackage,
model.getCustomizationConfig().getServiceSpecificClientConfigClass());
return MethodSpec.methodBuilder("serviceConfiguration")
.addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC)
.returns(TypeVariableName.get("B"))
.addParameter(serviceConfiguration, "serviceConfiguration")
.build();
}
private String generateEventInterfaceClass(List<EventInfo> events, String originalPackageName, String originalClassName) {
String interfaceName = generateClassName(originalClassName);
TypeSpec.Builder builder = TypeSpec.interfaceBuilder(interfaceName)
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(IEventsDefine.class)
.addJavadoc("Auto generate code, do not modify!!!");
for (EventInfo event : events) {
ClassName lebClassName = ClassName.get(LEB_PACKAGE_NAME, LEB_CLASS_NAME);
ClassName obsClassName = lebClassName.nestedClass(LEB_OBSERVER_CLASS_NAME);
TypeName returnType;
String eventTypeStr = event.getType();
if (eventTypeStr == null || eventTypeStr.length() == 0) {
returnType = ParameterizedTypeName.get(obsClassName, ClassName.get(Object.class));
} else {
Type eventType = getType(eventTypeStr);
if (eventType != null) {
returnType = ParameterizedTypeName.get(obsClassName, ClassName.get(eventType));
} else {
returnType = ParameterizedTypeName.get(obsClassName, TypeVariableName.get(eventTypeStr));
}
}
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(event.getName())
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(returnType);
builder.addMethod(methodBuilder.build());
}
TypeSpec typeSpec = builder.build();
String packageName = originalPackageName + GEN_PKG;
try {
JavaFile.builder(packageName, typeSpec)
.build()
.writeTo(filer);
} catch (IOException e) {
e.printStackTrace();
}
String className = packageName + "." + interfaceName;
System.out.println(TAG + "generateEventInterfaceClass: " + className);
return className;
}
private TypeName getTypeName(String name) {
if (name == null || name.length() == 0) {
return null;
}
java.lang.reflect.Type type = getType(name);
if (type != null) {
return ClassName.get(type);
} else {
return TypeVariableName.get(name);
}
}
private <T extends Type> void generateStaticArrayTypes(
Class<T> superclass, String path) throws IOException {
String packageName = createPackageName(superclass);
ClassName className;
for (int length = 1; length <= StaticArray.MAX_SIZE_OF_STATIC_ARRAY; length++) {
TypeVariableName typeVariableName = TypeVariableName.get("T").withBounds(Type.class);
MethodSpec constructorSpec = MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterizedTypeName.get(ClassName.get(List.class),
typeVariableName), "values")
.addStatement("super($L, $N)", length, "values")
.build();
MethodSpec arrayOverloadConstructorSpec = MethodSpec.constructorBuilder()
.addAnnotation(SafeVarargs.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(ArrayTypeName.of(typeVariableName), "values")
.varargs()
.addStatement("super($L, $N)", length, "values")
.build();
className = ClassName.get(packageName, superclass.getSimpleName() + length);
TypeSpec bytesType = TypeSpec
.classBuilder(className.simpleName())
.addTypeVariable(typeVariableName)
.addJavadoc(CODEGEN_WARNING)
.superclass(ParameterizedTypeName.get(ClassName.get(superclass),
typeVariableName))
.addModifiers(Modifier.PUBLIC)
.addMethods(Arrays.asList(constructorSpec, arrayOverloadConstructorSpec))
.build();
write(packageName, bytesType, path);
}
}
private MethodSpec endpointDiscovery() {
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeVariableName.get("B"))
.addParameter(boolean.class, "endpointDiscovery")
.build();
}
private <T extends Type> void generateStaticArrayTypes(
Class<T> superclass, String path) throws IOException {
String packageName = createPackageName(superclass);
ClassName className;
for (int length = 1; length <= StaticArray.MAX_SIZE_OF_STATIC_ARRAY; length++) {
TypeVariableName typeVariableName = TypeVariableName.get("T").withBounds(Type.class);
MethodSpec constructorSpec = MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addParameter(ParameterizedTypeName.get(ClassName.get(List.class),
typeVariableName), "values")
.addStatement("super($L, $N)", length, "values")
.build();
MethodSpec arrayOverloadConstructorSpec = MethodSpec.constructorBuilder()
.addAnnotation(SafeVarargs.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(ArrayTypeName.of(typeVariableName), "values")
.varargs()
.addStatement("super($L, $N)", length, "values")
.build();
className = ClassName.get(packageName, superclass.getSimpleName() + length);
TypeSpec bytesType = TypeSpec
.classBuilder(className.simpleName())
.addTypeVariable(typeVariableName)
.addJavadoc(CODEGEN_WARNING)
.superclass(ParameterizedTypeName.get(ClassName.get(superclass),
typeVariableName))
.addModifiers(Modifier.PUBLIC)
.addMethods(Arrays.asList(constructorSpec, arrayOverloadConstructorSpec))
.build();
write(packageName, bytesType, path);
}
}
private static MethodSpec buildLoad(
String className, Class authType, String authName) {
return MethodSpec.methodBuilder("load")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(TypeVariableName.get(className, Type.class))
.addParameter(String.class, CONTRACT_ADDRESS)
.addParameter(Web3j.class, WEB3J)
.addParameter(authType, authName)
.addParameter(BigInteger.class, GAS_PRICE)
.addParameter(BigInteger.class, GAS_LIMIT)
.addStatement("return new $L($L, $L, $L, $L, $L)", className,
CONTRACT_ADDRESS, WEB3J, authName, GAS_PRICE, GAS_LIMIT)
.build();
}
public static ImmutableList<SpecMethodModel<DelegateMethod, Void>> getDelegateMethods(
PsiClass psiClass,
List<Class<? extends Annotation>> permittedMethodAnnotations,
List<Class<? extends Annotation>> permittedInterStageInputAnnotations,
List<Class<? extends Annotation>> delegateMethodAnnotationsThatSkipDiffModels) {
final List<SpecMethodModel<DelegateMethod, Void>> delegateMethods = new ArrayList<>();
for (PsiMethod psiMethod : psiClass.getMethods()) {
final List<Annotation> methodAnnotations =
getMethodAnnotations(psiMethod, permittedMethodAnnotations);
if (!methodAnnotations.isEmpty()) {
final List<MethodParamModel> methodParams =
getMethodParams(
psiMethod,
DelegateMethodExtractor.getPermittedMethodParamAnnotations(
permittedInterStageInputAnnotations),
permittedInterStageInputAnnotations,
delegateMethodAnnotationsThatSkipDiffModels);
final SpecMethodModel<DelegateMethod, Void> delegateMethod =
new SpecMethodModel<>(
ImmutableList.copyOf(methodAnnotations),
PsiModifierExtractor.extractModifiers(psiMethod.getModifierList()),
psiMethod.getName(),
PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType()),
ImmutableList.<TypeVariableName>of(),
ImmutableList.copyOf(methodParams),
psiMethod,
null);
delegateMethods.add(delegateMethod);
}
}
return ImmutableList.copyOf(delegateMethods);
}
private static TypeVariableName toTypeVariableName(PsiTypeParameter psiTypeParameter) {
String typeName = psiTypeParameter.getName();
TypeName[] typeBounds =
Arrays.stream(psiTypeParameter.getBounds())
.filter(PsiType.class::isInstance)
.map(bound -> PsiTypeUtils.getTypeName((PsiType) bound))
.toArray(TypeName[]::new);
return TypeVariableName.get(typeName, typeBounds);
}
public static ImmutableList<SpecMethodModel<UpdateStateMethod, Void>> getOnUpdateStateMethods(
PsiClass psiClass,
List<Class<? extends Annotation>> permittedInterStageInputAnnotations,
boolean isTransition) {
final List<SpecMethodModel<UpdateStateMethod, Void>> delegateMethods = new ArrayList<>();
for (PsiMethod psiMethod : psiClass.getMethods()) {
final Annotation onUpdateStateAnnotation =
isTransition
? PsiAnnotationProxyUtils.findAnnotationInHierarchy(
psiMethod, OnUpdateStateWithTransition.class)
: PsiAnnotationProxyUtils.findAnnotationInHierarchy(psiMethod, OnUpdateState.class);
if (onUpdateStateAnnotation != null) {
final List<MethodParamModel> methodParams =
getMethodParams(
psiMethod,
getPermittedMethodParamAnnotations(permittedInterStageInputAnnotations),
permittedInterStageInputAnnotations,
ImmutableList.<Class<? extends Annotation>>of());
final SpecMethodModel<UpdateStateMethod, Void> delegateMethod =
SpecMethodModel.<UpdateStateMethod, Void>builder()
.annotations(ImmutableList.<Annotation>of(onUpdateStateAnnotation))
.modifiers(PsiModifierExtractor.extractModifiers(psiMethod.getModifierList()))
.name(psiMethod.getName())
.returnTypeSpec(PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType()))
.typeVariables(ImmutableList.<TypeVariableName>of())
.methodParams(copyOf(methodParams))
.representedObject(psiMethod)
.build();
delegateMethods.add(delegateMethod);
}
}
return copyOf(delegateMethods);
}
@Override
public TypeSpec poetSpec() {
TypeSpec.Builder builder =
PoetUtils.createClassBuilder(builderClassName)
.addModifiers(Modifier.ABSTRACT)
.addAnnotation(SdkInternalApi.class)
.addTypeVariable(PoetUtils.createBoundedTypeVariableName("B", builderInterfaceName, "B", "C"))
.addTypeVariable(TypeVariableName.get("C"))
.superclass(PoetUtils.createParameterizedTypeName(AwsDefaultClientBuilder.class, "B", "C"))
.addJavadoc("Internal base class for {@link $T} and {@link $T}.",
ClassName.get(basePackage, model.getMetadata().getSyncBuilder()),
ClassName.get(basePackage, model.getMetadata().getAsyncBuilder()));
// Only services that require endpoint discovery for at least one of their operations get a default value of
// 'true'
if (model.getEndpointOperation().isPresent()) {
builder.addField(FieldSpec.builder(boolean.class, "endpointDiscoveryEnabled")
.addModifiers(PROTECTED)
.initializer(resolveDefaultEndpointDiscovery() ? "true" : "false")
.build());
}
builder.addMethod(serviceEndpointPrefixMethod());
builder.addMethod(serviceNameMethod());
builder.addMethod(mergeServiceDefaultsMethod());
builder.addMethod(finalizeServiceConfigurationMethod());
builder.addMethod(defaultSignerMethod());
builder.addMethod(signingNameMethod());
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
builder.addMethod(setServiceConfigurationMethod())
.addMethod(beanStyleSetServiceConfigurationMethod());
}
addServiceHttpConfigIfNeeded(builder, model);
return builder.build();
}
private static TypeName getEnclosedImplClassName(final SpecModel enclosedSpecModel) {
final String componentTypeName = enclosedSpecModel.getComponentTypeName().toString();
if (enclosedSpecModel.getTypeVariables().isEmpty()) {
return ClassName.bestGuess(componentTypeName);
}
final TypeName[] typeNames =
enclosedSpecModel.getTypeVariables().stream()
.map(TypeVariableName::withoutAnnotations)
.collect(Collectors.toList())
.toArray(new TypeName[] {});
return ParameterizedTypeName.get(ClassName.bestGuess(componentTypeName), typeNames);
}
public static List<TypeVariableName> getTypeVariables(TypeName typeName) {
final List<TypeVariableName> typeVariables = new ArrayList<>();
if (typeName instanceof TypeVariableName) {
typeVariables.add((TypeVariableName) typeName);
} else if (typeName instanceof ParameterizedTypeName) {
for (TypeName typeArgument : ((ParameterizedTypeName) typeName).typeArguments) {
typeVariables.addAll(getTypeVariables(typeArgument));
}
}
return typeVariables;
}