int (@NotNull Document document, @NotNull PsiFile file, int start, int end) { PsiElement elementAtStartLineEnd = file.findElementAt(start); if (!PsiUtil.isJavaToken(elementAtStartLineEnd, JavaTokenType.SEMICOLON)) return -1; PsiElement elementAtNextLineStart = file.findElementAt(end); if (elementAtNextLineStart == null) return -1; PsiLocalVariable firstVar = ObjectUtils.tryCast(elementAtStartLineEnd.getParent(), PsiLocalVariable.class); if (firstVar == null) return -1; PsiDeclarationStatement firstDeclaration = ObjectUtils.tryCast(firstVar.getParent(), PsiDeclarationStatement.class); if (firstDeclaration == null) return -1; PsiLocalVariable leftMostVar = (PsiLocalVariable)firstDeclaration.getDeclaredElements()[0]; PsiLocalVariable secondVar = PsiTreeUtil.getParentOfType(elementAtNextLineStart, PsiLocalVariable.class); if (secondVar == null || secondVar == firstVar) return -1; PsiDeclarationStatement secondDeclaration = ObjectUtils.tryCast(secondVar.getParent(), PsiDeclarationStatement.class); if (secondDeclaration == null) return -1; if (PsiTreeUtil.skipWhitespacesForward(firstDeclaration) != secondDeclaration) return -1; return joinVariables(document, elementAtStartLineEnd, leftMostVar, secondVar); }