Rename: analyzeFullyAndGetResult -> analyzeWithAllCompilerChecks in resolutionApi.kt

This commit is contained in:
Nikolay Krasko
2018-03-22 13:16:30 +03:00
parent 804d340c5f
commit f2b478f304
12 changed files with 27 additions and 25 deletions
@@ -140,14 +140,14 @@ fun KtElement.analyzeFully(): BindingContext = getResolutionFacade().analyzeFull
// for the given element and its children (including diagnostics, trace slices, descriptors, etc.) // for the given element and its children (including diagnostics, trace slices, descriptors, etc.)
// Not recommended to call both of them without real need // Not recommended to call both of them without real need
// See also KotlinResolveCache, KotlinResolveDataProvider // See also KotlinResolveCache, KotlinResolveDataProvider
fun KtFile.analyzeFullyAndGetResult(vararg extraFiles: KtFile): AnalysisResult = fun KtFile.analyzeWithAllCompilerChecks(vararg extraFiles: KtFile): AnalysisResult =
KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this) + extraFiles.toList()).analyzeFullyAndGetResult(listOf(this)) KotlinCacheService.getInstance(project).getResolutionFacade(listOf(this) + extraFiles.toList()).analyzeFullyAndGetResult(listOf(this))
@Deprecated( @Deprecated(
"Use either KtFile.analyzeFullyAndGetResult() or KtElement.analyzeAndGetResult()", "Use either KtFile.analyzeWithAllCompilerChecks() or KtElement.analyzeAndGetResult()",
ReplaceWith("analyzeAndGetResult()") ReplaceWith("analyzeAndGetResult()")
) )
fun KtElement.analyzeFullyAndGetResult(): AnalysisResult = getResolutionFacade().analyzeFullyAndGetResult(listOf(this)) fun KtElement.analyzeWithAllCompilerChecks(): AnalysisResult = getResolutionFacade().analyzeFullyAndGetResult(listOf(this))
// this method don't check visibility and collect all descriptors with given fqName // this method don't check visibility and collect all descriptors with given fqName
fun ResolutionFacade.resolveImportReference( fun ResolutionFacade.resolveImportReference(
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
import org.jetbrains.kotlin.idea.quickfix.QuickFixes import org.jetbrains.kotlin.idea.quickfix.QuickFixes
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
@@ -64,7 +64,7 @@ open class KotlinPsiChecker : Annotator, HighlightRangeExtension {
if (!KotlinHighlightingUtil.shouldHighlight(file)) return if (!KotlinHighlightingUtil.shouldHighlight(file)) return
val analysisResult = file.analyzeFullyAndGetResult() val analysisResult = file.analyzeWithAllCompilerChecks()
if (analysisResult.isError()) { if (analysisResult.isError()) {
throw ProcessCanceledException(analysisResult.error) throw ProcessCanceledException(analysisResult.error)
} }
@@ -72,7 +72,7 @@ class ResolveElementCache(
} }
} }
// drop whole cache after change "out of code block" // drop whole cache after change "out of code block", each entry is checked with own modification stamp
private val fullResolveCache: CachedValue<MutableMap<KtElement, CachedFullResolve>> = private val fullResolveCache: CachedValue<MutableMap<KtElement, CachedFullResolve>> =
CachedValuesManager.getManager(project).createCachedValue( CachedValuesManager.getManager(project).createCachedValue(
CachedValueProvider<MutableMap<KtElement, ResolveElementCache.CachedFullResolve>> { CachedValueProvider<MutableMap<KtElement, ResolveElementCache.CachedFullResolve>> {
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.debugger.BinaryCacheKey import org.jetbrains.kotlin.idea.debugger.BinaryCacheKey
import org.jetbrains.kotlin.idea.debugger.BytecodeDebugInfo import org.jetbrains.kotlin.idea.debugger.BytecodeDebugInfo
import org.jetbrains.kotlin.idea.debugger.WeakBytecodeDebugInfoStorage import org.jetbrains.kotlin.idea.debugger.WeakBytecodeDebugInfoStorage
@@ -183,7 +183,7 @@ class KotlinDebuggerCaches(project: Project) {
private fun createTypeMapperForSourceFile(file: KtFile): KotlinTypeMapper = private fun createTypeMapperForSourceFile(file: KtFile): KotlinTypeMapper =
runInReadActionWithWriteActionPriorityWithPCE { runInReadActionWithWriteActionPriorityWithPCE {
createTypeMapper(file, file.analyzeFullyAndGetResult().apply(AnalysisResult::throwIfError)) createTypeMapper(file, file.analyzeWithAllCompilerChecks().apply(AnalysisResult::throwIfError))
} }
private fun createTypeMapper(file: KtFile, analysisResult: AnalysisResult): KotlinTypeMapper { private fun createTypeMapper(file: KtFile, analysisResult: AnalysisResult): KotlinTypeMapper {
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.console.KotlinConsoleKeeper import org.jetbrains.kotlin.console.KotlinConsoleKeeper
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.debugger.DebuggerUtils import org.jetbrains.kotlin.idea.debugger.DebuggerUtils
import org.jetbrains.kotlin.idea.refactoring.getLineNumber import org.jetbrains.kotlin.idea.refactoring.getLineNumber
@@ -164,7 +164,7 @@ class KtCompilingExecutor(file: ScratchFile) : ScratchExecutor(file) {
return@runReadAction false return@runReadAction false
} }
val analysisResult = psiFile.analyzeFullyAndGetResult() val analysisResult = psiFile.analyzeWithAllCompilerChecks()
if (analysisResult.isError()) { if (analysisResult.isError()) {
handlers.forEach { it.error(file, analysisResult.error.message ?: "Couldn't compile ${psiFile.name}") } handlers.forEach { it.error(file, analysisResult.error.message ?: "Couldn't compile ${psiFile.name}") }
@@ -26,7 +26,7 @@ import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiChecker import org.jetbrains.kotlin.idea.highlighter.KotlinPsiChecker
import org.jetbrains.kotlin.idea.quickfix.CleanupFix import org.jetbrains.kotlin.idea.quickfix.CleanupFix
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
@@ -50,7 +50,7 @@ class KotlinCleanupInspection : LocalInspectionTool(), CleanupLocalInspectionToo
return null return null
} }
val analysisResult = file.analyzeFullyAndGetResult() val analysisResult = file.analyzeWithAllCompilerChecks()
if (analysisResult.isError()) { if (analysisResult.isError()) {
throw ProcessCanceledException(analysisResult.error) throw ProcessCanceledException(analysisResult.error)
} }
@@ -41,7 +41,9 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.idea.caches.resolve.* import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaClassDescriptor import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaClassDescriptor
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.* import org.jetbrains.kotlin.idea.core.*
@@ -161,7 +163,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
private val elementsToShorten = ArrayList<KtElement>() private val elementsToShorten = ArrayList<KtElement>()
private fun updateCurrentModule() { private fun updateCurrentModule() {
_currentFileModule = config.currentFile.analyzeFullyAndGetResult().moduleDescriptor _currentFileModule = config.currentFile.analyzeWithAllCompilerChecks().moduleDescriptor
} }
fun computeTypeCandidates(typeInfo: TypeInfo): List<TypeCandidate> = fun computeTypeCandidates(typeInfo: TypeInfo): List<TypeCandidate> =
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.CallableInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.CallableInfo
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.FunctionInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.FunctionInfo
@@ -45,7 +45,7 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
val variableExpr: KtExpression = ((element.loopParameter ?: element.destructuringDeclaration) ?: return null) as KtExpression val variableExpr: KtExpression = ((element.loopParameter ?: element.destructuringDeclaration) ?: return null) as KtExpression
val iterableType = TypeInfo(iterableExpr, Variance.IN_VARIANCE) val iterableType = TypeInfo(iterableExpr, Variance.IN_VARIANCE)
val (bindingContext, moduleDescriptor) = file.analyzeFullyAndGetResult() val (bindingContext, moduleDescriptor) = file.analyzeWithAllCompilerChecks()
val returnJetType = moduleDescriptor.builtIns.iterator.defaultType val returnJetType = moduleDescriptor.builtIns.iterator.defaultType
val returnJetTypeParameterTypes = variableExpr.guessTypes(bindingContext, moduleDescriptor) val returnJetTypeParameterTypes = variableExpr.guessTypes(bindingContext, moduleDescriptor)
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.refactoring.canRefactor
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes
import org.jetbrains.kotlin.idea.refactoring.canRefactor
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinTypeInfo import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinTypeInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar
@@ -38,7 +38,7 @@ object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUsageFact
} }
override fun extractFixData(element: KtValueArgument, diagnostic: Diagnostic): CreateParameterData<KtValueArgument>? { override fun extractFixData(element: KtValueArgument, diagnostic: Diagnostic): CreateParameterData<KtValueArgument>? {
val result = (diagnostic.psiFile as? KtFile)?.analyzeFullyAndGetResult() ?: return null val result = (diagnostic.psiFile as? KtFile)?.analyzeWithAllCompilerChecks() ?: return null
val context = result.bindingContext val context = result.bindingContext
val name = element.getArgumentName()?.text ?: return null val name = element.getArgumentName()?.text ?: return null
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getExpressionForTypeGuess import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getExpressionForTypeGuess
@@ -51,7 +51,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<KtSim
} }
fun extractFixData(element: KtSimpleNameExpression): CreateParameterData<KtSimpleNameExpression>? { fun extractFixData(element: KtSimpleNameExpression): CreateParameterData<KtSimpleNameExpression>? {
val (context, moduleDescriptor) = (element.containingFile as? KtFile)?.analyzeFullyAndGetResult() ?: return null val (context, moduleDescriptor) = (element.containingFile as? KtFile)?.analyzeWithAllCompilerChecks() ?: return null
val varExpected = element.getAssignmentByLHS() != null val varExpected = element.getAssignmentByLHS() != null
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.highlighter
import com.intellij.psi.PsiComment import com.intellij.psi.PsiComment
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
@@ -21,7 +21,7 @@ abstract class AbstractDslHighlighterTest : LightCodeInsightFixtureTestCase() {
protected fun doTest(filePath: String) { protected fun doTest(filePath: String) {
val psiFile = myFixture.configureByFile(filePath) as KtFile val psiFile = myFixture.configureByFile(filePath) as KtFile
val extension = DslHighlighterExtension() val extension = DslHighlighterExtension()
val bindingContext = psiFile.analyzeFullyAndGetResult().bindingContext val bindingContext = psiFile.analyzeWithAllCompilerChecks().bindingContext
fun checkCall(element: KtElement) { fun checkCall(element: KtElement) {
val call = element.getResolvedCall(bindingContext) ?: return val call = element.getResolvedCall(bindingContext) ?: return
@@ -54,7 +54,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.jsonUtils.getNullableString import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
import org.jetbrains.kotlin.idea.jsonUtils.getString import org.jetbrains.kotlin.idea.jsonUtils.getString
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
@@ -300,7 +300,7 @@ abstract class AbstractRenameTest : KotlinLightCodeInsightFixtureTestCase() {
doTestCommittingDocuments(context) { doTestCommittingDocuments(context) {
val ktFile = myFixture.configureFromTempProjectFile(mainFilePath) as KtFile val ktFile = myFixture.configureFromTempProjectFile(mainFilePath) as KtFile
val module = ktFile.analyzeFullyAndGetResult().moduleDescriptor val module = ktFile.analyzeWithAllCompilerChecks().moduleDescriptor
val (declaration, scopeToSearch) = if (classIdStr != null) { val (declaration, scopeToSearch) = if (classIdStr != null) {
module.findClassAcrossModuleDependencies(classIdStr.toClassId())!!.let { it to it.defaultType.memberScope } module.findClassAcrossModuleDependencies(classIdStr.toClassId())!!.let { it to it.defaultType.memberScope }