Inspections: Add inspection on equals()/hashCode()

This commit is contained in:
Alexey Sedunov
2015-10-15 18:57:08 +03:00
parent 127cb36602
commit 6f5d977728
8 changed files with 222 additions and 23 deletions
@@ -0,0 +1,42 @@
<problems>
<problem>
<file>test.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">equals() and hashCode() not paired</problem_class>
<description>Class has &lt;code&gt;equals()&lt;/code&gt; defined but does not define &lt;code&gt;hashCode()&lt;/code&gt;</description>
</problem>
<problem>
<file>test.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">equals() and hashCode() not paired</problem_class>
<description>Class has &lt;code&gt;hashCode()&lt;/code&gt; defined but does not define &lt;code&gt;equals()&lt;/code&gt;</description>
</problem>
<problem>
<file>test.kt</file>
<line>14</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">equals() and hashCode() not paired</problem_class>
<description>equals()/hashCode() in object declaration</description>
</problem>
<problem>
<file>test.kt</file>
<line>18</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">equals() and hashCode() not paired</problem_class>
<description>equals()/hashCode() in object declaration</description>
</problem>
<problem>
<file>test.kt</file>
<line>22</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">equals() and hashCode() not paired</problem_class>
<description>equals()/hashCode() in object declaration</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.EqualsOrHashCodeInspection
+39
View File
@@ -0,0 +1,39 @@
class C1 {
override fun equals(other: Any?) = true
}
class C2 {
override fun hashCode() = 0
}
class C3 {
override fun equals(other: Any?) = true
override fun hashCode() = 0
}
object O1 {
override fun equals(other: Any?) = true
}
object O2 {
override fun hashCode() = 0
}
object O3 {
override fun equals(other: Any?) = true
override fun hashCode() = 0
}
class C4 {
override fun equals(other: С4) = true
}
interface I {
override fun equals(other: Any?) = true
override fun hashCode() = 0
}
enum E {
override fun equals(other: Any?) = true
override fun hashCode() = 0
}