[FIR] Add RedundantSetterParameterType Checker
This commit is contained in:
Vendored
+28
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
var x: Int
|
||||||
|
get() = 1
|
||||||
|
set(@Ann private x) { }
|
||||||
|
|
||||||
|
|
||||||
|
var x: String = ""
|
||||||
|
set(param: <!REDUNDANT_SETTER_PARAMETER_TYPE!>String<!>) {
|
||||||
|
field = "$param "
|
||||||
|
}
|
||||||
|
|
||||||
|
class My {
|
||||||
|
var y: Int = 1
|
||||||
|
set(param: <!REDUNDANT_SETTER_PARAMETER_TYPE!>Int<!>) {
|
||||||
|
field = param - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
var z: Double = 3.14
|
||||||
|
private set
|
||||||
|
|
||||||
|
var w: Boolean = true
|
||||||
|
set(param) {
|
||||||
|
field = !param
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
FILE: RedundantSetterParameterTypeChecker.kt
|
||||||
|
@R|kotlin/annotation/Target|(vararg(Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.CLASS|)) public final annotation class Ann : R|kotlin/Annotation| {
|
||||||
|
public constructor(): R|Ann| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final var x: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int| {
|
||||||
|
^ Int(1)
|
||||||
|
}
|
||||||
|
public set(@R|Ann|() x: R|kotlin/Int|): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
public final var x: R|kotlin/String| = String()
|
||||||
|
public get(): R|kotlin/String|
|
||||||
|
public set(param: R|kotlin/String|): R|kotlin/Unit| {
|
||||||
|
F|/x| = <strcat>(R|<local>/param|.R|kotlin/Any.toString|(), String( ))
|
||||||
|
}
|
||||||
|
public final class My : R|kotlin/Any| {
|
||||||
|
public constructor(): R|My| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final var y: R|kotlin/Int| = Int(1)
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
public set(param: R|kotlin/Int|): R|kotlin/Unit| {
|
||||||
|
this@R|/My|.F|/My.y| = R|<local>/param|.R|kotlin/Int.minus|(Int(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
public final var z: R|kotlin/Double| = Double(3.14)
|
||||||
|
public get(): R|kotlin/Double|
|
||||||
|
private set(value: R|kotlin/Double|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
public final var w: R|kotlin/Boolean| = Boolean(true)
|
||||||
|
public get(): R|kotlin/Boolean|
|
||||||
|
public set(param: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||||
|
this@R|/My|.F|/My.w| = R|<local>/param|.R|kotlin/Boolean.not|()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Generated
+5
@@ -48,6 +48,11 @@ public class ExtendedFirDiagnosticsTestGenerated extends AbstractExtendedFirDiag
|
|||||||
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantReturnUnitTypeChecker.kt");
|
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantReturnUnitTypeChecker.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("RedundantSetterParameterTypeChecker.kt")
|
||||||
|
public void testRedundantSetterParameterTypeChecker() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantSetterParameterTypeChecker.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("RedundantSingleExpressionStringTemplateChecker.kt")
|
@TestMetadata("RedundantSingleExpressionStringTemplateChecker.kt")
|
||||||
public void testRedundantSingleExpressionStringTemplateChecker() throws Exception {
|
public void testRedundantSingleExpressionStringTemplateChecker() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantSingleExpressionStringTemplateChecker.kt");
|
runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantSingleExpressionStringTemplateChecker.kt");
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,8 @@ object ExtendedDeclarationCheckers : DeclarationCheckers() {
|
|||||||
|
|
||||||
override val memberDeclarationCheckers = listOf(
|
override val memberDeclarationCheckers = listOf(
|
||||||
RedundantModalityModifierChecker,
|
RedundantModalityModifierChecker,
|
||||||
RedundantExplicitTypeChecker
|
RedundantExplicitTypeChecker,
|
||||||
|
RedundantSetterParameterTypeChecker
|
||||||
)
|
)
|
||||||
|
|
||||||
override val controlFlowAnalyserCheckers: List<FirControlFlowChecker> = listOf(
|
override val controlFlowAnalyserCheckers: List<FirControlFlowChecker> = listOf(
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.analysis.checkers.extended
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirMemberDeclarationChecker
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_SETTER_PARAMETER_TYPE
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||||
|
|
||||||
|
object RedundantSetterParameterTypeChecker : FirMemberDeclarationChecker() {
|
||||||
|
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
|
if (declaration !is FirProperty) return
|
||||||
|
val setter = declaration.setter ?: return
|
||||||
|
if (setter is FirDefaultPropertyAccessor) return
|
||||||
|
val valueParameter = setter.valueParameters.firstOrNull() ?: return
|
||||||
|
val propertyTypeSource = declaration.returnTypeRef.source
|
||||||
|
val setterParameterTypeSource = valueParameter.returnTypeRef.source ?: return
|
||||||
|
if (setterParameterTypeSource != propertyTypeSource) {
|
||||||
|
reporter.report(setterParameterTypeSource, REDUNDANT_SETTER_PARAMETER_TYPE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,4 +107,5 @@ object FirErrors {
|
|||||||
val REDUNDANT_CALL_OF_CONVERSION_METHOD by warning0<FirSourceElement, PsiElement>()
|
val REDUNDANT_CALL_OF_CONVERSION_METHOD by warning0<FirSourceElement, PsiElement>()
|
||||||
val ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS by warning0<FirSourceElement, PsiElement>()
|
val ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS by warning0<FirSourceElement, PsiElement>()
|
||||||
val EMPTY_RANGE by warning0<FirSourceElement, PsiElement>()
|
val EMPTY_RANGE by warning0<FirSourceElement, PsiElement>()
|
||||||
|
val REDUNDANT_SETTER_PARAMETER_TYPE by warning0<FirSourceElement, PsiElement>()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user