Cleanup: when possible, do analyzeFullyAndGetResult -> analyzeFully

Also, when possible, do analyzeAndGetResult -> analyze
This commit is contained in:
Mikhail Glukhikh
2017-04-06 18:01:35 +03:00
parent ceff19ee74
commit ba04dac4b7
10 changed files with 17 additions and 23 deletions
@@ -44,7 +44,6 @@ import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.quickfix.QuickFixes
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.test
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Document
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
@@ -33,7 +32,7 @@ import com.intellij.util.Consumer
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.LibraryModificationTracker
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
import org.jetbrains.kotlin.idea.util.application.runWriteAction
@@ -75,7 +74,7 @@ fun Module.configureAs(kind: ModuleKind) {
}
fun KtFile.dumpTextWithErrors(): String {
val diagnostics = analyzeFullyAndGetResult().bindingContext.diagnostics
val diagnostics = analyzeFully().diagnostics
val errors = diagnostics.filter { it.severity == Severity.ERROR }
if (errors.isEmpty()) return text
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
@@ -25,7 +25,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -120,7 +120,7 @@ class KotlinEditorTextProvider : EditorTextProvider {
return when {
newExpression is KtExpression -> newExpression
ktElement is KtSimpleNameExpression -> {
val context = ktElement.analyzeAndGetResult().bindingContext
val context = ktElement.analyze()
val qualifier = context[BindingContext.QUALIFIER, ktElement]
if (qualifier != null && !DescriptorUtils.isObject(qualifier.descriptor)) {
null
@@ -24,7 +24,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.util.ExceptionUtil
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
@@ -154,7 +154,7 @@ private fun KtFile.findContextElement(): KtElement? {
private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyableUserDataProperty(Key.create("DEBUG_SMART_CAST"))
private fun KtCodeFragment.markSmartCasts() {
val bindingContext = runInReadActionWithWriteActionPriority { analyzeFullyAndGetResult() }.bindingContext
val bindingContext = runInReadActionWithWriteActionPriority { analyzeFully() }
val factory = KtPsiFactory(project)
getContentElement()?.forEachDescendantOfType<KtExpression> { expression ->
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.setVisibility
import org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection
import org.jetbrains.kotlin.idea.intentions.*
@@ -237,7 +237,7 @@ object J2KPostProcessingRegistrar {
override fun createAction(element: KtElement, diagnostics: Diagnostics): (() -> Unit)? {
if (element !is KtBinaryExpressionWithTypeRHS) return null
val context = element.analyzeAndGetResult().bindingContext
val context = element.analyze()
val leftType = context.getType(element.left) ?: return null
val rightType = context.get(BindingContext.TYPE, element.right) ?: return null
@@ -262,7 +262,7 @@ object J2KPostProcessingRegistrar {
})
return null
val bindingContext = element.analyzeAndGetResult().bindingContext
val bindingContext = element.analyze()
val rightType = element.right?.getType(bindingContext) ?: return null
if (KotlinBuiltIns.isString(rightType)) {
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.project.builtIns
@@ -49,11 +49,10 @@ class ChangeFunctionLiteralReturnTypeFix(
private val appropriateQuickFix = createAppropriateQuickFix(functionLiteralExpression, type)
private fun createAppropriateQuickFix(functionLiteralExpression: KtLambdaExpression, type: KotlinType): IntentionAction? {
val analysisResult = functionLiteralExpression.containingKtFile.analyzeFullyAndGetResult()
val context = analysisResult.bindingContext
val context = functionLiteralExpression.containingKtFile.analyzeFully()
val functionLiteralType = context.getType(functionLiteralExpression) ?: error("Type of function literal not available in binding context")
val builtIns = analysisResult.moduleDescriptor.builtIns
val builtIns = functionLiteralType.constructor.builtIns
val functionClass = builtIns.getFunction(functionLiteralType.arguments.size - 1)
val functionClassTypeParameters = LinkedList<KotlinType>()
for (typeProjection in functionLiteralType.arguments) {
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject
import org.jetbrains.kotlin.idea.core.overrideImplement.generateMember
@@ -44,7 +44,7 @@ class SpecifyOverrideExplicitlyFix(
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val element = element ?: return
val context = element.analyzeFullyAndGetResult().bindingContext
val context = element.analyzeFully()
val delegatedDescriptor = context.diagnostics.forElement(element).mapNotNull {
if (it.factory == Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE)
Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE.cast(it).a
@@ -51,9 +51,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<KtSim
}
fun extractFixData(element: KtSimpleNameExpression): CreateParameterData<KtSimpleNameExpression>? {
val result = (element.containingFile as? KtFile)?.analyzeFullyAndGetResult() ?: return null
val context = result.bindingContext
val moduleDescriptor = result.moduleDescriptor
val (context, moduleDescriptor) = (element.containingFile as? KtFile)?.analyzeFullyAndGetResult() ?: return null
val varExpected = element.getAssignmentByLHS() != null
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.codeInliner.CallableUsageReplacementStrategy
@@ -127,7 +127,7 @@ class KotlinInlineFunctionHandler: InlineActionHandler() {
}
private fun KtNamedFunction.isRecursive(): Boolean {
val context = analyzeFullyAndGetResult().bindingContext
val context = analyzeFully()
return bodyExpression?.includesCallOf(context[BindingContext.FUNCTION, this] ?: return false, context) ?: false
}
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.search.usagesSearch.constructor
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand