From 6610bbd62269df7557585d4fd5c328aa30f2a659 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 7 Mar 2020 15:36:02 +0900 Subject: [PATCH 01/15] =?UTF-8?q?KPropertyIgnore=E3=81=AB=E9=96=A2?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mapk/kmapper/KPropertyIgnoreTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt diff --git a/src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt b/src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt new file mode 100644 index 0000000..3221d21 --- /dev/null +++ b/src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt @@ -0,0 +1,29 @@ +package com.mapk.kmapper + +import com.mapk.annotations.KPropertyIgnore +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +class KPropertyIgnoreTest { + data class Src1(val arg1: Int, val arg2: String, @KPropertyIgnore val arg3: Short) + data class Src2(@KPropertyIgnore val arg2: String, val arg3: Int, val arg4: String) + + data class Dst(val arg1: Int, val arg2: String, val arg3: Int, val arg4: String) + + @Test + @DisplayName("フィールドを無視するテスト") + fun test() { + val src1 = Src1(1, "2-1", 31) + val src2 = Src2("2-2", 32, "4") + + val mapper = KMapper(::Dst) + + val dst1 = mapper.map(src1, src2) + val dst2 = mapper.map(src2, src1) + + assertTrue(dst1 == dst2) + assertEquals(Dst(1, "2-1", 32, "4"), dst1) + } +} From b374c3c1ced96db64c8966e18cb0f476d4dff904 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:09:01 +0900 Subject: [PATCH 02/15] =?UTF-8?q?property=E3=81=8C=E5=85=AC=E9=96=8B?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AF=E6=97=A9=E6=9C=9F=E3=83=AA=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=B3=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index 556742f..ce25cbc 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -52,8 +52,11 @@ class KMapper private constructor( private fun bindArguments(argumentBucket: ArgumentBucket, src: Any) { src::class.memberProperties.forEach { property -> + // propertyが公開されていない場合は処理を行わない + if (property.visibility != KVisibility.PUBLIC) return + val javaGetter: Method? = property.javaGetter - if (javaGetter != null && property.visibility == KVisibility.PUBLIC && property.annotations.none { annotation -> annotation is KPropertyIgnore }) { + if (javaGetter != null && property.annotations.none { annotation -> annotation is KPropertyIgnore }) { parameterMap[property.findAnnotation()?.value ?: property.name]?.let { // javaGetterを呼び出す方が高速 javaGetter.isAccessible = true From f741ffc78d00555de587047f75e17bab4173528c Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:12:21 +0900 Subject: [PATCH 03/15] =?UTF-8?q?shared=E3=82=92=E3=82=A2=E3=83=83?= =?UTF-8?q?=E3=83=97=E3=83=87=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 01f1bdf..1efed45 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation(kotlin("reflect")) - implementation("com.github.ProjectMapK:Shared:0.2") + implementation("com.github.ProjectMapK:Shared:0.3") // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.0") { From 0da190bf843bdf732a678e760986e48428eb1492 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:12:58 +0900 Subject: [PATCH 04/15] =?UTF-8?q?KPropertyAlias=20->=20KParameterAlias?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 4 ++-- src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index ce25cbc..d5a79af 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -2,7 +2,7 @@ package com.mapk.kmapper import com.mapk.annotations.KConstructor import com.mapk.annotations.KGetterAlias -import com.mapk.annotations.KPropertyAlias +import com.mapk.annotations.KParameterAlias import com.mapk.annotations.KPropertyIgnore import com.mapk.core.ArgumentBucket import com.mapk.core.EnumMapper @@ -35,7 +35,7 @@ class KMapper private constructor( private val parameterMap: Map> = function.parameters .filter { it.kind != KParameter.Kind.INSTANCE } .associate { - (it.findAnnotation()?.value ?: propertyNameConverter(it.name!!)) to + (it.findAnnotation()?.value ?: propertyNameConverter(it.name!!)) to ParameterForMap.newInstance(it) } diff --git a/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt b/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt index 97d5f19..ed052f4 100644 --- a/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt +++ b/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt @@ -1,14 +1,14 @@ package com.mapk.kmapper import com.mapk.annotations.KGetterAlias -import com.mapk.annotations.KPropertyAlias +import com.mapk.annotations.KParameterAlias import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test private data class AliasedDst( val arg1: Double, - @param:KPropertyAlias("arg3") val arg2: Int + @param:KParameterAlias("arg3") val arg2: Int ) private data class AliasedSrc( From 5534685fd82b09a4e81910388fa42cf5efddfab4 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:19:58 +0900 Subject: [PATCH 05/15] =?UTF-8?q?=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AE=E4=BB=98=E4=B8=8E=E5=AF=BE?= =?UTF-8?q?=E8=B1=A1=E3=81=AF=E3=82=B2=E3=83=83=E3=82=BF=E3=83=BC=E3=81=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=96=B9=E3=81=8C=E6=AD=A3=E3=81=97=E3=81=84?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapk/annotations/{KPropertyIgnore.kt => KGetterIgnore.kt} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/kotlin/com/mapk/annotations/{KPropertyIgnore.kt => KGetterIgnore.kt} (54%) diff --git a/src/main/kotlin/com/mapk/annotations/KPropertyIgnore.kt b/src/main/kotlin/com/mapk/annotations/KGetterIgnore.kt similarity index 54% rename from src/main/kotlin/com/mapk/annotations/KPropertyIgnore.kt rename to src/main/kotlin/com/mapk/annotations/KGetterIgnore.kt index 70db6ee..c9eac8b 100644 --- a/src/main/kotlin/com/mapk/annotations/KPropertyIgnore.kt +++ b/src/main/kotlin/com/mapk/annotations/KGetterIgnore.kt @@ -1,6 +1,6 @@ package com.mapk.annotations -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.PROPERTY_GETTER) @Retention(AnnotationRetention.RUNTIME) @MustBeDocumented -annotation class KPropertyIgnore +annotation class KGetterIgnore From 27b3c55e609ba26df5b764d5b3fc50138879de64 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:20:32 +0900 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BB=98=E4=B8=8E=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E5=8C=96=E3=81=AB=E4=BC=B4=E3=81=84=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index d5a79af..e288a5a 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -2,8 +2,8 @@ package com.mapk.kmapper import com.mapk.annotations.KConstructor import com.mapk.annotations.KGetterAlias +import com.mapk.annotations.KGetterIgnore import com.mapk.annotations.KParameterAlias -import com.mapk.annotations.KPropertyIgnore import com.mapk.core.ArgumentBucket import com.mapk.core.EnumMapper import com.mapk.core.KFunctionForCall @@ -56,7 +56,7 @@ class KMapper private constructor( if (property.visibility != KVisibility.PUBLIC) return val javaGetter: Method? = property.javaGetter - if (javaGetter != null && property.annotations.none { annotation -> annotation is KPropertyIgnore }) { + if (javaGetter != null && javaGetter.annotations.none { annotation -> annotation is KGetterIgnore }) { parameterMap[property.findAnnotation()?.value ?: property.name]?.let { // javaGetterを呼び出す方が高速 javaGetter.isAccessible = true From db5191082a041356eaa1ff08fae1c6d9aff6f71c Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:20:49 +0900 Subject: [PATCH 07/15] =?UTF-8?q?KPropertyIgnore=20->=20KGetterIgnore?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{KPropertyIgnoreTest.kt => KGetterIgnoreTest.kt} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/test/kotlin/com/mapk/kmapper/{KPropertyIgnoreTest.kt => KGetterIgnoreTest.kt} (73%) diff --git a/src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt b/src/test/kotlin/com/mapk/kmapper/KGetterIgnoreTest.kt similarity index 73% rename from src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt rename to src/test/kotlin/com/mapk/kmapper/KGetterIgnoreTest.kt index 3221d21..f2985d1 100644 --- a/src/test/kotlin/com/mapk/kmapper/KPropertyIgnoreTest.kt +++ b/src/test/kotlin/com/mapk/kmapper/KGetterIgnoreTest.kt @@ -1,14 +1,14 @@ package com.mapk.kmapper -import com.mapk.annotations.KPropertyIgnore +import com.mapk.annotations.KGetterIgnore import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -class KPropertyIgnoreTest { - data class Src1(val arg1: Int, val arg2: String, @KPropertyIgnore val arg3: Short) - data class Src2(@KPropertyIgnore val arg2: String, val arg3: Int, val arg4: String) +class KGetterIgnoreTest { + data class Src1(val arg1: Int, val arg2: String, @get:KGetterIgnore val arg3: Short) + data class Src2(@get:KGetterIgnore val arg2: String, val arg3: Int, val arg4: String) data class Dst(val arg1: Int, val arg2: String, val arg3: Int, val arg4: String) From 187f86001eee9b10c6c5c868a7a7159562473c9d Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:22:26 +0900 Subject: [PATCH 08/15] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E5=90=8D?= =?UTF-8?q?=E3=82=92=E9=81=A9=E5=88=87=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapk/kmapper/{ParamAliasTest.kt => PropertyAliasTest.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/kotlin/com/mapk/kmapper/{ParamAliasTest.kt => PropertyAliasTest.kt} (97%) diff --git a/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt b/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt similarity index 97% rename from src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt rename to src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt index ed052f4..f01168a 100644 --- a/src/test/kotlin/com/mapk/kmapper/ParamAliasTest.kt +++ b/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt @@ -18,7 +18,7 @@ private data class AliasedSrc( ) @DisplayName("エイリアスを貼った場合のテスト") -class ParamAliasTest { +class PropertyAliasTest { @Test @DisplayName("パラメータにエイリアスを貼った場合") fun paramAliasTest() { From 9dd144575b00064e5510b2b63945472d5b692b4e Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:47:01 +0900 Subject: [PATCH 09/15] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=87=E3=83=B3?= =?UTF-8?q?=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index e288a5a..0236064 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -60,12 +60,7 @@ class KMapper private constructor( parameterMap[property.findAnnotation()?.value ?: property.name]?.let { // javaGetterを呼び出す方が高速 javaGetter.isAccessible = true - argumentBucket.setArgument(javaGetter.invoke(src)?.let { value -> - mapObject( - it, - value - ) - }, it.index) + argumentBucket.setArgument(javaGetter.invoke(src)?.let { value -> mapObject(it, value) }, it.index) // 終了判定 if (argumentBucket.isInitialized) return } From 4666228152d1ffa22315e1e2c8c28ff0c3f460aa Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:53:48 +0900 Subject: [PATCH 10/15] =?UTF-8?q?=E4=BB=98=E4=B8=8E=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=82=92getter=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/annotations/KGetterAlias.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/annotations/KGetterAlias.kt b/src/main/kotlin/com/mapk/annotations/KGetterAlias.kt index 8195905..8aed5f4 100644 --- a/src/main/kotlin/com/mapk/annotations/KGetterAlias.kt +++ b/src/main/kotlin/com/mapk/annotations/KGetterAlias.kt @@ -1,5 +1,5 @@ package com.mapk.annotations -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.PROPERTY_GETTER) @Retention(AnnotationRetention.RUNTIME) annotation class KGetterAlias(val value: String) From 4b288a4a6a35bc5e6a2e039ba88ef5d6ccf7b7e3 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:54:03 +0900 Subject: [PATCH 11/15] =?UTF-8?q?getter=E3=81=8B=E3=82=89=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index 0236064..3412479 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -57,7 +57,7 @@ class KMapper private constructor( val javaGetter: Method? = property.javaGetter if (javaGetter != null && javaGetter.annotations.none { annotation -> annotation is KGetterIgnore }) { - parameterMap[property.findAnnotation()?.value ?: property.name]?.let { + parameterMap[javaGetter.getAnnotation(KGetterAlias::class.java)?.value ?: property.name]?.let { // javaGetterを呼び出す方が高速 javaGetter.isAccessible = true argumentBucket.setArgument(javaGetter.invoke(src)?.let { value -> mapObject(it, value) }, it.index) From 1de7e4754b28a1facab348bad7f693511519dc2e Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 03:54:13 +0900 Subject: [PATCH 12/15] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt b/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt index f01168a..16cc936 100644 --- a/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt +++ b/src/test/kotlin/com/mapk/kmapper/PropertyAliasTest.kt @@ -12,7 +12,7 @@ private data class AliasedDst( ) private data class AliasedSrc( - @KGetterAlias("arg1") + @get:KGetterAlias("arg1") val arg2: Double, val arg3: Int ) From e445dd52d5655cd2d191df0a22f4befbb611f69a Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 04:09:49 +0900 Subject: [PATCH 13/15] =?UTF-8?q?=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E5=88=A4=E5=AE=9A=E3=81=AE=E3=83=AB?= =?UTF-8?q?=E3=83=BC=E3=83=97=E3=82=921=E3=81=A4=E3=81=AB=E7=B5=9E?= =?UTF-8?q?=E3=82=8B=E3=81=93=E3=81=A8=E3=81=A7=E9=AB=98=E9=80=9F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ついでにvisiblityがprivateなものが混ざっていると、breakではなく関数そのものを脱出する挙動になっていたため修正 --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 31 +++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index 3412479..0d7d38b 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -51,19 +51,26 @@ class KMapper private constructor( } private fun bindArguments(argumentBucket: ArgumentBucket, src: Any) { - src::class.memberProperties.forEach { property -> + src::class.memberProperties.forEach outer@{ property -> // propertyが公開されていない場合は処理を行わない - if (property.visibility != KVisibility.PUBLIC) return - - val javaGetter: Method? = property.javaGetter - if (javaGetter != null && javaGetter.annotations.none { annotation -> annotation is KGetterIgnore }) { - parameterMap[javaGetter.getAnnotation(KGetterAlias::class.java)?.value ?: property.name]?.let { - // javaGetterを呼び出す方が高速 - javaGetter.isAccessible = true - argumentBucket.setArgument(javaGetter.invoke(src)?.let { value -> mapObject(it, value) }, it.index) - // 終了判定 - if (argumentBucket.isInitialized) return - } + if (property.visibility != KVisibility.PUBLIC) return@outer + + // ゲッターが取れない場合は処理を行わない + val javaGetter: Method = property.javaGetter ?: return@outer + + var alias: String? = null + // NOTE: IgnoreとAliasが同時に指定されるようなパターンを考慮してbreakしていない、アノテーションは数も限られると考えれば影響は無いはず + javaGetter.annotations.forEach { + if (it is KGetterIgnore) return@outer + if (it is KGetterAlias) alias = it.value + } + + parameterMap[alias ?: property.name]?.let { + // javaGetterを呼び出す方が高速 + javaGetter.isAccessible = true + argumentBucket.setArgument(javaGetter.invoke(src)?.let { value -> mapObject(it, value) }, it.index) + // 終了判定 + if (argumentBucket.isInitialized) return } } } From 7bee4362323f6ce5863834a2547ed1b659581e72 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 04:22:41 +0900 Subject: [PATCH 14/15] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index 0d7d38b..d2a35b3 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -61,7 +61,7 @@ class KMapper private constructor( var alias: String? = null // NOTE: IgnoreとAliasが同時に指定されるようなパターンを考慮してbreakしていない、アノテーションは数も限られると考えれば影響は無いはず javaGetter.annotations.forEach { - if (it is KGetterIgnore) return@outer + if (it is KGetterIgnore) return@outer // ignoreされている場合は処理を行わない if (it is KGetterAlias) alias = it.value } From 1109c257000ec73d2757d529c789654309108191 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 8 Mar 2020 04:24:09 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/KMapper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index d2a35b3..4e79408 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -59,7 +59,7 @@ class KMapper private constructor( val javaGetter: Method = property.javaGetter ?: return@outer var alias: String? = null - // NOTE: IgnoreとAliasが同時に指定されるようなパターンを考慮してbreakしていない、アノテーションは数も限られると考えれば影響は無いはず + // NOTE: IgnoreとAliasが同時に指定されるようなパターンを考慮してaliasが取れてもbreakしていない javaGetter.annotations.forEach { if (it is KGetterIgnore) return@outer // ignoreされている場合は処理を行わない if (it is KGetterAlias) alias = it.value