From 72e9822d9970d576566ac04dfca4eb7bb8eaca55 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 2 Jul 2014 18:26:38 +0400 Subject: [PATCH] All RESOLVED_CALL getters replaced with util methods JetElement.getResolvedCall(BindingContext) JetElement.getResolvedCallForSure(BindingContext) --- .../jet/codegen/AnnotationCodegen.java | 4 +- .../jet/codegen/ExpressionCodegen.java | 51 +++++------ .../codegen/ImplementationBodyCodegen.java | 10 +-- .../jet/codegen/TailRecursionCodegen.java | 8 +- .../binding/CodegenAnnotatingVisitor.java | 5 +- .../codegen/intrinsics/JavaClassArray.java | 12 ++- .../codegen/intrinsics/JavaClassFunction.java | 9 +- .../intrinsics/MonitorInstruction.java | 7 +- .../jet/lang/cfg/JetControlFlowProcessor.java | 62 ++++++-------- .../lang/cfg/JetFlowInformationProvider.java | 6 +- .../evaluate/ConstantExpressionEvaluator.kt | 7 +- .../jetbrains/jet/lang/psi/JetPsiUtil.java | 24 ------ .../jet/lang/psi/psiUtil/jetPsiUtil.kt | 16 +++- .../jet/lang/resolve/AnnotationResolver.java | 3 +- .../jet/lang/resolve/BindingContextUtils.java | 19 +---- .../jet/lang/resolve/BindingContextUtils.kt | 85 ++++++++++++++----- .../resolve/DelegatedPropertyResolver.java | 4 +- .../lang/resolve/InlineDescriptorUtils.java | 4 +- .../jet/lang/resolve/calls/CallCompleter.kt | 4 +- .../lang/resolve/calls/CallTransformer.java | 2 +- .../calls/InlineCallResolverExtension.java | 12 ++- .../calls/autocasts/DataFlowValueFactory.java | 7 +- .../calls/tasks/TracingStrategyForInvoke.java | 1 + .../expressions/ExpressionTypingUtils.java | 3 +- .../inline/unaryExpressions/notOnCall.kt | 3 + .../checkers/JetDiagnosticsTestGenerated.java | 5 ++ .../calls/AbstractResolvedCallsTest.kt | 13 ++- .../plugin/codeInsight/ShortenReferences.kt | 5 +- .../plugin/debugger/JetPositionManager.java | 12 +-- .../debugger/KotlinSmartStepIntoHandler.kt | 10 +-- .../DeprecatedAnnotationVisitor.java | 3 +- .../FunctionsHighlightingVisitor.java | 39 +++++---- .../ConvertAssertToIfWithThrowIntention.kt | 4 +- .../ConvertIfWithThrowToAssertIntention.kt | 13 +-- .../ConvertToForEachLoopIntention.kt | 11 +-- .../intentions/InsertExplicitTypeArguments.kt | 6 +- .../MoveLambdaInsideParenthesesIntention.kt | 4 +- .../intentions/OperatorToFunctionIntention.kt | 11 +-- .../intentions/RemoveExplicitTypeArguments.kt | 17 ++-- .../ReplaceWithInfixFunctionCallIntention.kt | 9 +- .../AttributeCallReplacementIntention.kt | 11 ++- .../plugin/quickfix/AddNameToArgumentFix.java | 3 +- .../quickfix/ChangeFunctionReturnTypeFix.java | 3 +- .../QuickFixFactoryForTypeMismatchError.java | 10 +-- .../jet/plugin/quickfix/QuickFixUtil.java | 3 +- .../extractFunction/ExtractionData.kt | 6 +- .../inline/KotlinInlineValHandler.java | 46 +++------- .../KotlinIntroduceVariableHandler.java | 7 +- .../JetInvokeFunctionReference.java | 9 +- .../ClassInitializerTranslator.java | 5 +- .../operation/BinaryOperationTranslator.java | 4 +- .../OverloadedAssignmentTranslator.java | 4 +- .../OverloadedIncrementTranslator.java | 10 ++- .../operation/UnaryOperationTranslator.java | 4 +- .../AbstractCallExpressionTranslator.java | 5 +- .../InlinedCallExpressionTranslator.java | 2 +- .../reference/VariableAccessTranslator.java | 8 +- .../k2js/translate/utils/BindingUtils.java | 34 -------- .../k2js/translate/utils/PsiUtils.java | 7 -- 59 files changed, 319 insertions(+), 392 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java index 44b7ccc1ee3..4c01aec2443 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java @@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.JetModifierListOwner; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.*; +import org.jetbrains.jet.lang.resolve.constants.StringValue; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeUtils; @@ -45,6 +46,7 @@ import java.util.*; import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DELEGATION; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall; public abstract class AnnotationCodegen { @@ -131,7 +133,7 @@ public abstract class AnnotationCodegen { else { List annotationEntries = modifierList.getAnnotationEntries(); for (JetAnnotationEntry annotationEntry : annotationEntries) { - ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, annotationEntry.getCalleeExpression()); + ResolvedCall resolvedCall = getResolvedCall(annotationEntry, bindingContext); if (resolvedCall == null) continue; // Skipping annotations if they are not resolved. Needed for JetLightClass generation AnnotationDescriptor annotationDescriptor = bindingContext.get(BindingContext.ANNOTATION, annotationEntry); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index e1df985951f..b1752b50978 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -44,6 +44,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.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.*; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; @@ -77,6 +78,7 @@ import static org.jetbrains.jet.codegen.JvmCodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.*; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.*; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; @@ -322,13 +324,6 @@ public class ExpressionCodegen extends JetVisitor implem return type == null ? Type.VOID_TYPE : asmType(type); } - @NotNull - public ResolvedCall resolvedCall(JetExpression expression) { - ResolvedCall resolvedCall = bindingContext.get(RESOLVED_CALL, expression); - assert resolvedCall != null : "Unresolved call: " + expression.getText(); - return resolvedCall; - } - @Override public StackValue visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, StackValue receiver) { return genQualified(receiver, expression.getExpression()); @@ -466,7 +461,7 @@ public class ExpressionCodegen extends JetVisitor implem // Is it a "1..2" or so RangeCodegenUtil.BinaryCall binaryCall = RangeCodegenUtil.getRangeAsBinaryCall(forExpression); if (binaryCall != null) { - ResolvedCall resolvedCall = bindingContext.get(RESOLVED_CALL, binaryCall.op); + ResolvedCall resolvedCall = getResolvedCall(binaryCall.op, bindingContext); if (resolvedCall != null) { if (RangeCodegenUtil.isOptimizableRangeTo(resolvedCall.getResultingDescriptor())) { generateForLoop(new ForInRangeLiteralLoopGenerator(forExpression, binaryCall)); @@ -1348,7 +1343,7 @@ public class ExpressionCodegen extends JetVisitor implem assert superConstructor != null; CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor); Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes(); - ResolvedCall resolvedCall = resolvedCall(superCall.getCalleeExpression()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(superCall, bindingContext); pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(argumentTypes), false, defaultCallGenerator); } @@ -1657,7 +1652,7 @@ public class ExpressionCodegen extends JetVisitor implem @Override public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) { - ResolvedCall resolvedCall = bindingContext.get(RESOLVED_CALL, expression); + ResolvedCall resolvedCall = getResolvedCall(expression, bindingContext); DeclarationDescriptor descriptor; if (resolvedCall == null) { @@ -1933,10 +1928,7 @@ public class ExpressionCodegen extends JetVisitor implem @Override public StackValue visitCallExpression(@NotNull JetCallExpression expression, StackValue receiver) { - JetExpression callee = expression.getCalleeExpression(); - assert callee != null; - - ResolvedCall resolvedCall = resolvedCall(callee); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); CallableDescriptor funDescriptor = resolvedCall.getResultingDescriptor(); if (!(funDescriptor instanceof FunctionDescriptor)) { @@ -1949,7 +1941,7 @@ public class ExpressionCodegen extends JetVisitor implem return generateNewCall(expression, resolvedCall, receiver); } - Call call = bindingContext.get(CALL, expression.getCalleeExpression()); + Call call = getCall(expression, bindingContext); if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) { //noinspection ConstantConditions SamType samType = SamType.create(funDescriptor.getReturnType()); @@ -2455,7 +2447,7 @@ public class ExpressionCodegen extends JetVisitor implem @Override public StackValue visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression, StackValue data) { - ResolvedCall resolvedCall = resolvedCall(expression.getCallableReference()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression.getCallableReference(), bindingContext); FunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression); if (functionDescriptor != null) { CallableReferenceGenerationStrategy strategy = new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall); @@ -2732,7 +2724,7 @@ public class ExpressionCodegen extends JetVisitor implem return generateIn(StackValue.expression(Type.INT_TYPE, expression.getLeft(), this), expression.getRight(), reference); } else { - ResolvedCall resolvedCall = resolvedCall(reference); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); Callable callable = resolveToCallable(descriptor, false); @@ -2743,7 +2735,7 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.onStack(returnType); } - Call call = bindingContext.get(CALL, reference); + Call call = getCall(reference, bindingContext); return invokeFunction(call, receiver, resolvedCall); } } @@ -2754,11 +2746,8 @@ public class ExpressionCodegen extends JetVisitor implem genInIntRange(leftValue, (JetBinaryExpression) deparenthesized); } else { - invokeFunction( - bindingContext.get(CALL, operationReference), - StackValue.none(), - resolvedCall(operationReference) - ); + ResolvedCall resolvedCall = getResolvedCallWithAssert(operationReference, bindingContext); + invokeFunction(resolvedCall.getCall(), StackValue.none(), resolvedCall); } if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) { genInvertBoolean(v); @@ -2924,7 +2913,7 @@ public class ExpressionCodegen extends JetVisitor implem } private StackValue generateComparison(JetBinaryExpression expression, StackValue receiver) { - ResolvedCall resolvedCall = resolvedCall(expression.getOperationReference()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); JetExpression left = expression.getLeft(); @@ -2940,7 +2929,7 @@ public class ExpressionCodegen extends JetVisitor implem gen(right, type); } else { - Call call = bindingContext.get(CALL, expression.getOperationReference()); + Call call = getCall(expression, bindingContext); StackValue result = invokeFunction(call, receiver, resolvedCall); type = Type.INT_TYPE; result.put(type, v); @@ -2959,7 +2948,7 @@ public class ExpressionCodegen extends JetVisitor implem } private StackValue generateAugmentedAssignment(JetBinaryExpression expression) { - ResolvedCall resolvedCall = resolvedCall(expression.getOperationReference()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); Callable callable = resolveToCallable(descriptor, false); JetExpression lhs = expression.getLeft(); @@ -2996,8 +2985,7 @@ public class ExpressionCodegen extends JetVisitor implem @NotNull Type lhsType, boolean keepReturnValue ) { - Call call = bindingContext.get(CALL, expression.getOperationReference()); - assert call != null : "Call should be not null for operation reference in " + expression.getText(); + Call call = getCallWithAssert(expression, bindingContext); StackValue value = gen(expression.getLeft()); if (keepReturnValue) { @@ -3062,11 +3050,10 @@ public class ExpressionCodegen extends JetVisitor implem } DeclarationDescriptor cls = op.getContainingDeclaration(); - ResolvedCall resolvedCall = resolvedCall(expression.getOperationReference()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) { - Call call = bindingContext.get(CALL, expression.getOperationReference()); - return invokeFunction(call, receiver, resolvedCall); + return invokeFunction(resolvedCall.getCall(), receiver, resolvedCall); } CallableMethod callableMethod = (CallableMethod) callable; @@ -3144,7 +3131,7 @@ public class ExpressionCodegen extends JetVisitor implem storeType = type; } else { - ResolvedCall resolvedCall = resolvedCall(expression.getOperationReference()); + ResolvedCall resolvedCall = getResolvedCallWithAssert(expression, bindingContext); Callable callable = resolveToCallable((FunctionDescriptor) op, false); CallableMethod callableMethod = (CallableMethod) callable; callableMethod.invokeWithNotNullAssertion(v, state, resolvedCall); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 141c427e8ae..48e97a859cf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -45,6 +45,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.DeclarationResolver; import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; @@ -1387,7 +1388,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { private PropertyDescriptor getDelegatePropertyIfAny(JetExpression expression) { PropertyDescriptor propertyDescriptor = null; if (expression instanceof JetSimpleNameExpression) { - ResolvedCall call = bindingContext.get(BindingContext.RESOLVED_CALL, expression); + ResolvedCall call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext); if (call != null) { CallableDescriptor callResultingDescriptor = call.getResultingDescriptor(); if (callResultingDescriptor instanceof ValueParameterDescriptor) { @@ -1581,8 +1582,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor); - ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, ((JetCallElement) superCall).getCalleeExpression()); - assert resolvedCall != null; + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(superCall, bindingContext); ConstructorDescriptor superConstructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor(); //noinspection SuspiciousMethodCalls @@ -1683,9 +1683,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier); } - ResolvedCall resolvedCall = - bindingContext.get(BindingContext.RESOLVED_CALL, ((JetDelegatorToSuperCall) specifier).getCalleeExpression()); - assert resolvedCall != null : "Enum entry delegation specifier is unresolved: " + specifier.getText(); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(specifier, bindingContext); CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor()); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/TailRecursionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/TailRecursionCodegen.java index 69ee7e7c3d1..2864c66b499 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/TailRecursionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/TailRecursionCodegen.java @@ -18,8 +18,6 @@ package org.jetbrains.jet.codegen; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; -import org.jetbrains.org.objectweb.asm.Type; -import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.jet.codegen.context.MethodContext; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.lang.descriptors.CallableDescriptor; @@ -30,11 +28,13 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind; import org.jetbrains.jet.lang.resolve.calls.model.*; +import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.List; -import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL; import static org.jetbrains.jet.lang.resolve.BindingContext.TAIL_RECURSION_CALL; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall; public class TailRecursionCodegen { @@ -107,7 +107,7 @@ public class TailRecursionCodegen { JetExpression argumentExpression = argument == null ? null : argument.getArgumentExpression(); if (argumentExpression instanceof JetSimpleNameExpression) { - ResolvedCall resolvedCall = state.getBindingContext().get(RESOLVED_CALL, argumentExpression); + ResolvedCall resolvedCall = getResolvedCall(argumentExpression, state.getBindingContext()); if (resolvedCall != null && resolvedCall.getResultingDescriptor().equals(parameterDescriptor.getOriginal())) { // do nothing: we shouldn't store argument to itself again AsmUtil.pop(v, type); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index 00ef7e2abbb..72dcec36a8a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ExpressionValueArgument; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; @@ -310,7 +311,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { // working around a problem with shallow analysis if (functionDescriptor == null) return; - ResolvedCall referencedFunction = bindingContext.get(RESOLVED_CALL, expression.getCallableReference()); + ResolvedCall referencedFunction = BindingContextUtilPackage.getResolvedCall(expression.getCallableReference(), bindingContext); if (referencedFunction == null) return; Collection supertypes = runtimeTypes.getSupertypesForFunctionReference((FunctionDescriptor) referencedFunction.getResultingDescriptor()); @@ -401,7 +402,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { @Override public void visitCallExpression(@NotNull JetCallExpression expression) { super.visitCallExpression(expression); - ResolvedCall call = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression()); + ResolvedCall call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext); if (call == null) return; CallableDescriptor descriptor = call.getResultingDescriptor(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassArray.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassArray.java index 99fbec50088..374a9a01663 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassArray.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassArray.java @@ -19,17 +19,17 @@ package org.jetbrains.jet.codegen.intrinsics; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.org.objectweb.asm.Type; -import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.psi.JetCallExpression; +import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetExpression; -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.calls.model.VarargValueArgument; +import org.jetbrains.org.objectweb.asm.Type; +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.List; import java.util.Map; @@ -45,9 +45,7 @@ public class JavaClassArray extends IntrinsicMethod { @Nullable List arguments, StackValue receiver ) { - ResolvedCall call = - codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression()); - assert call != null; + ResolvedCall call = BindingContextUtilPackage.getResolvedCallWithAssert((JetElement) element, codegen.getBindingContext()); Map.Entry next = call.getValueArguments().entrySet().iterator().next(); codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue()); return returnType; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java index cc2c8c52be2..706a8c53df7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/JavaClassFunction.java @@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; -import org.jetbrains.jet.lang.psi.JetCallExpression; +import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetExpression; -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.org.objectweb.asm.Type; @@ -45,9 +45,8 @@ public class JavaClassFunction extends IntrinsicMethod { @Nullable List arguments, StackValue receiver ) { - JetCallExpression call = (JetCallExpression) element; - ResolvedCall resolvedCall = codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression()); - assert resolvedCall != null; + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert( + (JetElement) element, codegen.getBindingContext()); JetType returnType = resolvedCall.getResultingDescriptor().getReturnType(); assert returnType != null; putJavaLangClassInstance(v, codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType())); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/MonitorInstruction.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/MonitorInstruction.java index 5d4150152d7..b57712d283f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/MonitorInstruction.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/MonitorInstruction.java @@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; -import org.jetbrains.jet.lang.psi.JetCallExpression; +import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetExpression; -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.org.objectweb.asm.Opcodes; import org.jetbrains.org.objectweb.asm.Type; @@ -56,8 +56,7 @@ public class MonitorInstruction extends IntrinsicMethod { @Nullable StackValue receiver ) { assert element != null : "Element should not be null"; - ResolvedCall resolvedCall = - codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression()); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall((JetElement) element, codegen.getBindingContext()); assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null"; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index bdc9a8ed052..0c77ceeb365 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -53,6 +53,7 @@ import java.util.*; import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall; import static org.jetbrains.jet.lexer.JetTokens.*; public class JetControlFlowProcessor { @@ -235,7 +236,7 @@ public class JetControlFlowProcessor { @NotNull private AccessTarget getResolvedCallAccessTarget(JetElement element) { - ResolvedCall resolvedCall = trace.get(BindingContext.RESOLVED_CALL, element); + ResolvedCall resolvedCall = getResolvedCall(element, trace.getBindingContext()); return resolvedCall != null ? new AccessTarget.Call(resolvedCall) : AccessTarget.BlackBox.instance$; } @@ -268,7 +269,7 @@ public class JetControlFlowProcessor { @Override public void visitThisExpression(@NotNull JetThisExpression expression) { - ResolvedCall resolvedCall = getResolvedCall(expression); + ResolvedCall resolvedCall = getResolvedCall(expression, trace.getBindingContext()); if (resolvedCall == null) { createNonSyntheticValue(expression); return; @@ -290,7 +291,7 @@ public class JetControlFlowProcessor { @Override public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { - ResolvedCall resolvedCall = getResolvedCall(expression); + ResolvedCall resolvedCall = getResolvedCall(expression, trace.getBindingContext()); if (resolvedCall instanceof VariableAsFunctionResolvedCall) { VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall; generateCall(expression, variableAsFunctionResolvedCall.getVariableCall()); @@ -325,9 +326,9 @@ public class JetControlFlowProcessor { visitAssignment(left, getDeferredValue(right), expression); } else if (OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(operationType)) { - ResolvedCall resolvedCall = getResolvedCall(operationReference); + ResolvedCall resolvedCall = getResolvedCall(expression, trace.getBindingContext()); if (resolvedCall != null) { - PseudoValue rhsValue = generateCall(operationReference, resolvedCall).getOutputValue(); + PseudoValue rhsValue = generateCall(expression, resolvedCall).getOutputValue(); Name assignMethodName = OperatorConventions.getNameForOperationSymbol((JetToken) expression.getOperationToken()); if (!resolvedCall.getResultingDescriptor().getName().equals(assignMethodName)) { /* At this point assignment of the form a += b actually means a = a + b @@ -353,7 +354,7 @@ public class JetControlFlowProcessor { mergeValues(Arrays.asList(left, right), expression); } else { - if (!generateCall(operationReference)) { + if (!generateCall(expression)) { generateBothArgumentsAndMark(expression); } } @@ -572,11 +573,11 @@ public class JetControlFlowProcessor { } boolean incrementOrDecrement = isIncrementOrDecrement(operationType); - ResolvedCall resolvedCall = getResolvedCall(operationSign); + ResolvedCall resolvedCall = getResolvedCall(expression, trace.getBindingContext()); PseudoValue rhsValue; if (resolvedCall != null) { - rhsValue = generateCall(operationSign, resolvedCall).getOutputValue(); + rhsValue = generateCall(expression, resolvedCall).getOutputValue(); } else { generateInstructions(baseExpression); @@ -1069,8 +1070,7 @@ public class JetControlFlowProcessor { @Override public void visitCallExpression(@NotNull JetCallExpression expression) { - JetExpression calleeExpression = expression.getCalleeExpression(); - if (!generateCall(calleeExpression)) { + if (!generateCall(expression)) { List inputExpressions = new ArrayList(); for (ValueArgument argument : expression.getValueArguments()) { JetExpression argumentExpression = argument.getArgumentExpression(); @@ -1083,6 +1083,7 @@ public class JetControlFlowProcessor { generateInstructions(functionLiteral); inputExpressions.add(functionLiteral); } + JetExpression calleeExpression = expression.getCalleeExpression(); generateInstructions(calleeExpression); inputExpressions.add(calleeExpression); inputExpressions.add(generateAndGetReceiverIfAny(expression)); @@ -1373,38 +1374,26 @@ public class JetControlFlowProcessor { builder.unsupported(element); } - @Nullable - private ResolvedCall getResolvedCall(@NotNull JetElement expression) { - return trace.get(BindingContext.RESOLVED_CALL, expression); + private boolean generateCall(@Nullable JetExpression callExpression) { + if (callExpression == null) return false; + return checkAndGenerateCall(callExpression, getResolvedCall(callExpression, trace.getBindingContext())); } - - private boolean generateCall(@Nullable JetExpression calleeExpression) { - if (calleeExpression == null) return false; - return checkAndGenerateCall(calleeExpression, getResolvedCall(calleeExpression)); - } - - private boolean checkAndGenerateCall( - JetExpression calleeExpression, - @Nullable ResolvedCall resolvedCall - ) { + private boolean checkAndGenerateCall(@NotNull JetExpression callExpression, @Nullable ResolvedCall resolvedCall) { if (resolvedCall == null) { - builder.compilationError(calleeExpression, "No resolved call"); + builder.compilationError(callExpression, "No resolved call"); return false; } - generateCall(calleeExpression, resolvedCall); + generateCall(callExpression, resolvedCall); return true; } @NotNull - private InstructionWithValue generateCall(JetExpression calleeExpression, ResolvedCall resolvedCall) { + private InstructionWithValue generateCall(@NotNull JetExpression callExpression, @NotNull ResolvedCall resolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) { VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall; - return generateCall(calleeExpression, variableAsFunctionResolvedCall.getFunctionCall()); + return generateCall(callExpression, variableAsFunctionResolvedCall.getFunctionCall()); } - JetElement callElement = resolvedCall.getCall().getCallElement(); - JetExpression callExpression = callElement instanceof JetExpression ? (JetExpression) callElement : null; - CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); Map receivers = getReceiverValues(resolvedCall, true); SmartFMap parameterValues = SmartFMap.emptyMap(); @@ -1416,14 +1405,17 @@ public class JetControlFlowProcessor { } if (resultingDescriptor instanceof VariableDescriptor) { - assert callExpression != null - : "Variable-based call without call expression: " + callElement.getText(); + // If a callee of the call is just a variable (without 'invoke'), 'read variable' is generated. + // todo : process arguments for such a case (KT-5387) + JetExpression calleeExpression = PsiUtilPackage.getCalleeExpressionIfAny(callExpression); + assert calleeExpression != null + : "No callee for " + callExpression.getText(); assert parameterValues.isEmpty() - : "Variable-based call with non-empty argument list: " + callElement.getText(); - return builder.readVariable(calleeExpression, callExpression, resolvedCall, receivers); + : "Variable-based call with non-empty argument list: " + callExpression.getText(); + return builder.readVariable(calleeExpression, calleeExpression, resolvedCall, receivers); } mark(resolvedCall.getCall().getCallElement()); - return builder.call(calleeExpression, callExpression, resolvedCall, receivers, parameterValues); + return builder.call(callExpression, callExpression, resolvedCall, receivers, parameterValues); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 6566a125ad4..5f9b8469fa3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -68,7 +68,9 @@ import java.util.*; import static org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseState.*; import static org.jetbrains.jet.lang.cfg.pseudocodeTraverser.TraversalOrder.FORWARD; import static org.jetbrains.jet.lang.diagnostics.Errors.*; -import static org.jetbrains.jet.lang.resolve.BindingContext.*; +import static org.jetbrains.jet.lang.resolve.BindingContext.CAPTURED_IN_CLOSURE; +import static org.jetbrains.jet.lang.resolve.BindingContext.TAIL_RECURSION_CALL; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall; import static org.jetbrains.jet.lang.resolve.calls.TailRecursionKind.*; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType; @@ -725,7 +727,7 @@ public class JetFlowInformationProvider { if (!(instruction instanceof CallInstruction)) return; CallInstruction callInstruction = (CallInstruction) instruction; - ResolvedCall resolvedCall = trace.get(RESOLVED_CALL, callInstruction.getElement()); + ResolvedCall resolvedCall = getResolvedCall(callInstruction.getElement(), trace.getBindingContext()); if (resolvedCall == null) return; // is this a recursive call? diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt index 98336f2dd07..a0e0a11edeb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt @@ -33,6 +33,7 @@ import org.jetbrains.jet.JetNodeTypes import java.math.BigInteger import org.jetbrains.jet.lang.diagnostics.Errors import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor, JetType>() { @@ -179,7 +180,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet } private fun evaluateCall(callExpression: JetExpression, receiverExpression: JetExpression, expectedType: JetType?): CompileTimeConstant<*>? { - val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, callExpression) + val resolvedCall = callExpression.getResolvedCall(trace.getBindingContext()) if (resolvedCall == null) return null val resultingDescriptorName = resolvedCall.getResultingDescriptor().getName() @@ -309,7 +310,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet return EnumValue(enumDescriptor as ClassDescriptor, false); } - val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, expression) + val resolvedCall = expression.getResolvedCall(trace.getBindingContext()) if (resolvedCall != null) { val callableDescriptor = resolvedCall.getResultingDescriptor() if (callableDescriptor is VariableDescriptor) { @@ -351,7 +352,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet } override fun visitCallExpression(expression: JetCallExpression, expectedType: JetType?): CompileTimeConstant<*>? { - val call = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression()) + val call = expression.getResolvedCall(trace.getBindingContext()) if (call == null) return null val resultingDescriptor = call.getResultingDescriptor() diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index b61108671bd..0484b6b4dc0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -733,30 +733,6 @@ public class JetPsiUtil { return node == null ? null : node.getPsi(); } - @Nullable - public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) { - if (expression instanceof JetSimpleNameExpression) { - return expression; - } - if (expression instanceof JetCallElement) { - JetCallElement callExpression = (JetCallElement) expression; - return callExpression.getCalleeExpression(); - } - if (expression instanceof JetQualifiedExpression) { - JetExpression selectorExpression = ((JetQualifiedExpression) expression).getSelectorExpression(); - if (selectorExpression != null) { - return getCalleeExpressionIfAny(selectorExpression); - } - } - if (expression instanceof JetUnaryExpression) { - return ((JetUnaryExpression) expression).getOperationReference(); - } - if (expression instanceof JetBinaryExpression) { - return ((JetBinaryExpression) expression).getOperationReference(); - } - return null; - } - @Nullable public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate elementsToSkip) { if (element == null) return null; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt index 4664d11db9d..34b473827f8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt @@ -34,6 +34,7 @@ import com.intellij.psi.JavaDirectoryService import com.intellij.psi.PsiDirectory import org.jetbrains.jet.lang.psi.stubs.PsiJetClassOrObjectStub import org.jetbrains.jet.lang.types.expressions.OperatorConventions +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils public fun JetCallElement.getCallNameExpression(): JetSimpleNameExpression? { val calleeExpression = getCalleeExpression() @@ -312,4 +313,17 @@ public fun JetSimpleNameExpression.isImportDirectiveExpression(): Boolean { else { return parent is JetImportDirective || parent.getParent() is JetImportDirective } -} \ No newline at end of file +} + +public fun JetElement.getCalleeExpressionIfAny(): JetExpression? { + val element = if (this is JetExpression) JetPsiUtil.safeDeparenthesize(this, false) else this + return when (element) { + is JetSimpleNameExpression -> element + is JetCallElement -> element.getCalleeExpression() + is JetQualifiedExpression -> element.getSelectorExpression()?.getCalleeExpressionIfAny() + is JetOperationExpression -> element.getOperationReference() + else -> null + } +} + +public fun JetElement.getTextWithLocation(): String = "'${this.getText()}' at ${DiagnosticUtils.atLocation(this)}" \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java index 1a84f3a4671..31289173b2d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; @@ -324,7 +325,7 @@ public class AnnotationResolver { @NotNull JetCallExpression expression, @NotNull BindingTrace trace ) { - ResolvedCall resolvedCall = trace.get(BindingContext.RESOLVED_CALL, (expression).getCalleeExpression()); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, trace.getBindingContext()); if (resolvedCall == null || !CompileTimeConstantUtils.isArrayMethodCall(resolvedCall)) { return null; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java index 9ecd7c4685f..d68b957dd9e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; +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.calls.model.VariableAsFunctionResolvedCall; @@ -301,26 +302,12 @@ public class BindingContextUtils { @NotNull BindingContext context ) { if (expression instanceof JetCallExpression) { - return isCallExpressionWithValidReference(expression, context); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context); + return resolvedCall instanceof VariableAsFunctionResolvedCall; } - return expression instanceof JetReferenceExpression; } - public static boolean isCallExpressionWithValidReference( - @NotNull JetExpression expression, - @NotNull BindingContext context - ) { - if (expression instanceof JetCallExpression) { - JetExpression calleeExpression = ((JetCallExpression) expression).getCalleeExpression(); - ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, calleeExpression); - if (resolvedCall instanceof VariableAsFunctionResolvedCall) { - return true; - } - } - return false; - } - public static boolean isVarCapturedInClosure(BindingContext bindingContext, DeclarationDescriptor descriptor) { if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor) return false; VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt index 5e8d710cd46..c22c7ce8a8d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.kt @@ -20,10 +20,9 @@ import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.psi.Call import org.jetbrains.jet.lang.psi.JetPsiUtil import org.jetbrains.jet.lang.psi.JetCallExpression -import org.jetbrains.jet.lang.psi.JetQualifiedExpression import org.jetbrains.jet.lang.resolve.BindingContext -import org.jetbrains.jet.lang.psi.JetOperationExpression import org.jetbrains.jet.lang.resolve.BindingContext.CALL +import org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL import org.jetbrains.jet.lang.psi.JetReturnExpression import org.jetbrains.jet.lang.descriptors.FunctionDescriptor import org.jetbrains.jet.lang.resolve.BindingContext.LABEL_TARGET @@ -40,6 +39,15 @@ import org.jetbrains.jet.lang.psi.JetBinaryExpression import org.jetbrains.jet.lang.psi.JetSimpleNameExpression import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.jet.lang.psi.JetThisExpression +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall +import org.jetbrains.jet.lang.descriptors.CallableDescriptor +import org.jetbrains.jet.lang.psi.JetElement +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils +import org.jetbrains.jet.lang.psi.psiUtil.getCalleeExpressionIfAny +import org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke +import org.jetbrains.kotlin.util.sure +import org.jetbrains.jet.lang.psi.JetCallElement +import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation /** * For expressions like a(), a[i], a.b.c(), +a, a + b, (a()), a(): Int, @label a() @@ -48,46 +56,79 @@ import org.jetbrains.jet.lang.psi.JetThisExpression * Note: special construction like a!!, a ?: b, if (c) a else b are resolved as calls, * so there is a corresponding call for them. */ -fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? { - val expr = JetPsiUtil.deparenthesize(this) - if (expr == null) return null +public fun JetElement.getCall(context: BindingContext): Call? { + val element = if (this is JetExpression) JetPsiUtil.deparenthesize(this) else this + if (element == null) return null - if (expr is JetQualifiedExpression) { - return expr.getSelectorExpression()?.getCorrespondingCall(bindingContext) - } - val parent = expr.getParent() + val parent = element.getParent() val reference = when { parent is JetThisExpression -> parent : JetThisExpression - expr is JetCallExpression -> expr.getCalleeExpression() - expr is JetOperationExpression -> expr.getOperationReference() - else -> expr + else -> element.getCalleeExpressionIfAny() } - return bindingContext[CALL, reference] + if (reference != null) { + return context[CALL, reference] + } + return context[CALL, element] } -fun JetExpression.getEnclosingCall(bindingContext: BindingContext): Call? { - val parent = PsiTreeUtil.getNonStrictParentOfType( +public fun JetExpression.getParentCall(context: BindingContext): Call? { + val parent = PsiTreeUtil.getNonStrictParentOfType( this, - javaClass(), javaClass(), javaClass(), + javaClass(), javaClass(), javaClass(), javaClass(), javaClass()) - return parent?.getCorrespondingCall(bindingContext) + return parent?.getCall(context) } -fun Call.hasUnresolvedArguments(bindingContext: BindingContext): Boolean { +public fun Call?.getResolvedCall(context: BindingContext): ResolvedCall? { + if (this == null) return null + if (this is CallForImplicitInvoke) { + // callee for invoke is implicit (doesn't exist), so the key is callee of outer call (which is 'this object' for 'invoke' call) + return context[RESOLVED_CALL, this.getThisObject().getExpression()] + } + + return context[RESOLVED_CALL, this.getCalleeExpression()] +} + +public fun JetElement?.getResolvedCall(context: BindingContext): ResolvedCall? { + return this?.getCall(context)?.getResolvedCall(context) +} + +public fun JetElement.getCallWithAssert(context: BindingContext): Call { + return getCall(context).sure("No call for ${this.getTextWithLocation()}") +} + +public fun JetElement.getResolvedCallWithAssert(context: BindingContext): ResolvedCall { + return getResolvedCall(context).sure("No resolved call for ${this.getTextWithLocation()}") +} + +public fun Call.getResolvedCallWithAssert(context: BindingContext): ResolvedCall { + return getResolvedCall(context).sure("No resolved call for ${this.getCallElement().getTextWithLocation()}") +} + +public fun JetExpression.getFunctionResolvedCallWithAssert(context: BindingContext): ResolvedCall { + val resolvedCall = getResolvedCallWithAssert(context) + assert(resolvedCall.getResultingDescriptor() is FunctionDescriptor) { + "ResolvedCall for this expression must be ResolvedCall: ${this.getTextWithLocation()}" + } + [suppress("UNCHECKED_CAST")] + return resolvedCall as ResolvedCall +} + +public fun Call.hasUnresolvedArguments(context: BindingContext): Boolean { val arguments = getValueArguments().map { it?.getArgumentExpression() } return arguments.any { argument -> - val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, argument] + val expressionType = context[BindingContext.EXPRESSION_TYPE, argument] argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument) && (expressionType == null || expressionType.isError()) } } -public fun JetReturnExpression.getTargetFunctionDescriptor(bindingContext: BindingContext): FunctionDescriptor? { +public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? { val targetLabel = getTargetLabel() - if (targetLabel != null) return bindingContext[LABEL_TARGET, targetLabel]?.let { bindingContext[FUNCTION, it] } + if (targetLabel != null) return context[LABEL_TARGET, targetLabel]?.let { context[FUNCTION, it] } - val declarationDescriptor = bindingContext[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass())] + val declarationDescriptor = context[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass())] val containingFunctionDescriptor = DescriptorUtils.getParentOfType(declarationDescriptor, javaClass(), false) if (containingFunctionDescriptor == null) return null diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java index 327a1c81b5d..2577b404692 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.diagnostics.rendering.Renderers; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; @@ -49,6 +50,7 @@ import java.util.List; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression; import static org.jetbrains.jet.lang.psi.JetPsiFactory.createSimpleName; +import static org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage.getCalleeExpressionIfAny; import static org.jetbrains.jet.lang.resolve.BindingContext.*; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType; @@ -227,7 +229,7 @@ public class DelegatedPropertyResolver { @NotNull DataFlowInfo dataFlowInfo ) { TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property"); - JetExpression calleeExpression = JetPsiUtil.getCalleeExpressionIfAny(delegateExpression); + JetExpression calleeExpression = getCalleeExpressionIfAny(delegateExpression); ConstraintSystemCompleter completer = createConstraintSystemCompleter( jetProperty, propertyDescriptor, delegateExpression, accessorScope, trace); if (calleeExpression != null) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/InlineDescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/InlineDescriptorUtils.java index 6768b13e308..71a1a53c777 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/InlineDescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/InlineDescriptorUtils.java @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; public class InlineDescriptorUtils { @@ -45,8 +46,7 @@ public class InlineDescriptorUtils { boolean isInlinedLambda = false; JetExpression call = JetPsiUtil.getParentCallIfPresent((JetFunctionLiteralExpression) containingFunction); if (call != null) { - //TODO: ask sveta - ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, JetPsiUtil.getCalleeExpressionIfAny(call)); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(call, bindingContext); CallableDescriptor resultingDescriptor = resolvedCall == null ? null : resolvedCall.getResultingDescriptor(); if (resultingDescriptor instanceof SimpleFunctionDescriptor) { isInlinedLambda = ((SimpleFunctionDescriptor) resultingDescriptor).getInlineStrategy().isInline(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt index c83f03aaea3..2182199f50b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt @@ -52,7 +52,7 @@ import org.jetbrains.jet.lang.psi.Call import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils import org.jetbrains.jet.lang.psi.JetBlockExpression import org.jetbrains.jet.lang.psi.JetPsiUtil -import org.jetbrains.jet.lang.resolve.bindingContextUtil.getCorrespondingCall +import org.jetbrains.jet.lang.resolve.bindingContextUtil.getCall import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace @@ -286,7 +286,7 @@ public class CallCompleter( val lastStatement = JetPsiUtil.getLastStatementInABlock(argument) return getCallForArgument(lastStatement as? JetExpression, bindingContext) } - return argument?.getCorrespondingCall(bindingContext) + return argument?.getCall(bindingContext) } private fun updateRecordedTypeForArgument( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java index 40f3d802061..e452431528f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java @@ -273,7 +273,7 @@ public class CallTransformer { @NotNull @Override - public ReceiverValue getThisObject() { + public ExpressionReceiver getThisObject() { return calleeExpressionAsThisObject; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java index 0c8f9b90c4a..b2579aff75f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java @@ -23,11 +23,14 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; 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.DescriptorUtils; import org.jetbrains.jet.lang.resolve.InlineDescriptorUtils; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; -import org.jetbrains.jet.lang.resolve.calls.model.*; +import org.jetbrains.jet.lang.resolve.calls.model.DefaultValueArgument; +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; +import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; @@ -180,8 +183,9 @@ public class InlineCallResolverExtension implements CallResolverExtension { @NotNull JetExpression expression, boolean unwrapVariableAsFunction ) { - // todo ask sveta - ResolvedCall thisCall = context.trace.get(BindingContext.RESOLVED_CALL, expression); + if (!(expression instanceof JetSimpleNameExpression || expression instanceof JetThisExpression)) return null; + + ResolvedCall thisCall = BindingContextUtilPackage.getResolvedCall(expression, context.trace.getBindingContext()); if (unwrapVariableAsFunction && thisCall instanceof VariableAsFunctionResolvedCall) { return ((VariableAsFunctionResolvedCall) thisCall).getVariableCall().getResultingDescriptor(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java index d1cb39aaa77..43251b3e0e6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java @@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.JetModuleUtil; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.scopes.receivers.*; import org.jetbrains.jet.lang.types.JetType; @@ -31,7 +32,6 @@ import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET; -import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL; public class DataFlowValueFactory { private DataFlowValueFactory() {} @@ -166,13 +166,14 @@ public class DataFlowValueFactory { ) { DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression); if (declarationDescriptor instanceof VariableDescriptor) { - ResolvedCall resolvedCall = bindingContext.get(RESOLVED_CALL, simpleNameExpression); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(simpleNameExpression, bindingContext); // todo uncomment assert // KT-4113 // for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes // assert resolvedCall != null : "Cannot create right identifier info if the resolved call is not known yet for " + declarationDescriptor; - IdentifierInfo receiverInfo = resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null; + IdentifierInfo receiverInfo = + resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null; VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor; return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor))); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyForInvoke.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyForInvoke.java index 48663af04e1..a37f8654715 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyForInvoke.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TracingStrategyForInvoke.java @@ -68,6 +68,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy { public void bindResolvedCall( @NotNull BindingTrace trace, @NotNull ResolvedCall resolvedCall ) { + if (reference instanceof JetSimpleNameExpression) return; trace.record(RESOLVED_CALL, reference, resolvedCall); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index cc9a520d5ac..fc8ef5c88c4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -32,6 +32,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.*; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; @@ -153,7 +154,7 @@ public class ExpressionTypingUtils { return false; } - ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context); if (resolvedCall == null) { return false; } diff --git a/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt new file mode 100644 index 00000000000..2a9f4cda4f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt @@ -0,0 +1,3 @@ +public inline fun test(predicate: (Char) -> Boolean) { + !predicate('c') +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 022c1c99dcc..02e653c4fc6 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -4773,6 +4773,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.kt"); } + @TestMetadata("notOnCall.kt") + public void testNotOnCall() throws Exception { + doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt"); + } + @TestMetadata("notOperation.kt") public void testNotOperation() throws Exception { doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt"); diff --git a/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt b/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt index f81b6c0b3eb..de183ed1edc 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt +++ b/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt @@ -20,7 +20,6 @@ import org.jetbrains.jet.ConfigurationKind import org.jetbrains.jet.JetLiteFixture import org.jetbrains.jet.JetTestUtils import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment -import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver @@ -36,9 +35,10 @@ import com.intellij.openapi.util.io.FileUtil import org.jetbrains.jet.lang.psi.ValueArgument import org.jetbrains.jet.lang.psi.JetPsiFactory import org.jetbrains.jet.lang.psi.JetExpression -import org.jetbrains.jet.lang.resolve.bindingContextUtil.getEnclosingCall +import org.jetbrains.jet.lang.resolve.bindingContextUtil.getParentCall import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall +import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCallWithAssert public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY) @@ -51,19 +51,16 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { val element = jetFile.findElementAt(text.indexOf("")) val expression = PsiTreeUtil.getParentOfType(element, javaClass()) - val call = expression?.getEnclosingCall(bindingContext) + val call = expression?.getParentCall(bindingContext) - val cachedCall = bindingContext[BindingContext.RESOLVED_CALL, call?.getCalleeExpression()] - if (cachedCall == null) { - throw AssertionError("No resolved call for:\nelement: ${element.toString()}\nexpression: ${expression.toString()}\ncall: $call") - } + val cachedCall = call?.getResolvedCallWithAssert(bindingContext) val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall else if ("(" == element?.getText()) cachedCall.functionCall else cachedCall.variableCall val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt" - JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall.renderToText()}") + JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall?.renderToText()}") } } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt index e75d61165c7..0523edacb71 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt @@ -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() diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java index 5a7099236f9..b30274c8363 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java +++ b/idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java @@ -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()); diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt b/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt index 6975ea42d0e..d10a5f1c2a9 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/KotlinSmartStepIntoHandler.kt @@ -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() diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java index 3924ddde1d0..60ef099d17e 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java @@ -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); diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java index bc01eb62f60..782705365c4 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java @@ -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); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt index 9397250a2e8..14bae9c770b 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt @@ -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( "convert.assert.to.if.with.throw", javaClass()) { @@ -43,7 +43,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention("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." diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt index ab80ef2babe..bf41094ec4a 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt @@ -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("convert.to.for.each.loop.intention", javaClass()) { private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? { @@ -75,16 +74,14 @@ public class ConvertToForEachLoopIntention : JetSelfTargetingIntention( "insert.explicit.type.arguments", javaClass()) { @@ -40,7 +40,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention( "move.lambda.inside.parentheses", javaClass()) { @@ -44,7 +44,7 @@ public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention( "remove.explicit.type.arguments", javaClass()) { @@ -52,9 +51,9 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention("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 diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt index b79da247d09..4bdebfb6ba2 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt @@ -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(name, javaClass()) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java index b8785740004..ea4fb5d2021 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java @@ -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 { 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(); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java index 07672be9b08..d6a0d2db83e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java @@ -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 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; diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java index 617ee4ef412..22891521c2b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java @@ -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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java index 65e26224f91..c77378bde01 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java @@ -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) { diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt index a077d119d24..0a8f36c5b81 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt @@ -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 } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java index 52170cd9f7a..64bbeb3554f 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java @@ -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 typeArguments = Lists.newArrayList(); Map 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; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java index a8bfc98b21b..79290e9bf24 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java @@ -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; } } diff --git a/idea/src/org/jetbrains/jet/plugin/references/JetInvokeFunctionReference.java b/idea/src/org/jetbrains/jet/plugin/references/JetInvokeFunctionReference.java index ae0c1232a64..767a5cb71c3 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/JetInvokeFunctionReference.java +++ b/idea/src/org/jetbrains/jet/plugin/references/JetInvokeFunctionReference.java @@ -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 implements MultiRangeReference { public JetInvokeFunctionReference(@NotNull JetCallExpression expression) { @@ -49,13 +47,12 @@ class JetInvokeFunctionReference extends JetSimpleReference i @Override @NotNull protected Collection 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.singleton( ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor()); } - Call call = context.get(CALL, calleeExpression); if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) { return Collections.singleton(resolvedCall.getCandidateDescriptor()); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/initializer/ClassInitializerTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/initializer/ClassInitializerTranslator.java index 28aa0cdc19f..79062348d7c 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/initializer/ClassInitializerTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/initializer/ClassInitializerTranslator.java @@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetDelegationSpecifier; import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall; import org.jetbrains.jet.lang.psi.JetParameter; -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.lexer.JetTokens; @@ -124,8 +124,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator { @NotNull private List translateArguments(@NotNull JetDelegatorToSuperCall superCall) { - ResolvedCall call = context().bindingContext().get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression()); - assert call != null : "ResolvedCall for superCall must be not null"; + ResolvedCall call = BindingContextUtilPackage.getResolvedCallWithAssert(superCall, context().bindingContext()); return CallArgumentTranslator.translate(call, null, context()).getTranslateArguments(); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/operation/BinaryOperationTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/operation/BinaryOperationTranslator.java index 8f449d77c6c..8be8fa32245 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/operation/BinaryOperationTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/operation/BinaryOperationTranslator.java @@ -37,10 +37,10 @@ import org.jetbrains.k2js.translate.utils.TranslationUtils; import org.jetbrains.k2js.translate.utils.mutator.AssignToExpressionMutator; import org.jetbrains.k2js.translate.utils.mutator.LastExpressionMutator; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getFunctionResolvedCallWithAssert; import static org.jetbrains.k2js.translate.operation.AssignmentTranslator.isAssignmentOperator; import static org.jetbrains.k2js.translate.operation.CompareToTranslator.isCompareToCall; import static org.jetbrains.k2js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression; -import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionResolvedCall; import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToStatement; import static org.jetbrains.k2js.translate.utils.JsAstUtils.not; import static org.jetbrains.k2js.translate.utils.PsiUtils.*; @@ -154,7 +154,7 @@ public final class BinaryOperationTranslator extends AbstractTranslator { @NotNull private JsExpression translateAsOverloadedBinaryOperation() { - ResolvedCall resolvedCall = getFunctionResolvedCall(bindingContext(), expression.getOperationReference()); + ResolvedCall resolvedCall = getFunctionResolvedCallWithAssert(expression, bindingContext()); JsExpression result = CallTranslator.instance$.translate(context(), resolvedCall, getReceiver()); return mayBeWrapWithNegation(result); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedAssignmentTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedAssignmentTranslator.java index d7c76c6eeeb..a4e04581db6 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedAssignmentTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedAssignmentTranslator.java @@ -20,10 +20,10 @@ import com.google.dart.compiler.backend.js.ast.JsExpression; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.psi.JetBinaryExpression; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.context.TranslationContext; -import org.jetbrains.k2js.translate.utils.BindingUtils; public final class OverloadedAssignmentTranslator extends AssignmentTranslator { @@ -39,7 +39,7 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator { private OverloadedAssignmentTranslator(@NotNull JetBinaryExpression expression, @NotNull TranslationContext context) { super(expression, context); - resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); + resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, context.bindingContext()); } @NotNull diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedIncrementTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedIncrementTranslator.java index 3ec8f811c09..be7e59ce2cf 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedIncrementTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/operation/OverloadedIncrementTranslator.java @@ -20,20 +20,22 @@ import com.google.dart.compiler.backend.js.ast.JsExpression; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.psi.JetUnaryExpression; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.context.TranslationContext; -import org.jetbrains.k2js.translate.utils.BindingUtils; public final class OverloadedIncrementTranslator extends IncrementTranslator { @NotNull private final ResolvedCall resolvedCall; - /*package*/ OverloadedIncrementTranslator(@NotNull JetUnaryExpression expression, - @NotNull TranslationContext context) { + /*package*/ OverloadedIncrementTranslator( + @NotNull JetUnaryExpression expression, + @NotNull TranslationContext context + ) { super(expression, context); - this.resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); + this.resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, context.bindingContext()); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java index 4689461e70f..93a25ad7ce4 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java @@ -32,8 +32,8 @@ import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.utils.TranslationUtils; +import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getFunctionResolvedCallWithAssert; import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression; -import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionResolvedCall; import static org.jetbrains.k2js.translate.utils.PsiUtils.getBaseExpression; import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken; import static org.jetbrains.k2js.translate.utils.TranslationUtils.*; @@ -64,7 +64,7 @@ public final class UnaryOperationTranslator { return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression); } - ResolvedCall resolvedCall = getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); + ResolvedCall resolvedCall = getFunctionResolvedCallWithAssert(expression, context.bindingContext()); return CallTranslator.instance$.translate(context, resolvedCall, baseExpression); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java index e1b68279573..167a33295cf 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java @@ -21,12 +21,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.psi.JetCallExpression; +import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.general.AbstractTranslator; -import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCallForCallExpression; - public abstract class AbstractCallExpressionTranslator extends AbstractTranslator { @NotNull @@ -43,7 +42,7 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato ) { super(context); this.expression = expression; - this.resolvedCall = getResolvedCallForCallExpression(bindingContext(), expression); + this.resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, bindingContext()); this.receiver = receiver; } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java index 6d6c64da76a..df06116f109 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java @@ -51,7 +51,7 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio @SuppressWarnings("UnusedParameters") public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) { //TODO: inlining turned off - //ResolvedCall resolvedCall = getResolvedCallForCallExpression(context.bindingContext(), expression); + //ResolvedCall resolvedCall = BindingContextUtilPackage.getFunctionResolvedCall(expression, bindingContext()); //CallableDescriptor descriptor = resolvedCall.getCandidateDescriptor(); //if (descriptor instanceof SimpleFunctionDescriptor) { // return ((SimpleFunctionDescriptor)descriptor).isInline(); diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/VariableAccessTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/VariableAccessTranslator.java index da137357849..2661ca588c6 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/VariableAccessTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/VariableAccessTranslator.java @@ -21,12 +21,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.JetReferenceExpression; +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.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.context.TemporaryVariable; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.general.AbstractTranslator; -import org.jetbrains.k2js.translate.utils.BindingUtils; import java.util.Collections; import java.util.List; @@ -37,7 +38,10 @@ public class VariableAccessTranslator extends AbstractTranslator implements Acce @NotNull JetReferenceExpression referenceExpression, @Nullable JsExpression receiver ) { - ResolvedCall resolvedCall = BindingUtils.getResolvedCallForProperty(context.bindingContext(), referenceExpression); + ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(referenceExpression, context.bindingContext()); + if (resolvedCall instanceof VariableAsFunctionResolvedCall) { + resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall(); + } assert resolvedCall.getResultingDescriptor() instanceof VariableDescriptor; return new VariableAccessTranslator(context, (ResolvedCall) resolvedCall, receiver); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java index e0c10357bde..1d17503f03f 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java @@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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; import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.types.JetType; @@ -136,39 +135,6 @@ public final class BindingUtils { return context.get(BindingContext.REFERENCE_TARGET, reference); } - @NotNull - public static ResolvedCall getResolvedCall(@NotNull BindingContext context, @NotNull JetExpression expression) { - ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression); - assert resolvedCall != null : message(expression, expression.getText() + " must resolve to a call"); - return resolvedCall; - } - - @NotNull - public static ResolvedCall getResolvedCallForProperty(@NotNull BindingContext context, @NotNull JetExpression expression) { - ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression); - assert resolvedCall != null : message(expression, expression.getText() + " must resolve to a call"); - if (resolvedCall instanceof VariableAsFunctionResolvedCall) { - return ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall(); - } - return resolvedCall; - } - - @NotNull - public static ResolvedCall getResolvedCallForCallExpression(@NotNull BindingContext context, - @NotNull JetCallExpression expression) { - JetExpression calleeExpression = PsiUtils.getCallee(expression); - return getFunctionResolvedCall(context, calleeExpression); - } - - @NotNull - public static ResolvedCall getFunctionResolvedCall(@NotNull BindingContext context, - @NotNull JetExpression expression) { - ResolvedCall resolvedCall = getResolvedCall(context, expression); - assert resolvedCall.getResultingDescriptor() instanceof FunctionDescriptor - : message(expression, "ResolvedCall for this expression must be ResolvedCall"); - return (ResolvedCall) resolvedCall; - } - public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) { return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java b/js/js.translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java index f5b1b1b2231..7db083379db 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java @@ -93,13 +93,6 @@ public final class PsiUtils { return (binaryExpression.getOperationToken() == JetTokens.IN_KEYWORD); } - @NotNull - public static JetExpression getCallee(@NotNull JetCallExpression expression) { - JetExpression calleeExpression = expression.getCalleeExpression(); - assert calleeExpression != null; - return calleeExpression; - } - @NotNull public static JetExpression getLoopBody(@NotNull JetLoopExpression expression) { JetExpression body = expression.getBody();