Skip to content

Commit

Permalink
Merge pull request #134 from atschabu/trailingcomma
Browse files Browse the repository at this point in the history
chore #63: allow trailing comma
  • Loading branch information
lilgallon authored Oct 2, 2024
2 parents 04783ea + 96b9b90 commit ccd627d
Show file tree
Hide file tree
Showing 218 changed files with 1,315 additions and 1,316 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,8 @@ ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_assignment_wrap = normal
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.squareup.kotlinpoet.ksp.writeTo

class PartialProcessor(
private val codeGenerator: CodeGenerator,
private val logger: KSPLogger
private val logger: KSPLogger,
) : SymbolProcessor {

private val toPartialMethodName = "toPartial"
Expand All @@ -31,7 +31,7 @@ class PartialProcessor(
.forEach { (input, output) ->
output.writeTo(
codeGenerator,
Dependencies(true, input.containingFile!!)
Dependencies(true, input.containingFile!!),
)
}
}
Expand All @@ -46,7 +46,7 @@ class PartialProcessor(
.toSet()

private fun genPartialClasses(
partialAnnotatedClasses: Set<KSClassDeclaration>
partialAnnotatedClasses: Set<KSClassDeclaration>,
): List<Pair<KSClassDeclaration, FileSpec>> =
partialAnnotatedClasses.map { classDeclaration ->
val packageName = classDeclaration.packageName.asString()
Expand Down Expand Up @@ -83,7 +83,7 @@ class PartialProcessor(
ParameterSpec
.builder(
param.parameterName,
param.type.copy(nullable = true)
param.type.copy(nullable = true),
)
.build()
}
Expand All @@ -93,7 +93,7 @@ class PartialProcessor(
PropertySpec
.builder(
param.parameterName,
param.type.copy(nullable = true)
param.type.copy(nullable = true),
)
.initializer(param.parameterName)
.build()
Expand All @@ -105,12 +105,12 @@ class PartialProcessor(
.addKdoc(
"Partial representation of [${
classDescriptor.packageName.asString()
}.${classDescriptor.simpleName.asString()}]"
}.${classDescriptor.simpleName.asString()}]",
)
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameters(partialClassConstructorParameters)
.build()
.build(),
)
.addProperties(partialClassProperties)
.build()
Expand All @@ -137,7 +137,7 @@ class PartialProcessor(
| return ${className.toPartial()}(
| $partialClassConstructorParameters
| )
""".trimMargin()
""".trimMargin(),
)
.build()
}
Expand Down Expand Up @@ -169,16 +169,16 @@ class PartialProcessor(
return FunSpec.builder(toPartialMethodName)
.receiver(
ClassName("kotlin.collections", "List")
.parameterizedBy(ClassName(packageName, className))
.parameterizedBy(ClassName(packageName, className)),
)
.returns(
ClassName("kotlin.collections", "List")
.parameterizedBy(ClassName(packageName, className.toPartial()))
.parameterizedBy(ClassName(packageName, className.toPartial())),
)
.addCode(
"""
| return mapNotNull { it.$toPartialMethodName() }
""".trimMargin()
""".trimMargin(),
)
.build()
}
Expand All @@ -192,32 +192,32 @@ class PartialProcessor(
ClassName(
packageName = resolvedType.declaration.packageName.asString(),
simpleNames = listOf(
resolvedType.declaration.simpleName.asString()
)
resolvedType.declaration.simpleName.asString(),
),
).parameterizedBy(
resolvedType.arguments.map { generic ->
val genericResolved = generic.type!!.resolve()
ClassName(
packageName = genericResolved.declaration.packageName.asString(),
simpleNames = listOf(
genericResolved.declaration.simpleName.asString().wireWithExistingPartial()
)
genericResolved.declaration.simpleName.asString().wireWithExistingPartial(),
),
)
}
},
)
} else {
ClassName(
packageName = resolvedType.declaration.packageName.asString(),
simpleNames = listOf(
resolvedType.declaration.simpleName.asString().wireWithExistingPartial()
)
resolvedType.declaration.simpleName.asString().wireWithExistingPartial(),
),
)
}

FunctionParameter(
parameter.name?.asString() ?: throw IllegalStateException("null param name $parameter"),
resolvedType.isMarkedNullable,
typeName
typeName,
)
}.toList()
} else {
Expand Down Expand Up @@ -255,12 +255,12 @@ class PartialProcessor(
| ----------
| This code is generated AND MUST NOT BE EDITED
| ----------
""".trimMargin()
""".trimMargin(),
)

data class FunctionParameter(
val parameterName: String,
val nullable: Boolean,
val type: TypeName
val type: TypeName,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ inline fun <reified T> HttpResponse.parsePaginatedBody(offset: Int): OcpiRespons
limit = getHeader(Header.X_LIMIT)?.toInt()
?: throw OcpiToolkitMissingRequiredResponseHeaderException(Header.X_LIMIT),
offset = offset,
nextPageUrl = getHeader(Header.LINK)?.split("<")?.elementAtOrNull(1)?.split(">")?.first()
nextPageUrl = getHeader(Header.LINK)?.split("<")?.elementAtOrNull(1)?.split(">")?.first(),
),
statusCode = parsedBody.statusCode,
statusMessage = parsedBody.statusMessage,
timestamp = parsedBody.timestamp
timestamp = parsedBody.timestamp,
)
}

Expand Down Expand Up @@ -102,18 +102,18 @@ fun authorizationHeader(token: String): Pair<String, String> = Header.AUTHORIZAT
*/
suspend fun PartnerRepository.buildAuthorizationHeader(
partnerId: String,
allowTokenA: Boolean = false
allowTokenA: Boolean = false,
): Pair<String, String> =
if (allowTokenA) {
getCredentialsClientToken(partnerId = partnerId)
?: getCredentialsTokenA(partnerId = partnerId)
?: throw throw OcpiClientUnknownTokenException(
"Could not find token A or client token associated with partner $partnerId"
"Could not find token A or client token associated with partner $partnerId",
)
} else {
getCredentialsClientToken(partnerId = partnerId)
?: throw throw OcpiClientUnknownTokenException(
"Could not find client token associated with partner $partnerId"
"Could not find client token associated with partner $partnerId",
)
}
.let { token -> authorizationHeader(token = token) }
Expand All @@ -129,15 +129,15 @@ suspend fun PartnerRepository.buildAuthorizationHeader(
suspend fun HttpRequest.authenticate(
partnerRepository: PartnerRepository,
partnerId: String,
allowTokenA: Boolean = false
allowTokenA: Boolean = false,
): AuthenticatedHttpRequest =
withHeaders(
headers = headers.plus(
partnerRepository.buildAuthorizationHeader(
partnerId = partnerId,
allowTokenA = allowTokenA
)
)
allowTokenA = allowTokenA,
),
),
)

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ fun HttpRequest.messageRoutingHeaders(): RequestMessageRoutingHeaders =
toPartyId = headers.getByNormalizedKey(OCPI_TO_PARTY_ID),
toCountryCode = headers.getByNormalizedKey(OCPI_TO_COUNTRY_CODE),
fromPartyId = headers.getByNormalizedKey(OCPI_FROM_PARTY_ID),
fromCountryCode = headers.getByNormalizedKey(OCPI_FROM_COUNTRY_CODE)
fromCountryCode = headers.getByNormalizedKey(OCPI_FROM_COUNTRY_CODE),
)

/**
Expand All @@ -190,7 +190,7 @@ private fun RequestMessageRoutingHeaders.httpHeaders(): Map<String, String> =
OCPI_TO_PARTY_ID to toPartyId,
OCPI_TO_COUNTRY_CODE to toCountryCode,
OCPI_FROM_PARTY_ID to fromPartyId,
OCPI_FROM_COUNTRY_CODE to fromCountryCode
OCPI_FROM_COUNTRY_CODE to fromCountryCode,
)
.filter { it.value != null }
.mapValues { it.value!! }
Expand All @@ -200,7 +200,7 @@ fun ResponseMessageRoutingHeaders.httpHeaders(): Map<String, String> =
OCPI_TO_PARTY_ID to toPartyId,
OCPI_TO_COUNTRY_CODE to toCountryCode,
OCPI_FROM_PARTY_ID to fromPartyId,
OCPI_FROM_COUNTRY_CODE to fromCountryCode
OCPI_FROM_COUNTRY_CODE to fromCountryCode,
)
.filter { it.value != null }
.mapValues { it.value!! }
Expand All @@ -210,7 +210,7 @@ fun ResponseMessageRoutingHeaders.httpHeaders(): Map<String, String> =
*/
fun HttpRequest.extractTokenHeader(): TokenHeader =
TokenHeader(
token = parseAuthorizationHeader()
token = parseAuthorizationHeader(),
)

/**
Expand All @@ -233,12 +233,12 @@ fun HttpRequest.extractTokenHeader(): TokenHeader =
*/
suspend fun HttpRequest.withRequiredHeaders(
requestId: String,
correlationId: String
correlationId: String,
): HttpRequest =
withHeaders(
headers = headers
.plus(Header.X_REQUEST_ID to requestId)
.plus(Header.X_CORRELATION_ID to correlationId)
.plus(Header.X_CORRELATION_ID to correlationId),
)
.withContentTypeHeaderIfNeeded()
.withRequestMessageRoutingHeadersIfPresent()
Expand All @@ -262,7 +262,7 @@ suspend fun HttpRequest.withRequiredHeaders(
*/
fun HttpRequest.withUpdatedRequiredHeaders(
headers: Map<String, String>,
generatedRequestId: String
generatedRequestId: String,
): HttpRequest =
withHeaders(
headers = headers
Expand All @@ -271,8 +271,8 @@ fun HttpRequest.withUpdatedRequiredHeaders(
Header.X_CORRELATION_ID to (
headers.getByNormalizedKey(Header.X_CORRELATION_ID)
?: "error - could not get ${Header.X_CORRELATION_ID} header"
)
)
),
),
).withContentTypeHeaderIfNeeded()

/**
Expand All @@ -288,7 +288,7 @@ fun HttpRequest.withUpdatedRequiredHeaders(
*/
fun HttpRequest.getDebugHeaders() = listOfNotNull(
getHeader(Header.X_REQUEST_ID)?.let { Header.X_REQUEST_ID to it },
getHeader(Header.X_CORRELATION_ID)?.let { Header.X_CORRELATION_ID to it }
getHeader(Header.X_CORRELATION_ID)?.let { Header.X_CORRELATION_ID to it },
).toMap()

/**
Expand Down Expand Up @@ -342,7 +342,7 @@ fun HttpRequest.parseAuthorizationHeader() = getHeader(Header.AUTHORIZATION)
*
*/
suspend fun PartnerRepository.checkToken(
httpRequest: HttpRequest
httpRequest: HttpRequest,
) {
val token = httpRequest.parseAuthorizationHeader()

Expand All @@ -368,7 +368,7 @@ suspend fun PartnerRepository.checkToken(
// This method MUST return a HTTP status code 405: method not allowed if the client has not been registered before.
if (!validToken && httpRequest.path.contains(ModuleID.credentials.name) && httpRequest.method in listOf(
HttpMethod.PUT,
HttpMethod.DELETE
HttpMethod.DELETE,
)
) {
throw HttpException(HttpStatus.METHOD_NOT_ALLOWED, "Method not allowed")
Expand All @@ -382,7 +382,7 @@ suspend fun PartnerRepository.checkToken(
suspend fun TransportClientBuilder.buildFor(
module: ModuleID,
partnerId: String,
partnerRepository: PartnerRepository
partnerRepository: PartnerRepository,
): TransportClient =
partnerRepository
.getEndpoints(partnerId = partnerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ val mapper: ObjectMapper = jacksonObjectMapper()
.configure(KotlinFeature.NullIsSameAsDefault, false)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.StrictNullChecks, false)
.build()
.build(),
)
.registerModule(JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ suspend inline fun <reified T> getNextPage(
transportClientBuilder: TransportClientBuilder,
partnerId: String,
partnerRepository: PartnerRepository,
previousResponse: OcpiResponseBody<SearchResult<T>>
previousResponse: OcpiResponseBody<SearchResult<T>>,
): OcpiResponseBody<SearchResult<T>>? =
previousResponse.data?.nextPageUrl?.let { nextPageUrl ->
with(transportClientBuilder.build(nextPageUrl)) {
send(
HttpRequest(
method = HttpMethod.GET
method = HttpMethod.GET,
)
.withRequiredHeaders(
requestId = generateRequestId(),
correlationId = generateCorrelationId()
correlationId = generateCorrelationId(),
)
.authenticate(partnerRepository = partnerRepository, partnerId = partnerId)
.authenticate(partnerRepository = partnerRepository, partnerId = partnerId),
)
.parsePaginatedBody(previousResponse.data.offset)
}
Expand Down
Loading

0 comments on commit ccd627d

Please sign in to comment.