Skip to content

Commit 5149c16

Browse files
KON-692 Fix "StackOverflowError" Exception when trying to find indirect parents (#1583)
* fix bug * add tests * clean project * clean code
1 parent 97c3b98 commit 5149c16

8 files changed

+73
-13
lines changed

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koparent/KoParentDeclarationForKoSourceDeclarationProviderTest.kt

+35
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ class KoParentDeclarationForKoSourceDeclarationProviderTest {
302302
null,
303303
null,
304304
),
305+
arguments(
306+
"class-with-parent-interface-with-the-same-name",
307+
KoInterfaceDeclaration::class,
308+
KoClassDeclaration::class,
309+
null,
310+
"com.samplepackage.SampleInterface.SampleName",
311+
),
312+
arguments(
313+
"class-with-parent-class-with-the-same-name",
314+
KoClassDeclaration::class,
315+
KoInterfaceDeclaration::class,
316+
null,
317+
"com.samplepackage.SampleInterface.SampleName",
318+
),
305319
)
306320

307321
@Suppress("unused", "detekt.LongMethod")
@@ -364,6 +378,13 @@ class KoParentDeclarationForKoSourceDeclarationProviderTest {
364378
null,
365379
null,
366380
),
381+
arguments(
382+
"interface-with-parent-interface-with-the-same-name",
383+
KoInterfaceDeclaration::class,
384+
KoClassDeclaration::class,
385+
null,
386+
"com.samplepackage.SampleInterface.SampleName",
387+
),
367388
)
368389

369390
@Suppress("unused", "detekt.LongMethod")
@@ -510,6 +531,20 @@ class KoParentDeclarationForKoSourceDeclarationProviderTest {
510531
null,
511532
null,
512533
),
534+
arguments(
535+
"object-with-parent-interface-with-the-same-name",
536+
KoInterfaceDeclaration::class,
537+
KoClassDeclaration::class,
538+
null,
539+
"com.samplepackage.SampleInterface.SampleName",
540+
),
541+
arguments(
542+
"object-with-parent-class-with-the-same-name",
543+
KoClassDeclaration::class,
544+
KoInterfaceDeclaration::class,
545+
null,
546+
"com.samplepackage.SampleInterface.SampleName",
547+
),
513548
)
514549
}
515550
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.samplepackage
2+
3+
data class SampleName(val data: String) : SampleInterface.SampleName()
4+
5+
interface SampleInterface {
6+
open class SampleName
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.samplepackage
2+
3+
data class SampleName(val data: String) : SampleInterface.SampleName
4+
5+
interface SampleInterface {
6+
interface SampleName
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.samplepackage
2+
3+
interface SampleName : SampleInterface.SampleName
4+
5+
interface SampleInterface {
6+
interface SampleName
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.samplepackage
2+
3+
object SampleName : SampleInterface.SampleName()
4+
5+
interface SampleInterface {
6+
open class SampleName
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.samplepackage
2+
3+
object SampleName : SampleInterface.SampleName
4+
5+
interface SampleInterface {
6+
interface SampleName
7+
}

lib/src/main/kotlin/com/lemonappdev/konsist/core/declaration/KoParentDeclarationCore.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ internal class KoParentDeclarationCore(
105105
if (import.alias != null) {
106106
import.alias?.name == innerName
107107
} else {
108-
import.name.substringAfterLast(".") == innerName
108+
import.name.substringAfterLast(".") == outerName
109109
}
110110
}
111111

112112
val fullyQualifiedName =
113-
import
114-
?.name
115-
?: (containingFile.packagee?.name + "." + name)
113+
import?.name
114+
?: "${containingFile.packagee?.name?.let { "$it." } ?: ""}$name"
116115

117116
val isAlias = import?.alias != null
118117

lib/src/main/kotlin/com/lemonappdev/konsist/core/model/DataCore.kt

-9
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ fun getClass(
6060
?: containingFile
6161
.classes()
6262
.firstOrNull { decl -> decl.fullyQualifiedName == declarationQualifiedName }
63-
?: containingFile
64-
.classes()
65-
.firstOrNull { decl -> decl.name == name }
6663
}
6764

6865
fun getInterface(
@@ -84,9 +81,6 @@ fun getInterface(
8481
?: containingFile
8582
.interfaces()
8683
.firstOrNull { decl -> decl.fullyQualifiedName == declarationQualifiedName }
87-
?: containingFile
88-
.interfaces()
89-
.firstOrNull { decl -> decl.name == name }
9084
}
9185

9286
fun getObject(
@@ -108,9 +102,6 @@ fun getObject(
108102
?: containingFile
109103
.objects()
110104
.firstOrNull { decl -> decl.fullyQualifiedName == declarationQualifiedName }
111-
?: containingFile
112-
.objects()
113-
.firstOrNull { decl -> decl.name == name }
114105
}
115106

116107
fun getTypeAlias(

0 commit comments

Comments
 (0)