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