Add inspection for potentially wrongly placed unary operators

So #KT-18236 Fixed
This commit is contained in:
shiraji
2017-06-11 00:21:09 -04:00
committed by Mikhail Glukhikh
parent eaea160f0e
commit 647558c98a
11 changed files with 198 additions and 0 deletions
@@ -0,0 +1,58 @@
<problems>
<problem>
<file>simple.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>9</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>10</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>12</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>14</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>22</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
<problem>
<file>simple.kt</file>
<line>23</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/simple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Ambiguous unary operator use with number constant</problem_class>
<description>Wrap unary operator and value with ()</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.WrapUnaryOperatorInspection
+27
View File
@@ -0,0 +1,27 @@
object Constants {
val ONE = 1
}
fun foo() {
println(-1.inc())
val i = 100
println(-i.inc())
println(-1.1.dec())
println(-1.1f.dec())
println(1 - -1.dec().dec())
println(1 - -1.javaClass)
println(1 - - 1.dec().dec())
println(1 - - 1.javaClass)
println(1-1.inc()) // NG
println(1 - 1.dec().dec()) // NG
println(1 - 1.javaClass) // NG
println(-1) //NG
println(!true) // NG
println(!true.not()) // NG
println(+1) // NG
println(+1.inc())
println(+3.14.inc())
println(-Constants.ONE) // NG
println(-"2".toInt()) // NG
}