use of com.intellij.psi.ResolveResult in project intellij-elixir by KronicDeth.
the class NestedTest method testReference.
public void testReference() {
myFixture.configureByFiles("reference.ex", "suffix.ex", "nested.ex");
PsiElement alias = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent().getPrevSibling();
assertInstanceOf(alias, QualifiedAlias.class);
PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) alias.getReference();
assertNotNull(polyVariantReference);
ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
assertEquals(2, resolveResults.length);
// alias
assertEquals("alias Prefix.Suffix, as: As", resolveResults[0].getElement().getParent().getParent().getParent().getParent().getParent().getText());
// defmodule
assertEquals("defmodule Prefix.Suffix.Nested do\nend", resolveResults[1].getElement().getText());
}
use of com.intellij.psi.ResolveResult in project intellij-elixir by KronicDeth.
the class ImportTest method testImportModule.
/*
* Tests
*/
public void testImportModule() {
myFixture.configureByFiles("import_module.ex", "imported.ex");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
PsiElement maybeCall = elementAtCaret.getParent().getParent();
assertInstanceOf(maybeCall, Call.class);
Call call = (Call) maybeCall;
assertEquals("imported", call.functionName());
assertEquals(0, call.resolvedFinalArity());
PsiReference reference = call.getReference();
assertNotNull(reference);
assertInstanceOf(reference, PsiPolyVariantReference.class);
PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
assertEquals(2, resolveResults.length);
}
use of com.intellij.psi.ResolveResult in project intellij-elixir by KronicDeth.
the class ImportTest method testImportModuleOnlyNameArity.
public void testImportModuleOnlyNameArity() {
myFixture.configureByFiles("import_module_only_name_arity.ex", "imported.ex");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
PsiElement maybeCall = elementAtCaret.getParent().getParent();
assertInstanceOf(maybeCall, Call.class);
Call call = (Call) maybeCall;
assertEquals("imported", call.functionName());
assertEquals(0, call.resolvedFinalArity());
PsiReference reference = call.getReference();
assertNotNull(reference);
assertInstanceOf(reference, PsiPolyVariantReference.class);
PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
assertEquals(2, resolveResults.length);
}
use of com.intellij.psi.ResolveResult in project intellij-community by JetBrains.
the class PyDocReference method multiResolve.
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
ResolveResult[] results = super.multiResolve(incompleteCode);
if (results.length == 0) {
final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myElement.getProject());
final PsiLanguageInjectionHost host = languageManager.getInjectionHost(myElement);
final String referencedName = myElement.getReferencedName();
if (referencedName == null)
return ResolveResult.EMPTY_ARRAY;
if (host != null) {
final List<Pair<PsiElement, TextRange>> files = languageManager.getInjectedPsiFiles(host);
if (files != null) {
for (Pair<PsiElement, TextRange> pair : files) {
final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
PyResolveUtil.scopeCrawlUp(processor, (ScopeOwner) pair.getFirst(), referencedName, pair.getFirst());
final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, pair.getFirst(), pair.getFirst());
if (resultList.size() > 0) {
List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
return ret.toArray(new RatedResolveResult[ret.size()]);
}
}
}
final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
final ScopeOwner scopeOwner = getHostScopeOwner();
if (scopeOwner != null) {
final PsiFile topLevel = scopeOwner.getContainingFile();
PyResolveUtil.scopeCrawlUp(processor, scopeOwner, referencedName, topLevel);
final PsiElement referenceAnchor = getScopeControlFlowAnchor(host);
final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, referenceAnchor, topLevel);
if (resultList.size() > 0) {
final List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
return ret.toArray(new RatedResolveResult[ret.size()]);
}
}
}
}
return results;
}
use of com.intellij.psi.ResolveResult in project intellij-community by JetBrains.
the class PyResolveTest method testImplicitResolveInstanceAttribute.
public void testImplicitResolveInstanceAttribute() {
ResolveResult[] resolveResults = multiResolve();
assertEquals(1, resolveResults.length);
final PsiElement psiElement = resolveResults[0].getElement();
assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression) psiElement).getName()));
}
Aggregations