Skip to content

Commit

Permalink
Tweak generated extension method JVM names
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijsiez committed Apr 18, 2024
1 parent c75c1c4 commit 620b7c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
[![Reliability Rating](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=reliability_rating&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Maintainability Rating](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=sqale_rating&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Security Rating](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=security_rating&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Coverage](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=coverage&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)

[![Coverage](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=coverage&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Bugs](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=bugs&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Code Smells](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=code_smells&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Vulnerabilities](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=vulnerabilities&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Security Hotspots](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=security_hotspots&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Technical Debt](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=sqale_index&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Duplicated Lines (%)](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=duplicated_lines_density&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
[![Duplicated Lines (%)](https://sonarqube.icken.ch/api/project_badges/measure?project=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF&metric=duplicated_lines_density&token=sqb_a252a1b66285ba9fcf7f724d211c8f074751ff1a)](https://sonarqube.icken.ch/dashboard?id=Thijsiez_panache-kotlin-dsl_AYsggGcmXmm3_FAoLWCF)
<sup>Coverage reporting is inaccurate due to how SonarQube imports coverage reports from multimodule projects</sup>

# panache-kotlin-dsl
A dynamic, type-safe way to write your queries
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Thijs Koppen
* Copyright 2023-2024 Thijs Koppen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,8 +100,8 @@ class PanacheCompanionBaseProcessor(

val funSpecs = ksClasses.flatMap { ksClass ->
val className = ksClass.toClassName()
val objectName = ksClass.simpleName.asString() + COLUMN_NAME_OBJECT_SUFFIX
val objectClassName = ClassName(packageName, objectName)
val classSimpleName = ksClass.simpleName.asString()
val objectClassName = ClassName(packageName, classSimpleName + COLUMN_NAME_OBJECT_SUFFIX)

val idClassName = ksClass.getAllProperties()
.filter { it.hasAnnotation(JakartaPersistenceId) }
Expand Down Expand Up @@ -130,15 +130,15 @@ class PanacheCompanionBaseProcessor(
.returns(queryComponentType)
.addStatement("return %M($EXPRESSION_PARAM_NAME(%T))",
MemberName(QueryComponentClassName.packageName, WHERE), objectClassName)
.addAnnotation(jvmNameAnnotation("$WHERE$objectName"))
.addAnnotation(jvmNameAnnotation("$WHERE$classSimpleName"))
val whereGroup = FunSpec.builder(WHERE_GROUP)
.receiver(whereReceiver)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.addParameter(GROUP_COMPONENT_PARAM_NAME, groupComponentParameterType)
.returns(queryComponentType)
.addStatement("return %M($EXPRESSION_PARAM_NAME(%T), $GROUP_COMPONENT_PARAM_NAME)",
MemberName(QueryComponentClassName.packageName, WHERE_GROUP), objectClassName)
.addAnnotation(jvmNameAnnotation("$WHERE_GROUP$objectName"))
.addAnnotation(jvmNameAnnotation("$WHERE_GROUP$classSimpleName"))
//endregion

//region and
Expand All @@ -148,15 +148,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(AndQueryComponentClassName.plusParameter(className).plusParameter(idClassName))
.addStatement("return $AND($EXPRESSION_PARAM_NAME(%T))", objectClassName)
.addAnnotation(jvmNameAnnotation("$AND$objectName"))
.addAnnotation(jvmNameAnnotation("$AND$classSimpleName"))
val andGroup = FunSpec.builder(AND_GROUP)
.receiver(queryComponentType)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.addParameter(GROUP_COMPONENT_PARAM_NAME, groupComponentParameterType)
.returns(queryComponentType)
.addStatement("return $AND_GROUP($EXPRESSION_PARAM_NAME(%T), $GROUP_COMPONENT_PARAM_NAME)",
objectClassName)
.addAnnotation(jvmNameAnnotation("$AND_GROUP$objectName"))
.addAnnotation(jvmNameAnnotation("$AND_GROUP$classSimpleName"))
//endregion

//region or
Expand All @@ -166,15 +166,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(OrQueryComponentClassName.plusParameter(className).plusParameter(idClassName))
.addStatement("return $OR($EXPRESSION_PARAM_NAME(%T))", objectClassName)
.addAnnotation(jvmNameAnnotation("$OR$objectName"))
.addAnnotation(jvmNameAnnotation("$OR$classSimpleName"))
val orGroup = FunSpec.builder(OR_GROUP)
.receiver(queryComponentType)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.addParameter(GROUP_COMPONENT_PARAM_NAME, groupComponentParameterType)
.returns(queryComponentType)
.addStatement("return $OR_GROUP($EXPRESSION_PARAM_NAME(%T), $GROUP_COMPONENT_PARAM_NAME)",
objectClassName)
.addAnnotation(jvmNameAnnotation("$OR_GROUP$objectName"))
.addAnnotation(jvmNameAnnotation("$OR_GROUP$classSimpleName"))
//endregion

//region count, delete, find, stream
Expand All @@ -184,15 +184,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(LongClassName)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$COUNT()")
.addAnnotation(jvmNameAnnotation("$COUNT$objectName"))
.addAnnotation(jvmNameAnnotation("$COUNT$classSimpleName"))

val delete = FunSpec.builder(DELETE)
.addModifiers(KModifier.INLINE)
.receiver(whereReceiver)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(LongClassName)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$DELETE()")
.addAnnotation(jvmNameAnnotation("$DELETE$objectName"))
.addAnnotation(jvmNameAnnotation("$DELETE$classSimpleName"))

val findReturns = PanacheQueryClassName.plusParameter(className)
val find = FunSpec.builder(FIND)
Expand All @@ -201,15 +201,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(findReturns)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$FIND()")
.addAnnotation(jvmNameAnnotation("$FIND$objectName"))
.addAnnotation(jvmNameAnnotation("$FIND$classSimpleName"))
val findSorted = FunSpec.builder(FIND)
.addModifiers(KModifier.INLINE)
.receiver(whereReceiver)
.addParameter(SORT_PARAM_NAME, SortClassName)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(findReturns)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$FIND($SORT_PARAM_NAME)")
.addAnnotation(jvmNameAnnotation("$FIND_SORTED$objectName"))
.addAnnotation(jvmNameAnnotation("$FIND_SORTED$classSimpleName"))

val streamReturn = StreamClassName.plusParameter(className)
val stream = FunSpec.builder(STREAM)
Expand All @@ -218,15 +218,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(streamReturn)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$STREAM()")
.addAnnotation(jvmNameAnnotation("$STREAM$objectName"))
.addAnnotation(jvmNameAnnotation("$STREAM$classSimpleName"))
val streamSorted = FunSpec.builder(STREAM)
.addModifiers(KModifier.INLINE)
.receiver(whereReceiver)
.addParameter(SORT_PARAM_NAME, SortClassName)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(streamReturn)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).$STREAM($SORT_PARAM_NAME)")
.addAnnotation(jvmNameAnnotation("$STREAM_SORTED$objectName"))
.addAnnotation(jvmNameAnnotation("$STREAM_SORTED$classSimpleName"))
//endregion

//region single
Expand All @@ -236,14 +236,14 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(className)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).getSingle()")
.addAnnotation(jvmNameAnnotation("$SINGLE$objectName"))
.addAnnotation(jvmNameAnnotation("$SINGLE$classSimpleName"))
val singleSafe = FunSpec.builder(SINGLE_SAFE)
.addModifiers(KModifier.INLINE)
.receiver(whereReceiver)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(PanacheSingleResultClassName.plusParameter(WildcardTypeName.producerOf(className)))
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).getSingleSafe()")
.addAnnotation(jvmNameAnnotation("$SINGLE_SAFE$objectName"))
.addAnnotation(jvmNameAnnotation("$SINGLE_SAFE$classSimpleName"))
//endregion

//region multiple
Expand All @@ -254,15 +254,15 @@ class PanacheCompanionBaseProcessor(
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(multipleReturns)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).getMultiple()")
.addAnnotation(jvmNameAnnotation("$MULTIPLE$objectName"))
.addAnnotation(jvmNameAnnotation("$MULTIPLE$classSimpleName"))
val multipleSorted = FunSpec.builder(MULTIPLE)
.addModifiers(KModifier.INLINE)
.receiver(whereReceiver)
.addParameter(SORT_PARAM_NAME, SortClassName)
.addParameter(EXPRESSION_PARAM_NAME, expressionParameterType)
.returns(multipleReturns)
.addStatement("return $WHERE($EXPRESSION_PARAM_NAME).getMultiple($SORT_PARAM_NAME)")
.addAnnotation(jvmNameAnnotation("$MULTIPLE_SORTED$objectName"))
.addAnnotation(jvmNameAnnotation("$MULTIPLE_SORTED$classSimpleName"))
//endregion

listOf(where, whereGroup, and, andGroup, or, orGroup,
Expand Down

0 comments on commit 620b7c5

Please sign in to comment.