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

Commit

Permalink
Merge pull request #47 from k163377/update_libs
Browse files Browse the repository at this point in the history
Update libs.
  • Loading branch information
k163377 authored Dec 23, 2020
2 parents e22ceb6 + 2ccd08f commit 453da37
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id("maven")
id("java")
id("org.jetbrains.kotlin.jvm") version "1.4.10"
id("org.jetbrains.kotlin.jvm") version "1.4.21"
// その他補助系
id("org.jlleitschuh.gradle.ktlint") version "9.3.0"
id("org.jlleitschuh.gradle.ktlint") version "9.4.1"
id("jacoco")
id("com.github.ben-manes.versions") version "0.28.0"
}

group = "com.mapk"
version = "0.34"
version = "0.0.35"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -33,10 +33,10 @@ repositories {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(kotlin("reflect"))
api("com.github.ProjectMapK:Shared:0.18")
api("com.github.ProjectMapK:Shared:0.19")

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.2") {
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.7.0") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
// 現状プロパティ名の変換はテストでしか使っていないのでtestImplementation
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/com/mapk/kmapper/BoundKMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ class BoundKMapper<S : Any, D : Any> private constructor(
parameterNameConverter: ((String) -> String)?
) {
constructor(function: KFunction<D>, src: KClass<S>, parameterNameConverter: ((String) -> String)? = null) : this(
KFunctionForCall(function, parameterNameConverter), src, parameterNameConverter
KFunctionForCall(function, parameterNameConverter),
src,
parameterNameConverter
)

constructor(clazz: KClass<D>, src: KClass<S>, parameterNameConverter: ((String) -> String)? = null) : this(
clazz.toKConstructor(parameterNameConverter), src, parameterNameConverter
clazz.toKConstructor(parameterNameConverter),
src,
parameterNameConverter
)

private val parameters: List<BoundParameterForMap<S>>
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/com/mapk/kmapper/BoundParameterForMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ internal sealed class BoundParameterForMap<S> {
paramClazz == String::class -> ToString(param.name, propertyGetter)
// SrcがMapやPairならKMapperを使わないとマップできない
propertyClazz.isSubclassOf(Map::class) || propertyClazz.isSubclassOf(Pair::class) -> UseKMapper(
param.name, propertyGetter, KMapper(paramClazz, parameterNameConverter)
param.name,
propertyGetter,
KMapper(paramClazz, parameterNameConverter)
)
// 何にも当てはまらなければBoundKMapperでマップを試みる
else -> UseBoundKMapper(
param.name, propertyGetter, BoundKMapper(paramClazz, propertyClazz, parameterNameConverter)
param.name,
propertyGetter,
BoundKMapper(paramClazz, propertyClazz, parameterNameConverter)
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/com/mapk/kmapper/KMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class KMapper<T : Any> private constructor(
parameterNameConverter: ((String) -> String)?
) {
constructor(function: KFunction<T>, parameterNameConverter: ((String) -> String)? = null) : this(
KFunctionForCall(function, parameterNameConverter), parameterNameConverter
KFunctionForCall(function, parameterNameConverter),
parameterNameConverter
)

constructor(clazz: KClass<T>, parameterNameConverter: ((String) -> String)? = null) : this(
clazz.toKConstructor(parameterNameConverter), parameterNameConverter
clazz.toKConstructor(parameterNameConverter),
parameterNameConverter
)

private val parameterMap: Map<String, ParameterForMap<*>> = function.requiredParameters.associate {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/com/mapk/kmapper/PlainKMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class PlainKMapper<T : Any> private constructor(
parameterNameConverter: ((String) -> String)?
) {
constructor(function: KFunction<T>, parameterNameConverter: ((String) -> String)? = null) : this(
KFunctionForCall(function, parameterNameConverter), parameterNameConverter
KFunctionForCall(function, parameterNameConverter),
parameterNameConverter
)

constructor(clazz: KClass<T>, parameterNameConverter: ((String) -> String)? = null) : this(
clazz.toKConstructor(parameterNameConverter), parameterNameConverter
clazz.toKConstructor(parameterNameConverter),
parameterNameConverter
)

private val parameterMap: Map<String, PlainParameterForMap<*>> = function.requiredParameters.associate {
Expand Down
16 changes: 12 additions & 4 deletions src/test/kotlin/com/mapk/kmapper/BoundParameterForMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class BoundParameterForMapTest {
fun makeTwiceOrNull(int: Int?) = int?.let { it * 2 }

private val parameter = BoundParameterForMap.UseConverter<IntSrc>(
"", IntSrc::class.memberProperties.single().javaGetter!!, this::makeTwiceOrNull
"",
IntSrc::class.memberProperties.single().javaGetter!!,
this::makeTwiceOrNull
)

@Test
Expand All @@ -67,7 +69,9 @@ class BoundParameterForMapTest {
@DisplayName("UseKMapperのテスト")
inner class UseKMapperTest {
private val parameter = BoundParameterForMap.UseKMapper<ObjectSrc>(
"", ObjectSrc::class.memberProperties.single().javaGetter!!, KMapper(::ObjectDst)
"",
ObjectSrc::class.memberProperties.single().javaGetter!!,
KMapper(::ObjectDst)
)

@Test
Expand All @@ -88,7 +92,9 @@ class BoundParameterForMapTest {
@DisplayName("UseBoundKMapperのテスト")
inner class UseBoundKMapperTest {
private val parameter = BoundParameterForMap.UseBoundKMapper<ObjectSrc, InnerSrc>(
"", ObjectSrc::class.memberProperties.single().javaGetter!!, BoundKMapper(::ObjectDst, InnerSrc::class)
"",
ObjectSrc::class.memberProperties.single().javaGetter!!,
BoundKMapper(::ObjectDst, InnerSrc::class)
)

@Test
Expand All @@ -109,7 +115,9 @@ class BoundParameterForMapTest {
@DisplayName("ToEnumのテスト")
inner class ToEnumTest {
private val parameter = BoundParameterForMap.ToEnum<StringSrc>(
"", StringSrc::class.memberProperties.single().javaGetter!!, JvmLanguage::class.java
"",
StringSrc::class.memberProperties.single().javaGetter!!,
JvmLanguage::class.java
)

@Test
Expand Down

0 comments on commit 453da37

Please sign in to comment.