File tree Expand file tree Collapse file tree 4 files changed +34
-9
lines changed
utbot-cli/src/main/kotlin/org/utbot/cli
utbot-framework/src/main/kotlin/org/utbot/framework/util
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/util Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ class GenerateTestsCommand :
50
50
help = " Specifies source code file for a generated test"
51
51
)
52
52
.required()
53
- .check(" Must exist and ends with * .java suffix" ) {
54
- it.endsWith(" .java" ) && Files .exists(Paths .get(it))
53
+ .check(" Must exist and end with .java or .kt suffix" ) {
54
+ ( it.endsWith(" .java" ) || it.endsWith( " .kt " ) ) && Files .exists(Paths .get(it))
55
55
}
56
56
57
57
private val projectRoot by option(
Original file line number Diff line number Diff line change @@ -363,6 +363,9 @@ val ClassId.isIterableOrMap: Boolean
363
363
val ClassId .isEnum: Boolean
364
364
get() = jClass.isEnum
365
365
366
+ val ClassId .isData: Boolean
367
+ get() = kClass.isData
368
+
366
369
fun ClassId.findFieldByIdOrNull (fieldId : FieldId ): Field ? {
367
370
if (isNotSubtypeOf(fieldId.declaringClass)) {
368
371
return null
Original file line number Diff line number Diff line change 1
1
package org.utbot.framework.util
2
2
3
3
import org.utbot.framework.plugin.api.ExecutableId
4
- import org.utbot.framework.plugin.api.util.humanReadableName
4
+ import org.utbot.framework.plugin.api.util.isData
5
5
import org.utbot.framework.plugin.api.util.isEnum
6
6
7
- fun isKnownSyntheticMethod (method : ExecutableId ): Boolean =
7
+ fun isKnownSyntheticMethod (method : ExecutableId ): Boolean {
8
8
if (method.classId.isEnum)
9
- method.humanReadableName.substringBefore(' (' ) in KnownSyntheticMethodNames .enumSyntheticMethodNames
10
- else
11
- false
9
+ return method.name in KnownSyntheticMethodNames .enumSyntheticMethodNames
10
+
11
+ if (method.classId.isData)
12
+ return KnownSyntheticMethodNames .dataClassSyntheticMethodNames.any { it.matches(method.name) }
13
+
14
+ return false
15
+ }
12
16
13
17
/* *
14
18
* Contains names of methods that are always autogenerated and thus it is unlikely that
@@ -17,4 +21,14 @@ fun isKnownSyntheticMethod(method: ExecutableId): Boolean =
17
21
private object KnownSyntheticMethodNames {
18
22
/* * List with names of enum methods that are autogenerated */
19
23
val enumSyntheticMethodNames = listOf (" values" , " valueOf" )
24
+
25
+ /* * List with names of data classes methods that are autogenerated in Kotlin */
26
+ val dataClassSyntheticMethodNames = listOf (
27
+ " equals" ,
28
+ " hashCode" ,
29
+ " toString" ,
30
+ " copy" ,
31
+ " copy\\ \$ default" ,
32
+ " component[1-9][0-9]*"
33
+ ).map { it.toRegex() }
20
34
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import com.intellij.testIntegration.TestIntegrationUtils
9
9
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
10
10
import org.jetbrains.kotlin.asJava.elements.isGetter
11
11
import org.jetbrains.kotlin.asJava.elements.isSetter
12
+ import org.jetbrains.kotlin.psi.KtClass
12
13
import org.utbot.common.filterWhen
13
14
import org.utbot.framework.UtSettings
14
15
@@ -22,8 +23,15 @@ private val PsiMember.isKotlinGetterOrSetter: Boolean
22
23
return isGetter || isSetter
23
24
}
24
25
25
- private fun Iterable<MemberInfo>.filterTestableMethods (): List <MemberInfo > = this
26
- .filterWhen(UtSettings .skipTestGenerationForSyntheticMethods) { it.member !is SyntheticElement }
26
+ // By now, we think that method in Kotlin is synthetic iff navigation to its declaration leads to its declaring class
27
+ // rather than the method itself (because synthetic methods don't have bodies that we can navigate to)
28
+ private val PsiMember .isSyntheticKotlinMethod: Boolean
29
+ get() = this is KtLightMethod && navigationElement is KtClass
30
+
31
+ fun Iterable<MemberInfo>.filterTestableMethods (): List <MemberInfo > = this
32
+ .filterWhen(UtSettings .skipTestGenerationForSyntheticMethods) {
33
+ it.member !is SyntheticElement && ! it.member.isSyntheticKotlinMethod
34
+ }
27
35
.filterNot { it.member.isAbstract }
28
36
.filterNot { it.member.isKotlinGetterOrSetter }
29
37
You can’t perform that action at this time.
0 commit comments