Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit a0850b1

Browse files
authored
Merge pull request #13 from k163377/feature
Added a annotation support to use default arguments.
2 parents 62b1f90 + 438e796 commit a0850b1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "com.mapk"
9-
version = "0.15"
9+
version = "0.16"
1010

1111
java {
1212
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -30,7 +30,7 @@ repositories {
3030
dependencies {
3131
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
3232
implementation(kotlin("reflect"))
33-
implementation("com.github.ProjectMapK:Shared:0.6")
33+
api("com.github.ProjectMapK:Shared:0.7")
3434

3535
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
3636
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.0") {

src/main/kotlin/com/mapk/kmapper/KMapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.mapk.core.ArgumentBucket
66
import com.mapk.core.EnumMapper
77
import com.mapk.core.KFunctionForCall
88
import com.mapk.core.getAliasOrName
9+
import com.mapk.core.isUseDefaultArgument
910
import com.mapk.core.toKConstructor
1011
import java.lang.reflect.Method
1112
import kotlin.reflect.KClass
@@ -29,7 +30,7 @@ class KMapper<T : Any> private constructor(
2930
)
3031

3132
private val parameterMap: Map<String, ParameterForMap<*>> = function.parameters
32-
.filter { it.kind != KParameter.Kind.INSTANCE }
33+
.filter { it.kind != KParameter.Kind.INSTANCE && !it.isUseDefaultArgument() }
3334
.associate { (propertyNameConverter(it.getAliasOrName()!!)) to ParameterForMap.newInstance(it) }
3435

3536
private fun bindArguments(argumentBucket: ArgumentBucket, src: Any) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.mapk.kmapper
2+
3+
import com.mapk.annotations.KUseDefaultArgument
4+
import org.junit.jupiter.api.Assertions.assertEquals
5+
import org.junit.jupiter.api.DisplayName
6+
import org.junit.jupiter.api.Test
7+
8+
@DisplayName("デフォルト引数を指定するテスト")
9+
class DefaultArgumentTest {
10+
data class Dst(val fooArgument: Int, @param:KUseDefaultArgument val barArgument: String = "default")
11+
data class Src(val fooArgument: Int, val barArgument: String)
12+
13+
@Test
14+
fun test() {
15+
val src = Src(1, "src")
16+
17+
val result = KMapper(::Dst).map(src)
18+
assertEquals(Dst(1, "default"), result)
19+
}
20+
}

0 commit comments

Comments
 (0)