Fix usages of AnalyzerUtil
Sadly contains some changes that hard to merge into appropriate commits introduced after rebasing repeatedly
This commit is contained in:
@@ -32,20 +32,36 @@ import org.jetbrains.kotlin.types.expressions.JetTypeInfo
|
||||
jvmOverloads
|
||||
public fun JetExpression.computeTypeInfoInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
isStatement: Boolean = false
|
||||
): JetTypeInfo {
|
||||
return getResolutionFacade().frontendService<ExpressionTypingServices>(this).getTypeInfo(scope, this, expectedType, dataFlowInfo, trace)
|
||||
return contextExpression.getResolutionFacade().frontendService<ExpressionTypingServices>(contextExpression)
|
||||
.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
|
||||
}
|
||||
|
||||
jvmOverloads
|
||||
public fun JetExpression.analyzeInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
isStatement: Boolean = false
|
||||
): BindingContext {
|
||||
computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType, isStatement)
|
||||
return trace.getBindingContext()
|
||||
}
|
||||
|
||||
jvmOverloads
|
||||
public fun JetExpression.computeTypeInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
|
||||
): BindingContext {
|
||||
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType)
|
||||
return trace.getBindingContext()
|
||||
): JetType? {
|
||||
return computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType).type
|
||||
}
|
||||
|
||||
+2
-2
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
public class CodeFragmentAnalyzer(
|
||||
private val resolveSession: ResolveSession,
|
||||
@@ -57,7 +56,8 @@ public class CodeFragmentAnalyzer(
|
||||
codeFragmentExpression,
|
||||
TypeUtils.NO_EXPECTED_TYPE,
|
||||
dataFlowInfo,
|
||||
trace
|
||||
trace,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||
import org.jetbrains.kotlin.idea.imports.getImportableTargets
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -339,7 +339,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
|
||||
|
||||
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, qualifiedExpression] ?: return false
|
||||
val selectorCopy = selector.copy() as JetReferenceExpression
|
||||
val newContext = selectorCopy.analyzeInContext(scope)
|
||||
val newContext = selectorCopy.analyzeInContext(scope, selector)
|
||||
val targetsWhenShort = (selectorCopy.getCalleeExpressionIfAny() as JetReferenceExpression).targets(newContext)
|
||||
val targetsMatch = targetsWhenShort.singleOrNull()?.asString() == target.asString()
|
||||
|
||||
@@ -386,7 +386,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
|
||||
|
||||
val targetBefore = thisExpression.getInstanceReference().targets(bindingContext).singleOrNull() ?: return
|
||||
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, thisExpression] ?: return
|
||||
val newContext = simpleThis.analyzeInContext(scope)
|
||||
val newContext = simpleThis.analyzeInContext(scope, thisExpression)
|
||||
val targetAfter = simpleThis.getInstanceReference().targets(newContext).singleOrNull()
|
||||
if (targetBefore == targetAfter) {
|
||||
addElementToShorten(thisExpression)
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AddForLoopIndicesIntention : JetSelfTargetingRangeIntention<JetForE
|
||||
val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, element] ?: return null
|
||||
val potentialExpression = createWithIndexExpression(loopRange)
|
||||
|
||||
val newBindingContext = potentialExpression.analyzeInContext(resolutionScope)
|
||||
val newBindingContext = potentialExpression.analyzeInContext(resolutionScope, loopRange)
|
||||
val newResolvedCall = potentialExpression.getResolvedCall(newBindingContext) ?: return null
|
||||
if (newResolvedCall.resultingDescriptor.fqNameUnsafe.asString() != WITH_INDEX_FQ_NAME) return null
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.idea.intentions
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.idea.analysis.computeTypeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.CommentSaver
|
||||
@@ -97,8 +97,8 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen
|
||||
|
||||
val declaredType = (declaration.resolveToDescriptor() as? CallableDescriptor)?.getReturnType() ?: return false
|
||||
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
|
||||
val expressionType = expression.analyzeInContext(scope)
|
||||
return !expressionType.isError && expressionType.isSubtypeOf(declaredType)
|
||||
val expressionType = expression.computeTypeInContext(scope)
|
||||
return expressionType?.isSubtypeOf(declaredType) ?: false
|
||||
}
|
||||
|
||||
private fun calcValue(declaration: JetDeclarationWithBody): JetExpression? {
|
||||
|
||||
@@ -97,7 +97,14 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
val callExpressionCopy = ((qualifiedExpressionCopy as? JetQualifiedExpression)?.selectorExpression ?: qualifiedExpressionCopy) as JetCallExpression
|
||||
val newExpression = applyTo(callExpressionCopy, property.name)
|
||||
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
|
||||
val newBindingContext = newExpression.analyzeInContext(resolutionScope, bindingTrace, dataFlowInfo, expectedType, moduleDescriptor, isStatement = true)
|
||||
val newBindingContext = newExpression.analyzeInContext(
|
||||
resolutionScope,
|
||||
contextExpression = callExpression,
|
||||
trace = bindingTrace,
|
||||
dataFlowInfo = dataFlowInfo,
|
||||
expectedType = expectedType,
|
||||
isStatement = true
|
||||
)
|
||||
if (newBindingContext.diagnostics.any { it.severity == Severity.ERROR }) return null
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.idea.analysis.computeTypeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
@@ -681,9 +681,10 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
||||
if (valueType != null && !ErrorUtils.containsErrorType(valueType)) {
|
||||
val valueTypeWithoutExpectedType = value.computeTypeInContext(
|
||||
resolutionScope!!,
|
||||
expressionToBeReplaced,
|
||||
dataFlowInfo = bindingContext.getDataFlowInfo(expressionToBeReplaced)
|
||||
)
|
||||
if (ErrorUtils.containsErrorType(valueTypeWithoutExpectedType)) {
|
||||
if (valueTypeWithoutExpectedType == null || ErrorUtils.containsErrorType(valueTypeWithoutExpectedType)) {
|
||||
explicitType = valueType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.core.asExpression
|
||||
@@ -30,23 +28,25 @@ import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.intentions.InsertExplicitTypeArgumentsIntention
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.ArrayList
|
||||
import java.util.LinkedHashSet
|
||||
@@ -97,7 +97,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
val symbolScope = getResolutionScope(symbolDescriptor)
|
||||
val scope = ChainedScope(symbolDescriptor, "ReplaceWith resolution scope", ExplicitImportsScope(explicitlyImportedSymbols), symbolScope)
|
||||
|
||||
var bindingContext = expression.analyzeInContext(scope)
|
||||
var bindingContext = analyzeInContext(expression, symbolDescriptor, scope, resolutionFacade)
|
||||
|
||||
val typeArgsToAdd = ArrayList<Pair<JetCallExpression, JetTypeArgumentList>>()
|
||||
expression.forEachDescendantOfType<JetCallExpression> {
|
||||
@@ -112,7 +112,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
}
|
||||
|
||||
// reanalyze expression - new usages of type parameters may be added
|
||||
bindingContext = expression.analyzeInContext(scope)
|
||||
bindingContext = analyzeInContext(expression, symbolDescriptor, scope, resolutionFacade)
|
||||
}
|
||||
|
||||
val receiversToAdd = ArrayList<Pair<JetExpression, JetExpression>>()
|
||||
@@ -160,6 +160,18 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
return ReplacementExpression(expression, importFqNames)
|
||||
}
|
||||
|
||||
private fun analyzeInContext(
|
||||
expression: JetExpression,
|
||||
symbolDescriptor: CallableDescriptor,
|
||||
scope: ChainedScope,
|
||||
resolutionFacade: ResolutionFacade
|
||||
): BindingContext {
|
||||
val traceContext = BindingTraceContext()
|
||||
resolutionFacade.frontendService<ExpressionTypingServices>(symbolDescriptor.module)
|
||||
.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, traceContext, false)
|
||||
return traceContext.bindingContext
|
||||
}
|
||||
|
||||
private fun getResolutionScope(descriptor: DeclarationDescriptor): JetScope {
|
||||
return when (descriptor) {
|
||||
is PackageFragmentDescriptor -> {
|
||||
|
||||
+1
-5
@@ -66,19 +66,15 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.kotlin.psi.typeRefHelpers.TypeRefHelpersPackage;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -741,7 +737,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
JetSimpleNameExpression labelExpr = newExpr.getTargetLabel();
|
||||
if (labelExpr == null) continue;
|
||||
|
||||
BindingContext newContext = AnalysisPackage.analyzeInContext(newExpr, scope);
|
||||
BindingContext newContext = AnalysisPackage.analyzeInContext(newExpr, scope, originalExpr);
|
||||
|
||||
if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) {
|
||||
result.putValue(
|
||||
|
||||
+6
-4
@@ -42,9 +42,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
||||
import org.jetbrains.kotlin.idea.core.CorePackage;
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator;
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyIntention;
|
||||
import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention;
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.IntroducePackage;
|
||||
@@ -65,10 +65,12 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
@@ -137,7 +139,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
||||
|
||||
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
|
||||
JetType typeNoExpectedType = AnalysisPackage.computeTypeInfoInContext(
|
||||
expression, scope, bindingTrace, dataFlowInfo
|
||||
expression, scope, expression, bindingTrace, dataFlowInfo
|
||||
).getType();
|
||||
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
|
||||
typeNoExpectedType)) {
|
||||
|
||||
Reference in New Issue
Block a user