### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v
retrieving revision 1.116
diff -u -r1.116 DefaultCodeFormatterConstants.java
--- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 27 May 2010 15:54:44 -0000 1.116
+++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 19 Aug 2010 07:43:40 -0000
@@ -913,7 +913,7 @@
* void bar1() {}
* void bar2() {}
* }
- *
+ *
*
* If no enabling tag is found by the formatter after the disabling tag, then
* the end of the snippet won't be formatted.
@@ -951,7 +951,45 @@
* The tag cannot include newline character (i.e. '\n') but it can have white
* spaces.
* E.g. "format: off" is a valid disabling tag.
- * In the future, newlines may be used to support multiple disabling tags.
+ * In the future, newlines may be used to support multiple disabling tags.
+ *
+ * The tag can include line or block comments start/end tokens.
+ * If such tags are used, e.g. "//J-", then the single comment can
+ * also stop the formatting as shown in the following snippet:
+ *
+ * //J-
+ * // Formatting was stopped from comment above...
+ * public class X {
+ * //J+
+ * // Formatting is restarted from here...
+ * void foo() {}
+ *
+ * As any disabling tags, as soon as a comment includes it,
+ * the formatting stops from this comment:
+ *
+ * public class X {
+ * // Line comment including the disabling tag: //J-
+ * // Formatting was stopped from comment above...
+ * void foo1() {}
+ * //J+
+ * // Formatting restarts from here...
+ * void bar1() {}
+ * /*
+ * * Block comment including the disabling tag: //J+
+ * * The formatter stops from this comment...
+ * */
+ * void foo2() {}
+ * //J+
+ * // Formatting restarts from here...
+ * void bar2() {}
+ * /**
+ * * Javadoc comment including the enabling tag: //J+
+ * * The formatter stops from this comment...
+ * */
+ * void foo3() {}
+ * }
+ *
+ *
*
*
* @since 3.6
@@ -1012,7 +1050,7 @@
* // @formatter:on
* void bar2() {}
* }
- *
+ *
*
* If a mix of disabling and enabling tags is done in the same comment, then
* the formatter will only take into account the last encountered tag in the
@@ -1033,10 +1071,54 @@
* void bar() {}
* }
*
+ *
* The tag cannot include newline character (i.e. '\n') but it can have white
* spaces.
* E.g. "format: on" is a valid enabling tag
- * In the future, newlines may be used to support multiple enabling tags.
+ * In the future, newlines may be used to support multiple enabling tags.
+ *
+ * The tag can include line or block comments start/end tokens. Javadoc
+ * tokens are not considered as valid tags.
+ * If such tags are used, e.g. "//J+", then the single comment can
+ * also start the formatting as shown in the following snippet:
+ *
+ * //J-
+ * // Formatting was stopped from comment above...
+ * public class X {
+ * //J+
+ * // Formatting restarts from here...
+ * void foo() {}
+ * }
+ *
+ * As any enabling tags, as soon as a comment includes it,
+ * the formatting restarts just after the comment:
+ *
+ * public class X {
+ * //J-
+ * // Formatting was stopped from comment above...
+ * void foo1() {}
+ * // Line comment including the enabling tag: //J+
+ * // Formatting restarts from here...
+ * void bar1() {}
+ * //J-
+ * // Formatting was stopped from comment above...
+ * void foo2() {}
+ * /*
+ * * Block comment including the enabling tag: //J+
+ * * The formatter restarts after this comment...
+ * */
+ * // Formatting restarts from here...
+ * void bar2() {}
+ * //J-
+ * // Formatting was stopped from comment above...
+ * void foo3() {}
+ * /**
+ * * Javadoc comment including the enabling tag: //J+
+ * * The formatter restarts after this comment...
+ * */
+ * void bar3() {}
+ * }
+ *
*
*
*
Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v
retrieving revision 1.216
diff -u -r1.216 Scribe.java
--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 17 Aug 2010 10:16:57 -0000 1.216
+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 19 Aug 2010 07:43:41 -0000
@@ -108,6 +108,7 @@
/** disabling */
boolean editsEnabled;
boolean useTags;
+ int tagsKind;
/* Comments formatting */
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT;
@@ -1419,6 +1420,7 @@
private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) {
this.useTags = preferences.use_tags;
+ this.tagsKind = 0;
char[][] taskTags = null;
if (this.useTags) {
this.disablingTag = preferences.disabling_tag;
@@ -1433,6 +1435,23 @@
taskTags = new char[][] { this.disablingTag, this.enablingTag };
}
}
+ if (taskTags != null) {
+ loop: for (int i=0,length=taskTags.length; i 2 && taskTags[i][0] == '/') {
+ switch (taskTags[i][1]) {
+ case '/':
+ this.tagsKind = TerminalTokens.TokenNameCOMMENT_LINE;
+ break loop;
+ case '*':
+ if (taskTags[i][2] != '*') {
+ this.tagsKind = TerminalTokens.TokenNameCOMMENT_BLOCK;
+ break loop;
+ }
+ break;
+ }
+ }
+ }
+ }
this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/);
this.editsEnabled = true;
}
@@ -2368,10 +2387,10 @@
int lines = 0;
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
int foundTaskCount = this.scanner.foundTaskCount;
+ int tokenStartPosition = this.scanner.getCurrentTokenStartPosition();
switch(this.currentToken) {
case TerminalTokens.TokenNameWHITESPACE :
char[] whiteSpaces = this.scanner.getCurrentTokenSource();
- int whitespacesStartPosition = this.scanner.getCurrentTokenStartPosition();
int whitespacesEndPosition = this.scanner.getCurrentTokenEndPosition();
lines = 0;
for (int i = 0, max = whiteSpaces.length; i < max; i++) {
@@ -2445,7 +2464,7 @@
// if a line comment is consumed, no other comment can be on the same line after
if (hasLineComment) {
if (lines >= 1) {
- currentTokenStartPosition = whitespacesStartPosition;
+ currentTokenStartPosition = tokenStartPosition;
preserveEmptyLines(lines, currentTokenStartPosition);
addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
@@ -2457,7 +2476,7 @@
// if one or several new lines are consumed, following comments cannot be considered as trailing ones
if (lines >= 1) {
if (hasComment) {
- this.printNewLine(whitespacesStartPosition);
+ this.printNewLine(tokenStartPosition);
}
this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
return;
@@ -2465,37 +2484,47 @@
// delete consumed white spaces
hasWhitespaces = true;
currentTokenStartPosition = this.scanner.currentPosition;
- addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
} else {
if (lines == 0) {
hasWhitespaces = true;
- addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
} else if (hasLineComment) {
- currentTokenStartPosition = whitespacesStartPosition;
+ currentTokenStartPosition = tokenStartPosition;
preserveEmptyLines(lines, currentTokenStartPosition);
addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
} else if (hasComment) {
if (lines == 1) {
- this.printNewLine(whitespacesStartPosition);
+ this.printNewLine(tokenStartPosition);
} else {
- preserveEmptyLines(lines - 1, whitespacesStartPosition);
+ preserveEmptyLines(lines - 1, tokenStartPosition);
}
- addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
} else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) {
- addReplaceEdit(whitespacesStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1));
+ addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1));
} else {
- addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
}
}
currentTokenStartPosition = this.scanner.currentPosition;
break;
case TerminalTokens.TokenNameCOMMENT_LINE :
- if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
- if (!this.editsEnabled && this.editsIndex > 1) {
- OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
- if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
- printNewLinesBeforeDisablingComment();
+ if (this.useTags && this.editsEnabled) {
+ boolean turnOff = false;
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ turnOff = true;
+ } else if (this.tagsKind == this.currentToken
+ && CharOperation.fragmentEquals(this.disablingTag, this.scanner.source, tokenStartPosition, true)) {
+ this.editsEnabled = false;
+ turnOff = true;
+ }
+ if (turnOff) {
+ if (!this.editsEnabled && this.editsIndex > 1) {
+ OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
+ if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
+ printNewLinesBeforeDisablingComment();
+ }
}
}
}
@@ -2514,17 +2543,31 @@
currentTokenStartPosition = this.scanner.currentPosition;
hasLineComment = true;
lines = 0;
- if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
+ if (this.useTags && !this.editsEnabled) {
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ } else if (this.tagsKind == this.currentToken) {
+ this.editsEnabled = CharOperation.fragmentEquals(this.enablingTag, this.scanner.source, tokenStartPosition, true);
+ }
}
break;
case TerminalTokens.TokenNameCOMMENT_BLOCK :
- if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
- if (!this.editsEnabled && this.editsIndex > 1) {
- OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
- if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
- printNewLinesBeforeDisablingComment();
+ if (this.useTags && this.editsEnabled) {
+ boolean turnOff = false;
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ turnOff = true;
+ } else if (this.tagsKind == this.currentToken
+ && CharOperation.fragmentEquals(this.disablingTag, this.scanner.source, tokenStartPosition, true)) {
+ this.editsEnabled = false;
+ turnOff = true;
+ }
+ if (turnOff) {
+ if (!this.editsEnabled && this.editsIndex > 1) {
+ OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
+ if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
+ printNewLinesBeforeDisablingComment();
+ }
}
}
}
@@ -2550,8 +2593,12 @@
hasLineComment = false;
hasComment = true;
lines = 0;
- if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
+ if (this.useTags && !this.editsEnabled) {
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ } else if (this.tagsKind == this.currentToken) {
+ this.editsEnabled = CharOperation.fragmentEquals(this.enablingTag, this.scanner.source, tokenStartPosition, true);
+ }
}
break;
case TerminalTokens.TokenNameCOMMENT_JAVADOC :
@@ -4430,6 +4477,8 @@
boolean hasModifiers = false;
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
int foundTaskCount = this.scanner.foundTaskCount;
+ int tokenStartPosition = this.scanner.getCurrentTokenStartPosition();
+ int tokenEndPosition = this.scanner.getCurrentTokenEndPosition();
switch(this.currentToken) {
case TerminalTokens.TokenNamepublic :
case TerminalTokens.TokenNameprotected :
@@ -4494,35 +4543,64 @@
break;
case TerminalTokens.TokenNameCOMMENT_BLOCK :
case TerminalTokens.TokenNameCOMMENT_JAVADOC :
- if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
- if (!this.editsEnabled && this.editsIndex > 1) {
- OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
- if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
- printNewLinesBeforeDisablingComment();
+ if (this.useTags && this.editsEnabled) {
+ boolean turnOff = false;
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ turnOff = true;
+ } else if (this.tagsKind == this.currentToken
+ && CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1)) {
+ this.editsEnabled = false;
+ turnOff = true;
+ }
+ if (turnOff) {
+ if (!this.editsEnabled && this.editsIndex > 1) {
+ OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
+ if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
+ printNewLinesBeforeDisablingComment();
+ }
}
}
}
printBlockComment(this.currentToken == TerminalTokens.TokenNameCOMMENT_JAVADOC);
- if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
+ if (this.useTags && !this.editsEnabled) {
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ } else if (this.tagsKind == this.currentToken) {
+ this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1);
+ }
}
currentTokenStartPosition = this.scanner.currentPosition;
hasComment = true;
break;
case TerminalTokens.TokenNameCOMMENT_LINE :
- if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
- if (!this.editsEnabled && this.editsIndex > 1) {
- OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
- if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
- printNewLinesBeforeDisablingComment();
+ tokenEndPosition = -this.scanner.commentStops[this.scanner.commentPtr];
+ if (this.useTags && this.editsEnabled) {
+ boolean turnOff = false;
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ turnOff = true;
+ } else if (this.tagsKind == this.currentToken
+ && CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition)) {
+ this.editsEnabled = false;
+ turnOff = true;
+ }
+ if (turnOff) {
+ if (!this.editsEnabled && this.editsIndex > 1) {
+ OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
+ if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
+ printNewLinesBeforeDisablingComment();
+ }
}
}
}
printLineComment();
- if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
- setEditsEnabled(foundTaskCount);
+ if (this.useTags && !this.editsEnabled) {
+ if (foundTaskCount > 0) {
+ setEditsEnabled(foundTaskCount);
+ } else if (this.tagsKind == this.currentToken) {
+ this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition);
+ }
}
currentTokenStartPosition = this.scanner.currentPosition;
break;
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v
retrieving revision 1.35
diff -u -r1.35 FormatterBugsTests.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 17 Aug 2010 10:16:59 -0000 1.35
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 19 Aug 2010 07:43:45 -0000
@@ -363,17 +363,17 @@
this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
String source =
- "public class X04 {\r\n" +
- "\r\n" +
- "/* disable-formatter */\r\n" +
- "void foo( ) { \r\n" +
- " // unformatted comment \r\n" +
- "}\r\n" +
- "/* enable-formatter */\r\n" +
- "void bar( ) { \r\n" +
- " // formatted comment \r\n" +
- "}\r\n" +
- "}\r\n";
+ "public class X04 {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment \n" +
+ "}\n" +
+ "}\n";
formatSource(source,
"public class X04 {\n" +
"\n" +
@@ -410,22 +410,22 @@
"}\n" +
"}\n";
formatSource(source,
- "public class X04b {\r\n" +
- "\r\n" +
- "/* disable-formatter */\r\n" +
- "void foo( ) { \r\n" +
- " // unformatted comment \r\n" +
- "}\r\n" +
- "/* enable-formatter */\r\n" +
- " void bar() {\r\n" +
- " // formatted comment\r\n" +
- " }\r\n" +
- "}\r\n",
+ "public class X04b {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n",
CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
0 /* indentation level */,
0 /* offset */,
-1 /* length (all) */,
- "\r\n",
+ "\n",
true/*repeat*/);
}
public void testBug027079d3() throws JavaModelException {
@@ -433,34 +433,34 @@
this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
String source =
- "public class X04c {\r\n" +
- "\r\n" +
- "/* disable-formatter */\r\n" +
- "void foo( ) { \r\n" +
- " // unformatted comment \r\n" +
- "}\r\n" +
- "/* enable-formatter */\r\n" +
- "void bar( ) { \r\n" +
- " // formatted comment \r\n" +
- "}\r\n" +
- "}\r\n";
- formatSource(source,
- "public class X04c {\r\n" +
- "\r\n" +
- "/* disable-formatter */\r\n" +
- "void foo( ) { \r\n" +
- " // unformatted comment \r\n" +
- "}\r\n" +
- "/* enable-formatter */\r\n" +
- " void bar() {\r\n" +
- " // formatted comment\r\n" +
- " }\r\n" +
- "}\r\n",
+ "public class X04c {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment \n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X04c {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n",
CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
0 /* indentation level */,
0 /* offset */,
-1 /* length (all) */,
- "\r\n",
+ "\n",
true/*repeat*/);
}
public void testBug027079d4() throws JavaModelException {
@@ -6046,6 +6046,423 @@
}
/**
+ * @bug 311578: [formatter] Enable/disable tag detection should include comment start/end tokens
+ * @test Ensure that the formatter now accepts tags with comment start/end tokens
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311578"
+ */
+public void testBug311578a() throws JavaModelException {
+ this.formatterPrefs.use_tags = true;
+ this.formatterPrefs.disabling_tag = "//J-".toCharArray();
+ this.formatterPrefs.enabling_tag = "//J+".toCharArray();
+ String source =
+ "package a;\n" +
+ "public class Bug {\n" +
+ "int a = - 1 + 42;\n" +
+ "\n" +
+ "//J-\n" +
+ "int b = - 1 + 42;\n" +
+ "//J+\n" +
+ "\n" +
+ "char x;\n" +
+ "\n" +
+ "////J-\n" +
+ "int c = - 1 + 42;\n" +
+ "////J+\n" +
+ "\n" +
+ "char y;\n" +
+ "\n" +
+ "/* J- */\n" +
+ "int d = - 1 + 42;\n" +
+ "/* J+ */\n" +
+ "\n" +
+ "char z;\n" +
+ "\n" +
+ "/* //J- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //J+ */\n" +
+ "\n" +
+ "/** J-1 blabla */\n" +
+ "char t;\n" +
+ "}\n";
+ formatSource(source,
+ "package a;\n" +
+ "\n" +
+ "public class Bug {\n" +
+ " int a = -1 + 42;\n" +
+ "\n" +
+ "//J-\n" +
+ "int b = - 1 + 42;\n" +
+ "//J+\n" +
+ "\n" +
+ " char x;\n" +
+ "\n" +
+ "////J-\n" +
+ "int c = - 1 + 42;\n" +
+ "////J+\n" +
+ "\n" +
+ " char y;\n" +
+ "\n" +
+ " /* J- */\n" +
+ " int d = -1 + 42;\n" +
+ " /* J+ */\n" +
+ "\n" +
+ " char z;\n" +
+ "\n" +
+ "/* //J- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //J+ */\n" +
+ "\n" +
+ " /** J-1 blabla */\n" +
+ " char t;\n" +
+ "}\n"
+ );
+}
+public void testBug311578b() throws JavaModelException {
+ this.formatterPrefs.use_tags = true;
+ this.formatterPrefs.disabling_tag = "/* J- */".toCharArray();
+ this.formatterPrefs.enabling_tag = "/* J+ */".toCharArray();
+ String source =
+ "package a;\n" +
+ "public class Bug {\n" +
+ "int a = - 1 + 42;\n" +
+ "\n" +
+ "//J-\n" +
+ "int b = - 1 + 42;\n" +
+ "//J+\n" +
+ "\n" +
+ "char x;\n" +
+ "\n" +
+ "////J-\n" +
+ "int c = - 1 + 42;\n" +
+ "////J+\n" +
+ "\n" +
+ "char y;\n" +
+ "\n" +
+ "/* J- */\n" +
+ "int d = - 1 + 42;\n" +
+ "/* J+ */\n" +
+ "\n" +
+ "char z;\n" +
+ "\n" +
+ "/* //J- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //J+ */\n" +
+ "\n" +
+ "/** J-1 blabla */\n" +
+ "char t;\n" +
+ "}\n";
+ formatSource(source,
+ "package a;\n" +
+ "\n" +
+ "public class Bug {\n" +
+ " int a = -1 + 42;\n" +
+ "\n" +
+ " // J-\n" +
+ " int b = -1 + 42;\n" +
+ " // J+\n" +
+ "\n" +
+ " char x;\n" +
+ "\n" +
+ " // //J-\n" +
+ " int c = -1 + 42;\n" +
+ " // //J+\n" +
+ "\n" +
+ " char y;\n" +
+ "\n" +
+ "/* J- */\n" +
+ "int d = - 1 + 42;\n" +
+ "/* J+ */\n" +
+ "\n" +
+ " char z;\n" +
+ "\n" +
+ " /* //J- */\n" +
+ " int e = -1 + 42;\n" +
+ " /* //J+ */\n" +
+ "\n" +
+ " /** J-1 blabla */\n" +
+ " char t;\n" +
+ "}\n"
+ );
+}
+public void testBug311578c() throws JavaModelException {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE);
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "//F--");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "//F++");
+ String source =
+ "package a;\n" +
+ "public class Bug {\n" +
+ "int a = - 1 + 42;\n" +
+ "\n" +
+ "//F--\n" +
+ "int b = - 1 + 42;\n" +
+ "//F++\n" +
+ "\n" +
+ "char x;\n" +
+ "\n" +
+ "////F--\n" +
+ "int c = - 1 + 42;\n" +
+ "////F++\n" +
+ "\n" +
+ "char y;\n" +
+ "\n" +
+ "/* F-- */\n" +
+ "int d = - 1 + 42;\n" +
+ "/* F++ */\n" +
+ "\n" +
+ "char z;\n" +
+ "\n" +
+ "/* //F-- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //F++ */\n" +
+ "\n" +
+ "/** F--1 blabla */\n" +
+ "char t;\n" +
+ "}\n";
+ formatSource(source,
+ "package a;\n" +
+ "\n" +
+ "public class Bug {\n" +
+ " int a = -1 + 42;\n" +
+ "\n" +
+ "//F--\n" +
+ "int b = - 1 + 42;\n" +
+ "//F++\n" +
+ "\n" +
+ " char x;\n" +
+ "\n" +
+ "////F--\n" +
+ "int c = - 1 + 42;\n" +
+ "////F++\n" +
+ "\n" +
+ " char y;\n" +
+ "\n" +
+ " /* F-- */\n" +
+ " int d = -1 + 42;\n" +
+ " /* F++ */\n" +
+ "\n" +
+ " char z;\n" +
+ "\n" +
+ "/* //F-- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //F++ */\n" +
+ "\n" +
+ " /** F--1 blabla */\n" +
+ " char t;\n" +
+ "}\n"
+ );
+}
+public void testBug311578d() throws JavaModelException {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE);
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "/*F--*/");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "/*F++*/");
+ String source =
+ "package a;\n" +
+ "public class Bug {\n" +
+ "int a = - 1 + 42;\n" +
+ "\n" +
+ "//F--\n" +
+ "int b = - 1 + 42;\n" +
+ "//F++\n" +
+ "\n" +
+ "char x;\n" +
+ "\n" +
+ "////F--\n" +
+ "int c = - 1 + 42;\n" +
+ "////F++\n" +
+ "\n" +
+ "char y;\n" +
+ "\n" +
+ "/* F-- */\n" +
+ "int d = - 1 + 42;\n" +
+ "/* F++ */\n" +
+ "\n" +
+ "char y2;\n" +
+ "\n" +
+ "/*F--*/\n" +
+ "int d2 = - 1 + 42;\n" +
+ "/*F++*/\n" +
+ "\n" +
+ "char z;\n" +
+ "\n" +
+ "/* //F-- */\n" +
+ "int e = - 1 + 42;\n" +
+ "/* //F++ */\n" +
+ "\n" +
+ "/** F--1 blabla */\n" +
+ "char t;\n" +
+ "}\n";
+ formatSource(source,
+ "package a;\n" +
+ "\n" +
+ "public class Bug {\n" +
+ " int a = -1 + 42;\n" +
+ "\n" +
+ " // F--\n" +
+ " int b = -1 + 42;\n" +
+ " // F++\n" +
+ "\n" +
+ " char x;\n" +
+ "\n" +
+ " // //F--\n" +
+ " int c = -1 + 42;\n" +
+ " // //F++\n" +
+ "\n" +
+ " char y;\n" +
+ "\n" +
+ " /* F-- */\n" +
+ " int d = -1 + 42;\n" +
+ " /* F++ */\n" +
+ "\n" +
+ " char y2;\n" +
+ "\n" +
+ "/*F--*/\n" +
+ "int d2 = - 1 + 42;\n" +
+ "/*F++*/\n" +
+ "\n" +
+ " char z;\n" +
+ "\n" +
+ " /* //F-- */\n" +
+ " int e = -1 + 42;\n" +
+ " /* //F++ */\n" +
+ "\n" +
+ " /** F--1 blabla */\n" +
+ " char t;\n" +
+ "}\n"
+ );
+}
+public void testBug311578e() throws JavaModelException {
+ this.formatterPrefs.use_tags = true;
+ this.formatterPrefs.disabling_tag = "//J-".toCharArray();
+ this.formatterPrefs.enabling_tag = "//J+".toCharArray();
+ String source =
+ "package a;\n" +
+ "public class Bug {\n" +
+ "char z2;\n" +
+ "\n" +
+ "//J-1\n" +
+ "int f = - 1 + 42;\n" +
+ "//J+2\n" +
+ "\n" +
+ "char z3;\n" +
+ "\n" +
+ "//J- 1\n" +
+ "int g = - 1 + 42;\n" +
+ "//J+ 2\n" +
+ "\n" +
+ "char z4;\n" +
+ "\n" +
+ " //J-\n" +
+ "int h = - 1 + 42;\n" +
+ " //J+\n" +
+ "\n" +
+ "char z5;\n" +
+ "\n" +
+ "/*\n" +
+ "//J-\n" +
+ "*/\n" +
+ "int i = - 1 + 42;\n" +
+ "/*\n" +
+ " //J+\n" +
+ " */\n" +
+ "\n" +
+ "char z6;" +
+ "}\n";
+ formatSource(source,
+ "package a;\n" +
+ "\n" +
+ "public class Bug {\n" +
+ " char z2;\n" +
+ "\n" +
+ "//J-1\n" +
+ "int f = - 1 + 42;\n" +
+ "//J+2\n" +
+ "\n" +
+ " char z3;\n" +
+ "\n" +
+ "//J- 1\n" +
+ "int g = - 1 + 42;\n" +
+ "//J+ 2\n" +
+ "\n" +
+ " char z4;\n" +
+ "\n" +
+ " //J-\n" +
+ "int h = - 1 + 42;\n" +
+ " //J+\n" +
+ "\n" +
+ " char z5;\n" +
+ "\n" +
+ "/*\n" +
+ "//J-\n" +
+ "*/\n" +
+ "int i = - 1 + 42;\n" +
+ "/*\n" +
+ " //J+\n" +
+ " */\n" +
+ "\n" +
+ " char z6;\n" +
+ "}\n"
+ );
+}
+public void testBug311578_320754a() throws JavaModelException {
+ this.formatterPrefs.use_tags = true;
+ this.formatterPrefs.disabling_tag = "//J-".toCharArray();
+ this.formatterPrefs.enabling_tag = "//J+".toCharArray();
+ String source =
+ "//J-\n" +
+ "@MyAnnot (\n" +
+ " testAttribute = {\"test1\", \"test2\", \"test3\"}\n" +
+ ")\n" +
+ "//J+\n" +
+ "public class X\n" +
+ "{\n" +
+ " public void foo()\n" +
+ " {\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "//J-\n" +
+ "@MyAnnot (\n" +
+ " testAttribute = {\"test1\", \"test2\", \"test3\"}\n" +
+ ")\n" +
+ "//J+\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug311578_320754b() throws JavaModelException {
+ this.formatterPrefs.use_tags = true;
+ this.formatterPrefs.disabling_tag = "/*J-*/".toCharArray();
+ this.formatterPrefs.enabling_tag = "/*J+*/".toCharArray();
+ String source =
+ "/*J-*/\n" +
+ "@MyAnnot (\n" +
+ " testAttribute = {\"test1\", \"test2\", \"test3\"}\n" +
+ ")\n" +
+ "/*J+*/\n" +
+ "public class X\n" +
+ "{\n" +
+ " public void foo()\n" +
+ " {\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "/*J-*/\n" +
+ "@MyAnnot (\n" +
+ " testAttribute = {\"test1\", \"test2\", \"test3\"}\n" +
+ ")\n" +
+ "/*J+*/\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 311582: [formatter] Master switch to enable/disable on/off tags
* @test Ensure that the formatter does not take care of formatting tags by default
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311582"
@@ -6693,9 +7110,8 @@
}
/**
- * @bug 320754: [formatter] Add preference for improved lines wrapping in nested method calls
- * @test Ensure that the formatter keep previous eclipse versions behavior when
- * the "Try to keep nested expressions on one line" preference is set.
+ * @bug 320754: [formatter] formatter:off/on tags does not work correctly
+ * @test Ensure disabling/enabling tags work properly around annotations
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=320754"
*/
public void testBug320754_00() throws JavaModelException {