use of com.intellij.psi.PsiPolyVariantReference in project intellij-community by JetBrains.
the class PyCallExpressionHelper method getCallType.
public static PyType getCallType(@NotNull PyCallExpression call, @NotNull TypeEvalContext context) {
if (!TypeEvalStack.mayEvaluate(call)) {
return null;
}
try {
PyExpression callee = call.getCallee();
if (callee instanceof PyReferenceExpression) {
// hardwired special cases
if (PyNames.SUPER.equals(callee.getText())) {
final Maybe<PyType> superCallType = getSuperCallType(call, context);
if (superCallType.isDefined()) {
return superCallType.value();
}
}
if ("type".equals(callee.getText())) {
final PyExpression[] args = call.getArguments();
if (args.length == 1) {
final PyExpression arg = args[0];
final PyType argType = context.getType(arg);
if (argType instanceof PyClassType) {
final PyClassType classType = (PyClassType) argType;
if (!classType.isDefinition()) {
final PyClass cls = classType.getPyClass();
return context.getType(cls);
}
} else {
return null;
}
}
}
// normal cases
final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
final PsiPolyVariantReference reference = ((PyReferenceExpression) callee).getReference(resolveContext);
final List<PyType> members = new ArrayList<>();
for (PsiElement target : PyUtil.multiResolveTopPriority(reference)) {
PyUtil.verboseOnly(() -> PyPsiUtils.assertValid(target));
if (target != null) {
final Ref<? extends PyType> typeRef = getCallTargetReturnType(call, target, context);
if (typeRef != null) {
members.add(typeRef.get());
}
}
}
if (!members.isEmpty()) {
return PyUnionType.union(members);
}
}
if (callee == null) {
return null;
} else {
final PyType type = context.getType(callee);
if (type instanceof PyCallableType) {
final PyCallableType callableType = (PyCallableType) type;
return callableType.getCallType(context, call);
}
if (type instanceof PyUnionType) {
return getCallResultTypeFromUnion(call, context, (PyUnionType) type);
}
return null;
}
} finally {
TypeEvalStack.evaluated(call);
}
}
use of com.intellij.psi.PsiPolyVariantReference in project intellij-community by JetBrains.
the class RngHighlightingTest method testResolveIncludedRef2.
public void testResolveIncludedRef2() throws Throwable {
myTestFixture.copyFileToProject("include.rng");
final PsiReference ref = myTestFixture.getReferenceAtCaretPositionWithAssertion("resolve-include-ref-2.rng");
assertTrue("PolyVariantRef", ref instanceof PsiPolyVariantReference);
final PsiElement element = ref.resolve();
assertNull(element);
final ResolveResult[] results = ((PsiPolyVariantReference) ref).multiResolve(false);
assertEquals(2, results.length);
for (ResolveResult result : results) {
PsiElement e = result.getElement();
assertTrue(e instanceof XmlTag);
final int contentLength = ((XmlTag) e).getSubTags().length;
if (e.getContainingFile() == ref.getElement().getContainingFile()) {
assertEquals(1, contentLength);
} else {
assertEquals(0, contentLength);
}
}
}
use of com.intellij.psi.PsiPolyVariantReference in project intellij-community by JetBrains.
the class DependencyVisitor method visitPyReferenceExpression.
@Override
public void visitPyReferenceExpression(final PyReferenceExpression node) {
final PsiPolyVariantReference reference = node.getReference();
if (reference.isReferenceTo(myElementToFind)) {
myDependencyFound = true;
return;
}
// TODO: This step is member-type specific. Move to MemberManagers?
if (myElementToFind instanceof PyAssignmentStatement) {
final PyExpression[] targets = ((PyAssignmentStatement) myElementToFind).getTargets();
if (targets.length != 1) {
return;
}
final PyExpression expression = targets[0];
if (reference.isReferenceTo(expression)) {
myDependencyFound = true;
return;
}
if (node.getText().equals(expression.getText())) {
// Check by name also
myDependencyFound = true;
}
return;
}
final PsiElement declaration = reference.resolve();
myDependencyFound = PsiTreeUtil.findFirstParent(declaration, new PsiElementCondition()) != null;
}
use of com.intellij.psi.PsiPolyVariantReference in project kotlin by JetBrains.
the class BuiltInsReferenceResolverTest method doTest.
private void doTest() throws Exception {
PsiPolyVariantReference reference = (PsiPolyVariantReference) myFixture.getReferenceAtCaretPosition(getTestName(true) + ".kt");
assert reference != null;
PsiElement resolved = reference.resolve();
assertNotNull(resolved);
assertEquals(1, reference.multiResolve(false).length);
String text = myFixture.getFile().getText();
String expectedBinaryFile = InTextDirectivesUtils.findStringWithPrefixes(text, "// BINARY:");
String expectedSourceFile = InTextDirectivesUtils.findStringWithPrefixes(text, "// SRC:");
String expectedTarget = InTextDirectivesUtils.findStringWithPrefixes(text, "// TARGET:");
assertEquals(expectedBinaryFile, getFileWithDir(resolved));
assertEquals(expectedTarget, renderAsGotoImplementation(resolved));
PsiElement srcElement = resolved.getNavigationElement();
Assert.assertNotEquals(srcElement, resolved);
assertEquals(expectedSourceFile, getFileWithDir(srcElement));
assertEquals(expectedTarget, renderAsGotoImplementation(srcElement));
}
use of com.intellij.psi.PsiPolyVariantReference in project intellij-elixir by KronicDeth.
the class ImportTest method testImportModuleExceptNameArity.
public void testImportModuleExceptNameArity() {
myFixture.configureByFiles("import_module_except_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);
}
Aggregations