All RESOLVED_CALL getters replaced with util methods

JetElement.getResolvedCall(BindingContext)
  JetElement.getResolvedCallForSure(BindingContext)
This commit is contained in:
Svetlana Isakova
2014-07-02 18:26:38 +04:00
parent e1fb5a9a04
commit 72e9822d99
59 changed files with 319 additions and 392 deletions
@@ -36,8 +36,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.jet.renderer.DescriptorRenderer.FQ_NAMES_IN_TYPES
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public object ShortenReferences {
public fun process(element: JetElement) {
@@ -318,8 +318,7 @@ public object ShortenReferences {
private fun resolveState(referenceExpression: JetReferenceExpression, bindingContext: BindingContext): Any? {
val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]
if (target != null) {
val resolvedCallKey = (referenceExpression.getParent() as? JetThisExpression) ?: referenceExpression
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, resolvedCallKey]
val resolvedCall = referenceExpression.getResolvedCall(bindingContext)
if (resolvedCall != null) return resolvedCall.asString()
return target.asString()
@@ -43,6 +43,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.jet.lang.resolve.extension.InlineAnalyzerExtension;
@@ -281,16 +282,9 @@ public class JetPositionManager implements PositionManager {
parent = parent.getParent();
}
if ((parent == null || !(parent instanceof JetBinaryExpression)) && !(parent instanceof JetCallExpression)) return false;
ResolvedCall<?> call = null;
if (parent instanceof JetCallExpression) {
call = context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) parent).getCalleeExpression());
}
if (parent instanceof JetBinaryExpression) {
call = context.get(BindingContext.RESOLVED_CALL, ((JetBinaryExpression) parent).getOperationReference());
}
if (!(parent instanceof JetElement)) return false;
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall((JetElement) parent, context);
if (call == null) return false;
InlineStrategy inlineType = InlineUtil.getInlineType(call.getResultingDescriptor());
@@ -20,7 +20,6 @@ import com.intellij.debugger.actions.JvmSmartStepIntoHandler
import com.intellij.debugger.SourcePosition
import com.intellij.debugger.actions.SmartStepTarget
import java.util.Collections
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.debugger.actions.MethodSmartStepTarget
import com.intellij.util.containers.OrderedSet
import com.intellij.util.Range
@@ -30,7 +29,6 @@ import org.jetbrains.jet.asJava.LightClassUtil
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
import com.intellij.psi.PsiElement
import com.intellij.util.text.CharArrayUtil
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import com.intellij.debugger.engine.MethodFilter
@@ -38,11 +36,9 @@ import com.intellij.debugger.engine.BasicStepMethodFilter
import com.intellij.debugger.engine.DebugProcessImpl
import com.sun.jdi.Location
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiFile
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiClass
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
@@ -127,7 +123,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
}
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, expression]
val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall != null) {
val propertyDescriptor = resolvedCall.getResultingDescriptor()
if (propertyDescriptor is PropertyDescriptor) {
@@ -162,7 +158,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
}
private fun recordFunction(expression: JetExpression) {
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, expression]
val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall == null) return
val descriptor = resolvedCall.getResultingDescriptor()
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
@@ -62,7 +63,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
@Override
public void visitReferenceExpression(@NotNull JetReferenceExpression expression) {
super.visitReferenceExpression(expression);
ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression);
ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) {
// Deprecated for invoke()
JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class);
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.types.JetType;
@@ -66,28 +67,26 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
@Override
public void visitCallExpression(@NotNull JetCallExpression expression) {
JetExpression callee = expression.getCalleeExpression();
if (callee instanceof JetReferenceExpression) {
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, (JetReferenceExpression) callee);
if (resolvedCall != null) {
DeclarationDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
JetPsiChecker.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor)
? JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL
: JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
if (callee instanceof JetReferenceExpression && resolvedCall != null) {
DeclarationDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
JetPsiChecker.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor)
? JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL
: JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
}
else {
if (calleeDescriptor instanceof ConstructorDescriptor) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
}
else {
if (calleeDescriptor instanceof ConstructorDescriptor) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
else if (calleeDescriptor instanceof FunctionDescriptor) {
FunctionDescriptor fun = (FunctionDescriptor) calleeDescriptor;
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
if (DescriptorUtils.isTopLevelDeclaration(fun)) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.PACKAGE_FUNCTION_CALL);
}
else if (calleeDescriptor instanceof FunctionDescriptor) {
FunctionDescriptor fun = (FunctionDescriptor) calleeDescriptor;
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
if (DescriptorUtils.isTopLevelDeclaration(fun)) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.PACKAGE_FUNCTION_CALL);
}
if (fun.getReceiverParameter() != null) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL);
}
if (fun.getReceiverParameter() != null) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL);
}
}
}
@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
@@ -29,6 +28,7 @@ import kotlin.properties.Delegates
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetIfExpression
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
"convert.assert.to.if.with.throw", javaClass()) {
@@ -43,7 +43,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
if (!(arguments == 1 && (lambdas == 1 || lambdas == 0)) && arguments != 2) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false
val valParameters = resolvedCall.getResultingDescriptor().getValueParameters()
@@ -19,26 +19,17 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.lang.psi.JetCallableReferenceExpression
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import kotlin.properties.Delegates
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetIfExpression
import org.jetbrains.jet.plugin.intentions.branchedTransformations.extractExpressionIfSingle
import org.jetbrains.jet.lang.psi.JetThrowExpression
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.jet.renderer.DescriptorRenderer
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetUserType
import org.jetbrains.jet.plugin.intentions.branchedTransformations.isNullExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertIfWithThrowToAssertIntention :
JetSelfTargetingIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) {
@@ -58,7 +49,7 @@ public class ConvertIfWithThrowToAssertIntention :
if (paramAmount > 1) return false
val context = AnalyzerFacadeWithCache.getContextForElement(thrownExpr)
val resolvedCall = context[BindingContext.RESOLVED_CALL, thrownExpr.getCalleeExpression()]
val resolvedCall = thrownExpr.getResolvedCall(context)
if (resolvedCall == null) return false
return DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() == "java.lang.AssertionError.<init>"
@@ -24,10 +24,9 @@ import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.psi.JetBinaryExpression
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetPsiUtil
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpression>("convert.to.for.each.loop.intention", javaClass()) {
private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? {
@@ -75,16 +74,14 @@ public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpres
}
}
val callee = JetPsiUtil.getCalleeExpressionIfAny(element)
val functionLiteral = getFunctionLiteralArgument(element)
if (callee != null &&
functionLiteral != null &&
if (functionLiteral != null &&
isWellFormedFunctionLiteral(functionLiteral) &&
checkTotalNumberOfArguments(element)) {
val context = element.getContainingJetFile().getLazyResolveSession().resolveToElement(callee)
val resolvedCall = context[BindingContext.RESOLVED_CALL, callee]
val context = element.getContainingJetFile().getLazyResolveSession().resolveToElement(element)
val resolvedCall = element.getResolvedCall(context)
val functionFqName = if (resolvedCall != null) DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() else null
return "kotlin.forEach".equals(functionFqName);
@@ -19,11 +19,11 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.types.ErrorUtils
import org.jetbrains.jet.renderer.DescriptorRenderer
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>(
"insert.explicit.type.arguments", javaClass()) {
@@ -40,7 +40,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false
val types = resolvedCall.getTypeArguments()
@@ -49,7 +49,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
override fun applyTo(element: JetCallExpression, editor: Editor) {
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return
val args = resolvedCall.getTypeArguments()
@@ -19,8 +19,8 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.caches.resolve.getBindingContext
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<JetCallExpression>(
"move.lambda.inside.parentheses", javaClass()) {
@@ -44,7 +44,7 @@ public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<Je
}
if (element.getValueArguments().any { it?.getArgumentName() != null}) {
val context = element.getBindingContext()
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val resolvedCall = element.getResolvedCall(context)
val literalName = resolvedCall?.getResultingDescriptor()?.getValueParameters()?.last?.getName().toString()
sb.append("$literalName = ")
}
@@ -29,12 +29,8 @@ import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElementSelector
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>("operator.to.function", javaClass()) {
fun isApplicablePrefix(element: JetPrefixExpression): Boolean {
@@ -60,7 +56,8 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
}
fun isApplicableCall(element: JetCallExpression): Boolean {
val resolvedCall = AnalyzerFacadeWithCache.getContextForElement(element)[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = element.getResolvedCall(bindingContext)
val descriptor = resolvedCall?.getResultingDescriptor()
if (descriptor is FunctionDescriptor && descriptor.getName().asString() == "invoke") {
val parent = element.getParent()
@@ -129,7 +126,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
}
val context = AnalyzerFacadeWithCache.getContextForElement(element)
val functionCandidate = context[BindingContext.RESOLVED_CALL, element.getOperationReference()]
val functionCandidate = element.getResolvedCall(context)
val functionName = functionCandidate?.getCandidateDescriptor()?.getName().toString()
val elemType = context[BindingContext.EXPRESSION_TYPE, left]
@@ -32,11 +32,10 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.lang.psi.JetTypeArgumentList
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetReturnExpression
import org.jetbrains.jet.lang.psi.JetDeclaration
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation
public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgumentList>(
"remove.explicit.type.arguments", javaClass()) {
@@ -52,9 +51,9 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
val injector = InjectorForMacros(callExpression.getProject(), resolveSession.getModuleDescriptor())
val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression]
val originalCall = context[BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()]?.getCall()
val originalCall = callExpression.getResolvedCall(context)
if (originalCall == null || scope !is JetScope) return false
val untypedCall = CallWithoutTypeArgs(originalCall)
val untypedCall = CallWithoutTypeArgs(originalCall.getCall())
// todo Check with expected type for other expressions
// If always use expected type from trace there is a problem with nested calls:
@@ -74,11 +73,13 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
TypeUtils.NO_EXPECTED_TYPE
}
val dataFlow = context[BindingContext.EXPRESSION_DATA_FLOW_INFO, callExpression] ?: DataFlowInfo.EMPTY
val resolvedCall = injector.getExpressionTypingServices()?.getCallResolver()?.resolveFunctionCall(
val resolutionResults = injector.getExpressionTypingServices()?.getCallResolver()?.resolveFunctionCall(
BindingTraceContext(), scope, untypedCall, jType, dataFlow, false)
assert (resolutionResults?.isSingleResult() ?: true) { "Removing type arguments changed resolve for: " +
"${callExpression.getTextWithLocation()} to ${resolutionResults?.getResultCode()}" }
val args = context[BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()]?.getTypeArguments()
val newArgs = resolvedCall?.getResultingCall()?.getTypeArguments()
val args = originalCall.getTypeArguments()
val newArgs = resolutionResults?.getResultingCall()?.getTypeArguments()
return args == newArgs
}
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.types.PackageType
import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils
import org.jetbrains.jet.lang.psi.JetPsiFactory
import com.intellij.codeInsight.hint.HintManager
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
override fun isApplicableTo(element: JetCallExpression): Boolean {
@@ -48,21 +49,19 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent
val parent = element.getParent()
if (parent is JetDotQualifiedExpression) {
val callee = element.getCalleeExpression()
val typeArguments = element.getTypeArgumentList()
val valueArguments = element.getValueArgumentList()
val functionLiteralArguments = element.getFunctionLiteralArguments()
val numOfTotalValueArguments = (valueArguments?.getArguments()?.size() ?: 0) + functionLiteralArguments.size()
if (typeArguments?.getArguments()?.size() ?: 0 == 0 &&
numOfTotalValueArguments == 1 &&
callee != null) {
numOfTotalValueArguments == 1) {
if (valueArguments?.getArguments()?.size() == 1 && valueArguments?.getArguments()?.first()?.isNamed() ?: false) {
val file = element.getContainingJetFile()
val bindingContext = file.getBindingContext()
val resolvedCallDescriptor = bindingContext[BindingContext.RESOLVED_CALL, callee]
val valueArgumentsMap = resolvedCallDescriptor?.getValueArguments()
val resolvedCall = element.getResolvedCall(bindingContext)
val valueArgumentsMap = resolvedCall?.getValueArguments()
val firstArgument = valueArguments?.getArguments()?.first()
return valueArgumentsMap?.keySet()?.any { it.getName().asString() == firstArgument?.getArgumentName()?.getText() && it.getIndex() == 0 } ?: false
@@ -24,7 +24,6 @@ import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.ValueArgument
import org.jetbrains.jet.plugin.JetBundle
import org.jetbrains.jet.lang.resolve.calls.model.DefaultValueArgument
@@ -33,6 +32,7 @@ import org.jetbrains.jet.plugin.util.Maybe
import org.jetbrains.jet.plugin.util.MaybeError
import org.jetbrains.jet.plugin.util.MaybeValue
import com.intellij.codeInsight.hint.HintManager
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
// Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription.
public class CallDescription internal (
@@ -87,15 +87,14 @@ public class CallDescription internal (
}
public fun JetQualifiedExpression.toCallDescription(): CallDescription? {
val call = getSelectorExpression()
if (call !is JetCallExpression) return null
val callExpression = getSelectorExpression() as? JetCallExpression ?: return null
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(call)
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(callExpression)
// This should work. Nothing that returns a CallableDescriptor returns null and (out T is T)
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, call.getCalleeExpression()] ?:
val resolvedCall = callExpression.getResolvedCall(bindingContext) ?:
return null
return CallDescription(this, call, resolvedCall)
return CallDescription(this, callExpression, resolvedCall)
}
public abstract class AttributeCallReplacementIntention(name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) {
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
@@ -66,7 +67,7 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
if (!(callee instanceof JetReferenceExpression)) return Collections.emptyList();
BindingContext context = ResolvePackage.getBindingContext(argument.getContainingJetFile());
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, (JetReferenceExpression) callee);
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callElement, context);
if (resolvedCall == null) return Collections.emptyList();
CallableDescriptor callableDescriptor = resolvedCall.getResultingDescriptor();
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.ErrorUtils;
@@ -183,7 +184,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression";
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile());
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall == null) return null;
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
if (!(compareTo instanceof JetFunction)) return null;
@@ -26,6 +26,8 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
@@ -69,8 +71,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
// Fixing overloaded operators:
if (expression instanceof JetOperationExpression) {
ResolvedCall<?> resolvedCall =
context.get(BindingContext.RESOLVED_CALL, ((JetOperationExpression) expression).getOperationReference());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) {
@@ -81,7 +82,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
if (expression.getParent() instanceof JetBinaryExpression) {
JetBinaryExpression parentBinary = (JetBinaryExpression) expression.getParent();
if (parentBinary.getRight() == expression) {
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, parentBinary.getOperationReference());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(parentBinary, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) {
@@ -94,8 +95,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
// Change function return type when TYPE_MISMATCH is reported on call expression:
if (expression instanceof JetCallExpression) {
ResolvedCall<?> resolvedCall =
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) {
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
@@ -107,7 +108,7 @@ public class QuickFixUtil {
@Nullable
public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) {
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile());
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context);
if (resolvedCall == null) return null;
PsiElement declaration = safeGetDeclaration(context, resolvedCall);
if (declaration instanceof JetFunction) {
@@ -27,7 +27,6 @@ import kotlin.properties.Delegates
import java.util.HashMap
import org.jetbrains.jet.plugin.codeInsight.JetFileReferencesResolver
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lang.psi.JetThisExpression
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil
import java.util.Collections
@@ -46,11 +45,11 @@ import org.jetbrains.jet.lang.psi.JetDeclaration
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
import org.jetbrains.jet.lang.psi.JetUserType
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.jet.lang.psi.JetParameter
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.psi.JetFunctionLiteral
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
data class ExtractionOptions(val inferUnitTypeForUnusedValues: Boolean) {
class object {
@@ -116,8 +115,7 @@ class ExtractionData(
for ((ref, context) in JetFileReferencesResolver.resolve(originalFile, getExpressions())) {
if (ref !is JetSimpleNameExpression) continue
val resolvedCallKey = (ref.getParent() as? JetThisExpression) ?: ref
val resolvedCall = context[BindingContext.RESOLVED_CALL, resolvedCallKey]?.let {
val resolvedCall = ref.getResolvedCall(context)?.let {
(it as? VariableAsFunctionResolvedCall)?.functionCall ?: it
}
@@ -53,6 +53,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
@@ -320,11 +321,13 @@ public class KotlinInlineValHandler extends InlineActionHandler {
ResolveSessionForBodies resolveSessionForBodies = ResolvePackage.getLazyResolveSession(containingFile);
for (JetExpression inlinedExpression : inlinedExpressions) {
JetCallExpression callExpression = getCallExpression(inlinedExpression);
assert callExpression != null : "can't find call expression for " + inlinedExpression.getText();
BindingContext context = resolveSessionForBodies.resolveToElement(inlinedExpression);
Call call = BindingContextUtilPackage.getCallWithAssert(inlinedExpression, context);
if (hasIncompleteTypeInferenceDiagnostic(callExpression, resolveSessionForBodies) && callExpression.getTypeArgumentList() == null) {
callsToAddArguments.add(callExpression);
JetElement callElement = call.getCallElement();
if (callElement instanceof JetCallExpression && hasIncompleteTypeInferenceDiagnostic(call, context) &&
call.getTypeArgumentList() == null) {
callsToAddArguments.add((JetCallExpression) callElement);
}
}
@@ -337,17 +340,9 @@ public class KotlinInlineValHandler extends InlineActionHandler {
@Nullable
private static String getTypeArgumentsStringForCall(@NotNull JetExpression initializer) {
JetCallExpression callExpression = getCallExpression(initializer);
if (callExpression == null) {
return null;
}
JetExpression callee = callExpression.getCalleeExpression();
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(initializer);
ResolvedCall<?> call = context.get(BindingContext.RESOLVED_CALL, callee);
if (call == null) {
return null;
}
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(initializer, context);
if (call == null) return null;
List<JetType> typeArguments = Lists.newArrayList();
Map<TypeParameterDescriptor, JetType> typeArgumentMap = call.getTypeArguments();
@@ -364,11 +359,10 @@ public class KotlinInlineValHandler extends InlineActionHandler {
}
private static boolean hasIncompleteTypeInferenceDiagnostic(
@NotNull JetCallExpression callExpression,
@NotNull ResolveSessionForBodies resolveSessionForBodies
@NotNull Call call,
@NotNull BindingContext context
) {
JetExpression callee = callExpression.getCalleeExpression();
BindingContext context = resolveSessionForBodies.resolveToElement(callExpression);
JetExpression callee = call.getCalleeExpression();
for (Diagnostic diagnostic : context.getDiagnostics()) {
if (diagnostic.getFactory() == Errors.TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER && diagnostic.getPsiElement() == callee) {
return true;
@@ -393,20 +387,4 @@ public class KotlinInlineValHandler extends InlineActionHandler {
}
return (JetExpression) referenceElement.replace(newExpression.copy());
}
@Nullable
private static JetCallExpression getCallExpression(@NotNull JetExpression expression) {
if (expression instanceof JetParenthesizedExpression) {
JetExpression inner = ((JetParenthesizedExpression) expression).getExpression();
return inner == null ? null : getCallExpression(inner);
}
if (expression instanceof JetCallExpression) {
return (JetCallExpression) expression;
}
if (expression instanceof JetQualifiedExpression) {
JetExpression selector = ((JetQualifiedExpression) expression).getSelectorExpression();
return selector == null ? null : getCallExpression(selector);
}
return null;
}
}
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -61,6 +62,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
private static final String INTRODUCE_VARIABLE = JetRefactoringBundle.message("introduce.variable");
@@ -487,8 +490,8 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
JetSimpleNameExpression expr1 = (JetSimpleNameExpression)element1.getParent();
JetSimpleNameExpression expr2 = (JetSimpleNameExpression)element2.getParent();
ResolvedCall<?> rc1 = bindingContext.get(BindingContext.RESOLVED_CALL, expr1);
ResolvedCall<?> rc2 = bindingContext.get(BindingContext.RESOLVED_CALL, expr2);
ResolvedCall<?> rc1 = getResolvedCall(expr1, bindingContext);
ResolvedCall<?> rc2 = getResolvedCall(expr2, bindingContext);
return (rc1 != null && rc2 != null) && compareCalleesAndReceivers(rc1, rc2) ? 0 : 1;
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lexer.JetTokens;
@@ -32,9 +33,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> implements MultiRangeReference {
public JetInvokeFunctionReference(@NotNull JetCallExpression expression) {
@@ -49,13 +47,12 @@ class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> i
@Override
@NotNull
protected Collection<DeclarationDescriptor> getTargetDescriptors(@NotNull BindingContext context) {
JetExpression calleeExpression = getExpression().getCalleeExpression();
ResolvedCall<?> resolvedCall = context.get(RESOLVED_CALL, calleeExpression);
Call call = BindingContextUtilPackage.getCall(getElement(), context);
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(call, context);
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
return Collections.<DeclarationDescriptor>singleton(
((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor());
}
Call call = context.get(CALL, calleeExpression);
if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) {
return Collections.<DeclarationDescriptor>singleton(resolvedCall.getCandidateDescriptor());
}