Skip to content

Commit cdf963e

Browse files
Implement prefix
1 parent 811335a commit cdf963e

File tree

8 files changed

+43
-2
lines changed

8 files changed

+43
-2
lines changed

convertible-core/src/main/kotlin/pro/vlprojects/convertible/core/annotation/Convertible.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ package pro.vlprojects.convertible.core.annotation
66
annotation class Convertible(
77
val scopes: Array<String> = [],
88
val nullable: Boolean = false,
9+
val prefix: String = "",
910
)

convertible-core/src/main/kotlin/pro/vlprojects/convertible/core/definition/ConvertibleDefinition.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data class ConvertibleDefinition(
1313
val source: KSFile,
1414
val scope: String,
1515
val nullable: Boolean,
16+
val prefix: String,
1617
val valueAccessor: ValueAccessor,
1718
val factoryAccessor: FactoryAccessor,
1819
) {

convertible-core/src/main/kotlin/pro/vlprojects/convertible/core/processor/ConvertibleVisitor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ConvertibleVisitor(
4747
source = classDeclaration.containingFile.let(::checkNotNull),
4848
scope = scope,
4949
nullable = nullable,
50+
prefix = annotation.getArgument<String>("prefix") ?: "",
5051
valueAccessor = valueAccessor,
5152
factoryAccessor = factoryAccessor,
5253
)

convertible-jpa/src/main/kotlin/pro/vlprojects/convertible/jpa/JpaAttributeConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class JpaAttributeConverter : ConvertibleStrategy {
2121

2222
override fun build(definition: ConvertibleDefinition): FileSpec {
2323

24-
val fileName = "${definition.objectClassName.simpleName}JpaConverter"
24+
val fileName = "${definition.prefix}${definition.objectClassName.simpleName}JpaConverter"
2525
val nullable = definition.nullable
2626
val objectType = definition.objectClassName.copy(nullable = nullable)
2727
val primitiveType = definition.valueAccessor.returnType.copy(nullable = nullable)

convertible-jpa/src/test/kotlin/pro/vlprojects/convertible/jpa/JpaAttributeConverterTests.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ class JpaAttributeConverterTests {
122122
TestCase("NullableEnumExample.kt", "NullableEnumExampleJpaConverter.kt"),
123123
)
124124
),
125+
Arguments.of(
126+
Named.of(
127+
"Prefix. Factory declared. Value declared",
128+
TestCase("Prefix.kt", "SomePrefixJpaConverter.kt"),
129+
)
130+
),
125131
)
126132
}
127133

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.vo
2+
3+
import jakarta.persistence.AttributeConverter
4+
import jakarta.persistence.Converter
5+
import kotlin.String
6+
import org.springframework.stereotype.Component
7+
8+
@Component
9+
@Converter(autoApply = true)
10+
public class SomePrefixJpaConverter : AttributeConverter<Prefix, String> {
11+
override fun convertToDatabaseColumn(attribute: Prefix): String = attribute.value
12+
13+
override fun convertToEntityAttribute(source: String): Prefix = source.let(Prefix::from)
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.vo
2+
3+
import pro.vlprojects.convertible.core.annotation.Convertible
4+
import pro.vlprojects.convertible.core.annotation.ConvertibleFactory
5+
import pro.vlprojects.convertible.core.annotation.ConvertibleValue
6+
import pro.vlprojects.convertible.core.annotation.Scope
7+
8+
@Convertible(scopes = [Scope.JPA], prefix = "Some")
9+
data class Prefix(val raw: String) {
10+
11+
@ConvertibleValue(scopes = [Scope.JPA])
12+
val value = raw
13+
14+
companion object Factory {
15+
@ConvertibleFactory(scopes = [Scope.JPA])
16+
fun from(input: String) = Prefix(input)
17+
}
18+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
group=pro.vlprojects
2-
version=0.1.0
2+
version=0.1.1
33
kotlin.version=2.1.21
44
kotlin.code.style=official

0 commit comments

Comments
 (0)