### 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 13 Aug 2009 09:53:40 -0000
@@ -10849,4 +10849,99 @@
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
+//Test to make sure that measureIndentInSpaces and extractIndentString do not throw illegalArgumentException with indentWidth set to zero.
+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
+//Test to make sure that a divide by zero exception isn't thrown when formatting with indent width and tab width set to zero
+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
+//To make sure that changeIndent no longer throws an illegal argument exception with indentWidth set to 0.
+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);
+ }
+}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285565
+//To make sure that trimIndent no longer throws an illegal argument exception with indentWidth set to 0.
+public void testBug285565d() {
+ 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.trimIndent("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));
+
+ } catch (IllegalArgumentException e) {
+ assertTrue("Should not happen", false);
+ }
+}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285565
+//To make sure that getChangeIndentEdits no longer throws an illegal argument exception with indentWidth set to 0.
+public void testBug285565e() {
+ try {
+ IndentManipulation.getChangeIndentEdits("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, " ");
+
+ } 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 13 Aug 2009 09:53:43 -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,26 +130,25 @@
* @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 nullindentsToRemove <= 0
the line is returned.
+ * has less indent than the given indentUnitsToRemove, all the available indentation is removed.
+ * If indentsToRemove <= 0 or indent == 0
the line is returned.
*
* @param line the line to trim
* @param tabWidth the width of one tab in space equivalents
@@ -185,19 +187,19 @@
* @return the trimmed string
* @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 zeroindentWidth
is lower or equals to zeroindentWidth
is lower than zerotabWidth
is lower than zerosource
is nullindentUnitsToRemove
is lower than zeroUse {@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 13 Aug 2009 09:53:45 -0000 @@ -929,6 +929,9 @@ 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 +2163,12 @@ 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); @@ -2339,13 +2347,19 @@ boolean useTabsForLeadingIndents = this.useTabsOnlyForLeadingIndents; int numberOfLeadingIndents = this.numberOfIndentations; int indentationsAsTab = 0; + int complement = 0; if (useTabsForLeadingIndents) { while (this.column <= this.indentationLevel) { if (indentationsAsTab < numberOfLeadingIndents) { if (buffer != null) buffer.append('\t'); indentationsAsTab++; - int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space - this.column += complement; + if(this.tabLength != 0) { + complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space + this.column += complement; + } + else { + this.column++; + } this.needSpace = false; } else { if (buffer != null) buffer.append(' '); @@ -2356,8 +2370,13 @@ } else { while (this.column <= this.indentationLevel) { if (buffer != null) buffer.append('\t'); - int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space - this.column += complement; + if(this.tabLength != 0) { + complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space + this.column += complement; + } + else { + this.column++; + } this.needSpace = false; } }