use of com.jetbrains.python.psi.PyImportStatementBase in project intellij-community by JetBrains.
the class PyAddImportFix method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PyElementGenerator generator = PyElementGenerator.getInstance(project);
final PyImportStatementBase statement = generator.createFromText(LanguageLevel.forElement(myFile), PyImportStatementBase.class, myImportToAdd);
final PsiElement recommendedPosition = AddImportHelper.getFileInsertPosition(myFile);
myFile.addAfter(statement, recommendedPosition);
}
use of com.jetbrains.python.psi.PyImportStatementBase in project intellij-community by JetBrains.
the class PyOptimizeImportsTest method testExtractImportBlockNoWhitespaceAtEnd.
public void testExtractImportBlockNoWhitespaceAtEnd() {
myFixture.configureByFile(getTestName(true) + ".py");
final PyFileImpl file = assertInstanceOf(myFixture.getFile(), PyFileImpl.class);
final List<PyImportStatementBase> block = file.getImportBlock();
assertSize(2, block);
}
use of com.jetbrains.python.psi.PyImportStatementBase in project intellij-community by JetBrains.
the class PyOptimizeImportsTest method testExtractImportBlockWithIntermediateComments.
public void testExtractImportBlockWithIntermediateComments() {
myFixture.configureByFile(getTestName(true) + ".py");
final PyFileImpl file = assertInstanceOf(myFixture.getFile(), PyFileImpl.class);
final List<PyImportStatementBase> block = file.getImportBlock();
assertSize(2, block);
}
use of com.jetbrains.python.psi.PyImportStatementBase in project intellij-community by JetBrains.
the class PyImportFilteringRule method isVisible.
@Override
public boolean isVisible(@NotNull Usage usage) {
if (usage instanceof PsiElementUsage) {
final PsiElement psiElement = ((PsiElementUsage) usage).getElement();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile instanceof PyFile) {
// check whether the element is in the import list
final PyImportStatementBase importStatement = PsiTreeUtil.getParentOfType(psiElement, PyImportStatementBase.class, true);
return importStatement == null;
}
}
return true;
}
Aggregations