Search in sources :

Example 1 with PySequenceExpression

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

the class PyConvertLiteralToTupleIntention method prepareOriginalElementCopy.

@NotNull
@Override
protected PsiElement prepareOriginalElementCopy(@NotNull PsiElement copy) {
    final PySequenceExpression sequenceExpression = unwrapCollection(copy);
    final PyExpression[] elements = sequenceExpression.getElements();
    if (elements.length == 1) {
        final PyExpression onlyElement = elements[0];
        final PsiElement next = PyPsiUtils.getNextNonCommentSibling(onlyElement, true);
        if (next != null && next.getNode().getElementType() != PyTokenTypes.COMMA) {
            final PyElementGenerator generator = PyElementGenerator.getInstance(copy.getProject());
            final ASTNode anchor = onlyElement.getNode().getTreeNext();
            sequenceExpression.getNode().addChild(generator.createComma(), anchor);
        }
    }
    return copy;
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression) ASTNode(com.intellij.lang.ASTNode) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator) PySequenceExpression(com.jetbrains.python.psi.PySequenceExpression) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)1 PyExpression (com.jetbrains.python.psi.PyExpression)1 PySequenceExpression (com.jetbrains.python.psi.PySequenceExpression)1 NotNull (org.jetbrains.annotations.NotNull)1