Fixed KT-6011 Smart completion works for argument of wrong method
#KT-6011 Fixed
This commit is contained in:
+7
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -37,6 +38,12 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
||||
this.resolvedCall = resolvedCall;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolutionStatus getStatus() {
|
||||
return resolvedCall.getStatus();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Call getCall() {
|
||||
|
||||
-3
@@ -28,9 +28,6 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
public interface MutableResolvedCall<D extends CallableDescriptor> extends ResolvedCall<D> {
|
||||
|
||||
@NotNull
|
||||
ResolutionStatus getStatus();
|
||||
|
||||
void addStatus(@NotNull ResolutionStatus status);
|
||||
|
||||
void setStatusToSuccess();
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -31,6 +32,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ResolvedCall<D extends CallableDescriptor> {
|
||||
@NotNull
|
||||
ResolutionStatus getStatus();
|
||||
|
||||
/** The call that was resolved to this ResolvedCall */
|
||||
@NotNull
|
||||
Call getCall();
|
||||
|
||||
@@ -67,6 +67,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus
|
||||
|
||||
enum class Tail {
|
||||
COMMA
|
||||
@@ -166,6 +167,9 @@ class ExpectedInfos(val bindingContext: BindingContext, val resolveSession: Reso
|
||||
|
||||
val expectedInfos = HashSet<ExpectedInfo>()
|
||||
for (candidate: ResolvedCall<FunctionDescriptor> in results.getAllCandidates()!!) {
|
||||
val status = candidate.getStatus()
|
||||
if (status == ResolutionStatus.RECEIVER_TYPE_ERROR || status == ResolutionStatus.RECEIVER_PRESENCE_ERROR) continue
|
||||
|
||||
// consider only candidates with more arguments than in the truncated call and with all arguments before the current one matched
|
||||
if (candidate.noErrorsInValueArguments() && (candidate.getCandidateDescriptor().getValueParameters().size > argumentIndex || isFunctionLiteralArgument)) {
|
||||
val descriptor = candidate.getResultingDescriptor()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fun String.foo(a: Int){}
|
||||
|
||||
class C {
|
||||
fun foo(s: String){}
|
||||
|
||||
fun bar(p1: String, p2: Int) {
|
||||
"".foo(<caret>)
|
||||
}
|
||||
}
|
||||
|
||||
// ABSENT: p1
|
||||
// EXIST: p2
|
||||
@@ -17,10 +17,13 @@
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -788,4 +788,10 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WrongReceiver.kt")
|
||||
public void testWrongReceiver() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/WrongReceiver.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user