All RESOLVED_CALL getters replaced with util methods
JetElement.getResolvedCall(BindingContext) JetElement.getResolvedCallForSure(BindingContext)
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -45,6 +46,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DELEGATION;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
|
||||
|
||||
public abstract class AnnotationCodegen {
|
||||
|
||||
@@ -131,7 +133,7 @@ public abstract class AnnotationCodegen {
|
||||
else {
|
||||
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||
for (JetAnnotationEntry annotationEntry : annotationEntries) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, annotationEntry.getCalleeExpression());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(annotationEntry, bindingContext);
|
||||
if (resolvedCall == null) continue; // Skipping annotations if they are not resolved. Needed for JetLightClass generation
|
||||
|
||||
AnnotationDescriptor annotationDescriptor = bindingContext.get(BindingContext.ANNOTATION, annotationEntry);
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
@@ -77,6 +78,7 @@ import static org.jetbrains.jet.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.*;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass;
|
||||
import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.OtherOrigin;
|
||||
@@ -322,13 +324,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return type == null ? Type.VOID_TYPE : asmType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ResolvedCall<?> resolvedCall(JetExpression expression) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, expression);
|
||||
assert resolvedCall != null : "Unresolved call: " + expression.getText();
|
||||
return resolvedCall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackValue visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, StackValue receiver) {
|
||||
return genQualified(receiver, expression.getExpression());
|
||||
@@ -466,7 +461,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
// Is it a "1..2" or so
|
||||
RangeCodegenUtil.BinaryCall binaryCall = RangeCodegenUtil.getRangeAsBinaryCall(forExpression);
|
||||
if (binaryCall != null) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, binaryCall.op);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(binaryCall.op, bindingContext);
|
||||
if (resolvedCall != null) {
|
||||
if (RangeCodegenUtil.isOptimizableRangeTo(resolvedCall.getResultingDescriptor())) {
|
||||
generateForLoop(new ForInRangeLiteralLoopGenerator(forExpression, binaryCall));
|
||||
@@ -1348,7 +1343,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
assert superConstructor != null;
|
||||
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor);
|
||||
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(superCall.getCalleeExpression());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(superCall, bindingContext);
|
||||
pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(argumentTypes), false, defaultCallGenerator);
|
||||
}
|
||||
|
||||
@@ -1657,7 +1652,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, expression);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression, bindingContext);
|
||||
|
||||
DeclarationDescriptor descriptor;
|
||||
if (resolvedCall == null) {
|
||||
@@ -1933,10 +1928,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitCallExpression(@NotNull JetCallExpression expression, StackValue receiver) {
|
||||
JetExpression callee = expression.getCalleeExpression();
|
||||
assert callee != null;
|
||||
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(callee);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
CallableDescriptor funDescriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
if (!(funDescriptor instanceof FunctionDescriptor)) {
|
||||
@@ -1949,7 +1941,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return generateNewCall(expression, resolvedCall, receiver);
|
||||
}
|
||||
|
||||
Call call = bindingContext.get(CALL, expression.getCalleeExpression());
|
||||
Call call = getCall(expression, bindingContext);
|
||||
if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) {
|
||||
//noinspection ConstantConditions
|
||||
SamType samType = SamType.create(funDescriptor.getReturnType());
|
||||
@@ -2455,7 +2447,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression, StackValue data) {
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getCallableReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression.getCallableReference(), bindingContext);
|
||||
FunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
|
||||
if (functionDescriptor != null) {
|
||||
CallableReferenceGenerationStrategy strategy = new CallableReferenceGenerationStrategy(state, functionDescriptor, resolvedCall);
|
||||
@@ -2732,7 +2724,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return generateIn(StackValue.expression(Type.INT_TYPE, expression.getLeft(), this), expression.getRight(), reference);
|
||||
}
|
||||
else {
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(reference);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||
|
||||
Callable callable = resolveToCallable(descriptor, false);
|
||||
@@ -2743,7 +2735,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return StackValue.onStack(returnType);
|
||||
}
|
||||
|
||||
Call call = bindingContext.get(CALL, reference);
|
||||
Call call = getCall(reference, bindingContext);
|
||||
return invokeFunction(call, receiver, resolvedCall);
|
||||
}
|
||||
}
|
||||
@@ -2754,11 +2746,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
genInIntRange(leftValue, (JetBinaryExpression) deparenthesized);
|
||||
}
|
||||
else {
|
||||
invokeFunction(
|
||||
bindingContext.get(CALL, operationReference),
|
||||
StackValue.none(),
|
||||
resolvedCall(operationReference)
|
||||
);
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = getResolvedCallWithAssert(operationReference, bindingContext);
|
||||
invokeFunction(resolvedCall.getCall(), StackValue.none(), resolvedCall);
|
||||
}
|
||||
if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) {
|
||||
genInvertBoolean(v);
|
||||
@@ -2924,7 +2913,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
private StackValue generateComparison(JetBinaryExpression expression, StackValue receiver) {
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||
|
||||
JetExpression left = expression.getLeft();
|
||||
@@ -2940,7 +2929,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
gen(right, type);
|
||||
}
|
||||
else {
|
||||
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||
Call call = getCall(expression, bindingContext);
|
||||
StackValue result = invokeFunction(call, receiver, resolvedCall);
|
||||
type = Type.INT_TYPE;
|
||||
result.put(type, v);
|
||||
@@ -2959,7 +2948,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
private StackValue generateAugmentedAssignment(JetBinaryExpression expression) {
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||
Callable callable = resolveToCallable(descriptor, false);
|
||||
JetExpression lhs = expression.getLeft();
|
||||
@@ -2996,8 +2985,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
@NotNull Type lhsType,
|
||||
boolean keepReturnValue
|
||||
) {
|
||||
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||
assert call != null : "Call should be not null for operation reference in " + expression.getText();
|
||||
Call call = getCallWithAssert(expression, bindingContext);
|
||||
|
||||
StackValue value = gen(expression.getLeft());
|
||||
if (keepReturnValue) {
|
||||
@@ -3062,11 +3050,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
|
||||
if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
|
||||
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||
return invokeFunction(call, receiver, resolvedCall);
|
||||
return invokeFunction(resolvedCall.getCall(), receiver, resolvedCall);
|
||||
}
|
||||
|
||||
CallableMethod callableMethod = (CallableMethod) callable;
|
||||
@@ -3144,7 +3131,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
storeType = type;
|
||||
}
|
||||
else {
|
||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||
CallableMethod callableMethod = (CallableMethod) callable;
|
||||
callableMethod.invokeWithNotNullAssertion(v, state, resolvedCall);
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DeclarationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
@@ -1387,7 +1388,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private PropertyDescriptor getDelegatePropertyIfAny(JetExpression expression) {
|
||||
PropertyDescriptor propertyDescriptor = null;
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
ResolvedCall<?> call = bindingContext.get(BindingContext.RESOLVED_CALL, expression);
|
||||
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
|
||||
if (call != null) {
|
||||
CallableDescriptor callResultingDescriptor = call.getResultingDescriptor();
|
||||
if (callResultingDescriptor instanceof ValueParameterDescriptor) {
|
||||
@@ -1581,8 +1582,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor);
|
||||
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, ((JetCallElement) superCall).getCalleeExpression());
|
||||
assert resolvedCall != null;
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(superCall, bindingContext);
|
||||
ConstructorDescriptor superConstructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor();
|
||||
|
||||
//noinspection SuspiciousMethodCalls
|
||||
@@ -1683,9 +1683,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier);
|
||||
}
|
||||
|
||||
ResolvedCall<?> resolvedCall =
|
||||
bindingContext.get(BindingContext.RESOLVED_CALL, ((JetDelegatorToSuperCall) specifier).getCalleeExpression());
|
||||
assert resolvedCall != null : "Enum entry delegation specifier is unresolved: " + specifier.getText();
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(specifier, bindingContext);
|
||||
|
||||
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor());
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
@@ -30,11 +28,13 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.TAIL_RECURSION_CALL;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
|
||||
|
||||
public class TailRecursionCodegen {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class TailRecursionCodegen {
|
||||
JetExpression argumentExpression = argument == null ? null : argument.getArgumentExpression();
|
||||
|
||||
if (argumentExpression instanceof JetSimpleNameExpression) {
|
||||
ResolvedCall<?> resolvedCall = state.getBindingContext().get(RESOLVED_CALL, argumentExpression);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(argumentExpression, state.getBindingContext());
|
||||
if (resolvedCall != null && resolvedCall.getResultingDescriptor().equals(parameterDescriptor.getOriginal())) {
|
||||
// do nothing: we shouldn't store argument to itself again
|
||||
AsmUtil.pop(v, type);
|
||||
|
||||
+3
-2
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ExpressionValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
@@ -310,7 +311,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
// working around a problem with shallow analysis
|
||||
if (functionDescriptor == null) return;
|
||||
|
||||
ResolvedCall<?> referencedFunction = bindingContext.get(RESOLVED_CALL, expression.getCallableReference());
|
||||
ResolvedCall<?> referencedFunction = BindingContextUtilPackage.getResolvedCall(expression.getCallableReference(), bindingContext);
|
||||
if (referencedFunction == null) return;
|
||||
Collection<JetType> supertypes =
|
||||
runtimeTypes.getSupertypesForFunctionReference((FunctionDescriptor) referencedFunction.getResultingDescriptor());
|
||||
@@ -401,7 +402,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
@Override
|
||||
public void visitCallExpression(@NotNull JetCallExpression expression) {
|
||||
super.visitCallExpression(expression);
|
||||
ResolvedCall<?> call = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCall(expression, bindingContext);
|
||||
if (call == null) return;
|
||||
|
||||
CallableDescriptor descriptor = call.getResultingDescriptor();
|
||||
|
||||
@@ -19,17 +19,17 @@ package org.jetbrains.jet.codegen.intrinsics;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VarargValueArgument;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -45,9 +45,7 @@ public class JavaClassArray extends IntrinsicMethod {
|
||||
@Nullable List<JetExpression> arguments,
|
||||
StackValue receiver
|
||||
) {
|
||||
ResolvedCall<?> call =
|
||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
|
||||
assert call != null;
|
||||
ResolvedCall<?> call = BindingContextUtilPackage.getResolvedCallWithAssert((JetElement) element, codegen.getBindingContext());
|
||||
Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next();
|
||||
codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue());
|
||||
return returnType;
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -45,9 +45,8 @@ public class JavaClassFunction extends IntrinsicMethod {
|
||||
@Nullable List<JetExpression> arguments,
|
||||
StackValue receiver
|
||||
) {
|
||||
JetCallExpression call = (JetCallExpression) element;
|
||||
ResolvedCall<?> resolvedCall = codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
|
||||
assert resolvedCall != null;
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCallWithAssert(
|
||||
(JetElement) element, codegen.getBindingContext());
|
||||
JetType returnType = resolvedCall.getResultingDescriptor().getReturnType();
|
||||
assert returnType != null;
|
||||
putJavaLangClassInstance(v, codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType()));
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -56,8 +56,7 @@ public class MonitorInstruction extends IntrinsicMethod {
|
||||
@Nullable StackValue receiver
|
||||
) {
|
||||
assert element != null : "Element should not be null";
|
||||
ResolvedCall<?> resolvedCall =
|
||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall((JetElement) element, codegen.getBindingContext());
|
||||
|
||||
assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null";
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
public class JetControlFlowProcessor {
|
||||
@@ -235,7 +236,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@NotNull
|
||||
private AccessTarget getResolvedCallAccessTarget(JetElement element) {
|
||||
ResolvedCall<?> resolvedCall = trace.get(BindingContext.RESOLVED_CALL, element);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(element, trace.getBindingContext());
|
||||
return resolvedCall != null ? new AccessTarget.Call(resolvedCall) : AccessTarget.BlackBox.instance$;
|
||||
}
|
||||
|
||||
@@ -268,7 +269,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(@NotNull JetThisExpression expression) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
|
||||
if (resolvedCall == null) {
|
||||
createNonSyntheticValue(expression);
|
||||
return;
|
||||
@@ -290,7 +291,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||
generateCall(expression, variableAsFunctionResolvedCall.getVariableCall());
|
||||
@@ -325,9 +326,9 @@ public class JetControlFlowProcessor {
|
||||
visitAssignment(left, getDeferredValue(right), expression);
|
||||
}
|
||||
else if (OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(operationType)) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(operationReference);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
|
||||
if (resolvedCall != null) {
|
||||
PseudoValue rhsValue = generateCall(operationReference, resolvedCall).getOutputValue();
|
||||
PseudoValue rhsValue = generateCall(expression, resolvedCall).getOutputValue();
|
||||
Name assignMethodName = OperatorConventions.getNameForOperationSymbol((JetToken) expression.getOperationToken());
|
||||
if (!resolvedCall.getResultingDescriptor().getName().equals(assignMethodName)) {
|
||||
/* At this point assignment of the form a += b actually means a = a + b
|
||||
@@ -353,7 +354,7 @@ public class JetControlFlowProcessor {
|
||||
mergeValues(Arrays.asList(left, right), expression);
|
||||
}
|
||||
else {
|
||||
if (!generateCall(operationReference)) {
|
||||
if (!generateCall(expression)) {
|
||||
generateBothArgumentsAndMark(expression);
|
||||
}
|
||||
}
|
||||
@@ -572,11 +573,11 @@ public class JetControlFlowProcessor {
|
||||
}
|
||||
|
||||
boolean incrementOrDecrement = isIncrementOrDecrement(operationType);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(operationSign);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(expression, trace.getBindingContext());
|
||||
|
||||
PseudoValue rhsValue;
|
||||
if (resolvedCall != null) {
|
||||
rhsValue = generateCall(operationSign, resolvedCall).getOutputValue();
|
||||
rhsValue = generateCall(expression, resolvedCall).getOutputValue();
|
||||
}
|
||||
else {
|
||||
generateInstructions(baseExpression);
|
||||
@@ -1069,8 +1070,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitCallExpression(@NotNull JetCallExpression expression) {
|
||||
JetExpression calleeExpression = expression.getCalleeExpression();
|
||||
if (!generateCall(calleeExpression)) {
|
||||
if (!generateCall(expression)) {
|
||||
List<JetExpression> inputExpressions = new ArrayList<JetExpression>();
|
||||
for (ValueArgument argument : expression.getValueArguments()) {
|
||||
JetExpression argumentExpression = argument.getArgumentExpression();
|
||||
@@ -1083,6 +1083,7 @@ public class JetControlFlowProcessor {
|
||||
generateInstructions(functionLiteral);
|
||||
inputExpressions.add(functionLiteral);
|
||||
}
|
||||
JetExpression calleeExpression = expression.getCalleeExpression();
|
||||
generateInstructions(calleeExpression);
|
||||
inputExpressions.add(calleeExpression);
|
||||
inputExpressions.add(generateAndGetReceiverIfAny(expression));
|
||||
@@ -1373,38 +1374,26 @@ public class JetControlFlowProcessor {
|
||||
builder.unsupported(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ResolvedCall<?> getResolvedCall(@NotNull JetElement expression) {
|
||||
return trace.get(BindingContext.RESOLVED_CALL, expression);
|
||||
private boolean generateCall(@Nullable JetExpression callExpression) {
|
||||
if (callExpression == null) return false;
|
||||
return checkAndGenerateCall(callExpression, getResolvedCall(callExpression, trace.getBindingContext()));
|
||||
}
|
||||
|
||||
private boolean generateCall(@Nullable JetExpression calleeExpression) {
|
||||
if (calleeExpression == null) return false;
|
||||
return checkAndGenerateCall(calleeExpression, getResolvedCall(calleeExpression));
|
||||
}
|
||||
|
||||
private boolean checkAndGenerateCall(
|
||||
JetExpression calleeExpression,
|
||||
@Nullable ResolvedCall<?> resolvedCall
|
||||
) {
|
||||
private boolean checkAndGenerateCall(@NotNull JetExpression callExpression, @Nullable ResolvedCall<?> resolvedCall) {
|
||||
if (resolvedCall == null) {
|
||||
builder.compilationError(calleeExpression, "No resolved call");
|
||||
builder.compilationError(callExpression, "No resolved call");
|
||||
return false;
|
||||
}
|
||||
generateCall(calleeExpression, resolvedCall);
|
||||
generateCall(callExpression, resolvedCall);
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private InstructionWithValue generateCall(JetExpression calleeExpression, ResolvedCall<?> resolvedCall) {
|
||||
private InstructionWithValue generateCall(@NotNull JetExpression callExpression, @NotNull ResolvedCall<?> resolvedCall) {
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||
return generateCall(calleeExpression, variableAsFunctionResolvedCall.getFunctionCall());
|
||||
return generateCall(callExpression, variableAsFunctionResolvedCall.getFunctionCall());
|
||||
}
|
||||
|
||||
JetElement callElement = resolvedCall.getCall().getCallElement();
|
||||
JetExpression callExpression = callElement instanceof JetExpression ? (JetExpression) callElement : null;
|
||||
|
||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
||||
Map<PseudoValue, ReceiverValue> receivers = getReceiverValues(resolvedCall, true);
|
||||
SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues = SmartFMap.emptyMap();
|
||||
@@ -1416,14 +1405,17 @@ public class JetControlFlowProcessor {
|
||||
}
|
||||
|
||||
if (resultingDescriptor instanceof VariableDescriptor) {
|
||||
assert callExpression != null
|
||||
: "Variable-based call without call expression: " + callElement.getText();
|
||||
// If a callee of the call is just a variable (without 'invoke'), 'read variable' is generated.
|
||||
// todo : process arguments for such a case (KT-5387)
|
||||
JetExpression calleeExpression = PsiUtilPackage.getCalleeExpressionIfAny(callExpression);
|
||||
assert calleeExpression != null
|
||||
: "No callee for " + callExpression.getText();
|
||||
assert parameterValues.isEmpty()
|
||||
: "Variable-based call with non-empty argument list: " + callElement.getText();
|
||||
return builder.readVariable(calleeExpression, callExpression, resolvedCall, receivers);
|
||||
: "Variable-based call with non-empty argument list: " + callExpression.getText();
|
||||
return builder.readVariable(calleeExpression, calleeExpression, resolvedCall, receivers);
|
||||
}
|
||||
mark(resolvedCall.getCall().getCallElement());
|
||||
return builder.call(calleeExpression, callExpression, resolvedCall, receivers, parameterValues);
|
||||
return builder.call(callExpression, callExpression, resolvedCall, receivers, parameterValues);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -68,7 +68,9 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseState.*;
|
||||
import static org.jetbrains.jet.lang.cfg.pseudocodeTraverser.TraversalOrder.FORWARD;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CAPTURED_IN_CLOSURE;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.TAIL_RECURSION_CALL;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.TailRecursionKind.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||
@@ -725,7 +727,7 @@ public class JetFlowInformationProvider {
|
||||
if (!(instruction instanceof CallInstruction)) return;
|
||||
CallInstruction callInstruction = (CallInstruction) instruction;
|
||||
|
||||
ResolvedCall<?> resolvedCall = trace.get(RESOLVED_CALL, callInstruction.getElement());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(callInstruction.getElement(), trace.getBindingContext());
|
||||
if (resolvedCall == null) return;
|
||||
|
||||
// is this a recursive call?
|
||||
|
||||
+4
-3
@@ -33,6 +33,7 @@ import org.jetbrains.jet.JetNodeTypes
|
||||
import java.math.BigInteger
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
|
||||
|
||||
public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() {
|
||||
|
||||
@@ -179,7 +180,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
}
|
||||
|
||||
private fun evaluateCall(callExpression: JetExpression, receiverExpression: JetExpression, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, callExpression)
|
||||
val resolvedCall = callExpression.getResolvedCall(trace.getBindingContext())
|
||||
if (resolvedCall == null) return null
|
||||
|
||||
val resultingDescriptorName = resolvedCall.getResultingDescriptor().getName()
|
||||
@@ -309,7 +310,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
return EnumValue(enumDescriptor as ClassDescriptor, false);
|
||||
}
|
||||
|
||||
val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, expression)
|
||||
val resolvedCall = expression.getResolvedCall(trace.getBindingContext())
|
||||
if (resolvedCall != null) {
|
||||
val callableDescriptor = resolvedCall.getResultingDescriptor()
|
||||
if (callableDescriptor is VariableDescriptor) {
|
||||
@@ -351,7 +352,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: JetCallExpression, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
val call = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression())
|
||||
val call = expression.getResolvedCall(trace.getBindingContext())
|
||||
if (call == null) return null
|
||||
|
||||
val resultingDescriptor = call.getResultingDescriptor()
|
||||
|
||||
@@ -733,30 +733,6 @@ public class JetPsiUtil {
|
||||
return node == null ? null : node.getPsi();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
return expression;
|
||||
}
|
||||
if (expression instanceof JetCallElement) {
|
||||
JetCallElement callExpression = (JetCallElement) expression;
|
||||
return callExpression.getCalleeExpression();
|
||||
}
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
JetExpression selectorExpression = ((JetQualifiedExpression) expression).getSelectorExpression();
|
||||
if (selectorExpression != null) {
|
||||
return getCalleeExpressionIfAny(selectorExpression);
|
||||
}
|
||||
}
|
||||
if (expression instanceof JetUnaryExpression) {
|
||||
return ((JetUnaryExpression) expression).getOperationReference();
|
||||
}
|
||||
if (expression instanceof JetBinaryExpression) {
|
||||
return ((JetBinaryExpression) expression).getOperationReference();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) {
|
||||
if (element == null) return null;
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.intellij.psi.JavaDirectoryService
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassOrObjectStub
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||
|
||||
public fun JetCallElement.getCallNameExpression(): JetSimpleNameExpression? {
|
||||
val calleeExpression = getCalleeExpression()
|
||||
@@ -312,4 +313,17 @@ public fun JetSimpleNameExpression.isImportDirectiveExpression(): Boolean {
|
||||
else {
|
||||
return parent is JetImportDirective || parent.getParent() is JetImportDirective
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
@@ -324,7 +325,7 @@ public class AnnotationResolver {
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
ResolvedCall<?> resolvedCall = trace.get(BindingContext.RESOLVED_CALL, (expression).getCalleeExpression());
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, trace.getBindingContext());
|
||||
if (resolvedCall == null || !CompileTimeConstantUtils.isArrayMethodCall(resolvedCall)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
@@ -301,26 +302,12 @@ public class BindingContextUtils {
|
||||
@NotNull BindingContext context
|
||||
) {
|
||||
if (expression instanceof JetCallExpression) {
|
||||
return isCallExpressionWithValidReference(expression, context);
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
|
||||
return resolvedCall instanceof VariableAsFunctionResolvedCall;
|
||||
}
|
||||
|
||||
return expression instanceof JetReferenceExpression;
|
||||
}
|
||||
|
||||
public static boolean isCallExpressionWithValidReference(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull BindingContext context
|
||||
) {
|
||||
if (expression instanceof JetCallExpression) {
|
||||
JetExpression calleeExpression = ((JetCallExpression) expression).getCalleeExpression();
|
||||
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, calleeExpression);
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isVarCapturedInClosure(BindingContext bindingContext, DeclarationDescriptor descriptor) {
|
||||
if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor) return false;
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
||||
|
||||
@@ -20,10 +20,9 @@ import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.psi.Call
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.psi.JetOperationExpression
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.CALL
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL
|
||||
import org.jetbrains.jet.lang.psi.JetReturnExpression
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.LABEL_TARGET
|
||||
@@ -40,6 +39,15 @@ import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetThisExpression
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getCalleeExpressionIfAny
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke
|
||||
import org.jetbrains.kotlin.util.sure
|
||||
import org.jetbrains.jet.lang.psi.JetCallElement
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation
|
||||
|
||||
/**
|
||||
* For expressions like <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,
|
||||
* so there is a corresponding call for them.
|
||||
*/
|
||||
fun JetExpression.getCorrespondingCall(bindingContext: BindingContext): Call? {
|
||||
val expr = JetPsiUtil.deparenthesize(this)
|
||||
if (expr == null) return null
|
||||
public fun JetElement.getCall(context: BindingContext): Call? {
|
||||
val element = if (this is JetExpression) JetPsiUtil.deparenthesize(this) else this
|
||||
if (element == null) return null
|
||||
|
||||
if (expr is JetQualifiedExpression) {
|
||||
return expr.getSelectorExpression()?.getCorrespondingCall(bindingContext)
|
||||
}
|
||||
val parent = expr.getParent()
|
||||
val parent = element.getParent()
|
||||
val reference = when {
|
||||
parent is JetThisExpression -> parent : JetThisExpression
|
||||
expr is JetCallExpression -> expr.getCalleeExpression()
|
||||
expr is JetOperationExpression -> expr.getOperationReference()
|
||||
else -> expr
|
||||
else -> element.getCalleeExpressionIfAny()
|
||||
}
|
||||
return bindingContext[CALL, reference]
|
||||
if (reference != null) {
|
||||
return context[CALL, reference]
|
||||
}
|
||||
return context[CALL, element]
|
||||
}
|
||||
|
||||
fun JetExpression.getEnclosingCall(bindingContext: BindingContext): Call? {
|
||||
val parent = PsiTreeUtil.getNonStrictParentOfType<JetExpression>(
|
||||
public fun JetExpression.getParentCall(context: BindingContext): Call? {
|
||||
val parent = PsiTreeUtil.getNonStrictParentOfType<JetElement>(
|
||||
this,
|
||||
javaClass<JetSimpleNameExpression>(), javaClass<JetCallExpression>(), javaClass<JetBinaryExpression>(),
|
||||
javaClass<JetSimpleNameExpression>(), javaClass<JetCallElement>(), javaClass<JetBinaryExpression>(),
|
||||
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() }
|
||||
return arguments.any {
|
||||
argument ->
|
||||
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, argument]
|
||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, argument]
|
||||
argument != null && !ArgumentTypeResolver.isFunctionLiteralArgument(argument)
|
||||
&& (expressionType == null || expressionType.isError())
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetReturnExpression.getTargetFunctionDescriptor(bindingContext: BindingContext): FunctionDescriptor? {
|
||||
public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? {
|
||||
val targetLabel = getTargetLabel()
|
||||
if (targetLabel != null) return bindingContext[LABEL_TARGET, targetLabel]?.let { bindingContext[FUNCTION, it] }
|
||||
if (targetLabel != null) return context[LABEL_TARGET, targetLabel]?.let { context[FUNCTION, it] }
|
||||
|
||||
val declarationDescriptor = bindingContext[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass<JetDeclarationWithBody>())]
|
||||
val declarationDescriptor = context[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass<JetDeclarationWithBody>())]
|
||||
val containingFunctionDescriptor = DescriptorUtils.getParentOfType(declarationDescriptor, javaClass<FunctionDescriptor>(), false)
|
||||
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.diagnostics.rendering.Renderers;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
@@ -49,6 +50,7 @@ import java.util.List;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression;
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createSimpleName;
|
||||
import static org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage.getCalleeExpressionIfAny;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||
@@ -227,7 +229,7 @@ public class DelegatedPropertyResolver {
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property");
|
||||
JetExpression calleeExpression = JetPsiUtil.getCalleeExpressionIfAny(delegateExpression);
|
||||
JetExpression calleeExpression = getCalleeExpressionIfAny(delegateExpression);
|
||||
ConstraintSystemCompleter completer = createConstraintSystemCompleter(
|
||||
jetProperty, propertyDescriptor, delegateExpression, accessorScope, trace);
|
||||
if (calleeExpression != null) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
|
||||
public class InlineDescriptorUtils {
|
||||
@@ -45,8 +46,7 @@ public class InlineDescriptorUtils {
|
||||
boolean isInlinedLambda = false;
|
||||
JetExpression call = JetPsiUtil.getParentCallIfPresent((JetFunctionLiteralExpression) containingFunction);
|
||||
if (call != null) {
|
||||
//TODO: ask sveta
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, JetPsiUtil.getCalleeExpressionIfAny(call));
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(call, bindingContext);
|
||||
CallableDescriptor resultingDescriptor = resolvedCall == null ? null : resolvedCall.getResultingDescriptor();
|
||||
if (resultingDescriptor instanceof SimpleFunctionDescriptor) {
|
||||
isInlinedLambda = ((SimpleFunctionDescriptor) resultingDescriptor).getInlineStrategy().isInline();
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.jetbrains.jet.lang.psi.Call
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getCorrespondingCall
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getCall
|
||||
import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace
|
||||
@@ -286,7 +286,7 @@ public class CallCompleter(
|
||||
val lastStatement = JetPsiUtil.getLastStatementInABlock(argument)
|
||||
return getCallForArgument(lastStatement as? JetExpression, bindingContext)
|
||||
}
|
||||
return argument?.getCorrespondingCall(bindingContext)
|
||||
return argument?.getCall(bindingContext)
|
||||
}
|
||||
|
||||
private fun updateRecordedTypeForArgument(
|
||||
|
||||
@@ -273,7 +273,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
public ExpressionReceiver getThisObject() {
|
||||
return calleeExpressionAsThisObject;
|
||||
}
|
||||
|
||||
|
||||
+8
-4
@@ -23,11 +23,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.InlineDescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.DefaultValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
@@ -180,8 +183,9 @@ public class InlineCallResolverExtension implements CallResolverExtension {
|
||||
@NotNull JetExpression expression,
|
||||
boolean unwrapVariableAsFunction
|
||||
) {
|
||||
// todo ask sveta
|
||||
ResolvedCall<?> thisCall = context.trace.get(BindingContext.RESOLVED_CALL, expression);
|
||||
if (!(expression instanceof JetSimpleNameExpression || expression instanceof JetThisExpression)) return null;
|
||||
|
||||
ResolvedCall<?> thisCall = BindingContextUtilPackage.getResolvedCall(expression, context.trace.getBindingContext());
|
||||
if (unwrapVariableAsFunction && thisCall instanceof VariableAsFunctionResolvedCall) {
|
||||
return ((VariableAsFunctionResolvedCall) thisCall).getVariableCall().getResultingDescriptor();
|
||||
}
|
||||
|
||||
+4
-3
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.JetModuleUtil;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -31,7 +32,6 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||
|
||||
public class DataFlowValueFactory {
|
||||
private DataFlowValueFactory() {}
|
||||
@@ -166,13 +166,14 @@ public class DataFlowValueFactory {
|
||||
) {
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, simpleNameExpression);
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(simpleNameExpression, bindingContext);
|
||||
// todo uncomment assert
|
||||
// KT-4113
|
||||
// for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes
|
||||
// assert resolvedCall != null : "Cannot create right identifier info if the resolved call is not known yet for " + declarationDescriptor;
|
||||
|
||||
IdentifierInfo receiverInfo = resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null;
|
||||
IdentifierInfo receiverInfo =
|
||||
resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null;
|
||||
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||
return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor)));
|
||||
|
||||
+1
@@ -68,6 +68,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy {
|
||||
public <D extends CallableDescriptor> void bindResolvedCall(
|
||||
@NotNull BindingTrace trace, @NotNull ResolvedCall<D> resolvedCall
|
||||
) {
|
||||
if (reference instanceof JetSimpleNameExpression) return;
|
||||
trace.record(RESOLVED_CALL, reference, resolvedCall);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||
@@ -153,7 +154,7 @@ public class ExpressionTypingUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context);
|
||||
if (resolvedCall == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@TestMetadata("notOnCall.kt")
|
||||
public void testNotOnCall() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOnCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notOperation.kt")
|
||||
public void testNotOperation() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt");
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.jetbrains.jet.ConfigurationKind
|
||||
import org.jetbrains.jet.JetLiteFixture
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver
|
||||
@@ -36,9 +35,10 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getEnclosingCall
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getParentCall
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCallWithAssert
|
||||
|
||||
public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
|
||||
@@ -51,19 +51,16 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
|
||||
val element = jetFile.findElementAt(text.indexOf("<caret>"))
|
||||
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()]
|
||||
if (cachedCall == null) {
|
||||
throw AssertionError("No resolved call for:\nelement: ${element.toString()}\nexpression: ${expression.toString()}\ncall: $call")
|
||||
}
|
||||
val cachedCall = call?.getResolvedCallWithAssert(bindingContext)
|
||||
|
||||
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
|
||||
else if ("(" == element?.getText()) cachedCall.functionCall
|
||||
else cachedCall.variableCall
|
||||
|
||||
val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt"
|
||||
JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall.renderToText()}")
|
||||
JetTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall?.renderToText()}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user