int (@NotNull Document document, @NotNull PsiFile file, int start, int end) { if (!(file instanceof GroovyFileBase)) return CANNOT_JOIN; final PsiElement startElement = file.findElementAt(start); if (startElement == null || !startElement.getNode().getElementType().equals(GroovyTokenTypes.mRPAREN)) return CANNOT_JOIN; final PsiElement parent = startElement.getParent(); if (!(parent instanceof GrIfStatement || parent instanceof GrWhileStatement || parent instanceof GrForStatement)) return CANNOT_JOIN; GrStatement inner; if (parent instanceof GrIfStatement) { inner = ((GrIfStatement)parent).getThenBranch(); } else if (parent instanceof GrWhileStatement) { inner = ((GrWhileStatement)parent).getBody(); } else /*if (parent instanceof GrForStatement)*/ { inner = ((GrForStatement)parent).getBody(); } if (inner instanceof GrBlockStatement) return CANNOT_JOIN; document.replaceString(start + 1, end, " "); return start + 2; }