All RESOLVED_CALL getters replaced with util methods

JetElement.getResolvedCall(BindingContext)
  JetElement.getResolvedCallForSure(BindingContext)
This commit is contained in:
Svetlana Isakova
2014-07-02 18:26:38 +04:00
parent e1fb5a9a04
commit 72e9822d99
59 changed files with 319 additions and 392 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.*; 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.resolve.name.FqName;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils; 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.descriptors.CallableMemberDescriptor.Kind.DELEGATION;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
public abstract class AnnotationCodegen { public abstract class AnnotationCodegen {
@@ -131,7 +133,7 @@ public abstract class AnnotationCodegen {
else { else {
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries(); List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
for (JetAnnotationEntry annotationEntry : annotationEntries) { 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 if (resolvedCall == null) continue; // Skipping annotations if they are not resolved. Needed for JetLightClass generation
AnnotationDescriptor annotationDescriptor = bindingContext.get(BindingContext.ANNOTATION, annotationEntry); AnnotationDescriptor annotationDescriptor = bindingContext.get(BindingContext.ANNOTATION, annotationEntry);
@@ -44,6 +44,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.model.*;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; 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.codegen.binding.CodegenBinding.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.*; 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.AsmTypeConstants.*;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass;
import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin; import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin;
@@ -322,13 +324,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return type == null ? Type.VOID_TYPE : asmType(type); 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 @Override
public StackValue visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, StackValue receiver) { public StackValue visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, StackValue receiver) {
return genQualified(receiver, expression.getExpression()); return genQualified(receiver, expression.getExpression());
@@ -466,7 +461,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
// Is it a "1..2" or so // Is it a "1..2" or so
RangeCodegenUtil.BinaryCall binaryCall = RangeCodegenUtil.getRangeAsBinaryCall(forExpression); RangeCodegenUtil.BinaryCall binaryCall = RangeCodegenUtil.getRangeAsBinaryCall(forExpression);
if (binaryCall != null) { if (binaryCall != null) {
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, binaryCall.op); ResolvedCall<?> resolvedCall = getResolvedCall(binaryCall.op, bindingContext);
if (resolvedCall != null) { if (resolvedCall != null) {
if (RangeCodegenUtil.isOptimizableRangeTo(resolvedCall.getResultingDescriptor())) { if (RangeCodegenUtil.isOptimizableRangeTo(resolvedCall.getResultingDescriptor())) {
generateForLoop(new ForInRangeLiteralLoopGenerator(forExpression, binaryCall)); generateForLoop(new ForInRangeLiteralLoopGenerator(forExpression, binaryCall));
@@ -1348,7 +1343,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
assert superConstructor != null; assert superConstructor != null;
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor); CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor);
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes(); Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
ResolvedCall<?> resolvedCall = resolvedCall(superCall.getCalleeExpression()); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(superCall, bindingContext);
pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(argumentTypes), false, defaultCallGenerator); pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(argumentTypes), false, defaultCallGenerator);
} }
@@ -1657,7 +1652,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override @Override
public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) { public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) {
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, expression); ResolvedCall<?> resolvedCall = getResolvedCall(expression, bindingContext);
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
if (resolvedCall == null) { if (resolvedCall == null) {
@@ -1933,10 +1928,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override @Override
public StackValue visitCallExpression(@NotNull JetCallExpression expression, StackValue receiver) { public StackValue visitCallExpression(@NotNull JetCallExpression expression, StackValue receiver) {
JetExpression callee = expression.getCalleeExpression(); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
assert callee != null;
ResolvedCall<?> resolvedCall = resolvedCall(callee);
CallableDescriptor funDescriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor funDescriptor = resolvedCall.getResultingDescriptor();
if (!(funDescriptor instanceof FunctionDescriptor)) { if (!(funDescriptor instanceof FunctionDescriptor)) {
@@ -1949,7 +1941,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return generateNewCall(expression, resolvedCall, receiver); return generateNewCall(expression, resolvedCall, receiver);
} }
Call call = bindingContext.get(CALL, expression.getCalleeExpression()); Call call = getCall(expression, bindingContext);
if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) { if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) {
//noinspection ConstantConditions //noinspection ConstantConditions
SamType samType = SamType.create(funDescriptor.getReturnType()); SamType samType = SamType.create(funDescriptor.getReturnType());
@@ -2455,7 +2447,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override @Override
public StackValue visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression, StackValue data) { 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); FunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
if (functionDescriptor != null) { if (functionDescriptor != null) {
CallableReferenceGenerationStrategy strategy = new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall); CallableReferenceGenerationStrategy strategy = new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall);
@@ -2732,7 +2724,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return generateIn(StackValue.expression(Type.INT_TYPE, expression.getLeft(), this), expression.getRight(), reference); return generateIn(StackValue.expression(Type.INT_TYPE, expression.getLeft(), this), expression.getRight(), reference);
} }
else { else {
ResolvedCall<?> resolvedCall = resolvedCall(reference); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
Callable callable = resolveToCallable(descriptor, false); Callable callable = resolveToCallable(descriptor, false);
@@ -2743,7 +2735,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return StackValue.onStack(returnType); return StackValue.onStack(returnType);
} }
Call call = bindingContext.get(CALL, reference); Call call = getCall(reference, bindingContext);
return invokeFunction(call, receiver, resolvedCall); return invokeFunction(call, receiver, resolvedCall);
} }
} }
@@ -2754,11 +2746,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
genInIntRange(leftValue, (JetBinaryExpression) deparenthesized); genInIntRange(leftValue, (JetBinaryExpression) deparenthesized);
} }
else { else {
invokeFunction( ResolvedCall<? extends CallableDescriptor> resolvedCall = getResolvedCallWithAssert(operationReference, bindingContext);
bindingContext.get(CALL, operationReference), invokeFunction(resolvedCall.getCall(), StackValue.none(), resolvedCall);
StackValue.none(),
resolvedCall(operationReference)
);
} }
if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) { if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) {
genInvertBoolean(v); genInvertBoolean(v);
@@ -2924,7 +2913,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
private StackValue generateComparison(JetBinaryExpression expression, StackValue receiver) { private StackValue generateComparison(JetBinaryExpression expression, StackValue receiver) {
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference()); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
JetExpression left = expression.getLeft(); JetExpression left = expression.getLeft();
@@ -2940,7 +2929,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
gen(right, type); gen(right, type);
} }
else { else {
Call call = bindingContext.get(CALL, expression.getOperationReference()); Call call = getCall(expression, bindingContext);
StackValue result = invokeFunction(call, receiver, resolvedCall); StackValue result = invokeFunction(call, receiver, resolvedCall);
type = Type.INT_TYPE; type = Type.INT_TYPE;
result.put(type, v); result.put(type, v);
@@ -2959,7 +2948,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
private StackValue generateAugmentedAssignment(JetBinaryExpression expression) { private StackValue generateAugmentedAssignment(JetBinaryExpression expression) {
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference()); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
Callable callable = resolveToCallable(descriptor, false); Callable callable = resolveToCallable(descriptor, false);
JetExpression lhs = expression.getLeft(); JetExpression lhs = expression.getLeft();
@@ -2996,8 +2985,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@NotNull Type lhsType, @NotNull Type lhsType,
boolean keepReturnValue boolean keepReturnValue
) { ) {
Call call = bindingContext.get(CALL, expression.getOperationReference()); Call call = getCallWithAssert(expression, bindingContext);
assert call != null : "Call should be not null for operation reference in " + expression.getText();
StackValue value = gen(expression.getLeft()); StackValue value = gen(expression.getLeft());
if (keepReturnValue) { if (keepReturnValue) {
@@ -3062,11 +3050,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
DeclarationDescriptor cls = op.getContainingDeclaration(); 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"))) { if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
Call call = bindingContext.get(CALL, expression.getOperationReference()); return invokeFunction(resolvedCall.getCall(), receiver, resolvedCall);
return invokeFunction(call, receiver, resolvedCall);
} }
CallableMethod callableMethod = (CallableMethod) callable; CallableMethod callableMethod = (CallableMethod) callable;
@@ -3144,7 +3131,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
storeType = type; storeType = type;
} }
else { else {
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference()); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
Callable callable = resolveToCallable((FunctionDescriptor) op, false); Callable callable = resolveToCallable((FunctionDescriptor) op, false);
CallableMethod callableMethod = (CallableMethod) callable; CallableMethod callableMethod = (CallableMethod) callable;
callableMethod.invokeWithNotNullAssertion(v, state, resolvedCall); callableMethod.invokeWithNotNullAssertion(v, state, resolvedCall);
@@ -45,6 +45,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DeclarationResolver; import org.jetbrains.jet.lang.resolve.DeclarationResolver;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.CallResolverUtil;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
@@ -1387,7 +1388,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private PropertyDescriptor getDelegatePropertyIfAny(JetExpression expression) { private PropertyDescriptor getDelegatePropertyIfAny(JetExpression expression) {
PropertyDescriptor propertyDescriptor = null; PropertyDescriptor propertyDescriptor = null;
if (expression instanceof JetSimpleNameExpression) { if (expression instanceof JetSimpleNameExpression) {
ResolvedCall<?> call = bindingContext.get(BindingContext.RESOLVED_CALL, expression); ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
if (call != null) { if (call != null) {
CallableDescriptor callResultingDescriptor = call.getResultingDescriptor(); CallableDescriptor callResultingDescriptor = call.getResultingDescriptor();
if (callResultingDescriptor instanceof ValueParameterDescriptor) { if (callResultingDescriptor instanceof ValueParameterDescriptor) {
@@ -1581,8 +1582,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor); CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor);
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, ((JetCallElement) superCall).getCalleeExpression()); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(superCall, bindingContext);
assert resolvedCall != null;
ConstructorDescriptor superConstructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor(); ConstructorDescriptor superConstructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor();
//noinspection SuspiciousMethodCalls //noinspection SuspiciousMethodCalls
@@ -1683,9 +1683,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier); throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier);
} }
ResolvedCall<?> resolvedCall = ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(specifier, bindingContext);
bindingContext.get(BindingContext.RESOLVED_CALL, ((JetDelegatorToSuperCall) specifier).getCalleeExpression());
assert resolvedCall != null : "Enum entry delegation specifier is unresolved: " + specifier.getText();
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor()); CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor());
@@ -18,8 +18,6 @@ package org.jetbrains.jet.codegen;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull; 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.context.MethodContext;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; 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.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind; import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind;
import org.jetbrains.jet.lang.resolve.calls.model.*; 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 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.BindingContext.TAIL_RECURSION_CALL;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
public class TailRecursionCodegen { public class TailRecursionCodegen {
@@ -107,7 +107,7 @@ public class TailRecursionCodegen {
JetExpression argumentExpression = argument == null ? null : argument.getArgumentExpression(); JetExpression argumentExpression = argument == null ? null : argument.getArgumentExpression();
if (argumentExpression instanceof JetSimpleNameExpression) { 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())) { if (resolvedCall != null && resolvedCall.getResultingDescriptor().equals(parameterDescriptor.getOriginal())) {
// do nothing: we shouldn't store argument to itself again // do nothing: we shouldn't store argument to itself again
AsmUtil.pop(v, type); AsmUtil.pop(v, type);
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.ExpressionValueArgument;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; 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.ResolvedValueArgument;
@@ -310,7 +311,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
// working around a problem with shallow analysis // working around a problem with shallow analysis
if (functionDescriptor == null) return; if (functionDescriptor == null) return;
ResolvedCall<?> referencedFunction = bindingContext.get(RESOLVED_CALL, expression.getCallableReference()); ResolvedCall<?> referencedFunction = BindingContextUtilPackage.getResolvedCall(expression.getCallableReference(), bindingContext);
if (referencedFunction == null) return; if (referencedFunction == null) return;
Collection<JetType> supertypes = Collection<JetType> supertypes =
runtimeTypes.getSupertypesForFunctionReference((FunctionDescriptor) referencedFunction.getResultingDescriptor()); runtimeTypes.getSupertypesForFunctionReference((FunctionDescriptor) referencedFunction.getResultingDescriptor());
@@ -401,7 +402,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
@Override @Override
public void visitCallExpression(@NotNull JetCallExpression expression) { public void visitCallExpression(@NotNull JetCallExpression expression) {
super.visitCallExpression(expression); super.visitCallExpression(expression);
ResolvedCall<?> call = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression()); ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
if (call == null) return; if (call == null) return;
CallableDescriptor descriptor = call.getResultingDescriptor(); CallableDescriptor descriptor = call.getResultingDescriptor();
@@ -19,17 +19,17 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; 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.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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.jet.lang.resolve.calls.model.VarargValueArgument; 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.List;
import java.util.Map; import java.util.Map;
@@ -45,9 +45,7 @@ public class JavaClassArray extends IntrinsicMethod {
@Nullable List<JetExpression> arguments, @Nullable List<JetExpression> arguments,
StackValue receiver StackValue receiver
) { ) {
ResolvedCall<?> call = ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCallWithAssert((JetElement) element, codegen.getBindingContext());
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
assert call != null;
Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next(); Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next();
codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue()); codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue());
return returnType; return returnType;
@@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; 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.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.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
@@ -45,9 +45,8 @@ public class JavaClassFunction extends IntrinsicMethod {
@Nullable List<JetExpression> arguments, @Nullable List<JetExpression> arguments,
StackValue receiver StackValue receiver
) { ) {
JetCallExpression call = (JetCallExpression) element; ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(
ResolvedCall<?> resolvedCall = codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression()); (JetElement) element, codegen.getBindingContext());
assert resolvedCall != null;
JetType returnType = resolvedCall.getResultingDescriptor().getReturnType(); JetType returnType = resolvedCall.getResultingDescriptor().getReturnType();
assert returnType != null; assert returnType != null;
putJavaLangClassInstance(v, codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType())); putJavaLangClassInstance(v, codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType()));
@@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; 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.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.ResolvedCall;
import org.jetbrains.org.objectweb.asm.Opcodes; import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
@@ -56,8 +56,7 @@ public class MonitorInstruction extends IntrinsicMethod {
@Nullable StackValue receiver @Nullable StackValue receiver
) { ) {
assert element != null : "Element should not be null"; assert element != null : "Element should not be null";
ResolvedCall<?> resolvedCall = ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall((JetElement) element, codegen.getBindingContext());
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null"; assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null";
@@ -53,6 +53,7 @@ import java.util.*;
import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*; import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; 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.*; import static org.jetbrains.jet.lexer.JetTokens.*;
public class JetControlFlowProcessor { public class JetControlFlowProcessor {
@@ -235,7 +236,7 @@ public class JetControlFlowProcessor {
@NotNull @NotNull
private AccessTarget getResolvedCallAccessTarget(JetElement element) { 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$; return resolvedCall != null ? new AccessTarget.Call(resolvedCall) : AccessTarget.BlackBox.instance$;
} }
@@ -268,7 +269,7 @@ public class JetControlFlowProcessor {
@Override @Override
public void visitThisExpression(@NotNull JetThisExpression expression) { public void visitThisExpression(@NotNull JetThisExpression expression) {
ResolvedCall<?> resolvedCall = getResolvedCall(expression); ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
if (resolvedCall == null) { if (resolvedCall == null) {
createNonSyntheticValue(expression); createNonSyntheticValue(expression);
return; return;
@@ -290,7 +291,7 @@ public class JetControlFlowProcessor {
@Override @Override
public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
ResolvedCall<?> resolvedCall = getResolvedCall(expression); ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall; VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
generateCall(expression, variableAsFunctionResolvedCall.getVariableCall()); generateCall(expression, variableAsFunctionResolvedCall.getVariableCall());
@@ -325,9 +326,9 @@ public class JetControlFlowProcessor {
visitAssignment(left, getDeferredValue(right), expression); visitAssignment(left, getDeferredValue(right), expression);
} }
else if (OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(operationType)) { else if (OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(operationType)) {
ResolvedCall<?> resolvedCall = getResolvedCall(operationReference); ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
if (resolvedCall != null) { if (resolvedCall != null) {
PseudoValue rhsValue = generateCall(operationReference, resolvedCall).getOutputValue(); PseudoValue rhsValue = generateCall(expression, resolvedCall).getOutputValue();
Name assignMethodName = OperatorConventions.getNameForOperationSymbol((JetToken) expression.getOperationToken()); Name assignMethodName = OperatorConventions.getNameForOperationSymbol((JetToken) expression.getOperationToken());
if (!resolvedCall.getResultingDescriptor().getName().equals(assignMethodName)) { if (!resolvedCall.getResultingDescriptor().getName().equals(assignMethodName)) {
/* At this point assignment of the form a += b actually means a = a + b /* 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); mergeValues(Arrays.asList(left, right), expression);
} }
else { else {
if (!generateCall(operationReference)) { if (!generateCall(expression)) {
generateBothArgumentsAndMark(expression); generateBothArgumentsAndMark(expression);
} }
} }
@@ -572,11 +573,11 @@ public class JetControlFlowProcessor {
} }
boolean incrementOrDecrement = isIncrementOrDecrement(operationType); boolean incrementOrDecrement = isIncrementOrDecrement(operationType);
ResolvedCall<?> resolvedCall = getResolvedCall(operationSign); ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
PseudoValue rhsValue; PseudoValue rhsValue;
if (resolvedCall != null) { if (resolvedCall != null) {
rhsValue = generateCall(operationSign, resolvedCall).getOutputValue(); rhsValue = generateCall(expression, resolvedCall).getOutputValue();
} }
else { else {
generateInstructions(baseExpression); generateInstructions(baseExpression);
@@ -1069,8 +1070,7 @@ public class JetControlFlowProcessor {
@Override @Override
public void visitCallExpression(@NotNull JetCallExpression expression) { public void visitCallExpression(@NotNull JetCallExpression expression) {
JetExpression calleeExpression = expression.getCalleeExpression(); if (!generateCall(expression)) {
if (!generateCall(calleeExpression)) {
List<JetExpression> inputExpressions = new ArrayList<JetExpression>(); List<JetExpression> inputExpressions = new ArrayList<JetExpression>();
for (ValueArgument argument : expression.getValueArguments()) { for (ValueArgument argument : expression.getValueArguments()) {
JetExpression argumentExpression = argument.getArgumentExpression(); JetExpression argumentExpression = argument.getArgumentExpression();
@@ -1083,6 +1083,7 @@ public class JetControlFlowProcessor {
generateInstructions(functionLiteral); generateInstructions(functionLiteral);
inputExpressions.add(functionLiteral); inputExpressions.add(functionLiteral);
} }
JetExpression calleeExpression = expression.getCalleeExpression();
generateInstructions(calleeExpression); generateInstructions(calleeExpression);
inputExpressions.add(calleeExpression); inputExpressions.add(calleeExpression);
inputExpressions.add(generateAndGetReceiverIfAny(expression)); inputExpressions.add(generateAndGetReceiverIfAny(expression));
@@ -1373,38 +1374,26 @@ public class JetControlFlowProcessor {
builder.unsupported(element); builder.unsupported(element);
} }
@Nullable private boolean generateCall(@Nullable JetExpression callExpression) {
private ResolvedCall<?> getResolvedCall(@NotNull JetElement expression) { if (callExpression == null) return false;
return trace.get(BindingContext.RESOLVED_CALL, expression); return checkAndGenerateCall(callExpression, getResolvedCall(callExpression, trace.getBindingContext()));
} }
private boolean checkAndGenerateCall(@NotNull JetExpression callExpression, @Nullable ResolvedCall<?> resolvedCall) {
private boolean generateCall(@Nullable JetExpression calleeExpression) {
if (calleeExpression == null) return false;
return checkAndGenerateCall(calleeExpression, getResolvedCall(calleeExpression));
}
private boolean checkAndGenerateCall(
JetExpression calleeExpression,
@Nullable ResolvedCall<?> resolvedCall
) {
if (resolvedCall == null) { if (resolvedCall == null) {
builder.compilationError(calleeExpression, "No resolved call"); builder.compilationError(callExpression, "No resolved call");
return false; return false;
} }
generateCall(calleeExpression, resolvedCall); generateCall(callExpression, resolvedCall);
return true; return true;
} }
@NotNull @NotNull
private InstructionWithValue generateCall(JetExpression calleeExpression, ResolvedCall<?> resolvedCall) { private InstructionWithValue generateCall(@NotNull JetExpression callExpression, @NotNull ResolvedCall<?> resolvedCall) {
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall; 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(); CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
Map<PseudoValue, ReceiverValue> receivers = getReceiverValues(resolvedCall, true); Map<PseudoValue, ReceiverValue> receivers = getReceiverValues(resolvedCall, true);
SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues = SmartFMap.emptyMap(); SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues = SmartFMap.emptyMap();
@@ -1416,14 +1405,17 @@ public class JetControlFlowProcessor {
} }
if (resultingDescriptor instanceof VariableDescriptor) { if (resultingDescriptor instanceof VariableDescriptor) {
assert callExpression != null // If a callee of the call is just a variable (without 'invoke'), 'read variable' is generated.
: "Variable-based call without call expression: " + callElement.getText(); // 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() assert parameterValues.isEmpty()
: "Variable-based call with non-empty argument list: " + callElement.getText(); : "Variable-based call with non-empty argument list: " + callExpression.getText();
return builder.readVariable(calleeExpression, callExpression, resolvedCall, receivers); return builder.readVariable(calleeExpression, calleeExpression, resolvedCall, receivers);
} }
mark(resolvedCall.getCall().getCallElement()); mark(resolvedCall.getCall().getCallElement());
return builder.call(calleeExpression, callExpression, resolvedCall, receivers, parameterValues); return builder.call(callExpression, callExpression, resolvedCall, receivers, parameterValues);
} }
@NotNull @NotNull
@@ -68,7 +68,9 @@ import java.util.*;
import static org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseState.*; 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.cfg.pseudocodeTraverser.TraversalOrder.FORWARD;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; 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.resolve.calls.TailRecursionKind.*;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType; import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@@ -725,7 +727,7 @@ public class JetFlowInformationProvider {
if (!(instruction instanceof CallInstruction)) return; if (!(instruction instanceof CallInstruction)) return;
CallInstruction callInstruction = (CallInstruction) instruction; CallInstruction callInstruction = (CallInstruction) instruction;
ResolvedCall<?> resolvedCall = trace.get(RESOLVED_CALL, callInstruction.getElement()); ResolvedCall<?> resolvedCall = getResolvedCall(callInstruction.getElement(), trace.getBindingContext());
if (resolvedCall == null) return; if (resolvedCall == null) return;
// is this a recursive call? // is this a recursive call?
@@ -33,6 +33,7 @@ import org.jetbrains.jet.JetNodeTypes
import java.math.BigInteger import java.math.BigInteger
import org.jetbrains.jet.lang.diagnostics.Errors import org.jetbrains.jet.lang.diagnostics.Errors
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() { public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() {
@@ -179,7 +180,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
} }
private fun evaluateCall(callExpression: JetExpression, receiverExpression: JetExpression, expectedType: JetType?): CompileTimeConstant<*>? { 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 if (resolvedCall == null) return null
val resultingDescriptorName = resolvedCall.getResultingDescriptor().getName() val resultingDescriptorName = resolvedCall.getResultingDescriptor().getName()
@@ -309,7 +310,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
return EnumValue(enumDescriptor as ClassDescriptor, false); return EnumValue(enumDescriptor as ClassDescriptor, false);
} }
val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, expression) val resolvedCall = expression.getResolvedCall(trace.getBindingContext())
if (resolvedCall != null) { if (resolvedCall != null) {
val callableDescriptor = resolvedCall.getResultingDescriptor() val callableDescriptor = resolvedCall.getResultingDescriptor()
if (callableDescriptor is VariableDescriptor) { if (callableDescriptor is VariableDescriptor) {
@@ -351,7 +352,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
} }
override fun visitCallExpression(expression: JetCallExpression, expectedType: JetType?): CompileTimeConstant<*>? { 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 if (call == null) return null
val resultingDescriptor = call.getResultingDescriptor() val resultingDescriptor = call.getResultingDescriptor()
@@ -733,30 +733,6 @@ public class JetPsiUtil {
return node == null ? null : node.getPsi(); 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 @Nullable
public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) { public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) {
if (element == null) return null; if (element == null) return null;
@@ -34,6 +34,7 @@ import com.intellij.psi.JavaDirectoryService
import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiDirectory
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassOrObjectStub import org.jetbrains.jet.lang.psi.stubs.PsiJetClassOrObjectStub
import org.jetbrains.jet.lang.types.expressions.OperatorConventions import org.jetbrains.jet.lang.types.expressions.OperatorConventions
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
public fun JetCallElement.getCallNameExpression(): JetSimpleNameExpression? { public fun JetCallElement.getCallNameExpression(): JetSimpleNameExpression? {
val calleeExpression = getCalleeExpression() val calleeExpression = getCalleeExpression()
@@ -312,4 +313,17 @@ public fun JetSimpleNameExpression.isImportDirectiveExpression(): Boolean {
else { else {
return parent is JetImportDirective || parent.getParent() is JetImportDirective return parent is JetImportDirective || parent.getParent() is JetImportDirective
} }
} }
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)}"
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator; import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.jet.lang.psi.*; 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.ArgumentTypeResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
@@ -324,7 +325,7 @@ public class AnnotationResolver {
@NotNull JetCallExpression expression, @NotNull JetCallExpression expression,
@NotNull BindingTrace trace @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)) { if (resolvedCall == null || !CompileTimeConstantUtils.isArrayMethodCall(resolvedCall)) {
return null; return null;
} }
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; 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.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
@@ -301,26 +302,12 @@ public class BindingContextUtils {
@NotNull BindingContext context @NotNull BindingContext context
) { ) {
if (expression instanceof JetCallExpression) { if (expression instanceof JetCallExpression) {
return isCallExpressionWithValidReference(expression, context); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
return resolvedCall instanceof VariableAsFunctionResolvedCall;
} }
return expression instanceof JetReferenceExpression; 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) { public static boolean isVarCapturedInClosure(BindingContext bindingContext, DeclarationDescriptor descriptor) {
if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor) return false; if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor) return false;
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor; VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
@@ -20,10 +20,9 @@ import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.Call import org.jetbrains.jet.lang.psi.Call
import org.jetbrains.jet.lang.psi.JetPsiUtil import org.jetbrains.jet.lang.psi.JetPsiUtil
import org.jetbrains.jet.lang.psi.JetCallExpression 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.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetOperationExpression
import org.jetbrains.jet.lang.resolve.BindingContext.CALL 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.psi.JetReturnExpression
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.lang.resolve.BindingContext.LABEL_TARGET 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 org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetThisExpression 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 <code>a(), a[i], a.b.c(), +a, a + b, (a()), a(): Int, @label a()</code> * For expressions like <code>a(), a[i], a.b.c(), +a, a + b, (a()), a(): Int, @label a()</code>
@@ -48,46 +56,79 @@ import org.jetbrains.jet.lang.psi.JetThisExpression
* Note: special construction like <code>a!!, a ?: b, if (c) a else b</code> are resolved as calls, * Note: special construction like <code>a!!, a ?: b, if (c) a else b</code> are resolved as calls,
* so there is a corresponding call for them. * so there is a corresponding call for them.
*/ */
fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? { public fun JetElement.getCall(context: BindingContext): Call? {
val expr = JetPsiUtil.deparenthesize(this) val element = if (this is JetExpression) JetPsiUtil.deparenthesize(this) else this
if (expr == null) return null if (element == null) return null
if (expr is JetQualifiedExpression) { val parent = element.getParent()
return expr.getSelectorExpression()?.getCorrespondingCall(bindingContext)
}
val parent = expr.getParent()
val reference = when { val reference = when {
parent is JetThisExpression -> parent : JetThisExpression parent is JetThisExpression -> parent : JetThisExpression
expr is JetCallExpression -> expr.getCalleeExpression() else -> element.getCalleeExpressionIfAny()
expr is JetOperationExpression -> expr.getOperationReference()
else -> expr
} }
return bindingContext[CALL, reference] if (reference != null) {
return context[CALL, reference]
}
return context[CALL, element]
} }
fun JetExpression.getEnclosingCall(bindingContext: BindingContext): Call? { public fun JetExpression.getParentCall(context: BindingContext): Call? {
val parent = PsiTreeUtil.getNonStrictParentOfType<JetExpression>( val parent = PsiTreeUtil.getNonStrictParentOfType<JetElement>(
this, this,
javaClass<JetSimpleNameExpression>(), javaClass<JetCallExpression>(), javaClass<JetBinaryExpression>(), javaClass<JetSimpleNameExpression>(), javaClass<JetCallElement>(), javaClass<JetBinaryExpression>(),
javaClass<JetUnaryExpression>(), javaClass<JetArrayAccessExpression>()) javaClass<JetUnaryExpression>(), javaClass<JetArrayAccessExpression>())
return parent?.getCorrespondingCall(bindingContext) return parent?.getCall(context)
} }
fun Call.hasUnresolvedArguments(bindingContext: BindingContext): Boolean { public fun Call?.getResolvedCall(context: BindingContext): ResolvedCall<out CallableDescriptor>? {
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<out CallableDescriptor>? {
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<out CallableDescriptor> {
return getResolvedCall(context).sure("No resolved call for ${this.getTextWithLocation()}")
}
public fun Call.getResolvedCallWithAssert(context: BindingContext): ResolvedCall<out CallableDescriptor> {
return getResolvedCall(context).sure("No resolved call for ${this.getCallElement().getTextWithLocation()}")
}
public fun JetExpression.getFunctionResolvedCallWithAssert(context: BindingContext): ResolvedCall<out FunctionDescriptor> {
val resolvedCall = getResolvedCallWithAssert(context)
assert(resolvedCall.getResultingDescriptor() is FunctionDescriptor) {
"ResolvedCall for this expression must be ResolvedCall<? extends FunctionDescriptor>: ${this.getTextWithLocation()}"
}
[suppress("UNCHECKED_CAST")]
return resolvedCall as ResolvedCall<out FunctionDescriptor>
}
public fun Call.hasUnresolvedArguments(context: BindingContext): Boolean {
val arguments = getValueArguments().map { it?.getArgumentExpression() } val arguments = getValueArguments().map { it?.getArgumentExpression() }
return arguments.any { return arguments.any {
argument -> argument ->
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, argument] val expressionType = context[BindingContext.EXPRESSION_TYPE, argument]
argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument) argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument)
&& (expressionType == null || expressionType.isError()) && (expressionType == null || expressionType.isError())
} }
} }
public fun JetReturnExpression.getTargetFunctionDescriptor(bindingContext: BindingContext): FunctionDescriptor? { public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? {
val targetLabel = getTargetLabel() 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<JetDeclarationWithBody>())] val declarationDescriptor = context[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass<JetDeclarationWithBody>())]
val containingFunctionDescriptor = DescriptorUtils.getParentOfType(declarationDescriptor, javaClass<FunctionDescriptor>(), false) val containingFunctionDescriptor = DescriptorUtils.getParentOfType(declarationDescriptor, javaClass<FunctionDescriptor>(), false)
if (containingFunctionDescriptor == null) return null if (containingFunctionDescriptor == null) return null
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers; import org.jetbrains.jet.lang.diagnostics.rendering.Renderers;
import org.jetbrains.jet.lang.psi.*; 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.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; 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.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression; 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.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.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType; import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@@ -227,7 +229,7 @@ public class DelegatedPropertyResolver {
@NotNull DataFlowInfo dataFlowInfo @NotNull DataFlowInfo dataFlowInfo
) { ) {
TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property"); TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property");
JetExpression calleeExpression = JetPsiUtil.getCalleeExpressionIfAny(delegateExpression); JetExpression calleeExpression = getCalleeExpressionIfAny(delegateExpression);
ConstraintSystemCompleter completer = createConstraintSystemCompleter( ConstraintSystemCompleter completer = createConstraintSystemCompleter(
jetProperty, propertyDescriptor, delegateExpression, accessorScope, trace); jetProperty, propertyDescriptor, delegateExpression, accessorScope, trace);
if (calleeExpression != null) { if (calleeExpression != null) {
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
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.ResolvedCall;
public class InlineDescriptorUtils { public class InlineDescriptorUtils {
@@ -45,8 +46,7 @@ public class InlineDescriptorUtils {
boolean isInlinedLambda = false; boolean isInlinedLambda = false;
JetExpression call = JetPsiUtil.getParentCallIfPresent((JetFunctionLiteralExpression) containingFunction); JetExpression call = JetPsiUtil.getParentCallIfPresent((JetFunctionLiteralExpression) containingFunction);
if (call != null) { if (call != null) {
//TODO: ask sveta ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(call, bindingContext);
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, JetPsiUtil.getCalleeExpressionIfAny(call));
CallableDescriptor resultingDescriptor = resolvedCall == null ? null : resolvedCall.getResultingDescriptor(); CallableDescriptor resultingDescriptor = resolvedCall == null ? null : resolvedCall.getResultingDescriptor();
if (resultingDescriptor instanceof SimpleFunctionDescriptor) { if (resultingDescriptor instanceof SimpleFunctionDescriptor) {
isInlinedLambda = ((SimpleFunctionDescriptor) resultingDescriptor).getInlineStrategy().isInline(); isInlinedLambda = ((SimpleFunctionDescriptor) resultingDescriptor).getInlineStrategy().isInline();
@@ -52,7 +52,7 @@ import org.jetbrains.jet.lang.psi.Call
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils
import org.jetbrains.jet.lang.psi.JetBlockExpression import org.jetbrains.jet.lang.psi.JetBlockExpression
import org.jetbrains.jet.lang.psi.JetPsiUtil 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.psi.JetSafeQualifiedExpression
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace
@@ -286,7 +286,7 @@ public class CallCompleter(
val lastStatement = JetPsiUtil.getLastStatementInABlock(argument) val lastStatement = JetPsiUtil.getLastStatementInABlock(argument)
return getCallForArgument(lastStatement as? JetExpression, bindingContext) return getCallForArgument(lastStatement as? JetExpression, bindingContext)
} }
return argument?.getCorrespondingCall(bindingContext) return argument?.getCall(bindingContext)
} }
private fun updateRecordedTypeForArgument( private fun updateRecordedTypeForArgument(
@@ -273,7 +273,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
@NotNull @NotNull
@Override @Override
public ReceiverValue getThisObject() { public ExpressionReceiver getThisObject() {
return calleeExpressionAsThisObject; return calleeExpressionAsThisObject;
} }
@@ -23,11 +23,14 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; 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.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.InlineDescriptorUtils; 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.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.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
@@ -180,8 +183,9 @@ public class InlineCallResolverExtension implements CallResolverExtension {
@NotNull JetExpression expression, @NotNull JetExpression expression,
boolean unwrapVariableAsFunction boolean unwrapVariableAsFunction
) { ) {
// todo ask sveta if (!(expression instanceof JetSimpleNameExpression || expression instanceof JetThisExpression)) return null;
ResolvedCall<?> thisCall = context.trace.get(BindingContext.RESOLVED_CALL, expression);
ResolvedCall<?> thisCall = BindingContextUtilPackage.getResolvedCall(expression, context.trace.getBindingContext());
if (unwrapVariableAsFunction && thisCall instanceof VariableAsFunctionResolvedCall) { if (unwrapVariableAsFunction && thisCall instanceof VariableAsFunctionResolvedCall) {
return ((VariableAsFunctionResolvedCall) thisCall).getVariableCall().getResultingDescriptor(); return ((VariableAsFunctionResolvedCall) thisCall).getVariableCall().getResultingDescriptor();
} }
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.JetModuleUtil; 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.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.receivers.*; import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
import org.jetbrains.jet.lang.types.JetType; 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 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.REFERENCE_TARGET;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
public class DataFlowValueFactory { public class DataFlowValueFactory {
private DataFlowValueFactory() {} private DataFlowValueFactory() {}
@@ -166,13 +166,14 @@ public class DataFlowValueFactory {
) { ) {
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression); DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
if (declarationDescriptor instanceof VariableDescriptor) { if (declarationDescriptor instanceof VariableDescriptor) {
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, simpleNameExpression); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(simpleNameExpression, bindingContext);
// todo uncomment assert // todo uncomment assert
// KT-4113 // KT-4113
// for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes // 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; // 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; VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor))); return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor)));
@@ -68,6 +68,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy {
public <D extends CallableDescriptor> void bindResolvedCall( public <D extends CallableDescriptor> void bindResolvedCall(
@NotNull BindingTrace trace, @NotNull ResolvedCall<D> resolvedCall @NotNull BindingTrace trace, @NotNull ResolvedCall<D> resolvedCall
) { ) {
if (reference instanceof JetSimpleNameExpression) return;
trace.record(RESOLVED_CALL, reference, resolvedCall); trace.record(RESOLVED_CALL, reference, resolvedCall);
} }
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; 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.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
@@ -153,7 +154,7 @@ public class ExpressionTypingUtils {
return false; return false;
} }
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context);
if (resolvedCall == null) { if (resolvedCall == null) {
return false; return false;
} }
@@ -0,0 +1,3 @@
public inline fun test(predicate: (Char) -> Boolean) {
!predicate('c')
}
@@ -4773,6 +4773,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/mathOperation.kt"); 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") @TestMetadata("notOperation.kt")
public void testNotOperation() throws Exception { public void testNotOperation() throws Exception {
doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt"); doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt");
@@ -20,7 +20,6 @@ import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.JetLiteFixture import org.jetbrains.jet.JetLiteFixture
import org.jetbrains.jet.JetTestUtils import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment 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.calls.model.ResolvedCall
import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver 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.ValueArgument
import org.jetbrains.jet.lang.psi.JetPsiFactory import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetExpression 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 com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCallWithAssert
public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY) override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
@@ -51,19 +51,16 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
val element = jetFile.findElementAt(text.indexOf("<caret>")) val element = jetFile.findElementAt(text.indexOf("<caret>"))
val expression = PsiTreeUtil.getParentOfType(element, javaClass<JetExpression>()) val expression = PsiTreeUtil.getParentOfType(element, javaClass<JetExpression>())
val call = expression?.getEnclosingCall(bindingContext) val call = expression?.getParentCall(bindingContext)
val cachedCall = bindingContext[BindingContext.RESOLVED_CALL, call?.getCalleeExpression()] val cachedCall = call?.getResolvedCallWithAssert(bindingContext)
if (cachedCall == null) {
throw AssertionError("No resolved call for:\nelement: ${element.toString()}\nexpression: ${expression.toString()}\ncall: $call")
}
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
else if ("(" == element?.getText()) cachedCall.functionCall else if ("(" == element?.getText()) cachedCall.functionCall
else cachedCall.variableCall else cachedCall.variableCall
val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt" 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()}")
} }
} }
@@ -36,8 +36,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiDocumentManager
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall 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.renderer.DescriptorRenderer.FQ_NAMES_IN_TYPES
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public object ShortenReferences { public object ShortenReferences {
public fun process(element: JetElement) { public fun process(element: JetElement) {
@@ -318,8 +318,7 @@ public object ShortenReferences {
private fun resolveState(referenceExpression: JetReferenceExpression, bindingContext: BindingContext): Any? { private fun resolveState(referenceExpression: JetReferenceExpression, bindingContext: BindingContext): Any? {
val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression] val target = bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]
if (target != null) { if (target != null) {
val resolvedCallKey = (referenceExpression.getParent() as? JetThisExpression) ?: referenceExpression val resolvedCall = referenceExpression.getResolvedCall(bindingContext)
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, resolvedCallKey]
if (resolvedCall != null) return resolvedCall.asString() if (resolvedCall != null) return resolvedCall.asString()
return target.asString() return target.asString()
@@ -43,6 +43,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; 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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.jet.lang.resolve.extension.InlineAnalyzerExtension; import org.jetbrains.jet.lang.resolve.extension.InlineAnalyzerExtension;
@@ -281,16 +282,9 @@ public class JetPositionManager implements PositionManager {
parent = parent.getParent(); parent = parent.getParent();
} }
if ((parent == null || !(parent instanceof JetBinaryExpression)) && !(parent instanceof JetCallExpression)) return false; if (!(parent instanceof JetElement)) 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());
}
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall((JetElement) parent, context);
if (call == null) return false; if (call == null) return false;
InlineStrategy inlineType = InlineUtil.getInlineType(call.getResultingDescriptor()); InlineStrategy inlineType = InlineUtil.getInlineType(call.getResultingDescriptor());
@@ -20,7 +20,6 @@ import com.intellij.debugger.actions.JvmSmartStepIntoHandler
import com.intellij.debugger.SourcePosition import com.intellij.debugger.SourcePosition
import com.intellij.debugger.actions.SmartStepTarget import com.intellij.debugger.actions.SmartStepTarget
import java.util.Collections import java.util.Collections
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.debugger.actions.MethodSmartStepTarget import com.intellij.debugger.actions.MethodSmartStepTarget
import com.intellij.util.containers.OrderedSet import com.intellij.util.containers.OrderedSet
import com.intellij.util.Range 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.resolve.BindingContextUtils
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.util.text.CharArrayUtil
import org.jetbrains.jet.lang.psi.* import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import com.intellij.debugger.engine.MethodFilter import com.intellij.debugger.engine.MethodFilter
@@ -38,11 +36,9 @@ import com.intellij.debugger.engine.BasicStepMethodFilter
import com.intellij.debugger.engine.DebugProcessImpl import com.intellij.debugger.engine.DebugProcessImpl
import com.sun.jdi.Location import com.sun.jdi.Location
import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiFile
import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils
import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiClass import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
@@ -127,7 +123,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
} }
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) { override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, expression] val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall != null) { if (resolvedCall != null) {
val propertyDescriptor = resolvedCall.getResultingDescriptor() val propertyDescriptor = resolvedCall.getResultingDescriptor()
if (propertyDescriptor is PropertyDescriptor) { if (propertyDescriptor is PropertyDescriptor) {
@@ -162,7 +158,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
} }
private fun recordFunction(expression: JetExpression) { private fun recordFunction(expression: JetExpression) {
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, expression] val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall == null) return if (resolvedCall == null) return
val descriptor = resolvedCall.getResultingDescriptor() val descriptor = resolvedCall.getResultingDescriptor()
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
@@ -62,7 +63,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
@Override @Override
public void visitReferenceExpression(@NotNull JetReferenceExpression expression) { public void visitReferenceExpression(@NotNull JetReferenceExpression expression) {
super.visitReferenceExpression(expression); super.visitReferenceExpression(expression);
ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression); ResolvedCall resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) {
// Deprecated for invoke() // Deprecated for invoke()
JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class); JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class);
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -66,28 +67,26 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
@Override @Override
public void visitCallExpression(@NotNull JetCallExpression expression) { public void visitCallExpression(@NotNull JetCallExpression expression) {
JetExpression callee = expression.getCalleeExpression(); JetExpression callee = expression.getCalleeExpression();
if (callee instanceof JetReferenceExpression) { ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, (JetReferenceExpression) callee); if (callee instanceof JetReferenceExpression && resolvedCall != null) {
if (resolvedCall != null) { DeclarationDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
DeclarationDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor(); if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { JetPsiChecker.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor)
JetPsiChecker.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor) ? JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL
? JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL : JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
: JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL); }
else {
if (calleeDescriptor instanceof ConstructorDescriptor) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
} }
else { else if (calleeDescriptor instanceof FunctionDescriptor) {
if (calleeDescriptor instanceof ConstructorDescriptor) { FunctionDescriptor fun = (FunctionDescriptor) calleeDescriptor;
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL); JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
if (DescriptorUtils.isTopLevelDeclaration(fun)) {
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.PACKAGE_FUNCTION_CALL);
} }
else if (calleeDescriptor instanceof FunctionDescriptor) { if (fun.getReceiverParameter() != null) {
FunctionDescriptor fun = (FunctionDescriptor) calleeDescriptor; JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL);
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);
}
} }
} }
} }
@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache 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.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences 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.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetIfExpression import org.jetbrains.jet.lang.psi.JetIfExpression
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>( public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
"convert.assert.to.if.with.throw", javaClass()) { "convert.assert.to.if.with.throw", javaClass()) {
@@ -43,7 +43,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
if (!(arguments == 1 && (lambdas == 1 || lambdas == 0)) && arguments != 2) return false if (!(arguments == 1 && (lambdas == 1 || lambdas == 0)) && arguments != 2) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element) val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false if (resolvedCall == null) return false
val valParameters = resolvedCall.getResultingDescriptor().getValueParameters() val valParameters = resolvedCall.getResultingDescriptor().getValueParameters()
@@ -19,26 +19,17 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache 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.JetPsiFactory
import org.jetbrains.jet.lang.psi.JetPrefixExpression import org.jetbrains.jet.lang.psi.JetPrefixExpression
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.lang.psi.JetCallableReferenceExpression
import org.jetbrains.jet.lang.resolve.DescriptorUtils import org.jetbrains.jet.lang.resolve.DescriptorUtils
import kotlin.properties.Delegates
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetIfExpression import org.jetbrains.jet.lang.psi.JetIfExpression
import org.jetbrains.jet.plugin.intentions.branchedTransformations.extractExpressionIfSingle import org.jetbrains.jet.plugin.intentions.branchedTransformations.extractExpressionIfSingle
import org.jetbrains.jet.lang.psi.JetThrowExpression import org.jetbrains.jet.lang.psi.JetThrowExpression
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.jet.renderer.DescriptorRenderer
import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetUserType
import org.jetbrains.jet.plugin.intentions.branchedTransformations.isNullExpression import org.jetbrains.jet.plugin.intentions.branchedTransformations.isNullExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertIfWithThrowToAssertIntention : public class ConvertIfWithThrowToAssertIntention :
JetSelfTargetingIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) { JetSelfTargetingIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) {
@@ -58,7 +49,7 @@ public class ConvertIfWithThrowToAssertIntention :
if (paramAmount > 1) return false if (paramAmount > 1) return false
val context = AnalyzerFacadeWithCache.getContextForElement(thrownExpr) val context = AnalyzerFacadeWithCache.getContextForElement(thrownExpr)
val resolvedCall = context[BindingContext.RESOLVED_CALL, thrownExpr.getCalleeExpression()] val resolvedCall = thrownExpr.getResolvedCall(context)
if (resolvedCall == null) return false if (resolvedCall == null) return false
return DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() == "java.lang.AssertionError.<init>" return DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() == "java.lang.AssertionError.<init>"
@@ -24,10 +24,9 @@ import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.lang.psi.JetBinaryExpression import org.jetbrains.jet.lang.psi.JetBinaryExpression
import org.jetbrains.jet.lang.resolve.DescriptorUtils 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.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpression>("convert.to.for.each.loop.intention", javaClass()) { public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpression>("convert.to.for.each.loop.intention", javaClass()) {
private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? { private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? {
@@ -75,16 +74,14 @@ public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpres
} }
} }
val callee = JetPsiUtil.getCalleeExpressionIfAny(element)
val functionLiteral = getFunctionLiteralArgument(element) val functionLiteral = getFunctionLiteralArgument(element)
if (callee != null && if (functionLiteral != null &&
functionLiteral != null &&
isWellFormedFunctionLiteral(functionLiteral) && isWellFormedFunctionLiteral(functionLiteral) &&
checkTotalNumberOfArguments(element)) { checkTotalNumberOfArguments(element)) {
val context = element.getContainingJetFile().getLazyResolveSession().resolveToElement(callee) val context = element.getContainingJetFile().getLazyResolveSession().resolveToElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, callee] val resolvedCall = element.getResolvedCall(context)
val functionFqName = if (resolvedCall != null) DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() else null val functionFqName = if (resolvedCall != null) DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() else null
return "kotlin.forEach".equals(functionFqName); return "kotlin.forEach".equals(functionFqName);
@@ -19,11 +19,11 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache 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.JetPsiFactory
import org.jetbrains.jet.lang.types.ErrorUtils import org.jetbrains.jet.lang.types.ErrorUtils
import org.jetbrains.jet.renderer.DescriptorRenderer import org.jetbrains.jet.renderer.DescriptorRenderer
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>( public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>(
"insert.explicit.type.arguments", javaClass()) { "insert.explicit.type.arguments", javaClass()) {
@@ -40,7 +40,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false
val context = AnalyzerFacadeWithCache.getContextForElement(element) val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return false if (resolvedCall == null) return false
val types = resolvedCall.getTypeArguments() val types = resolvedCall.getTypeArguments()
@@ -49,7 +49,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
override fun applyTo(element: JetCallExpression, editor: Editor) { override fun applyTo(element: JetCallExpression, editor: Editor) {
val context = AnalyzerFacadeWithCache.getContextForElement(element) val context = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val resolvedCall = element.getResolvedCall(context)
if (resolvedCall == null) return if (resolvedCall == null) return
val args = resolvedCall.getTypeArguments() val args = resolvedCall.getTypeArguments()
@@ -19,8 +19,8 @@ package org.jetbrains.jet.plugin.intentions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.lang.psi.JetPsiFactory import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.caches.resolve.getBindingContext import org.jetbrains.jet.plugin.caches.resolve.getBindingContext
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<JetCallExpression>( public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<JetCallExpression>(
"move.lambda.inside.parentheses", javaClass()) { "move.lambda.inside.parentheses", javaClass()) {
@@ -44,7 +44,7 @@ public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<Je
} }
if (element.getValueArguments().any { it?.getArgumentName() != null}) { if (element.getValueArguments().any { it?.getArgumentName() != null}) {
val context = element.getBindingContext() val context = element.getBindingContext()
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val resolvedCall = element.getResolvedCall(context)
val literalName = resolvedCall?.getResultingDescriptor()?.getValueParameters()?.last?.getName().toString() val literalName = resolvedCall?.getResultingDescriptor()?.getValueParameters()?.last?.getName().toString()
sb.append("$literalName = ") sb.append("$literalName = ")
} }
@@ -29,12 +29,8 @@ import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElementSelector
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>("operator.to.function", javaClass()) { public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>("operator.to.function", javaClass()) {
fun isApplicablePrefix(element: JetPrefixExpression): Boolean { fun isApplicablePrefix(element: JetPrefixExpression): Boolean {
@@ -60,7 +56,8 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
} }
fun isApplicableCall(element: JetCallExpression): Boolean { fun isApplicableCall(element: JetCallExpression): Boolean {
val resolvedCall = AnalyzerFacadeWithCache.getContextForElement(element)[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val bindingContext = AnalyzerFacadeWithCache.getContextForElement(element)
val resolvedCall = element.getResolvedCall(bindingContext)
val descriptor = resolvedCall?.getResultingDescriptor() val descriptor = resolvedCall?.getResultingDescriptor()
if (descriptor is FunctionDescriptor && descriptor.getName().asString() == "invoke") { if (descriptor is FunctionDescriptor && descriptor.getName().asString() == "invoke") {
val parent = element.getParent() val parent = element.getParent()
@@ -129,7 +126,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
} }
val context = AnalyzerFacadeWithCache.getContextForElement(element) val context = AnalyzerFacadeWithCache.getContextForElement(element)
val functionCandidate = context[BindingContext.RESOLVED_CALL, element.getOperationReference()] val functionCandidate = element.getResolvedCall(context)
val functionName = functionCandidate?.getCandidateDescriptor()?.getName().toString() val functionName = functionCandidate?.getCandidateDescriptor()?.getName().toString()
val elemType = context[BindingContext.EXPRESSION_TYPE, left] val elemType = context[BindingContext.EXPRESSION_TYPE, left]
@@ -32,11 +32,10 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
import org.jetbrains.jet.lang.psi.JetProperty import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.lang.psi.JetTypeArgumentList import org.jetbrains.jet.lang.psi.JetTypeArgumentList
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetReturnExpression import org.jetbrains.jet.lang.psi.JetReturnExpression
import org.jetbrains.jet.lang.psi.JetDeclaration
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation
public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgumentList>( public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgumentList>(
"remove.explicit.type.arguments", javaClass()) { "remove.explicit.type.arguments", javaClass()) {
@@ -52,9 +51,9 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
val injector = InjectorForMacros(callExpression.getProject(), resolveSession.getModuleDescriptor()) val injector = InjectorForMacros(callExpression.getProject(), resolveSession.getModuleDescriptor())
val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression]
val originalCall = context[BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()]?.getCall() val originalCall = callExpression.getResolvedCall(context)
if (originalCall == null || scope !is JetScope) return false if (originalCall == null || scope !is JetScope) return false
val untypedCall = CallWithoutTypeArgs(originalCall) val untypedCall = CallWithoutTypeArgs(originalCall.getCall())
// todo Check with expected type for other expressions // todo Check with expected type for other expressions
// If always use expected type from trace there is a problem with nested calls: // If always use expected type from trace there is a problem with nested calls:
@@ -74,11 +73,13 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
TypeUtils.NO_EXPECTED_TYPE TypeUtils.NO_EXPECTED_TYPE
} }
val dataFlow = context[BindingContext.EXPRESSION_DATA_FLOW_INFO, callExpression] ?: DataFlowInfo.EMPTY val dataFlow = context[BindingContext.EXPRESSION_DATA_FLOW_INFO, callExpression] ?: DataFlowInfo.EMPTY
val resolvedCall = injector.getExpressionTypingServices()?.getCallResolver()?.resolveFunctionCall( val resolutionResults = injector.getExpressionTypingServices()?.getCallResolver()?.resolveFunctionCall(
BindingTraceContext(), scope, untypedCall, jType, dataFlow, false) BindingTraceContext(), scope, untypedCall, jType, dataFlow, false)
assert (resolutionResults?.isSingleResult() ?: true) { "Removing type arguments changed resolve for: " +
"${callExpression.getTextWithLocation()} to ${resolutionResults?.getResultCode()}" }
val args = context[BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()]?.getTypeArguments() val args = originalCall.getTypeArguments()
val newArgs = resolvedCall?.getResultingCall()?.getTypeArguments() val newArgs = resolutionResults?.getResultingCall()?.getTypeArguments()
return args == newArgs return args == newArgs
} }
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.types.PackageType
import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils import org.jetbrains.jet.lang.psi.JetPsiUnparsingUtils
import org.jetbrains.jet.lang.psi.JetPsiFactory import org.jetbrains.jet.lang.psi.JetPsiFactory
import com.intellij.codeInsight.hint.HintManager import com.intellij.codeInsight.hint.HintManager
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) { public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
override fun isApplicableTo(element: JetCallExpression): Boolean { override fun isApplicableTo(element: JetCallExpression): Boolean {
@@ -48,21 +49,19 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent
val parent = element.getParent() val parent = element.getParent()
if (parent is JetDotQualifiedExpression) { if (parent is JetDotQualifiedExpression) {
val callee = element.getCalleeExpression()
val typeArguments = element.getTypeArgumentList() val typeArguments = element.getTypeArgumentList()
val valueArguments = element.getValueArgumentList() val valueArguments = element.getValueArgumentList()
val functionLiteralArguments = element.getFunctionLiteralArguments() val functionLiteralArguments = element.getFunctionLiteralArguments()
val numOfTotalValueArguments = (valueArguments?.getArguments()?.size() ?: 0) + functionLiteralArguments.size() val numOfTotalValueArguments = (valueArguments?.getArguments()?.size() ?: 0) + functionLiteralArguments.size()
if (typeArguments?.getArguments()?.size() ?: 0 == 0 && if (typeArguments?.getArguments()?.size() ?: 0 == 0 &&
numOfTotalValueArguments == 1 && numOfTotalValueArguments == 1) {
callee != null) {
if (valueArguments?.getArguments()?.size() == 1 && valueArguments?.getArguments()?.first()?.isNamed() ?: false) { if (valueArguments?.getArguments()?.size() == 1 && valueArguments?.getArguments()?.first()?.isNamed() ?: false) {
val file = element.getContainingJetFile() val file = element.getContainingJetFile()
val bindingContext = file.getBindingContext() val bindingContext = file.getBindingContext()
val resolvedCallDescriptor = bindingContext[BindingContext.RESOLVED_CALL, callee] val resolvedCall = element.getResolvedCall(bindingContext)
val valueArgumentsMap = resolvedCallDescriptor?.getValueArguments() val valueArgumentsMap = resolvedCall?.getValueArguments()
val firstArgument = valueArguments?.getArguments()?.first() val firstArgument = valueArguments?.getArguments()?.first()
return valueArgumentsMap?.keySet()?.any { it.getName().asString() == firstArgument?.getArgumentName()?.getText() && it.getIndex() == 0 } ?: false return valueArgumentsMap?.keySet()?.any { it.getName().asString() == firstArgument?.getArgumentName()?.getText() && it.getIndex() == 0 } ?: false
@@ -24,7 +24,6 @@ import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.descriptors.CallableDescriptor 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.lang.psi.ValueArgument
import org.jetbrains.jet.plugin.JetBundle import org.jetbrains.jet.plugin.JetBundle
import org.jetbrains.jet.lang.resolve.calls.model.DefaultValueArgument 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.MaybeError
import org.jetbrains.jet.plugin.util.MaybeValue import org.jetbrains.jet.plugin.util.MaybeValue
import com.intellij.codeInsight.hint.HintManager 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. // Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription.
public class CallDescription internal ( public class CallDescription internal (
@@ -87,15 +87,14 @@ public class CallDescription internal (
} }
public fun JetQualifiedExpression.toCallDescription(): CallDescription? { public fun JetQualifiedExpression.toCallDescription(): CallDescription? {
val call = getSelectorExpression() val callExpression = getSelectorExpression() as? JetCallExpression ?: return null
if (call !is 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) // 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 null
return CallDescription(this, call, resolvedCall) return CallDescription(this, callExpression, resolvedCall)
} }
public abstract class AttributeCallReplacementIntention(name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) { public abstract class AttributeCallReplacementIntention(name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) {
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; 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.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
@@ -66,7 +67,7 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
if (!(callee instanceof JetReferenceExpression)) return Collections.emptyList(); if (!(callee instanceof JetReferenceExpression)) return Collections.emptyList();
BindingContext context = ResolvePackage.getBindingContext(argument.getContainingJetFile()); 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(); if (resolvedCall == null) return Collections.emptyList();
CallableDescriptor callableDescriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor callableDescriptor = resolvedCall.getResultingDescriptor();
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorResolver; 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.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
@@ -183,7 +184,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class); JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression"; assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression";
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile()); 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; if (resolvedCall == null) return null;
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
if (!(compareTo instanceof JetFunction)) return null; if (!(compareTo instanceof JetFunction)) return null;
@@ -26,6 +26,8 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; 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.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
@@ -69,8 +71,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
// Fixing overloaded operators: // Fixing overloaded operators:
if (expression instanceof JetOperationExpression) { if (expression instanceof JetOperationExpression) {
ResolvedCall<?> resolvedCall = ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
context.get(BindingContext.RESOLVED_CALL, ((JetOperationExpression) expression).getOperationReference());
if (resolvedCall != null) { if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall); JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) { if (declaration != null) {
@@ -81,7 +82,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
if (expression.getParent() instanceof JetBinaryExpression) { if (expression.getParent() instanceof JetBinaryExpression) {
JetBinaryExpression parentBinary = (JetBinaryExpression) expression.getParent(); JetBinaryExpression parentBinary = (JetBinaryExpression) expression.getParent();
if (parentBinary.getRight() == expression) { if (parentBinary.getRight() == expression) {
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, parentBinary.getOperationReference()); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(parentBinary, context);
if (resolvedCall != null) { if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall); JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) { if (declaration != null) {
@@ -94,8 +95,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
// Change function return type when TYPE_MISMATCH is reported on call expression: // Change function return type when TYPE_MISMATCH is reported on call expression:
if (expression instanceof JetCallExpression) { if (expression instanceof JetCallExpression) {
ResolvedCall<?> resolvedCall = ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
if (resolvedCall != null) { if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall); JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
if (declaration != null) { if (declaration != null) {
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; 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.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.DeferredType; import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -107,7 +108,7 @@ public class QuickFixUtil {
@Nullable @Nullable
public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) { public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) {
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile()); 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; if (resolvedCall == null) return null;
PsiElement declaration = safeGetDeclaration(context, resolvedCall); PsiElement declaration = safeGetDeclaration(context, resolvedCall);
if (declaration instanceof JetFunction) { if (declaration instanceof JetFunction) {
@@ -27,7 +27,6 @@ import kotlin.properties.Delegates
import java.util.HashMap import java.util.HashMap
import org.jetbrains.jet.plugin.codeInsight.JetFileReferencesResolver import org.jetbrains.jet.plugin.codeInsight.JetFileReferencesResolver
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression 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.lang.resolve.BindingContext
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil
import java.util.Collections 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.JetDeclarationWithBody
import org.jetbrains.jet.lang.psi.JetUserType import org.jetbrains.jet.lang.psi.JetUserType
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall 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.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.psi.JetPsiFactory import org.jetbrains.jet.lang.psi.JetPsiFactory
import org.jetbrains.jet.lang.resolve.BindingContextUtils import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.psi.JetFunctionLiteral import org.jetbrains.jet.lang.psi.JetFunctionLiteral
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
data class ExtractionOptions(val inferUnitTypeForUnusedValues: Boolean) { data class ExtractionOptions(val inferUnitTypeForUnusedValues: Boolean) {
class object { class object {
@@ -116,8 +115,7 @@ class ExtractionData(
for ((ref, context) in JetFileReferencesResolver.resolve(originalFile, getExpressions())) { for ((ref, context) in JetFileReferencesResolver.resolve(originalFile, getExpressions())) {
if (ref !is JetSimpleNameExpression) continue if (ref !is JetSimpleNameExpression) continue
val resolvedCallKey = (ref.getParent() as? JetThisExpression) ?: ref val resolvedCall = ref.getResolvedCall(context)?.let {
val resolvedCall = context[BindingContext.RESOLVED_CALL, resolvedCallKey]?.let {
(it as? VariableAsFunctionResolvedCall)?.functionCall ?: it (it as? VariableAsFunctionResolvedCall)?.functionCall ?: it
} }
@@ -53,6 +53,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; 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.ResolvedCall;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -320,11 +321,13 @@ public class KotlinInlineValHandler extends InlineActionHandler {
ResolveSessionForBodies resolveSessionForBodies = ResolvePackage.getLazyResolveSession(containingFile); ResolveSessionForBodies resolveSessionForBodies = ResolvePackage.getLazyResolveSession(containingFile);
for (JetExpression inlinedExpression : inlinedExpressions) { for (JetExpression inlinedExpression : inlinedExpressions) {
JetCallExpression callExpression = getCallExpression(inlinedExpression); BindingContext context = resolveSessionForBodies.resolveToElement(inlinedExpression);
assert callExpression != null : "can't find call expression for " + inlinedExpression.getText(); Call call = BindingContextUtilPackage.getCallWithAssert(inlinedExpression, context);
if (hasIncompleteTypeInferenceDiagnostic(callExpression, resolveSessionForBodies) && callExpression.getTypeArgumentList() == null) { JetElement callElement = call.getCallElement();
callsToAddArguments.add(callExpression); if (callElement instanceof JetCallExpression && hasIncompleteTypeInferenceDiagnostic(call, context) &&
call.getTypeArgumentList() == null) {
callsToAddArguments.add((JetCallExpression) callElement);
} }
} }
@@ -337,17 +340,9 @@ public class KotlinInlineValHandler extends InlineActionHandler {
@Nullable @Nullable
private static String getTypeArgumentsStringForCall(@NotNull JetExpression initializer) { 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); BindingContext context = AnalyzerFacadeWithCache.getContextForElement(initializer);
ResolvedCall<?> call = context.get(BindingContext.RESOLVED_CALL, callee); ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(initializer, context);
if (call == null) { if (call == null) return null;
return null;
}
List<JetType> typeArguments = Lists.newArrayList(); List<JetType> typeArguments = Lists.newArrayList();
Map<TypeParameterDescriptor, JetType> typeArgumentMap = call.getTypeArguments(); Map<TypeParameterDescriptor, JetType> typeArgumentMap = call.getTypeArguments();
@@ -364,11 +359,10 @@ public class KotlinInlineValHandler extends InlineActionHandler {
} }
private static boolean hasIncompleteTypeInferenceDiagnostic( private static boolean hasIncompleteTypeInferenceDiagnostic(
@NotNull JetCallExpression callExpression, @NotNull Call call,
@NotNull ResolveSessionForBodies resolveSessionForBodies @NotNull BindingContext context
) { ) {
JetExpression callee = callExpression.getCalleeExpression(); JetExpression callee = call.getCalleeExpression();
BindingContext context = resolveSessionForBodies.resolveToElement(callExpression);
for (Diagnostic diagnostic : context.getDiagnostics()) { for (Diagnostic diagnostic : context.getDiagnostics()) {
if (diagnostic.getFactory() == Errors.TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER && diagnostic.getPsiElement() == callee) { if (diagnostic.getFactory() == Errors.TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER && diagnostic.getPsiElement() == callee) {
return true; return true;
@@ -393,20 +387,4 @@ public class KotlinInlineValHandler extends InlineActionHandler {
} }
return (JetExpression) referenceElement.replace(newExpression.copy()); return (JetExpression) referenceElement.replace(newExpression.copy());
} }
@Nullable
private static JetCallExpression getCallExpression(@NotNull JetExpression expression) {
if (expression instanceof JetParenthesizedExpression) {
JetExpression inner = ((JetParenthesizedExpression) expression).getExpression();
return inner == null ? null : getCallExpression(inner);
}
if (expression instanceof JetCallExpression) {
return (JetCallExpression) expression;
}
if (expression instanceof JetQualifiedExpression) {
JetExpression selector = ((JetQualifiedExpression) expression).getSelectorExpression();
return selector == null ? null : getCallExpression(selector);
}
return null;
}
} }
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace; 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.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -61,6 +62,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
private static final String INTRODUCE_VARIABLE = JetRefactoringBundle.message("introduce.variable"); 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 expr1 = (JetSimpleNameExpression)element1.getParent();
JetSimpleNameExpression expr2 = (JetSimpleNameExpression)element2.getParent(); JetSimpleNameExpression expr2 = (JetSimpleNameExpression)element2.getParent();
ResolvedCall<?> rc1 = bindingContext.get(BindingContext.RESOLVED_CALL, expr1); ResolvedCall<?> rc1 = getResolvedCall(expr1, bindingContext);
ResolvedCall<?> rc2 = bindingContext.get(BindingContext.RESOLVED_CALL, expr2); ResolvedCall<?> rc2 = getResolvedCall(expr2, bindingContext);
return (rc1 != null && rc2 != null) && compareCalleesAndReceivers(rc1, rc2) ? 0 : 1; return (rc1 != null && rc2 != null) && compareCalleesAndReceivers(rc1, rc2) ? 0 : 1;
} }
} }
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; 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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
@@ -32,9 +33,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> implements MultiRangeReference { class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> implements MultiRangeReference {
public JetInvokeFunctionReference(@NotNull JetCallExpression expression) { public JetInvokeFunctionReference(@NotNull JetCallExpression expression) {
@@ -49,13 +47,12 @@ class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> i
@Override @Override
@NotNull @NotNull
protected Collection<DeclarationDescriptor> getTargetDescriptors(@NotNull BindingContext context) { protected Collection<DeclarationDescriptor> getTargetDescriptors(@NotNull BindingContext context) {
JetExpression calleeExpression = getExpression().getCalleeExpression(); Call call = BindingContextUtilPackage.getCall(getElement(), context);
ResolvedCall<?> resolvedCall = context.get(RESOLVED_CALL, calleeExpression); ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(call, context);
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
return Collections.<DeclarationDescriptor>singleton( return Collections.<DeclarationDescriptor>singleton(
((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor()); ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall().getCandidateDescriptor());
} }
Call call = context.get(CALL, calleeExpression);
if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) { if (call != null && resolvedCall != null && call.getCallType() == Call.CallType.INVOKE) {
return Collections.<DeclarationDescriptor>singleton(resolvedCall.getCandidateDescriptor()); return Collections.<DeclarationDescriptor>singleton(resolvedCall.getCandidateDescriptor());
} }
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier; import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall; import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
import org.jetbrains.jet.lang.psi.JetParameter; 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.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
@@ -124,8 +124,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
@NotNull @NotNull
private List<JsExpression> translateArguments(@NotNull JetDelegatorToSuperCall superCall) { private List<JsExpression> translateArguments(@NotNull JetDelegatorToSuperCall superCall) {
ResolvedCall<?> call = context().bindingContext().get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression()); ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCallWithAssert(superCall, context().bindingContext());
assert call != null : "ResolvedCall for superCall must be not null";
return CallArgumentTranslator.translate(call, null, context()).getTranslateArguments(); return CallArgumentTranslator.translate(call, null, context()).getTranslateArguments();
} }
@@ -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.AssignToExpressionMutator;
import org.jetbrains.k2js.translate.utils.mutator.LastExpressionMutator; 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.AssignmentTranslator.isAssignmentOperator;
import static org.jetbrains.k2js.translate.operation.CompareToTranslator.isCompareToCall; 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.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.convertToStatement;
import static org.jetbrains.k2js.translate.utils.JsAstUtils.not; import static org.jetbrains.k2js.translate.utils.JsAstUtils.not;
import static org.jetbrains.k2js.translate.utils.PsiUtils.*; import static org.jetbrains.k2js.translate.utils.PsiUtils.*;
@@ -154,7 +154,7 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
@NotNull @NotNull
private JsExpression translateAsOverloadedBinaryOperation() { private JsExpression translateAsOverloadedBinaryOperation() {
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(bindingContext(), expression.getOperationReference()); ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCallWithAssert(expression, bindingContext());
JsExpression result = CallTranslator.instance$.translate(context(), resolvedCall, getReceiver()); JsExpression result = CallTranslator.instance$.translate(context(), resolvedCall, getReceiver());
return mayBeWrapWithNegation(result); return mayBeWrapWithNegation(result);
} }
@@ -20,10 +20,10 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetBinaryExpression; 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.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.utils.BindingUtils;
public final class OverloadedAssignmentTranslator extends AssignmentTranslator { public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
@@ -39,7 +39,7 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
private OverloadedAssignmentTranslator(@NotNull JetBinaryExpression expression, private OverloadedAssignmentTranslator(@NotNull JetBinaryExpression expression,
@NotNull TranslationContext context) { @NotNull TranslationContext context) {
super(expression, context); super(expression, context);
resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, context.bindingContext());
} }
@NotNull @NotNull
@@ -20,20 +20,22 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetUnaryExpression; 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.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.utils.BindingUtils;
public final class OverloadedIncrementTranslator extends IncrementTranslator { public final class OverloadedIncrementTranslator extends IncrementTranslator {
@NotNull @NotNull
private final ResolvedCall<? extends FunctionDescriptor> resolvedCall; private final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
/*package*/ OverloadedIncrementTranslator(@NotNull JetUnaryExpression expression, /*package*/ OverloadedIncrementTranslator(
@NotNull TranslationContext context) { @NotNull JetUnaryExpression expression,
@NotNull TranslationContext context
) {
super(expression, context); super(expression, context);
this.resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); this.resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, context.bindingContext());
} }
@@ -32,8 +32,8 @@ import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.utils.TranslationUtils; 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.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.getBaseExpression;
import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken; import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken;
import static org.jetbrains.k2js.translate.utils.TranslationUtils.*; import static org.jetbrains.k2js.translate.utils.TranslationUtils.*;
@@ -64,7 +64,7 @@ public final class UnaryOperationTranslator {
return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression); return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression);
} }
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference()); ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCallWithAssert(expression, context.bindingContext());
return CallTranslator.instance$.translate(context, resolvedCall, baseExpression); return CallTranslator.instance$.translate(context, resolvedCall, baseExpression);
} }
@@ -21,12 +21,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression; 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.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.general.AbstractTranslator; import org.jetbrains.k2js.translate.general.AbstractTranslator;
import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCallForCallExpression;
public abstract class AbstractCallExpressionTranslator extends AbstractTranslator { public abstract class AbstractCallExpressionTranslator extends AbstractTranslator {
@NotNull @NotNull
@@ -43,7 +42,7 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato
) { ) {
super(context); super(context);
this.expression = expression; this.expression = expression;
this.resolvedCall = getResolvedCallForCallExpression(bindingContext(), expression); this.resolvedCall = BindingContextUtilPackage.getFunctionResolvedCallWithAssert(expression, bindingContext());
this.receiver = receiver; this.receiver = receiver;
} }
@@ -51,7 +51,7 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) { public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) {
//TODO: inlining turned off //TODO: inlining turned off
//ResolvedCall<?> resolvedCall = getResolvedCallForCallExpression(context.bindingContext(), expression); //ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getFunctionResolvedCall(expression, bindingContext());
//CallableDescriptor descriptor = resolvedCall.getCandidateDescriptor(); //CallableDescriptor descriptor = resolvedCall.getCandidateDescriptor();
//if (descriptor instanceof SimpleFunctionDescriptor) { //if (descriptor instanceof SimpleFunctionDescriptor) {
// return ((SimpleFunctionDescriptor)descriptor).isInline(); // return ((SimpleFunctionDescriptor)descriptor).isInline();
@@ -21,12 +21,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.JetReferenceExpression; 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.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.k2js.translate.callTranslator.CallTranslator; import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
import org.jetbrains.k2js.translate.context.TemporaryVariable; import org.jetbrains.k2js.translate.context.TemporaryVariable;
import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.context.TranslationContext;
import org.jetbrains.k2js.translate.general.AbstractTranslator; import org.jetbrains.k2js.translate.general.AbstractTranslator;
import org.jetbrains.k2js.translate.utils.BindingUtils;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -37,7 +38,10 @@ public class VariableAccessTranslator extends AbstractTranslator implements Acce
@NotNull JetReferenceExpression referenceExpression, @NotNull JetReferenceExpression referenceExpression,
@Nullable JsExpression receiver @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; assert resolvedCall.getResultingDescriptor() instanceof VariableDescriptor;
return new VariableAccessTranslator(context, (ResolvedCall<? extends VariableDescriptor>) resolvedCall, receiver); return new VariableAccessTranslator(context, (ResolvedCall<? extends VariableDescriptor>) resolvedCall, receiver);
} }
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; 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.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -136,39 +135,6 @@ public final class BindingUtils {
return context.get(BindingContext.REFERENCE_TARGET, reference); 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<? extends FunctionDescriptor> getResolvedCallForCallExpression(@NotNull BindingContext context,
@NotNull JetCallExpression expression) {
JetExpression calleeExpression = PsiUtils.getCallee(expression);
return getFunctionResolvedCall(context, calleeExpression);
}
@NotNull
public static ResolvedCall<? extends FunctionDescriptor> 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<? extends FunctionDescriptor>");
return (ResolvedCall<? extends FunctionDescriptor>) resolvedCall;
}
public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) { public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) {
return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression); return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression);
} }
@@ -93,13 +93,6 @@ public final class PsiUtils {
return (binaryExpression.getOperationToken() == JetTokens.IN_KEYWORD); return (binaryExpression.getOperationToken() == JetTokens.IN_KEYWORD);
} }
@NotNull
public static JetExpression getCallee(@NotNull JetCallExpression expression) {
JetExpression calleeExpression = expression.getCalleeExpression();
assert calleeExpression != null;
return calleeExpression;
}
@NotNull @NotNull
public static JetExpression getLoopBody(@NotNull JetLoopExpression expression) { public static JetExpression getLoopBody(@NotNull JetLoopExpression expression) {
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();