Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("maven")
id("java")
id("org.jetbrains.kotlin.jvm") version "1.3.72"
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
id("org.jlleitschuh.gradle.ktlint") version "9.3.0"
id("jacoco")
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mapk/core/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.reflect.full.functions

inline fun <reified A : Annotation> KClass<*>.getAnnotatedFunctionsFromCompanionObject(): Pair<Any, List<KFunction<*>>>? {
return this.companionObject?.let { companionObject ->
val temp = companionObject.functions.filter { functions -> functions.annotations.any { it is A } }
val temp = companionObject.functions.filter { function -> function.annotations.any { it is A } }

if (temp.isEmpty()) {
// 空ならその後の処理をしてもしょうがないのでnullに合わせる
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mapk/core/KFunctionForCall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.mapk.core.internal.ParameterNameConverter
import com.mapk.core.internal.getAliasOrName
import com.mapk.core.internal.getKConstructor
import com.mapk.core.internal.isUseDefaultArgument
import org.jetbrains.annotations.TestOnly
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.KParameter
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.jvm.isAccessible
import org.jetbrains.annotations.TestOnly

class KFunctionForCall<T> internal constructor(
@TestOnly
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/com/mapk/core/internal/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ internal fun KParameter.getAliasOrName(): String? = findAnnotation<KParameterAli
* デフォルト引数を用いるかチェックする関数
*/
internal fun KParameter.isUseDefaultArgument(): Boolean {
if (annotations.any { it is KUseDefaultArgument }) {
if (!isOptional) throw IllegalArgumentException(
return annotations.any { it is KUseDefaultArgument }.apply {
if (this && !isOptional) throw IllegalArgumentException(
"Find ${KUseDefaultArgument::class.jvmName}, but it's not has default argument."
)
return true
}
return false
}

@Suppress("UNCHECKED_CAST")
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/mapk/core/FunctionsTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.mapk.core

import com.mapk.annotations.KConstructor
import kotlin.reflect.full.companionObjectInstance
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.reflect.full.companionObjectInstance

@DisplayName("共通利用関数関連のテスト")
class FunctionsTest {
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/mapk/core/KFunctionForCallTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.mapk.core

import io.mockk.spyk
import io.mockk.verify
import kotlin.reflect.KParameter
import kotlin.reflect.full.functions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import kotlin.reflect.KParameter
import kotlin.reflect.full.functions

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class KFunctionForCallTest {
Expand Down
8 changes: 4 additions & 4 deletions src/test/kotlin/com/mapk/core/ToKConstructorTest.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mapk.core

import com.mapk.annotations.KConstructor
import kotlin.reflect.KFunction
import kotlin.reflect.full.memberProperties
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.isAccessible
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.reflect.KFunction
import kotlin.reflect.full.memberProperties
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.isAccessible

@Suppress("UNCHECKED_CAST", "unused")
@DisplayName("クラスからのコンストラクタ抽出関連テスト")
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/com/mapk/core/internal/FunctionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.mapk.annotations.KParameterAlias
import com.mapk.annotations.KUseDefaultArgument
import io.mockk.every
import io.mockk.mockk
import java.lang.IllegalArgumentException
import kotlin.reflect.KParameter
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
Expand All @@ -14,6 +12,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.reflect.KParameter

@DisplayName("関数類のテスト")
class FunctionsTest {
Expand Down