Search in sources :

Example 1 with PyTupleExpression

use of com.jetbrains.python.psi.PyTupleExpression in project intellij-community by JetBrains.

the class ReplaceListComprehensionsQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement expression = descriptor.getPsiElement();
    if (expression instanceof PyTupleExpression) {
        PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
        PyExpressionStatement statement = elementGenerator.createFromText(LanguageLevel.forElement(expression), PyExpressionStatement.class, "(" + expression.getText() + ")");
        expression.replace(statement.getExpression());
    }
}
Also used : PyExpressionStatement(com.jetbrains.python.psi.PyExpressionStatement) PyTupleExpression(com.jetbrains.python.psi.PyTupleExpression) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)1 PyExpressionStatement (com.jetbrains.python.psi.PyExpressionStatement)1 PyTupleExpression (com.jetbrains.python.psi.PyTupleExpression)1