use of com.jetbrains.python.psi.PyFromImportStatement in project intellij-community by JetBrains.
the class UnresolvedRefAddFutureImportQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
PyFile file = (PyFile) element.getContainingFile();
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
PyFromImportStatement statement = elementGenerator.createFromText(LanguageLevel.forElement(element), PyFromImportStatement.class, "from __future__ import with_statement");
file.addBefore(statement, file.getStatements().get(0));
}
use of com.jetbrains.python.psi.PyFromImportStatement in project intellij-community by JetBrains.
the class PyResolveProcessor method tryAddResult.
private boolean tryAddResult(@Nullable PsiElement element, @Nullable PyImportedNameDefiner definer) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(definer != null ? definer : element);
if (myOwner == null) {
myOwner = owner;
}
final boolean sameScope = owner == myOwner;
if (sameScope) {
// XXX: In 'from foo import foo' inside __init__.py the preferred result is explicitly imported 'foo'
if (definer instanceof PyFromImportStatement) {
myImplicitlyImportedResults.put(element, definer);
} else {
myResults.put(element, definer);
}
}
return sameScope;
}
Aggregations