static void deleteWholeStatement(PsiElement element, PsiElementFactory factory) throws IncorrectOperationException { // just delete it altogether if (element.getParent() instanceof PsiExpressionStatement) { PsiExpressionStatement parent = (PsiExpressionStatement) element.getParent(); if (parent.getParent() instanceof PsiCodeBlock) { parent.delete(); } else { // replace with empty statement (to handle with 'if (..) i=0;' ) parent.replace(createStatementIfNeeded(null, factory, element)); } } else { element.delete(); } }
public static void translate(PsiExpressionStatement element, TranslationContext ctx) { boolean loopDeclaration = false; PsiElement parent = element.getParent(); if (parent instanceof PsiLoopStatement && !((PsiLoopStatement) parent).getBody().equals(element)) { loopDeclaration = true; } if (!loopDeclaration) { ctx.print(""); } ExpressionTranslator.translate(element.getExpression(), ctx); if (!loopDeclaration) { ctx.append(";\n"); } }