From 58301d8820f485e070263a29bc990956ba4f740b Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 19 Nov 2020 16:13:53 +0300 Subject: [PATCH] FIR exposed visibility checkers: use positioning strategy --- .../FirExposedVisibilityDeclarationChecker.kt | 17 +++-------------- .../fir/analysis/diagnostics/FirErrors.kt | 16 ++++++++-------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt index 06e138f8c3f1e..f30329addc267 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt @@ -6,11 +6,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration import com.intellij.psi.PsiElement -import com.intellij.psi.PsiNameIdentifierOwner import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext -import org.jetbrains.kotlin.fir.analysis.checkers.getChildren import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClass import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory3 @@ -20,7 +18,6 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolved import org.jetbrains.kotlin.fir.types.* -import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.utils.addToStdlib.safeAs // TODO: check why coneTypeSafe is necessary at some points inside @@ -97,7 +94,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() { restricting, typeAliasVisibility, restricting.getEffectiveVisibility(context), - declaration.source?.getIdentifierSource() ?: declaration.source + declaration.source ) } } @@ -115,7 +112,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() { restricting, functionVisibility, restricting.getEffectiveVisibility(context), - declaration.source?.getIdentifierSource() ?: declaration.source + declaration.source ) } } @@ -151,7 +148,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() { restricting, propertyVisibility, restricting.getEffectiveVisibility(context), - declaration.source?.getIdentifierSource() ?: declaration.source + declaration.source ) } checkMemberReceiver(declaration.receiverTypeRef, declaration, reporter, context) @@ -229,14 +226,6 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() { } } - private fun FirSourceElement.getIdentifierSource() = when (this) { - is FirPsiSourceElement<*> -> (this.psi as? PsiNameIdentifierOwner)?.nameIdentifier?.toFirPsiSourceElement() - is FirLightSourceElement -> { - val identifier = lighterASTNode.getChildren(treeStructure).find { it?.tokenType == KtTokens.IDENTIFIER } - identifier?.toFirLightSourceElement(treeStructure) - } - } - private fun FirMemberDeclaration.getEffectiveVisibility(context: CheckerContext) = getEffectiveVisibility(context.session, context.containingDeclarations, context.sessionHolder.scopeSession) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index be48b7a810285..fefec26e9d0a5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -94,14 +94,14 @@ object FirErrors { val VAR_ANNOTATION_PARAMETER by error0(LightTreePositioningStrategies.VAL_OR_VAR_NODE) // Exposed visibility group - val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3() - val EXPOSED_FUNCTION_RETURN_TYPE by error3() - val EXPOSED_RECEIVER_TYPE by error3() - val EXPOSED_PROPERTY_TYPE by error3() - val EXPOSED_PARAMETER_TYPE by error3() - val EXPOSED_SUPER_INTERFACE by error3() - val EXPOSED_SUPER_CLASS by error3() - val EXPOSED_TYPE_PARAMETER_BOUND by error3() + val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_FUNCTION_RETURN_TYPE by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_RECEIVER_TYPE by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_PROPERTY_TYPE by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_PARAMETER_TYPE by error3(/* // NB: for parameter FE 1.0 reports not on a name for some reason */) + val EXPOSED_SUPER_INTERFACE by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_SUPER_CLASS by error3(LightTreePositioningStrategies.DECLARATION_NAME) + val EXPOSED_TYPE_PARAMETER_BOUND by error3(LightTreePositioningStrategies.DECLARATION_NAME) // Modifiers val INAPPLICABLE_INFIX_MODIFIER by existing1()