### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v
retrieving revision 1.247
diff -u -r1.247 FormatterRegressionTests.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 27 Jul 2009 18:20:49 -0000 1.247
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 11 Aug 2009 08:31:36 -0000
@@ -10849,4 +10849,60 @@
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285565
+public void testBug285565a() {
+ try {
+ assertEquals("Should be 0", 0, IndentManipulation.measureIndentInSpaces("", 0));
+ assertEquals("Should be 0", 0, IndentManipulation.measureIndentInSpaces("\t", 0));
+ assertEquals("Should be 1", 1, IndentManipulation.measureIndentInSpaces("\t ", 0));
+ assertEquals("Should be blank", "\t", IndentManipulation.extractIndentString("\tabc", 0, 0));
+ } catch (IllegalArgumentException e) {
+ assertTrue("Should not happen", false);
+ }
+}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285565
+public void testBug285565b() {
+ this.formatterPrefs.indentation_size = 0;
+ this.formatterPrefs.tab_size = 0;
+ String source = "public class test {\n"
+ + " public static void main(String[] args) {\n"
+ + " int B= 12;\n"
+ + " int C= B - 1;\n"
+ + " int K= 99;\n"
+ + " int f1= K - 1 - C;\n"
+ + " int f2= K - C - C - C;\n"
+ + " }\n" + "}\n";
+ formatSource(source, "public class test {\n"
+ + "public static void main(String[] args) {\n"
+ + "int B = 12;\n"
+ + "int C = B - 1;\n"
+ + "int K = 99;\n"
+ + "int f1 = K - 1 - C;\n"
+ + "int f2 = K - C - C - C;\n"
+ + "}\n"
+ + "}\n");
+}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285565
+public void testBug285565c() {
+ String result = "int B = 12;\n"
+ + " int C = B - 1;\n"
+ + " int K = 99;\n"
+ + " int f1 = K - 1 - C;\n"
+ + " int f2 = K - C - C - C;" ;
+
+ try {
+ assertEquals("Should be as shown", result, IndentManipulation.changeIndent("int B = 12;\n"
+ + "int C = B - 1;\n"
+ + "int K = 99;\n"
+ + "int f1 = K - 1 - C;\n"
+ + "int f2 = K - C - C - C;" ,0,0,0, " ","\n"));
+
+ } catch (IllegalArgumentException e) {
+ assertTrue("Should not happen", false);
+ }
+}
+
}
#P org.eclipse.jdt.core
Index: formatter/org/eclipse/jdt/core/formatter/IndentManipulation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/IndentManipulation.java,v
retrieving revision 1.9
diff -u -r1.9 IndentManipulation.java
--- formatter/org/eclipse/jdt/core/formatter/IndentManipulation.java 14 Jul 2009 19:54:26 -0000 1.9
+++ formatter/org/eclipse/jdt/core/formatter/IndentManipulation.java 11 Aug 2009 08:31:41 -0000
@@ -109,8 +109,7 @@
for (int i= 0; i < max; i++) {
char ch= line.charAt(i);
if (ch == '\t') {
- int reminder= length % tabWidth;
- length += tabWidth - reminder;
+ length = calculateSpaceEquivalents(tabWidth, length);
} else if (isIndentChar(ch)) {
length++;
} else {
@@ -131,13 +130,13 @@
* @return the indent part of line
, but no odd spaces
* @exception IllegalArgumentException if:
*
indentWidth
is lower or equals to zeroindentWidth
is lower than zerotabWidth
is lower than zeroline
is nullindentWidth
is lower or equals to zeroindentWidth
is lower than zerotabWidth
is lower than zerocode
is nullindentUnitsToRemove
is lower than zeroindentUnitsToRemove
is greater than zero when indentWidth equals zeronewIndentString
is nulllineDelim
is nullindentWidth
is lower or equals to zeroindentWidth
is lower than zerotabWidth
is lower than zerosource
is nullindentUnitsToRemove
is lower than zeroindentUnitsToRemove
is greater than zero when indentWidth equals zeronewIndentString
is nullUse {@link org.eclipse.jdt.core.IJavaProject#getOptions(boolean)} to get the most current project options.
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.169 diff -u -r1.169 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 20 Jul 2009 15:10:59 -0000 1.169 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 11 Aug 2009 08:31:45 -0000 @@ -929,6 +929,8 @@ if (this.useTabsOnlyForLeadingIndents) { return indent; } + if (this.indentationSize == 0) + return indent; int rem = indent % this.indentationSize; int addition = rem == 0 ? 0 : this.indentationSize - rem; // round to superior return indent + addition; @@ -2160,7 +2162,10 @@ int indentLevel = this.indentationLevel; int indentations = this.numberOfIndentations; this.indentationLevel = getNextIndentationLevel(firstColumn); - this.numberOfIndentations = this.indentationLevel / this.indentationSize; + if (this.indentationSize != 0) + this.numberOfIndentations = this.indentationLevel / this.indentationSize; + else + this.numberOfIndentations = 0; // Consume the comment prefix this.scanner.resetTo(commentStart, commentEnd);