Skip to content

Commit 7fceff7

Browse files
authored
jacodb-approximations: fix fields and methods equality (#173)
1 parent b3704b8 commit 7fceff7

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

jacodb-approximations/src/main/kotlin/org/jacodb/approximation/VirtualInstances.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ class JcEnrichedVirtualMethod(
5959
it.flowGraph(this)
6060
}!!.flowGraph
6161

62+
override fun equals(other: Any?): Boolean {
63+
if (this === other) return true
64+
if (javaClass != other?.javaClass) return false
65+
66+
other as JcEnrichedVirtualMethod
67+
68+
if (name != other.name) return false
69+
if (enclosingClass != other.enclosingClass) return false
70+
if (description != other.description) return false
71+
72+
return true
73+
}
74+
75+
override fun hashCode(): Int =
76+
name.hashCode() * 31 + enclosingClass.hashCode()
77+
6278
override val signature: String?
6379
get() = null
6480
}
@@ -79,4 +95,18 @@ class JcEnrichedVirtualField(
7995
) : JcVirtualFieldImpl(name, access, type) {
8096
override val signature: String?
8197
get() = null
98+
99+
override fun equals(other: Any?): Boolean {
100+
if (this === other) return true
101+
if (javaClass != other?.javaClass) return false
102+
103+
other as JcEnrichedVirtualField
104+
105+
if (name != other.name) return false
106+
if (enclosingClass != other.enclosingClass) return false
107+
108+
return true
109+
}
110+
111+
override fun hashCode(): Int = name.hashCode() * 31 + enclosingClass.hashCode()
82112
}

jacodb-approximations/src/test/kotlin/org/jacodb/approximations/ApproximationsTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ApproximationsTest : BaseTest() {
9494
assertTrue("sameApproximationTarget" in originalFieldsNames)
9595
assertTrue("anotherApproximationTarget" in originalFieldsNames)
9696
assertTrue("fieldWithoutApproximation" in originalFieldsNames)
97+
98+
assertEquals(fields, classec.declaredFields)
9799
}
98100

99101
@Test
@@ -119,6 +121,8 @@ class ApproximationsTest : BaseTest() {
119121

120122
assertTrue(originalMethods.size == 1)
121123
assertTrue("methodWithoutApproximation" in originalMethodsNames)
124+
125+
assertEquals(methods, classec.declaredMethods)
122126
}
123127

124128
@Test

0 commit comments

Comments
 (0)