Search in sources :

Example 6 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class PyJavaImportCandidateProvider method addImportCandidates.

@Override
public void addImportCandidates(PsiReference reference, String name, AutoImportQuickFix quickFix) {
    final PsiElement element = reference.getElement();
    final Project project = element.getProject();
    Module module = ModuleUtil.findModuleForPsiElement(element);
    GlobalSearchScope scope = module == null ? ProjectScope.getAllScope(project) : module.getModuleWithDependenciesAndLibrariesScope(false);
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
    final PsiClass[] classesByName = cache.getClassesByName(name, scope);
    for (PsiClass psiClass : classesByName) {
        final String qualifiedName = psiClass.getQualifiedName();
        if (qualifiedName == null) {
            continue;
        }
        final QualifiedName packageQName = QualifiedName.fromDottedString(qualifiedName).removeLastComponent();
        quickFix.addImport(psiClass, psiClass.getContainingFile(), packageQName);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) QualifiedName(com.intellij.psi.util.QualifiedName) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 7 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method generateFixes.

/**
   * Generates pack of fixes available for some unresolved import statement.
   * Be sure to call {@link #isApplicable(com.jetbrains.python.psi.PyImportStatementBase)} first to make sure this statement is supported
   *
   * @param importStatementBase statement to fix
   * @return pack of fixes
   */
@NotNull
public static Collection<GenerateBinaryStubsFix> generateFixes(@NotNull final PyImportStatementBase importStatementBase) {
    final List<String> names = importStatementBase.getFullyQualifiedObjectNames();
    final List<GenerateBinaryStubsFix> result = new ArrayList<>(names.size());
    if (importStatementBase instanceof PyFromImportStatement && names.isEmpty()) {
        final QualifiedName qName = ((PyFromImportStatement) importStatementBase).getImportSourceQName();
        if (qName != null) {
            result.add(new GenerateBinaryStubsFix(importStatementBase, qName.toString()));
        }
    }
    for (final String qualifiedName : names) {
        result.add(new GenerateBinaryStubsFix(importStatementBase, qualifiedName));
    }
    return result;
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with QualifiedName

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;
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with QualifiedName

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) QualifiedName(com.intellij.psi.util.QualifiedName)

Example 10 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class InstructionBuilder method buildInstructions.

public static List<Instruction> buildInstructions(ControlFlowBuilder builder, List<PyTypeAssertionEvaluator.Assertion> assertions) {
    List<Instruction> result = Lists.newArrayList();
    for (PyTypeAssertionEvaluator.Assertion def : assertions) {
        final PyReferenceExpression e = def.getElement();
        final QualifiedName qname = e.asQualifiedName();
        final String name = qname != null ? qname.toString() : e.getName();
        result.add(ReadWriteInstruction.assertType(builder, e, name, def.getTypeEvalFunction()));
    }
    return result;
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) Instruction(com.intellij.codeInsight.controlflow.Instruction) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression)

Aggregations

QualifiedName (com.intellij.psi.util.QualifiedName)63 Nullable (org.jetbrains.annotations.Nullable)22 NotNull (org.jetbrains.annotations.NotNull)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Project (com.intellij.openapi.project.Project)8 ScopeOwner (com.jetbrains.python.codeInsight.controlflow.ScopeOwner)7 PsiElement (com.intellij.psi.PsiElement)6 ArrayList (java.util.ArrayList)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PsiFile (com.intellij.psi.PsiFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)2 StringRef (com.intellij.util.io.StringRef)2 PyClass (com.jetbrains.python.psi.PyClass)2 PyFunction (com.jetbrains.python.psi.PyFunction)2 PyClassTypeImpl (com.jetbrains.python.psi.types.PyClassTypeImpl)2 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)2 Instruction (com.intellij.codeInsight.controlflow.Instruction)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1