use of com.jetbrains.python.psi.resolve.ImplicitResolveResult in project intellij-community by JetBrains.
the class PyQualifiedReference method isReferenceTo.
@Override
public boolean isReferenceTo(PsiElement element) {
// performance: a qualified reference can never resolve to a local variable or parameter
if (isLocalScope(element)) {
return false;
}
final String referencedName = myElement.getReferencedName();
PyResolveContext resolveContext = myContext.withoutImplicits();
// Guess type eval context origin for switching to local dataflow and return type analysis
if (resolveContext.getTypeEvalContext().getOrigin() == null) {
final PsiFile containingFile = myElement.getContainingFile();
if (containingFile instanceof StubBasedPsiElement) {
assert ((StubBasedPsiElement) containingFile).getStub() == null : "Stub origin for type eval context in isReferenceTo()";
}
final TypeEvalContext context = TypeEvalContext.codeAnalysis(containingFile.getProject(), containingFile);
resolveContext = resolveContext.withTypeEvalContext(context);
}
if (element instanceof PyFunction && Comparing.equal(referencedName, ((PyFunction) element).getName()) && ((PyFunction) element).getContainingClass() != null && !PyNames.INIT.equals(referencedName)) {
final PyExpression qualifier = myElement.getQualifier();
if (qualifier != null) {
final PyType qualifierType = resolveContext.getTypeEvalContext().getType(qualifier);
if (qualifierType == null || (qualifierType instanceof PyStructuralType && ((PyStructuralType) qualifierType).isInferredFromUsages())) {
return true;
}
}
}
for (ResolveResult result : copyWithResolveContext(resolveContext).multiResolve(false)) {
LOG.assertTrue(!(result instanceof ImplicitResolveResult));
PsiElement resolveResult = result.getElement();
if (isResolvedToResult(element, resolveResult)) {
return true;
}
}
return false;
}
use of com.jetbrains.python.psi.resolve.ImplicitResolveResult in project intellij-community by JetBrains.
the class PyQualifiedReference method addImplicitResolveResults.
private void addImplicitResolveResults(String referencedName, ResolveResultList ret) {
final Project project = myElement.getProject();
final GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(project);
final Collection functions = PyFunctionNameIndex.find(referencedName, project, scope);
final PsiFile containingFile = myElement.getContainingFile();
final List<QualifiedName> imports;
if (containingFile instanceof PyFile) {
imports = collectImports((PyFile) containingFile);
} else {
imports = Collections.emptyList();
}
for (Object function : functions) {
if (!(function instanceof PyFunction)) {
FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, new Throwable("found non-function object " + function + " in function list"));
break;
}
PyFunction pyFunction = (PyFunction) function;
if (pyFunction.getContainingClass() != null) {
ret.add(new ImplicitResolveResult(pyFunction, getImplicitResultRate(pyFunction, imports)));
}
}
final Collection attributes = PyInstanceAttributeIndex.find(referencedName, project, scope);
for (Object attribute : attributes) {
if (!(attribute instanceof PyTargetExpression)) {
FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, new Throwable("found non-target expression object " + attribute + " in target expression list"));
break;
}
ret.add(new ImplicitResolveResult((PyTargetExpression) attribute, getImplicitResultRate((PyTargetExpression) attribute, imports)));
}
}
Aggregations