Skip to content

Commit

Permalink
FIR IDE: do not collect diagnostics for generated declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
darthorimar committed Nov 23, 2020
1 parent 60cc302 commit 164f4d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import org.jetbrains.kotlin.fir.analysis.collectors.DiagnosticCollectorDeclarati
import org.jetbrains.kotlin.fir.containingClass
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.realPsi
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.idea.fir.low.level.api.diagnostics.FirIdeStructureElementDiagnosticsCollector
import org.jetbrains.kotlin.idea.fir.low.level.api.file.builder.ModuleFileCache
import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.FirLazyDeclarationResolver
import org.jetbrains.kotlin.idea.fir.low.level.api.providers.FirIdeProvider
import org.jetbrains.kotlin.idea.fir.low.level.api.util.isGeneratedDeclaration
import org.jetbrains.kotlin.idea.fir.low.level.api.util.ktDeclaration
import org.jetbrains.kotlin.idea.fir.low.level.api.util.replaceFirst
import org.jetbrains.kotlin.psi.*
Expand Down Expand Up @@ -138,6 +140,7 @@ internal class NonReanalyzableDeclarationStructureElement(
firFile,
onDeclarationEnter = { firDeclaration ->
when {
firDeclaration.isGeneratedDeclaration -> DiagnosticCollectorDeclarationAction.SKIP
firDeclaration is FirFile -> DiagnosticCollectorDeclarationAction.CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration == fir -> {
inCurrentDeclaration = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ private fun KtTypeAlias.findFir(firSymbolProvider: FirSymbolProvider): FirTypeAl
}
}

val FirDeclaration.isGeneratedDeclaration
get() = realPsi == null
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import org.jetbrains.kotlin.fir.diagnostics.FirDiagnosticHolder
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.idea.util.getElementTextInContext
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.Lock

Expand Down Expand Up @@ -61,7 +63,15 @@ internal val FirDeclaration.ktDeclaration: KtDeclaration
get() {
val psi = psi
?: error("PSI element was not found for${render()}")
return psi as KtDeclaration
return psi as? KtDeclaration
?: error(
"""
FirDeclaration.psi (${this::class.simpleName}) should be KtDeclaration but was ${psi::class.simpleName}
${(psi as? KtElement)?.getElementTextInContext() ?: psi.text}
${render()}
""".trimIndent()
)
}

internal val FirDeclaration.containingKtFileIfAny: KtFile?
Expand Down

0 comments on commit 164f4d1

Please sign in to comment.