boolean (@NotNull 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); } PyElement pyElement = ObjectUtils.tryCast(element, PyElement.class); if (pyElement == null) { return false; } if (Objects.equals(referencedName, pyElement.getName()) && !PyUtil.isInitOrNewMethod(element)) { 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; }