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);
}
}
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;
}
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 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;
}
Aggregations