use of com.jetbrains.python.psi.PyTryExceptStatement in project intellij-community by JetBrains.
the class ReplaceExceptPartQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement exceptPart = descriptor.getPsiElement();
if (exceptPart instanceof PyExceptPart) {
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
PsiElement element = ((PyExceptPart) exceptPart).getExceptClass().getNextSibling();
while (element instanceof PsiWhiteSpace) {
element = element.getNextSibling();
}
assert element != null;
PyTryExceptStatement newElement = elementGenerator.createFromText(LanguageLevel.forElement(exceptPart), PyTryExceptStatement.class, "try: pass except a as b: pass");
ASTNode node = newElement.getExceptParts()[0].getNode().findChildByType(PyTokenTypes.AS_KEYWORD);
assert node != null;
element.replace(node.getPsi());
}
}
Aggregations