int (@NotNull Document document, @NotNull PsiFile file, int start, int end) { if (!(file instanceof GroovyFileBase)) return CANNOT_JOIN; final PsiElement element = file.findElementAt(end); final GrStatementOwner statementOwner = PsiTreeUtil.getParentOfType(element, GrStatementOwner.class, true, GroovyFileBase.class); if (statementOwner == null) return CANNOT_JOIN; GrStatement first = null; GrStatement last = null; for (PsiElement child = statementOwner.getFirstChild(); child != null; child = child.getNextSibling()) { final TextRange range = child.getTextRange(); if (range.getEndOffset() == start) { first = skipSemicolonsAndWhitespaces(child, false); } else if (range.getStartOffset() == end) { last = skipSemicolonsAndWhitespaces(child, true); } } if (last == null || first == null) return CANNOT_JOIN; return tryJoinStatements(first, last); }