KT-763 Ctrl click failed on unresolved reference
This commit is contained in:
@@ -11,9 +11,9 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCallImpl;
|
|
||||||
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_TARGET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_TARGET;
|
||||||
@@ -83,6 +83,8 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
|||||||
}
|
}
|
||||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
||||||
if (declarationDescriptors != null) return null;
|
if (declarationDescriptors != null) return null;
|
||||||
|
|
||||||
|
// TODO: Need a better resolution for intrinsic function (KT-975)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,15 +93,19 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
|||||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
||||||
if (declarationDescriptors == null) return ResolveResult.EMPTY_ARRAY;
|
if (declarationDescriptors == null) return ResolveResult.EMPTY_ARRAY;
|
||||||
ResolveResult[] results = new ResolveResult[declarationDescriptors.size()];
|
|
||||||
int i = 0;
|
ArrayList<ResolveResult> results = new ArrayList<ResolveResult>(declarationDescriptors.size());
|
||||||
|
|
||||||
for (DeclarationDescriptor descriptor : declarationDescriptors) {
|
for (DeclarationDescriptor descriptor : declarationDescriptors) {
|
||||||
PsiElement element = bindingContext.get(DESCRIPTOR_TO_DECLARATION, descriptor);
|
PsiElement element = bindingContext.get(DESCRIPTOR_TO_DECLARATION, descriptor);
|
||||||
if (element != null) {
|
if (element == null) {
|
||||||
results[i] = new PsiElementResolveResult(element, true);
|
// TODO: Need a better resolution for intrinsic function (KT-975)
|
||||||
i++;
|
element = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results.add(new PsiElementResolveResult(element, true));
|
||||||
}
|
}
|
||||||
return results;
|
|
||||||
|
return results.toArray(new ResolveResult[results.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package ctrl_click
|
||||||
|
|
||||||
|
fun IntArray(vararg content : Int) : IntArray = content
|
||||||
|
fun <T> array(vararg t : T) : Array<T> = t
|
||||||
|
|
||||||
|
fun main(args : ArrayList<String>) {
|
||||||
|
var a = <caret>IntArray(array(1, 2, 3))
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package org.jetbrains.jet.resolve;
|
||||||
|
|
||||||
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
|
import com.intellij.psi.PsiPolyVariantReference;
|
||||||
|
import com.intellij.psi.PsiReference;
|
||||||
|
import com.intellij.psi.ResolveResult;
|
||||||
|
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class ResolveBaseTest extends LightCodeInsightTestCase {
|
||||||
|
|
||||||
|
private final String myPath;
|
||||||
|
private final String myName;
|
||||||
|
|
||||||
|
protected ResolveBaseTest(@NotNull String path, @NotNull String name) {
|
||||||
|
myPath = path;
|
||||||
|
myName = name;
|
||||||
|
|
||||||
|
// Set name explicitly because otherwise there will be "TestCase.fName cannot be null"
|
||||||
|
setName("testResolve");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Sdk getProjectJDK() {
|
||||||
|
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestDataPath() {
|
||||||
|
return new File(PluginTestCaseBase.getTestDataPathBase(), myPath).getPath() +
|
||||||
|
File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "test" + myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResolve() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Currently this test is only for KT-763 bug - it should be extended to framework for testing references
|
||||||
|
protected void doTest() throws Exception {
|
||||||
|
final String testName = getTestName(false);
|
||||||
|
configureByFile(testName + ".kt");
|
||||||
|
|
||||||
|
final PsiReference psiReference =
|
||||||
|
getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
|
||||||
|
|
||||||
|
assertTrue(psiReference instanceof PsiPolyVariantReference);
|
||||||
|
|
||||||
|
final PsiPolyVariantReference variantReference = (PsiPolyVariantReference) psiReference;
|
||||||
|
|
||||||
|
final ResolveResult[] results = variantReference.multiResolve(true);
|
||||||
|
for (ResolveResult result : results) {
|
||||||
|
assertNotNull(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static TestSuite suite() {
|
||||||
|
TestSuite suite = new TestSuite();
|
||||||
|
|
||||||
|
JetTestCaseBuilder.appendTestsInDirectory(
|
||||||
|
PluginTestCaseBase.getTestDataPathBase(), "/resolve/", false,
|
||||||
|
JetTestCaseBuilder.emptyFilter, new JetTestCaseBuilder.NamedTestFactory() {
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) {
|
||||||
|
return new ResolveBaseTest(dataPath, name);
|
||||||
|
}
|
||||||
|
}, suite);
|
||||||
|
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user