Highlighting unused type parameter.
This commit is contained in:
@@ -120,6 +120,7 @@ goto.super.class.chooser.title=Choose super class or interface
|
||||
unused.class=Class ''{0}'' is never used
|
||||
unused.function=Function ''{0}'' is never used
|
||||
unused.property=Property ''{0}'' is never used
|
||||
unused.type.parameter=Type parameter ''{0}'' is never used
|
||||
|
||||
livetemplate.description.main=main() function
|
||||
livetemplate.description.soutp=Prints function parameter names and values to System.out
|
||||
|
||||
@@ -49,6 +49,8 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.PropertyUsagesSearchHelper
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.getAccessorNames
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.dataClassComponentFunctionName
|
||||
import org.jetbrains.kotlin.psi.JetTypeParameter
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.DefaultSearchHelper
|
||||
|
||||
public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
private val javaInspection = UnusedDeclarationInspection()
|
||||
@@ -120,6 +122,18 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
) // TODO add quick fix to delete it
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(parameter: JetTypeParameter) {
|
||||
if (parameter.getName() == null) return
|
||||
|
||||
if (hasNonTrivialUsages(parameter)) return
|
||||
|
||||
holder.registerProblem(
|
||||
parameter.getNameIdentifier(),
|
||||
JetBundle.message("unused.type.parameter", parameter.getName()),
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
) // TODO add quick fix to delete it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +191,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
is JetClass -> ClassUsagesSearchHelper(constructorUsages = true, nonConstructorUsages = true, skipImports = true)
|
||||
is JetNamedFunction -> FunctionUsagesSearchHelper(skipImports = true)
|
||||
is JetProperty, is JetParameter -> PropertyUsagesSearchHelper(skipImports = true)
|
||||
else -> return false
|
||||
else -> DefaultSearchHelper<JetNamedDeclaration>()
|
||||
}
|
||||
|
||||
val request = searchHelper.newRequest(UsagesSearchTarget(declaration, useScope))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>unusedFunctionTypeParameter.kt</file>
|
||||
<line>1</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/unusedFunctionTypeParameter.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused Symbol</problem_class>
|
||||
<description>Type parameter 'T' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>unusedClassTypeParameter.kt</file>
|
||||
<line>1</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/unusedClassTypeParameter.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused Symbol</problem_class>
|
||||
<description>Type parameter 'T' is never used</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
||||
@@ -0,0 +1,9 @@
|
||||
class UnusedClassTypeParameter<T>(p: String) {
|
||||
{
|
||||
println(p)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
UnusedClassTypeParameter("")
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun <T> unusedFunctionTypeParameter(p: String) {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
unusedFunctionTypeParameter("")
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class UsedClassTypeParameter<T>(t: T) {
|
||||
{
|
||||
println(t)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
UsedClassTypeParameter("")
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun <T> usedFunctionTypeParameter(t: T) {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
usedFunctionTypeParameter("")
|
||||
}
|
||||
@@ -101,5 +101,11 @@ public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/inspections/unusedSymbol/property/inspectionData/inspections.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unusedSymbol/typeParameter/inspectionData/inspections.test")
|
||||
public void testUnusedSymbol_typeParameter_inspectionData_Inspections_test() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/inspections/unusedSymbol/typeParameter/inspectionData/inspections.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user