Skip to content

Commit 664a25c

Browse files
committed
Polish KT-22011 inspection: message, level, group, range, etc.
1 parent 7d6cb78 commit 664a25c

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<html>
22
<body>
3-
This inspection reports immutable Kotlin collection may be changed with Java Collections method.
3+
This inspection report calls of Java mutator methods (like fill, reverse, shuffle, sort) on immutable Kotlin collection.
4+
This will likely produce UnsupportedOperationException at runtime.
45
</body>
56
</html>

idea/src/META-INF/plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,11 +2624,11 @@
26242624
/>
26252625

26262626
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.JavaCollectionsStaticMethodOnImmutableListInspection"
2627-
displayName="Immutable Kotlin collection may be changed with Java Collections method"
2627+
displayName="Call of Java mutator method on immutable Kotlin collection"
26282628
groupPath="Kotlin"
2629-
groupName="Probable bugs"
2629+
groupName="Java interop issues"
26302630
enabledByDefault="true"
2631-
level="WEAK WARNING"
2631+
level="WARNING"
26322632
language="kotlin"
26332633
/>
26342634

idea/src/org/jetbrains/kotlin/idea/inspections/JavaCollectionsStaticMethodOnImmutableListInspection.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ package org.jetbrains.kotlin.idea.inspections
77

88
import com.intellij.codeInspection.ProblemsHolder
99
import com.intellij.psi.PsiElementVisitor
10+
import org.jetbrains.kotlin.idea.intentions.callExpression
1011
import org.jetbrains.kotlin.psi.dotQualifiedExpressionVisitor
1112

1213
class JavaCollectionsStaticMethodOnImmutableListInspection : AbstractKotlinInspection() {
1314
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
1415
return dotQualifiedExpressionVisitor(fun(expression) {
1516
val (methodName, firstArg) = JavaCollectionsStaticMethodInspection.getTargetMethodOnImmutableList(expression) ?: return
1617
holder.registerProblem(
17-
expression,
18-
"The '${firstArg.text}' may be changed with Java Collections method '$methodName'"
18+
expression.callExpression?.calleeExpression ?: expression,
19+
"Call of Java mutator '$methodName' on immutable Kotlin collection '${firstArg.text}'"
1920
)
2021
})
2122
}

idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/expected.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<line>5</line>
55
<module>light_idea_test_case</module>
66
<entry_point TYPE="file" FQNAME="test.kt" />
7-
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Immutable Kotlin collection may be changed with Java Collections method</problem_class>
8-
<description>The 'immutableList' may be changed with Java Collections method 'reverse'</description>
7+
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Call of Java mutator method on immutable Kotlin collection</problem_class>
8+
<description>Call of Java mutator 'reverse' on immutable Kotlin collection 'immutableList'</description>
99
</problem>
1010
</problems>

0 commit comments

Comments
 (0)