Unused symbol inspection should detect enum entry

#KT-30612 Fixed
This commit is contained in:
Dmitry Gridin
2019-03-26 12:08:38 +07:00
parent ce1ec49625
commit dbe0b4aa71
16 changed files with 136 additions and 2 deletions
@@ -63,7 +63,6 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.getAccessorNames
import org.jetbrains.kotlin.idea.search.usagesSearch.getClassNameForCompanionObject
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.idea.util.compat.psiSearchHelperInstance
import org.jetbrains.kotlin.idea.util.hasActualsFor
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
@@ -199,7 +198,6 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
// Simple PSI-based checks
if (declaration is KtObjectDeclaration && declaration.isCompanion()) return // never mark companion object as unused (there are too many reasons it can be needed for)
if (declaration is KtEnumEntry) return
if (declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
if (declaration is KtProperty && declaration.isLocal) return
if (declaration is KtParameter && (declaration.getParent().parent !is KtPrimaryConstructor || !declaration.hasValOrVar())) return
@@ -0,0 +1,12 @@
// PROBLEM: none
enum class MyEnum(val i: Int) {
HELLO<caret>(42),
WORLD("42")
;
constructor(s: String): this(42)
}
fun test() {
MyEnum.HELLO
}
@@ -0,0 +1,9 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum {
HELLO,
WORLD<caret>
}
fun main() {
MyEnum.HELLO
}
@@ -0,0 +1,8 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum {
HELLO,
}
fun main() {
MyEnum.HELLO
}
+13
View File
@@ -0,0 +1,13 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum(val i: Int) {
HELLO(42),
WORLD<caret>("42"),
E(24)
;
constructor(s: String): this(42)
}
fun test() {
MyEnum.HELLO
}
@@ -0,0 +1,12 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum(val i: Int) {
HELLO(42),
E(24)
;
constructor(s: String): this(42)
}
fun test() {
MyEnum.HELLO
}
+12
View File
@@ -0,0 +1,12 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum(val i: Int) {
WORLD<caret>("42"),
HELLO(42)
;
constructor(s: String): this(42)
}
fun test() {
MyEnum.HELLO
}
@@ -0,0 +1,11 @@
// "Safe delete 'WORLD'" "true"
enum class MyEnum(val i: Int) {
HELLO(42)
;
constructor(s: String): this(42)
}
fun test() {
MyEnum.HELLO
}
@@ -0,0 +1,4 @@
// "Safe delete 'HELLO'" "true"
enum class MyEnum {
HELLO<caret>
}
@@ -0,0 +1,3 @@
// "Safe delete 'HELLO'" "true"
enum class MyEnum {
}
@@ -0,0 +1,4 @@
// "Safe delete 'HELLO'" "true"
enum class MyEnum {
HELLO<caret>,
}
@@ -0,0 +1,3 @@
// "Safe delete 'HELLO'" "true"
enum class MyEnum {
}
@@ -0,0 +1,6 @@
// "Safe delete 'HELLO'" "true"
import MyEnum.HELLO
enum class MyEnum {
HELLO<caret>,
}
@@ -0,0 +1,4 @@
// "Safe delete 'HELLO'" "true"
enum class MyEnum {
}
@@ -8728,6 +8728,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/unusedSymbol/typeAlias.kt");
}
@TestMetadata("unusedEnumEntry.kt")
public void testUnusedEnumEntry() throws Exception {
runTest("idea/testData/inspectionsLocal/unusedSymbol/unusedEnumEntry.kt");
}
@TestMetadata("withJvmNameUsedFromKotlin.kt")
public void testWithJvmNameUsedFromKotlin() throws Exception {
runTest("idea/testData/inspectionsLocal/unusedSymbol/withJvmNameUsedFromKotlin.kt");
@@ -10121,6 +10121,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/removeUnused/notTriangle.kt");
}
@TestMetadata("simpleUnusedEnumEntry.kt")
public void testSimpleUnusedEnumEntry() throws Exception {
runTest("idea/testData/quickfix/removeUnused/simpleUnusedEnumEntry.kt");
}
@TestMetadata("triangle.kt")
public void testTriangle() throws Exception {
runTest("idea/testData/quickfix/removeUnused/triangle.kt");
@@ -10156,6 +10161,31 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/removeUnused/unusedDelegatedConstructorSuper.kt");
}
@TestMetadata("unusedEnumEntry.kt")
public void testUnusedEnumEntry() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedEnumEntry.kt");
}
@TestMetadata("unusedEnumEntry2.kt")
public void testUnusedEnumEntry2() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedEnumEntry2.kt");
}
@TestMetadata("unusedEnumEntry3.kt")
public void testUnusedEnumEntry3() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedEnumEntry3.kt");
}
@TestMetadata("unusedEnumEntry4.kt")
public void testUnusedEnumEntry4() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedEnumEntry4.kt");
}
@TestMetadata("unusedEnumEntry5.kt")
public void testUnusedEnumEntry5() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedEnumEntry5.kt");
}
@TestMetadata("unusedFunction.kt")
public void testUnusedFunction() throws Exception {
runTest("idea/testData/quickfix/removeUnused/unusedFunction.kt");