Skip to content

Commit

Permalink
FIR exposed visibility checkers: use positioning strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mglukhikh committed Nov 26, 2020
1 parent f095a33 commit 58301d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -97,7 +94,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
restricting,
typeAliasVisibility,
restricting.getEffectiveVisibility(context),
declaration.source?.getIdentifierSource() ?: declaration.source
declaration.source
)
}
}
Expand All @@ -115,7 +112,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
restricting,
functionVisibility,
restricting.getEffectiveVisibility(context),
declaration.source?.getIdentifierSource() ?: declaration.source
declaration.source
)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ object FirErrors {
val VAR_ANNOTATION_PARAMETER by error0<FirSourceElement, KtParameter>(LightTreePositioningStrategies.VAL_OR_VAR_NODE)

// Exposed visibility group
val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_FUNCTION_RETURN_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_RECEIVER_TYPE by error3<FirSourceElement, KtTypeReference, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_PROPERTY_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_PARAMETER_TYPE by error3<FirSourceElement, KtParameter, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_SUPER_INTERFACE by error3<FirSourceElement, KtSuperTypeListEntry, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_SUPER_CLASS by error3<FirSourceElement, KtSuperTypeListEntry, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_TYPE_PARAMETER_BOUND by error3<FirSourceElement, KtTypeParameter, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>()
val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_FUNCTION_RETURN_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_RECEIVER_TYPE by error3<FirSourceElement, KtTypeReference, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_PROPERTY_TYPE by error3<FirSourceElement, PsiElement, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_PARAMETER_TYPE by error3<FirSourceElement, KtParameter, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(/* // NB: for parameter FE 1.0 reports not on a name for some reason */)
val EXPOSED_SUPER_INTERFACE by error3<FirSourceElement, KtSuperTypeListEntry, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_SUPER_CLASS by error3<FirSourceElement, KtSuperTypeListEntry, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)
val EXPOSED_TYPE_PARAMETER_BOUND by error3<FirSourceElement, KtTypeParameter, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>(LightTreePositioningStrategies.DECLARATION_NAME)

// Modifiers
val INAPPLICABLE_INFIX_MODIFIER by existing1<FirSourceElement, PsiElement, String>()
Expand Down

0 comments on commit 58301d8

Please sign in to comment.