diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceChildren.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceChildren.kt index cfa96d86f6b..83f5a334e48 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceChildren.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceChildren.kt @@ -9,32 +9,32 @@ import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.fir.* -fun FirSourceElement.getChildren(type: IElementType, index: Int = 0, depth: Int = -1): FirSourceElement? { - return getChildren(setOf(type), index, depth) +fun FirSourceElement.getChild(type: IElementType, index: Int = 0, depth: Int = -1): FirSourceElement? { + return getChild(setOf(type), index, depth) } -fun FirSourceElement.getChildren(types: TokenSet, index: Int = 0, depth: Int = -1): FirSourceElement? { - return getChildren(types.types.toSet(), index, depth) +fun FirSourceElement.getChild(types: TokenSet, index: Int = 0, depth: Int = -1): FirSourceElement? { + return getChild(types.types.toSet(), index, depth) } -fun FirSourceElement.getChildren(types: Set, index: Int = 0, depth: Int = -1): FirSourceElement? { +fun FirSourceElement.getChild(types: Set, index: Int = 0, depth: Int = -1): FirSourceElement? { return when (this) { is FirPsiSourceElement<*> -> { - getChildren(types, index, depth) + getChild(types, index, depth) } is FirLightSourceElement -> { - getChildren(types, index, depth) + getChild(types, index, depth) } else -> null } } -private fun FirPsiSourceElement<*>.getChildren(types: Set, index: Int, depth: Int): FirSourceElement? { +private fun FirPsiSourceElement<*>.getChild(types: Set, index: Int, depth: Int): FirSourceElement? { val visitor = PsiElementFinderByType(types, index, depth) return visitor.find(psi)?.toFirPsiSourceElement() } -private fun FirLightSourceElement.getChildren(types: Set, index: Int, depth: Int): FirSourceElement? { +private fun FirLightSourceElement.getChild(types: Set, index: Int, depth: Int): FirSourceElement? { val visitor = LighterTreeElementFinderByType(tree, types, index, depth) return visitor.find(lightNode)?.let { it.toFirLightSourceElement(it.startOffset, it.endOffset, tree) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/LightTreeKinddedElementVisitor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/LighterTreeElementFinderByType.kt similarity index 100% rename from compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/LightTreeKinddedElementVisitor.kt rename to compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/LighterTreeElementFinderByType.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/ArrayEqualityCanBeReplacedWithEquals.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/ArrayEqualityCanBeReplacedWithEquals.kt index 3676d3c0009..7501efc6166 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/ArrayEqualityCanBeReplacedWithEquals.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/ArrayEqualityCanBeReplacedWithEquals.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirBasicExpresionChecker import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS -import org.jetbrains.kotlin.fir.analysis.getChildren +import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.expressions.FirEqualityOperatorCall import org.jetbrains.kotlin.fir.expressions.FirOperation import org.jetbrains.kotlin.fir.expressions.FirStatement @@ -29,7 +29,7 @@ object ArrayEqualityCanBeReplacedWithEquals : FirBasicExpresionChecker() { if (left.typeRef.coneType.classId != StandardClassIds.Array) return if (right.typeRef.coneType.classId != StandardClassIds.Array) return - val source = expression.source?.getChildren(setOf(KtTokens.EQEQ, KtTokens.EXCLEQ)) + val source = expression.source?.getChild(setOf(KtTokens.EQEQ, KtTokens.EXCLEQ)) reporter.report(source, ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS) } } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/CanBeReplacedWithOperatorAssignmentChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/CanBeReplacedWithOperatorAssignmentChecker.kt index 5c516808181..bb344b7ceb0 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/CanBeReplacedWithOperatorAssignmentChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/CanBeReplacedWithOperatorAssignmentChecker.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirExpressionChecker import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors -import org.jetbrains.kotlin.fir.analysis.getChildren +import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol @@ -62,7 +62,7 @@ object CanBeReplacedWithOperatorAssignmentChecker : FirExpressionChecker>.modalitySource(): FirSourceElement? { - return this.firstOrNull { - it.token == KtTokens.FINAL_KEYWORD - || it.token == KtTokens.OPEN_KEYWORD - || it.token == KtTokens.SEALED_KEYWORD - || it.token == KtTokens.ABSTRACT_KEYWORD - }?.source - } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt index b70e87edd84..687a0c81bc4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors -import org.jetbrains.kotlin.fir.analysis.getChildren +import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens @@ -56,7 +56,7 @@ object RedundantVisibilityModifierChecker : FirBasicDeclarationChecker() { && declaration.setter?.visibility == Visibilities.Public ) return - reporter.report(declaration.source?.getChildren(KtTokens.VISIBILITY_MODIFIERS), FirErrors.REDUNDANT_VISIBILITY_MODIFIER) + reporter.report(declaration.source?.getChild(KtTokens.VISIBILITY_MODIFIERS), FirErrors.REDUNDANT_VISIBILITY_MODIFIER) } private fun FirDeclaration.implicitVisibility(context: CheckerContext): Visibility { @@ -127,10 +127,6 @@ object RedundantVisibilityModifierChecker : FirBasicDeclarationChecker() { private val CheckerContext.containingPropertyVisibility get() = (this.containingDeclarations.last() as? FirProperty)?.visibility - - private val FirModifier<*>.isVisibilityModifier - get() = this.token.toVisibilityOrNull() != null - private fun List.visibilityOrNull() = firstOrNull { it.token.toVisibilityOrNull() != null }?.token?.toVisibilityOrNull() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt index cf0c69f71e7..91b62241091 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClass import org.jetbrains.kotlin.fir.analysis.checkers.isIterator import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors -import org.jetbrains.kotlin.fir.analysis.getChildren +import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.dfa.cfg.* @@ -203,5 +203,5 @@ object UnusedChecker : FirControlFlowChecker() { get() = fir.initializer?.source?.kind == FirFakeSourceElementKind.DesugaredForLoop private val FirPropertySymbol.identifierSource: FirSourceElement? - get() = fir.source?.getChildren(KtTokens.IDENTIFIER, 0, 1) + get() = fir.source?.getChild(KtTokens.IDENTIFIER, 0, 1) } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 833c66412d5..9fd4c2d9bb9 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -343,10 +343,10 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { map.put(ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS, "Replace '==' with 'Arrays.equals'") map.put(EMPTY_RANGE, "Range is empty") map.put(REDUNDANT_SETTER_PARAMETER_TYPE, "Redundant setter parameter type") - map.put(UNUSED_VARIABLE, "Unused variable") + map.put(UNUSED_VARIABLE, "Variable is unused") map.put(ASSIGNED_VALUE_IS_NEVER_READ, "Assigned value is never read") - map.put(VARIABLE_INITIALIZER_IS_REDUNDANT, "Initialized is redundant") - map.put(VARIABLE_NEVER_READ, "Variable never read") + map.put(VARIABLE_INITIALIZER_IS_REDUNDANT, "Initializer is redundant") + map.put(VARIABLE_NEVER_READ, "Variable is never read") } } }