use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class DocStringTypeReference method bindToElement.
@Nullable
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (element.equals(resolve())) {
return element;
}
if (myElement instanceof PyStringLiteralExpression && element instanceof PyClass) {
final PyStringLiteralExpression e = (PyStringLiteralExpression) myElement;
final PyClass cls = (PyClass) element;
QualifiedName qname = QualifiedNameFinder.findCanonicalImportPath(cls, element);
if (qname != null) {
qname = qname.append(cls.getName());
ElementManipulator<PyStringLiteralExpression> manipulator = ElementManipulators.getManipulator(e);
myType = new PyClassTypeImpl(cls, false);
return manipulator.handleContentChange(e, myFullRange, qname.toString());
}
}
return null;
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PythonDocumentationProvider method promptToConfigureDocumentation.
@Override
public void promptToConfigureDocumentation(@NotNull PsiElement element) {
final Project project = element.getProject();
final QualifiedName qName = QualifiedNameFinder.findCanonicalImportPath(element, element);
if (qName != null && qName.getComponentCount() > 0) {
ApplicationManager.getApplication().invokeLater(() -> {
final int rc = Messages.showOkCancelDialog(project, "No external documentation URL configured for module " + qName.getComponents().get(0) + ".\nWould you like to configure it now?", "Python External Documentation", Messages.getQuestionIcon());
if (rc == Messages.OK) {
ShowSettingsUtilImpl.showSettingsDialog(project, PythonDocumentationConfigurable.ID, "");
}
}, ModalityState.NON_MODAL);
}
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyReferenceExpressionImpl method getGenericTypeFromTarget.
@Nullable
private static PyType getGenericTypeFromTarget(@NotNull PsiElement target, @NotNull TypeEvalContext context, @NotNull PyReferenceExpression anchor) {
if (!(target instanceof PyTargetExpression)) {
// PyTargetExpression will ask about its type itself
final PyType pyType = getReferenceTypeFromProviders(target, context, anchor);
if (pyType != null) {
return pyType;
}
}
if (target instanceof PyTargetExpression) {
final String name = ((PyTargetExpression) target).getName();
if (PyNames.NONE.equals(name)) {
return PyNoneType.INSTANCE;
}
if (PyNames.TRUE.equals(name) || PyNames.FALSE.equals(name)) {
return PyBuiltinCache.getInstance(target).getBoolType();
}
}
if (target instanceof PyFile) {
return new PyModuleType((PyFile) target);
}
if ((target instanceof PyTargetExpression || target instanceof PyNamedParameter) && context.allowDataFlow(anchor)) {
final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(anchor);
if (scopeOwner != null && scopeOwner == ScopeUtil.getScopeOwner(target)) {
final String name = ((PyElement) target).getName();
if (name != null) {
final PyType type = getTypeByControlFlow(name, context, anchor, scopeOwner);
if (type != null) {
return type;
}
}
}
}
if (target instanceof PyFunction) {
final PyDecoratorList decoratorList = ((PyFunction) target).getDecoratorList();
if (decoratorList != null) {
final PyDecorator propertyDecorator = decoratorList.findDecorator(PyNames.PROPERTY);
if (propertyDecorator != null) {
return PyBuiltinCache.getInstance(target).getObjectType(PyNames.PROPERTY);
}
for (PyDecorator decorator : decoratorList.getDecorators()) {
final QualifiedName qName = decorator.getQualifiedName();
if (qName != null && (qName.endsWith(PyNames.SETTER) || qName.endsWith(PyNames.DELETER) || qName.endsWith(PyNames.GETTER))) {
return PyBuiltinCache.getInstance(target).getObjectType(PyNames.PROPERTY);
}
}
}
}
if (target instanceof PyTypedElement) {
return context.getType((PyTypedElement) target);
}
if (target instanceof PsiDirectory) {
final PsiDirectory dir = (PsiDirectory) target;
final PsiFile file = dir.findFile(PyNames.INIT_DOT_PY);
if (file != null) {
return getTypeFromTarget(file, context, anchor);
}
if (PyUtil.isPackage(dir, anchor)) {
final PsiFile containingFile = anchor.getContainingFile();
if (containingFile instanceof PyFile) {
final QualifiedName qualifiedName = QualifiedNameFinder.findShortestImportableQName(dir);
if (qualifiedName != null) {
final PyImportedModule module = new PyImportedModule(null, (PyFile) containingFile, qualifiedName);
return new PyImportedModuleType(module);
}
}
}
}
return null;
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyReferenceExpressionImpl method getQualifiedReferenceTypeByControlFlow.
@Nullable
private PyType getQualifiedReferenceTypeByControlFlow(@NotNull TypeEvalContext context) {
PyExpression qualifier = getQualifier();
if (context.allowDataFlow(this) && qualifier != null) {
PyExpression next = qualifier;
while (next != null) {
qualifier = next;
next = qualifier instanceof PyQualifiedExpression ? ((PyQualifiedExpression) qualifier).getQualifier() : null;
}
final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(this);
final QualifiedName qname = asQualifiedName();
if (qname != null && scopeOwner != null) {
return getTypeByControlFlow(qname.toString(), context, qualifier, scopeOwner);
}
}
return null;
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyImportReference method resolveInner.
@NotNull
@Override
protected List<RatedResolveResult> resolveInner() {
//importRef.getParent();
final PyImportElement parent = PsiTreeUtil.getParentOfType(myElement, PyImportElement.class);
final QualifiedName qname = myElement.asQualifiedName();
return qname == null ? Collections.<RatedResolveResult>emptyList() : ResolveImportUtil.resolveNameInImportStatement(parent, qname);
}
Aggregations