boolean () { List<PatchLine> lastHunkLines = Objects.requireNonNull(ContainerUtil.getLastItem(myHunks)).getLines(); PatchLine lastBaseLine = ContainerUtil.findLast(lastHunkLines, line -> line.getType() != PatchLine.Type.ADD); PatchLine lastPatchedLine = ContainerUtil.findLast(lastHunkLines, line -> line.getType() != PatchLine.Type.REMOVE); if (lastBaseLine != null) { boolean lastLineAlreadyApplied = !lastBaseLine.isSuppressNewLine() && baseLine + 1 == myLineOffsets.getLineCount() && getLineContent(baseLine).length() == 0 || lastBaseLine.isSuppressNewLine() && baseLine == myLineOffsets.getLineCount(); if (lastLineAlreadyApplied) { boolean isNoNewlinePatched = lastPatchedLine != null ? lastPatchedLine.isSuppressNewLine() : lastBaseLine.isSuppressNewLine(); if (!isNoNewlinePatched) { if (patchedLine > 0) sb.append('\n'); } return true; } return false; } // insertion into empty file - use "No newline at end of file" flag from patch if (baseLine == 0 && myText.length() == 0) { boolean isNoNewlinePatched = lastPatchedLine != null && lastPatchedLine.isSuppressNewLine(); if (!isNoNewlinePatched) { if (patchedLine > 0) sb.append('\n'); } return true; } return false; }