[Code Analysis. Inspection] IDEA-234302 System.getProperty(str) inspection implementation.

Call to System.getProperty(str) could be simplified for certain predefined constants. Implementation includes inspection and quickfix.

GitOrigin-RevId: 8b7edf6c4a6849062535ded1c49e733b8fed05a8
This commit is contained in:
Georgii Ustinov
2023-09-21 21:19:26 +03:00
committed by intellij-monorepo-bot
parent 89dd759681
commit 0382910261
9 changed files with 282 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package com.intellij.codeInspection.tests.kotlin
import com.intellij.codeInspection.tests.JvmLanguage
import com.intellij.codeInspection.tests.SystemGetPropertyInspectionTestBase
class KotlinSystemGetPropertyInspectionTest : SystemGetPropertyInspectionTestBase() {
fun `test highlighting`() {
myFixture.testHighlighting(JvmLanguage.KOTLIN, """
fun foo() {
System.<warning descr="Call 'getProperty' can be simplified for 'file.separator'">getProperty</warning>("file.separator")
System.<warning descr="Call 'getProperty' can be simplified for 'path.separator'">getProperty</warning>("path.separator")
System.<warning descr="Call 'getProperty' can be simplified for 'line.separator'">getProperty</warning>("line.separator")
System.<warning descr="Call 'getProperty' can be simplified for 'file.encoding'">getProperty</warning>("file.encoding")
}
""".trimIndent())
}
fun `test quickfix file-separator`() {
myFixture.testQuickFix(JvmLanguage.KOTLIN, """
fun foo() {
System.getPrope<caret>rty("file.separator")
}
""".trimIndent(), """
import java.nio.file.FileSystems
fun foo() {
FileSystems.getDefault().getSeparator()
}
""".trimIndent(), "Replace with 'java.nio.file.FileSystems.getDefault().getSeparator()'")
}
fun `test quickfix path-separator`() {
myFixture.testQuickFix(JvmLanguage.KOTLIN, """
fun foo() {
System.getPrope<caret>rty("path.separator")
}
""".trimIndent(), """
import java.io.File
fun foo() {
File.pathSeparator
}
""".trimIndent(), "Replace with 'java.io.File.pathSeparator'")
}
fun `test quickfix line-separator`() {
myFixture.testQuickFix(JvmLanguage.KOTLIN, """
fun foo() {
System.getPrope<caret>rty("line.separator")
}
""".trimIndent(), """
fun foo() {
System.lineSeparator()
}
""".trimIndent(), "Replace with 'java.lang.System.lineSeparator()'")
}
fun `test quickfix file-encoding`() {
myFixture.testQuickFix(JvmLanguage.KOTLIN, """
fun foo() {
System.getPrope<caret>rty("file.encoding")
}
""".trimIndent(), """
import java.nio.charset.Charset
fun foo() {
Charset.defaultCharset().displayName()
}
""".trimIndent(), "Replace with 'java.nio.charset.Charset.defaultCharset().displayName()'")
}
}