Remove setter parameter type: do not suggest if type is empty

So #KT-22339 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-01-18 15:02:55 +03:00
parent f0b172ca35
commit 512e287f3a
4 changed files with 51 additions and 24 deletions
@@ -12,16 +12,20 @@ import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeIntention
import org.jetbrains.kotlin.idea.intentions.isSetterParameter
import org.jetbrains.kotlin.psi.parameterVisitor
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class RemoveSetterParameterTypeInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return parameterVisitor { dcl ->
val typeReference = dcl.takeIf { it.isSetterParameter }?.typeReference ?: return@parameterVisitor
return parameterVisitor { parameter ->
val typeReference = parameter.takeIf { it.isSetterParameter }
?.typeReference
?.takeIf { it.endOffset > it.startOffset } ?: return@parameterVisitor
holder.registerProblem(
typeReference,
"Redundant setter parameter type",
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
IntentionWrapper(RemoveExplicitTypeIntention(), dcl.containingKtFile)
IntentionWrapper(RemoveExplicitTypeIntention(), parameter.containingKtFile)
)
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RemoveSetterParameterTypeInspection
@@ -0,0 +1,7 @@
// PROBLEM: none
// SKIP_ERRORS_BEFORE
// SKIP_ERRORS_AFTER
var x: String
get() = "123"
set(v:<caret> ) {}
@@ -3100,6 +3100,21 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/removeSetterParameterType")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RemoveSetterParameterType extends AbstractLocalInspectionTest {
public void testAllFilesPresentInRemoveSetterParameterType() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/removeSetterParameterType"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("emptyType.kt")
public void testEmptyType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeSetterParameterType/emptyType.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/removeToStringInStringTemplate")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -4060,27 +4075,6 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnusedLambdaExpressionBody extends AbstractLocalInspectionTest {
public void testAllFilesPresentInUnusedLambdaExpressionBody() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/unusedLambdaExpressionBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("inEnumEntry.kt")
public void testInEnumEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody/inEnumEntry.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody/simple.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/unsafeCastFromDynamic")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -4108,6 +4102,27 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnusedLambdaExpressionBody extends AbstractLocalInspectionTest {
public void testAllFilesPresentInUnusedLambdaExpressionBody() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/unusedLambdaExpressionBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("inEnumEntry.kt")
public void testInEnumEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody/inEnumEntry.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedLambdaExpressionBody/simple.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)