Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-14 14:40:09 -0400
committerMarco Stornelli2019-07-07 03:37:23 -0400
commitcd627b0a493dbfc3c8308f78e4ece529689b7d09 (patch)
tree71104e98c7eb6f81afeff029a94311080b246cd9 /core/org.eclipse.cdt.core
parentb953649c095baf883a0512513a68c44faf1767e1 (diff)
downloadorg.eclipse.cdt-cd627b0a493dbfc3c8308f78e4ece529689b7d09.tar.gz
org.eclipse.cdt-cd627b0a493dbfc3c8308f78e4ece529689b7d09.tar.xz
org.eclipse.cdt-cd627b0a493dbfc3c8308f78e4ece529689b7d09.zip
Bug 540001 - Added option to control comments formatting
Change-Id: I97b1813113f2c53a549b5be7d91ff834fce86bd5 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF2
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java30
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java33
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/InactivePosition.java8
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java403
5 files changed, 279 insertions, 197 deletions
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index 4962a0fd26..36394ef428 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
-Bundle-Version: 6.8.100.qualifier
+Bundle-Version: 6.9.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java
index 8be16e9d2a..a4cfe65934 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java
@@ -122,6 +122,36 @@ public class DefaultCodeFormatterConstants {
*/
public static final String FORMATTER_USE_COMMENT_TAG = CCorePlugin.PLUGIN_ID
+ ".formatter.use_comment_formatter_tag"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Formatter option to format header comment
+ * - option id: "org.eclipse.cdt.core.formatter.format_header_comment"
+ * - default: true
+ * </pre>
+ * @since 6.9
+ */
+ public static final String FORMATTER_COMMENT_HEADER = CCorePlugin.PLUGIN_ID
+ + ".formatter.format_header_comment"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Formatter option to format block comment
+ * - option id: "org.eclipse.cdt.core.formatter.format_block_comment"
+ * - default: true
+ * </pre>
+ * @since 6.9
+ */
+ public static final String FORMATTER_COMMENT_BLOCK = CCorePlugin.PLUGIN_ID
+ + ".formatter.format_block_comment"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Formatter option to format line comment
+ * - option id: "org.eclipse.cdt.core.formatter.format_line_comment"
+ * - default: true
+ * </pre>
+ * @since 6.9
+ */
+ public static final String FORMATTER_COMMENT_LINE = CCorePlugin.PLUGIN_ID
+ + ".formatter.format_line_comment"; //$NON-NLS-1$
// /**
// * <pre>
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
index 6a21ac31e0..2db0bbd129 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterOptions.java
@@ -322,6 +322,18 @@ public class DefaultCodeFormatterOptions {
public String comment_formatter_off_tag;
/** @since 6.7 */
public boolean use_fomatter_comment_tag;
+ /**
+ * @since 6.9
+ */
+ public boolean format_block_comment;
+ /**
+ * @since 6.9
+ */
+ public boolean format_line_comment;
+ /**
+ * @since 6.9
+ */
+ public boolean format_header_comment;
private DefaultCodeFormatterOptions() {
// cannot be instantiated
@@ -345,6 +357,12 @@ public class DefaultCodeFormatterOptions {
options.put(DefaultCodeFormatterConstants.FORMATTER_USE_COMMENT_TAG,
this.use_fomatter_comment_tag ? DefaultCodeFormatterConstants.TRUE
: DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE,
+ format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_BLOCK,
+ format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_HEADER,
+ format_header_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
// options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_allocation_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
getAlignment(this.alignment_for_arguments_in_method_invocation));
@@ -2214,6 +2232,18 @@ public class DefaultCodeFormatterOptions {
if (useFormatterCommentTag != null) {
this.use_fomatter_comment_tag = DefaultCodeFormatterConstants.TRUE.equals(useFormatterCommentTag);
}
+ final Object formatHeaderComment = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_HEADER);
+ if (formatHeaderComment != null) {
+ this.format_header_comment = DefaultCodeFormatterConstants.TRUE.equals(formatHeaderComment);
+ }
+ final Object formatBlockComment = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_BLOCK);
+ if (formatBlockComment != null) {
+ this.format_block_comment = DefaultCodeFormatterConstants.TRUE.equals(formatBlockComment);
+ }
+ final Object formatLineComment = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE);
+ if (formatLineComment != null) {
+ this.format_line_comment = DefaultCodeFormatterConstants.TRUE.equals(formatLineComment);
+ }
}
public void setDefaultSettings() {
@@ -2221,6 +2251,9 @@ public class DefaultCodeFormatterOptions {
this.comment_formatter_on_tag = DefaultCodeFormatterConstants.FORMATTER_ON_TAG;
this.comment_formatter_off_tag = DefaultCodeFormatterConstants.FORMATTER_OFF_TAG;
this.use_fomatter_comment_tag = true;
+ this.format_block_comment = true;
+ this.format_header_comment = true;
+ this.format_line_comment = true;
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
this.alignment_for_assignment = Alignment.M_COMPACT_SPLIT;
this.alignment_for_base_clause_in_type_declaration = Alignment.M_NEXT_PER_LINE_SPLIT;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/InactivePosition.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/InactivePosition.java
index 0edc4fde7b..fda70315d8 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/InactivePosition.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/InactivePosition.java
@@ -1,7 +1,3 @@
-package org.eclipse.cdt.internal.formatter;
-
-import org.eclipse.jface.text.Position;
-
/*******************************************************************************
* Copyright (c) 2019 Marco Stornelli
*
@@ -13,6 +9,10 @@ import org.eclipse.jface.text.Position;
* SPDX-License-Identifier: EPL-2.0
*
*******************************************************************************/
+package org.eclipse.cdt.internal.formatter;
+
+import org.eclipse.jface.text.Position;
+
public class InactivePosition extends Position {
private boolean preprocessorRegion;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java
index 8bba672f41..33e072c299 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java
@@ -934,78 +934,86 @@ public class Scribe {
int currentTokenStartPosition = scanner.getCurrentTokenStartPosition();
int currentTokenEndPosition = scanner.getCurrentTokenEndPosition() + 1;
- scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
- int currentCharacter;
- boolean isNewLine = false;
- int start = currentTokenStartPosition;
- int nextCharacterStart = currentTokenStartPosition;
- printIndentationIfNecessary();
- if (pendingSpace) {
- addInsertEdit(currentTokenStartPosition, SPACE);
- }
- needSpace = false;
- pendingSpace = false;
- int previousStart = currentTokenStartPosition;
+ boolean oldState = inactiveState;
+ if ((currentTokenStartPosition > 0 && !preferences.format_block_comment)
+ || (currentTokenStartPosition == 0 && !preferences.format_header_comment))
+ inactiveState = true;
+ try {
+ scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
+ int currentCharacter;
+ boolean isNewLine = false;
+ int start = currentTokenStartPosition;
+ int nextCharacterStart = currentTokenStartPosition;
+ printIndentationIfNecessary();
+ if (pendingSpace) {
+ addInsertEdit(currentTokenStartPosition, SPACE);
+ }
+ needSpace = false;
+ pendingSpace = false;
+ int previousStart = currentTokenStartPosition;
- while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = scanner.getNextChar()) != -1) {
- nextCharacterStart = scanner.getCurrentPosition();
+ while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = scanner.getNextChar()) != -1) {
+ nextCharacterStart = scanner.getCurrentPosition();
- switch (currentCharacter) {
- case '\r':
- if (isNewLine) {
- line++;
- }
- start = previousStart;
- isNewLine = true;
- if (scanner.getNextChar('\n')) {
- currentCharacter = '\n';
- nextCharacterStart = scanner.getCurrentPosition();
- }
- break;
- case '\n':
- if (isNewLine) {
- line++;
- }
- start = previousStart;
- isNewLine = true;
- break;
- default:
- if (isNewLine) {
- if (Character.isWhitespace((char) currentCharacter)) {
- int previousStartPosition = scanner.getCurrentPosition();
- while (currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n'
- && Character.isWhitespace((char) currentCharacter)) {
- previousStart = nextCharacterStart;
- previousStartPosition = scanner.getCurrentPosition();
- currentCharacter = scanner.getNextChar();
- nextCharacterStart = scanner.getCurrentPosition();
- }
- if (currentCharacter == '\r' || currentCharacter == '\n') {
- nextCharacterStart = previousStartPosition;
- }
+ switch (currentCharacter) {
+ case '\r':
+ if (isNewLine) {
+ line++;
}
- column = 1;
- line++;
+ start = previousStart;
+ isNewLine = true;
+ if (scanner.getNextChar('\n')) {
+ currentCharacter = '\n';
+ nextCharacterStart = scanner.getCurrentPosition();
+ }
+ break;
+ case '\n':
+ if (isNewLine) {
+ line++;
+ }
+ start = previousStart;
+ isNewLine = true;
+ break;
+ default:
+ if (isNewLine) {
+ if (Character.isWhitespace((char) currentCharacter)) {
+ int previousStartPosition = scanner.getCurrentPosition();
+ while (currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n'
+ && Character.isWhitespace((char) currentCharacter)) {
+ previousStart = nextCharacterStart;
+ previousStartPosition = scanner.getCurrentPosition();
+ currentCharacter = scanner.getNextChar();
+ nextCharacterStart = scanner.getCurrentPosition();
+ }
+ if (currentCharacter == '\r' || currentCharacter == '\n') {
+ nextCharacterStart = previousStartPosition;
+ }
+ }
+ column = 1;
+ line++;
- StringBuilder buffer = new StringBuilder();
- buffer.append(lineSeparator);
- printIndentationIfNecessary(buffer);
- buffer.append(' ');
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(lineSeparator);
+ printIndentationIfNecessary(buffer);
+ buffer.append(' ');
- addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
- } else {
- column += (nextCharacterStart - previousStart);
+ addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
+ } else {
+ column += (nextCharacterStart - previousStart);
+ }
+ isNewLine = false;
}
- isNewLine = false;
+ previousStart = nextCharacterStart;
+ scanner.setCurrentPosition(nextCharacterStart);
}
- previousStart = nextCharacterStart;
- scanner.setCurrentPosition(nextCharacterStart);
- }
- lastNumberOfNewLines = 0;
- needSpace = false;
- scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
- if (forceNewLine) {
- startNewLine();
+ lastNumberOfNewLines = 0;
+ needSpace = false;
+ scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
+ if (forceNewLine) {
+ startNewLine();
+ }
+ } finally {
+ inactiveState = oldState;
}
}
@@ -1092,17 +1100,20 @@ public class Scribe {
if (startOffset < endOffset) {
int savedIndentLevel = indentationLevel;
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scanner.eofPosition);
- inactiveState = true;
- /**
- * We are entering in inactive state so if we added a new line previously,
- * starting a new line, we need to remove it.
- */
- if (inactivePos.isPreprocessorRegion() && editsIndex > 0
- && lineSeparator.equals(edits[editsIndex - 1].replacement)) {
- editsIndex--;
+ try {
+ inactiveState = true;
+ /**
+ * We are entering in inactive state so if we added a new line previously,
+ * starting a new line, we need to remove it.
+ */
+ if (inactivePos.isPreprocessorRegion() && editsIndex > 0
+ && lineSeparator.equals(edits[editsIndex - 1].replacement)) {
+ editsIndex--;
+ }
+ printRaw(startOffset, endOffset - startOffset);
+ } finally {
+ inactiveState = false;
}
- printRaw(startOffset, endOffset - startOffset);
- inactiveState = false;
while (indentationLevel > savedIndentLevel) {
unIndent();
}
@@ -1329,150 +1340,158 @@ public class Scribe {
int start = currentTokenStartPosition;
int nextCharacterStart = currentTokenStartPosition;
- // Print comment line indentation
- int commentIndentationLevel;
- boolean onFirstColumn = isOnFirstColumn(start);
- if (!preferences.comment_line_up_line_comment_in_blocks_on_first_column && indentationLevel == 0) {
- commentIndentationLevel = column - 1;
- } else {
- if (onFirstColumn && preferences.never_indent_line_comments_on_first_column) {
+ boolean oldState = inactiveState;
+ if ((currentTokenStartPosition > 0 && !preferences.format_line_comment)
+ || (currentTokenStartPosition == 0 && !preferences.format_header_comment))
+ inactiveState = true;
+ try {
+ // Print comment line indentation
+ int commentIndentationLevel;
+ boolean onFirstColumn = isOnFirstColumn(start);
+ if (!preferences.comment_line_up_line_comment_in_blocks_on_first_column && indentationLevel == 0) {
commentIndentationLevel = column - 1;
} else {
- // Indentation may be specific for contiguous comment
- // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
- if (lastLineComment.contiguous) {
- // The leading spaces have been set while looping in the printComment(int) method
- int currentCommentIndentation = computeIndentation(lastLineComment.leadingSpaces, 0);
- // Keep the current comment indentation when over the previous contiguous line comment
- // and the previous comment has not been re-indented
- int relativeIndentation = currentCommentIndentation - lastLineComment.currentIndentation;
- boolean similarCommentsIndentation = false;
- if (tabLength == 0) {
- similarCommentsIndentation = relativeIndentation == 0;
- } else if (relativeIndentation > -tabLength) {
- similarCommentsIndentation = relativeIndentation == 0
- || currentCommentIndentation != 0 && lastLineComment.currentIndentation != 0;
- }
- if (similarCommentsIndentation && lastLineComment.indentation != indentationLevel) {
- int currentIndentationLevel = indentationLevel;
- indentationLevel = lastLineComment.indentation;
- printIndentationIfNecessary();
- indentationLevel = currentIndentationLevel;
- commentIndentationLevel = lastLineComment.indentation;
+ if (onFirstColumn && preferences.never_indent_line_comments_on_first_column) {
+ commentIndentationLevel = column - 1;
+ } else {
+ // Indentation may be specific for contiguous comment
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
+ if (lastLineComment.contiguous) {
+ // The leading spaces have been set while looping in the printComment(int) method
+ int currentCommentIndentation = computeIndentation(lastLineComment.leadingSpaces, 0);
+ // Keep the current comment indentation when over the previous contiguous line comment
+ // and the previous comment has not been re-indented
+ int relativeIndentation = currentCommentIndentation - lastLineComment.currentIndentation;
+ boolean similarCommentsIndentation = false;
+ if (tabLength == 0) {
+ similarCommentsIndentation = relativeIndentation == 0;
+ } else if (relativeIndentation > -tabLength) {
+ similarCommentsIndentation = relativeIndentation == 0
+ || currentCommentIndentation != 0 && lastLineComment.currentIndentation != 0;
+ }
+ if (similarCommentsIndentation && lastLineComment.indentation != indentationLevel) {
+ int currentIndentationLevel = indentationLevel;
+ indentationLevel = lastLineComment.indentation;
+ printIndentationIfNecessary();
+ indentationLevel = currentIndentationLevel;
+ commentIndentationLevel = lastLineComment.indentation;
+ } else {
+ printIndentationIfNecessary();
+ commentIndentationLevel = column - 1;
+ }
} else {
printIndentationIfNecessary();
commentIndentationLevel = column - 1;
}
- } else {
- printIndentationIfNecessary();
- commentIndentationLevel = column - 1;
}
}
- }
- // Prepare white space before the comment.
- StringBuilder whitespace = null;
- if (!lastLineComment.contiguous && commentIndentationLevel != indentationLevel
- && !(preferences.never_indent_line_comments_on_first_column && onFirstColumn)) {
- whitespace = new StringBuilder();
- int whitespaceStartPosition = currentTokenStartPosition - lastLineComment.leadingSpaces.length;
- int indent = getIndentationOfOffset(whitespaceStartPosition);
- int distance = computeIndentation(lastLineComment.leadingSpaces, indent) - indent;
- if (preferences.comment_preserve_white_space_between_code_and_line_comment
- && distance >= preferences.comment_min_distance_between_code_and_line_comment) {
- whitespace.append(lastLineComment.leadingSpaces);
- } else {
- for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
- whitespace.append(' ');
+ // Prepare white space before the comment.
+ StringBuilder whitespace = null;
+ if (!lastLineComment.contiguous && commentIndentationLevel != indentationLevel
+ && !(preferences.never_indent_line_comments_on_first_column && onFirstColumn)) {
+ whitespace = new StringBuilder();
+ int whitespaceStartPosition = currentTokenStartPosition - lastLineComment.leadingSpaces.length;
+ int indent = getIndentationOfOffset(whitespaceStartPosition);
+ int distance = computeIndentation(lastLineComment.leadingSpaces, indent) - indent;
+ if (preferences.comment_preserve_white_space_between_code_and_line_comment
+ && distance >= preferences.comment_min_distance_between_code_and_line_comment) {
+ whitespace.append(lastLineComment.leadingSpaces);
+ } else {
+ for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
+ whitespace.append(' ');
+ }
}
}
- }
- // Store line comment information
- lastLineComment.currentIndentation = getIndentationOfOffset(currentTokenStartPosition);
- lastLineComment.contiguous = true;
+ // Store line comment information
+ lastLineComment.currentIndentation = getIndentationOfOffset(currentTokenStartPosition);
+ lastLineComment.contiguous = true;
- while (true) {
- Location location = new Location(this, scanner.getCurrentPosition());
- int commentIndent = commentIndentationLevel;
+ while (true) {
+ Location location = new Location(this, scanner.getCurrentPosition());
+ int commentIndent = commentIndentationLevel;
- // Add pending space if necessary
- if (whitespace != null) {
- addInsertEdit(currentTokenStartPosition, whitespace);
- commentIndent = computeIndentation(whitespace, commentIndentationLevel);
- needSpace = false;
- pendingSpace = false;
- }
- lastLineComment.indentation = commentIndent;
+ // Add pending space if necessary
+ if (whitespace != null) {
+ addInsertEdit(currentTokenStartPosition, whitespace);
+ commentIndent = computeIndentation(whitespace, commentIndentationLevel);
+ needSpace = false;
+ pendingSpace = false;
+ }
+ lastLineComment.indentation = commentIndent;
- int previousStart = currentTokenStartPosition;
+ int previousStart = currentTokenStartPosition;
- int indent = commentIndent;
- loop: while (nextCharacterStart <= currentTokenEndPosition
- && (currentCharacter = scanner.getNextChar()) != -1) {
- nextCharacterStart = scanner.getCurrentPosition();
+ int indent = commentIndent;
+ loop: while (nextCharacterStart <= currentTokenEndPosition
+ && (currentCharacter = scanner.getNextChar()) != -1) {
+ nextCharacterStart = scanner.getCurrentPosition();
- switch (currentCharacter) {
- case '\r':
- case '\n':
- start = previousStart;
- break loop;
+ switch (currentCharacter) {
+ case '\r':
+ case '\n':
+ start = previousStart;
+ break loop;
+ }
+ indent = computeIndentation((char) currentCharacter, indent);
+ previousStart = nextCharacterStart;
}
- indent = computeIndentation((char) currentCharacter, indent);
- previousStart = nextCharacterStart;
- }
- if (start != currentTokenStartPosition) {
- // This means that the line comment doesn't end the file
- addReplaceEdit(start, currentTokenEndPosition - 1, lineSeparator);
- line++;
- column = 1;
- lastNumberOfNewLines = 1;
- }
- if (!checkLineWrapping || indent <= pageWidth || whitespace == null || commentIndent
- - commentIndentationLevel <= preferences.comment_min_distance_between_code_and_line_comment) {
- break;
- }
+ if (start != currentTokenStartPosition) {
+ // This means that the line comment doesn't end the file
+ addReplaceEdit(start, currentTokenEndPosition - 1, lineSeparator);
+ line++;
+ column = 1;
+ lastNumberOfNewLines = 1;
+ }
+ if (!checkLineWrapping || indent <= pageWidth || whitespace == null || commentIndent
+ - commentIndentationLevel <= preferences.comment_min_distance_between_code_and_line_comment) {
+ break;
+ }
- // Maximum line length was exceeded. Try to reduce white space before the comment by
- // removing the last white space character.
- whitespace.deleteCharAt(whitespace.length() - 1);
- if (computeIndentation(lastLineComment.leadingSpaces, commentIndentationLevel)
- - commentIndentationLevel < preferences.comment_min_distance_between_code_and_line_comment) {
- // The white space shrank too much. Rebuild it to satisfy the minimum distance
- // requirement.
- whitespace.delete(0, whitespace.length());
- for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
- whitespace.append(' ');
+ // Maximum line length was exceeded. Try to reduce white space before the comment by
+ // removing the last white space character.
+ whitespace.deleteCharAt(whitespace.length() - 1);
+ if (computeIndentation(lastLineComment.leadingSpaces, commentIndentationLevel)
+ - commentIndentationLevel < preferences.comment_min_distance_between_code_and_line_comment) {
+ // The white space shrank too much. Rebuild it to satisfy the minimum distance
+ // requirement.
+ whitespace.delete(0, whitespace.length());
+ for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
+ whitespace.append(' ');
+ }
}
+ resetAt(location);
+ scanner.resetTo(location.inputOffset, scanner.eofPosition);
}
- resetAt(location);
- scanner.resetTo(location.inputOffset, scanner.eofPosition);
- }
- needSpace = false;
- pendingSpace = false;
- // realign to the proper value
- if (currentAlignment != null) {
- if (memberAlignment != null) {
- // select the last alignment
- if (currentAlignment.location.inputOffset > memberAlignment.location.inputOffset) {
- if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
- currentAlignment.performFragmentEffect();
+ needSpace = false;
+ pendingSpace = false;
+ // realign to the proper value
+ if (currentAlignment != null) {
+ if (memberAlignment != null) {
+ // select the last alignment
+ if (currentAlignment.location.inputOffset > memberAlignment.location.inputOffset) {
+ if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
+ currentAlignment.performFragmentEffect();
+ }
+ } else {
+ indentationLevel = Math.max(indentationLevel, memberAlignment.breakIndentationLevel);
}
- } else {
- indentationLevel = Math.max(indentationLevel, memberAlignment.breakIndentationLevel);
+ } else if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
+ currentAlignment.performFragmentEffect();
+ }
+ if (currentAlignment.name.equals(Alignment.BINARY_EXPRESSION) && currentAlignment.enclosing != null
+ && currentAlignment.enclosing.equals(Alignment.BINARY_EXPRESSION)
+ && indentationLevel < currentAlignment.breakIndentationLevel) {
+ indentationLevel = currentAlignment.breakIndentationLevel;
}
- } else if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
- currentAlignment.performFragmentEffect();
- }
- if (currentAlignment.name.equals(Alignment.BINARY_EXPRESSION) && currentAlignment.enclosing != null
- && currentAlignment.enclosing.equals(Alignment.BINARY_EXPRESSION)
- && indentationLevel < currentAlignment.breakIndentationLevel) {
- indentationLevel = currentAlignment.breakIndentationLevel;
}
+ scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
+ } finally {
+ inactiveState = oldState;
}
- scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
}
public void printEmptyLines(int linesNumber) {

Back to the top