use of com.intellij.psi.PsiPolyVariantReference 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.PsiPolyVariantReference 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.PsiPolyVariantReference 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.PsiPolyVariantReference in project intellij-community by JetBrains.
the class PyTypingTypeProvider method tryResolving.
@NotNull
private static List<PsiElement> tryResolving(@NotNull PyExpression expression, @NotNull TypeEvalContext context) {
final List<PsiElement> elements = Lists.newArrayList();
if (expression instanceof PyReferenceExpression) {
final PyReferenceExpression referenceExpr = (PyReferenceExpression) expression;
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
final PsiPolyVariantReference reference = referenceExpr.getReference(resolveContext);
final List<PsiElement> resolved = PyUtil.multiResolveTopPriority(reference);
for (PsiElement element : resolved) {
if (element instanceof PyFunction) {
final PyFunction function = (PyFunction) element;
if (PyUtil.isInit(function)) {
final PyClass cls = function.getContainingClass();
if (cls != null) {
elements.add(cls);
continue;
}
}
}
final String name = element != null ? getQualifiedName(element) : null;
if (name != null && OPAQUE_NAMES.contains(name)) {
elements.add(element);
continue;
}
if (element instanceof PyTargetExpression) {
final PyTargetExpression targetExpr = (PyTargetExpression) element;
// XXX: Requires switching from stub to AST
final PyExpression assignedValue = targetExpr.findAssignedValue();
if (assignedValue != null) {
elements.add(assignedValue);
continue;
}
}
if (element != null) {
elements.add(element);
}
}
}
return !elements.isEmpty() ? elements : Collections.singletonList(expression);
}
use of com.intellij.psi.PsiPolyVariantReference in project intellij-community by JetBrains.
the class PyAddExceptionSuperClassQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (element instanceof PyCallExpression) {
PyExpression callee = ((PyCallExpression) element).getCallee();
if (callee instanceof PyReferenceExpression) {
final PsiPolyVariantReference reference = ((PyReferenceExpression) callee).getReference();
PsiElement psiElement = reference.resolve();
if (psiElement instanceof PyClass) {
final PyElementGenerator generator = PyElementGenerator.getInstance(project);
final PyArgumentList list = ((PyClass) psiElement).getSuperClassExpressionList();
if (list != null) {
final PyExpression exception = generator.createExpressionFromText(LanguageLevel.forElement(element), "Exception");
list.addArgument(exception);
} else {
final PyArgumentList expressionList = generator.createFromText(LanguageLevel.forElement(element), PyClass.class, "class A(Exception): pass").getSuperClassExpressionList();
assert expressionList != null;
final ASTNode nameNode = ((PyClass) psiElement).getNameNode();
assert nameNode != null;
psiElement.addAfter(expressionList, nameNode.getPsi());
}
}
}
}
}
Aggregations