private String getPreserveEmptyLines(int count, int emptyLinesRules) { if (count == 0) { int currentIndentationLevel = this.indentationLevel; int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules); switch (useAlignmentBreakIndentation) { case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION: return Util.EMPTY_STRING; default: // Return the new indented line StringBuffer buffer = new StringBuffer(getNewLine()); printIndentationIfNecessary(buffer); if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) { this.indentationLevel = currentIndentationLevel; } return buffer.toString(); } } if (this.blank_lines_between_import_groups >= 0) { useAlignmentBreakIndentation(emptyLinesRules); return getEmptyLines(this.blank_lines_between_import_groups); } if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { useAlignmentBreakIndentation(emptyLinesRules); int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); return getEmptyLines(linesToPreserve); } return getNewLine(); } private int useAlignmentBreakIndentation(int emptyLinesRules) {
private String getPreserveEmptyLines(int count, int emptyLinesRules) { if (count == 0) { int currentIndentationLevel = this.indentationLevel; int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules); switch (useAlignmentBreakIndentation) { case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION: return Util.EMPTY_STRING; default: // Return the new indented line StringBuffer buffer = new StringBuffer(getNewLine()); printIndentationIfNecessary(buffer); if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) { this.indentationLevel = currentIndentationLevel; } return buffer.toString(); } } if (this.blank_lines_between_import_groups >= 0) { useAlignmentBreakIndentation(emptyLinesRules); return getEmptyLines(this.blank_lines_between_import_groups); } if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { useAlignmentBreakIndentation(emptyLinesRules); int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); return getEmptyLines(linesToPreserve); } return getNewLine(); } private int useAlignmentBreakIndentation(int emptyLinesRules) {
private String getPreserveEmptyLines(int count, int emptyLinesRules) { if (count == 0) { int currentIndentationLevel = this.indentationLevel; int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules); switch (useAlignmentBreakIndentation) { case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION: return Util.EMPTY_STRING; default: // Return the new indented line StringBuffer buffer = new StringBuffer(getNewLine()); printIndentationIfNecessary(buffer); if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) { this.indentationLevel = currentIndentationLevel; } return buffer.toString(); } } if (this.blank_lines_between_import_groups >= 0) { useAlignmentBreakIndentation(emptyLinesRules); return getEmptyLines(this.blank_lines_between_import_groups); } if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { useAlignmentBreakIndentation(emptyLinesRules); int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); return getEmptyLines(linesToPreserve); } return getNewLine(); } private int useAlignmentBreakIndentation(int emptyLinesRules) {
useAlignmentBreakIndentation(emptyLinesRules); currentTokenStartPosition = tokenStartPosition; preserveEmptyLines(lines, currentTokenStartPosition); addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); } else if (hasComment) { useAlignmentBreakIndentation(emptyLinesRules); if (lines == 1) { this.printNewLine(tokenStartPosition); addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1, emptyLinesRules)); } else { useAlignmentBreakIndentation(emptyLinesRules); addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
useAlignmentBreakIndentation(emptyLinesRules); currentTokenStartPosition = tokenStartPosition; preserveEmptyLines(lines, currentTokenStartPosition); addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); } else if (hasComment) { useAlignmentBreakIndentation(emptyLinesRules); if (lines == 1) { this.printNewLine(tokenStartPosition); addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1, emptyLinesRules)); } else { useAlignmentBreakIndentation(emptyLinesRules); addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
useAlignmentBreakIndentation(emptyLinesRules); currentTokenStartPosition = tokenStartPosition; preserveEmptyLines(lines, currentTokenStartPosition); addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); } else if (hasComment) { useAlignmentBreakIndentation(emptyLinesRules); if (lines == 1) { this.printNewLine(tokenStartPosition); addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1, emptyLinesRules)); } else { useAlignmentBreakIndentation(emptyLinesRules); addDeleteEdit(tokenStartPosition, whitespacesEndPosition);