Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Fusier2009-10-08 11:42:12 +0000
committerFrederic Fusier2009-10-08 11:42:12 +0000
commitc452d85f5b9faf48fa8a85b49fecaa0f67f45c39 (patch)
tree2133765fb384ad2e248db858dda653cc02d2c8de
parent4ae89c67461250efe44d14d74a7763f5a5b547b2 (diff)
downloadeclipse.jdt.core-c452d85f5b9faf48fa8a85b49fecaa0f67f45c39.tar.gz
eclipse.jdt.core-c452d85f5b9faf48fa8a85b49fecaa0f67f45c39.tar.xz
eclipse.jdt.core-c452d85f5b9faf48fa8a85b49fecaa0f67f45c39.zip
R3_5_maintenance - 290905
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java416
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java271
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.classpath6
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.project17
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java18
6 files changed, 474 insertions, 257 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java
index 0878ebe418..da7255691d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -51,6 +51,7 @@ public class RunFormatterTests extends junit.framework.TestCase {
String type = System.getProperty("type");
if (type == null || !type.equals("javadoc")) {
allClasses.add(FormatterRegressionTests.class);
+ allClasses.add(FormatterBugsTests.class);
}
allClasses.add(CommentsTestSuite.class);
allClasses.addAll(TEST_SUITES);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
new file mode 100644
index 0000000000..0a6156bfda
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -0,0 +1,416 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.formatter;
+
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
+
+import junit.framework.Test;
+
+public class FormatterBugsTests extends FormatterRegressionTests {
+
+public static Test suite() {
+ return buildModelTestSuite(FormatterBugsTests.class);
+}
+
+public FormatterBugsTests(String name) {
+ super(name);
+}
+
+/**
+ * Create project and set the jar placeholder.
+ */
+public void setUpSuite() throws Exception {
+ if (JAVA_PROJECT == null) {
+ JAVA_PROJECT = setUpJavaProject("FormatterBugs", "1.5"); //$NON-NLS-1$
+ }
+ super.setUpSuite();
+}
+/**
+ * @bug 198074: [formatter] the code formatter doesn't respect my new lines
+ * @test Ensure that the formatter keep line breaks wrapping set by users in the code
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
+ */
+public void testBug198074() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ "String x = \"select x \"\n" +
+ " + \"from y \"\n" +
+ " + \"where z=a\";\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " String x = \"select x \"\n" +
+ " + \"from y \"\n" +
+ " + \"where z=a\";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+// another test case put in bug's comment 1
+public void testBug198074_c1() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " String foo(boolean enabled) {\n" +
+ "if (enabled)\n" +
+ "{\n" +
+ " // we need x\n" +
+ " // we need a select\n" +
+ " return \"select x \"\n" +
+ " + \"from X\";}\n" +
+ " return null;}\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " String foo(boolean enabled) {\n" +
+ " if (enabled) {\n" +
+ " // we need x\n" +
+ " // we need a select\n" +
+ " return \"select x \"\n" +
+ " + \"from X\";\n" +
+ " }\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+// another test case put in bug's comment 3
+public void testBug198074_c3() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ "public String toString() {\n" +
+ " return \"YAD01: \"\n" +
+ " + \" nommbr=\'\"+getName()+\"\'\"\n" +
+ " + \" nomgrp=\'\"+getService().getArgtbl()+\"\'\"\n" +
+ " + \" typmbr=\'\"+getMemberType().getArgument()+\"\'\"\n" +
+ " + \" srcpat=\'\"+getPhysicalPath()+\"\'\"\n" +
+ " + \" nommdl=\'\"+getModel()+\"\'\"\n" +
+ " ;\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " public String toString() {\n" +
+ " return \"YAD01: \"\n" +
+ " + \" nommbr=\'\" + getName() + \"\'\"\n" +
+ " + \" nomgrp=\'\" + getService().getArgtbl() + \"\'\"\n" +
+ " + \" typmbr=\'\" + getMemberType().getArgument() + \"\'\"\n" +
+ " + \" srcpat=\'\" + getPhysicalPath() + \"\'\"\n" +
+ " + \" nommdl=\'\" + getModel() + \"\'\";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug198074_comments() throws JavaModelException {
+ this.formatterPrefs.join_lines_in_comments = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ "String x = \"select x \"\n" +
+ " + \"from y \"\n" +
+ " + \"where z=a\";\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " String x = \"select x \" + \"from y \" + \"where z=a\";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=201022
+public void testBug201022() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " String sQuery =\n" +
+ " \"select * \" +\n" +
+ " \"from person p, address a \" +\n" +
+ " \"where p.person_id = a.person_id \" +\n" +
+ " \"and p.person_id = ?\";\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " String sQuery =\n" +
+ " \"select * \" +\n" +
+ " \"from person p, address a \" +\n" +
+ " \"where p.person_id = a.person_id \" +\n" +
+ " \"and p.person_id = ?\";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
+public void testBug208541() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class MyTest {\n" +
+ "\n" +
+ " public void testname() throws Exception {\n" +
+ " int i = 5, j = 6, k = 7;\n" +
+ " if (new String().length() != 0 &&\n" +
+ " (i < j && j < k)) {\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class MyTest {\n" +
+ "\n" +
+ " public void testname() throws Exception {\n" +
+ " int i = 5, j = 6, k = 7;\n" +
+ " if (new String().length() != 0 &&\n" +
+ " (i < j && j < k)) {\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700
+public void testBug213700() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;\n" +
+ "if( (a == b && b == c) &&\n" +
+ " (d == e) &&\n" +
+ " (f == g && h == i) \n" +
+ " ){\n" +
+ "}\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0;\n" +
+ " if ((a == b && b == c) &&\n" +
+ " (d == e) &&\n" +
+ " (f == g && h == i)) {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467
+public void testBug283467() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "public class TestFormatter {\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " int variable = TestFormatter.doInCallback(new Runnable() {\n" +
+ " public void run() {\n" +
+ " // Some comments or code here\n" +
+ " }\n" +
+ " });\n" +
+ " System.out.println(variable);\n" +
+ " }\n" +
+ "\n" +
+ " public static int doInCallback(Runnable r) {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class TestFormatter {\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " int variable = TestFormatter.doInCallback(new Runnable() {\n" +
+ " public void run() {\n" +
+ " // Some comments or code here\n" +
+ " }\n" +
+ " });\n" +
+ " System.out.println(variable);\n" +
+ " }\n" +
+ "\n" +
+ " public static int doInCallback(Runnable r) {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
+/**
+ * @bug 290905: [formatter] Certain formatter pref constellation cause endless loop ==> OOME
+ * @test Verify that there's endless loop when setting tab length to zero.
+ * As the fix finalize bug 285565 implementation, added tests address only
+ * missed test cases.
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=290905"
+ */
+public void testBug290905a() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 2;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
+ String source =
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 2, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "void foo() throws Exception { if (true) return; else throw new Exception(); }\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 2, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ " void foo() throws Exception {\n" +
+ " if (true)\n" +
+ " return;\n" +
+ " else\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug290905b() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 2;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
+ String source =
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 2, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "void foo() throws Exception { if (true) return; else throw new Exception(); }\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 2, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ " void foo() throws Exception {\n" +
+ " if (true)\n" +
+ " return;\n" +
+ " else\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug290905c() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 0;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
+ String source =
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 0, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the format line comment preference is activated\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 0, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the\n" +
+ " // format line comment preference is activated\n" +
+ "}\n",
+ false /* do not repeat */
+ );
+}
+public void testBug290905d() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 0;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
+ String source =
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 0, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the format line comment preference is activated\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test mixed, tab size = 0, indent size = 0, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the\n" +
+ " // format line comment preference is activated\n" +
+ "}\n",
+ false /* do not repeat */
+ );
+}
+public void testBug290905e() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 0;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
+ String source =
+ "/**\n" +
+ " * Test tab char = TAB, tab size = 0, indent size = 0, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the format line comment preference is activated\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test tab char = TAB, tab size = 0, indent size = 0, use tabs to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the\n" +
+ " // format line comment preference is activated\n" +
+ "}\n",
+ false /* do not repeat */
+ );
+}
+public void testBug290905f() throws JavaModelException {
+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB;
+ this.formatterPrefs.tab_size = 0;
+ this.formatterPrefs.indentation_size = 0;
+ this.formatterPrefs.use_tabs_only_for_leading_indentations = false;
+ String source =
+ "/**\n" +
+ " * Test tab char = TAB, tab size = 0, indent size = 0, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the format line comment preference is activated\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Test tab char = TAB, tab size = 0, indent size = 0, use spaces to indent\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "int i; // this is a long comment which should be split into two lines as the\n" +
+ "// format line comment preference is activated\n" +
+ "}\n",
+ false /* do not repeat */
+ );
+}
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index aa5fd6fcd4..adb7ab897c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -10580,254 +10580,27 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
runTest(codeFormatter, "test719", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
}
-
-/**
- * @bug 198074: [formatter] the code formatter doesn't respect my new lines
- * @test Ensure that the formatter keep line breaks wrapping set by users in the code
- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
- */
-public void testBug198074() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- "String x = \"select x \"\n" +
- " + \"from y \"\n" +
- " + \"where z=a\";\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " String x = \"select x \"\n" +
- " + \"from y \"\n" +
- " + \"where z=a\";\n" +
- " }\n" +
- "}\n"
- );
-}
-// another test case put in bug's comment 1
-public void testBug198074_c1() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class Test {\n" +
- "\n" +
- " String foo(boolean enabled) {\n" +
- "if (enabled)\n" +
- "{\n" +
- " // we need x\n" +
- " // we need a select\n" +
- " return \"select x \"\n" +
- " + \"from X\";}\n" +
- " return null;}\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " String foo(boolean enabled) {\n" +
- " if (enabled) {\n" +
- " // we need x\n" +
- " // we need a select\n" +
- " return \"select x \"\n" +
- " + \"from X\";\n" +
- " }\n" +
- " return null;\n" +
- " }\n" +
- "}\n"
- );
-}
-// another test case put in bug's comment 3
-public void testBug198074_c3() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class Test {\n" +
- "\n" +
- "public String toString() {\n" +
- " return \"YAD01: \"\n" +
- " + \" nommbr=\'\"+getName()+\"\'\"\n" +
- " + \" nomgrp=\'\"+getService().getArgtbl()+\"\'\"\n" +
- " + \" typmbr=\'\"+getMemberType().getArgument()+\"\'\"\n" +
- " + \" srcpat=\'\"+getPhysicalPath()+\"\'\"\n" +
- " + \" nommdl=\'\"+getModel()+\"\'\"\n" +
- " ;\n" +
- "}\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " public String toString() {\n" +
- " return \"YAD01: \"\n" +
- " + \" nommbr=\'\" + getName() + \"\'\"\n" +
- " + \" nomgrp=\'\" + getService().getArgtbl() + \"\'\"\n" +
- " + \" typmbr=\'\" + getMemberType().getArgument() + \"\'\"\n" +
- " + \" srcpat=\'\" + getPhysicalPath() + \"\'\"\n" +
- " + \" nommdl=\'\" + getModel() + \"\'\";\n" +
- " }\n" +
- "}\n"
- );
-}
-public void testBug198074_comments() throws JavaModelException {
- this.formatterPrefs.join_lines_in_comments = false;
- String source =
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- "String x = \"select x \"\n" +
- " + \"from y \"\n" +
- " + \"where z=a\";\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " String x = \"select x \" + \"from y \" + \"where z=a\";\n" +
- " }\n" +
- "}\n"
- );
-}
-// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=201022
-public void testBug201022() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " String sQuery =\n" +
- " \"select * \" +\n" +
- " \"from person p, address a \" +\n" +
- " \"where p.person_id = a.person_id \" +\n" +
- " \"and p.person_id = ?\";\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " String sQuery =\n" +
- " \"select * \" +\n" +
- " \"from person p, address a \" +\n" +
- " \"where p.person_id = a.person_id \" +\n" +
- " \"and p.person_id = ?\";\n" +
- " }\n" +
- "}\n"
- );
-}
-// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
-public void testBug208541() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class MyTest {\n" +
- "\n" +
- " public void testname() throws Exception {\n" +
- " int i = 5, j = 6, k = 7;\n" +
- " if (new String().length() != 0 &&\n" +
- " (i < j && j < k)) {\n" +
- "\n" +
- " }\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class MyTest {\n" +
- "\n" +
- " public void testname() throws Exception {\n" +
- " int i = 5, j = 6, k = 7;\n" +
- " if (new String().length() != 0 &&\n" +
- " (i < j && j < k)) {\n" +
- "\n" +
- " }\n" +
- " }\n" +
- "}\n"
- );
-}
-// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700
-public void testBug213700() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;\n" +
- "if( (a == b && b == c) &&\n" +
- " (d == e) &&\n" +
- " (f == g && h == i) \n" +
- " ){\n" +
- "}\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class Test {\n" +
- "\n" +
- " void foo() {\n" +
- " int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0;\n" +
- " if ((a == b && b == c) &&\n" +
- " (d == e) &&\n" +
- " (f == g && h == i)) {\n" +
- " }\n" +
- " }\n" +
- "}\n"
- );
-}
-// https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
-public void test720() {
- final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
- DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
- Map compilerOptions = new HashMap();
- compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
- compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
- compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
- DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
- runTest(codeFormatter, "test720", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
-}
-//https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
-public void test721() {
- final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
- DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
- Map compilerOptions = new HashMap();
- compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
- compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
- compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
- DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
- runTest(codeFormatter, "test721", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
-}
-//https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467
-public void testBug283467() throws JavaModelException {
- this.formatterPrefs.join_wrapped_lines = false;
- String source =
- "public class TestFormatter {\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " int variable = TestFormatter.doInCallback(new Runnable() {\n" +
- " public void run() {\n" +
- " // Some comments or code here\n" +
- " }\n" +
- " });\n" +
- " System.out.println(variable);\n" +
- " }\n" +
- "\n" +
- " public static int doInCallback(Runnable r) {\n" +
- " return 0;\n" +
- " }\n" +
- "}\n";
- formatSource(source,
- "public class TestFormatter {\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " int variable = TestFormatter.doInCallback(new Runnable() {\n" +
- " public void run() {\n" +
- " // Some comments or code here\n" +
- " }\n" +
- " });\n" +
- " System.out.println(variable);\n" +
- " }\n" +
- "\n" +
- " public static int doInCallback(Runnable r) {\n" +
- " return 0;\n" +
- " }\n" +
- "}\n"
- );
-}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
+ public void test720() {
+ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
+ DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
+ Map compilerOptions = new HashMap();
+ compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+ DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
+ runTest(codeFormatter, "test720", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=270983
+ public void test721() {
+ final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
+ DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
+ Map compilerOptions = new HashMap();
+ compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+ DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
+ runTest(codeFormatter, "test721", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.classpath b/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.classpath
new file mode 100644
index 0000000000..834972ef2a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.classpath
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="var" path="JCL15_LIB" sourcepath="JCL15_SRC" rootpath="JCL_SRCROOT"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.project b/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.project
new file mode 100644
index 0000000000..1d370db5bf
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterBugs/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>FormatterBugs</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java
index 13b1ed1b05..5a29b847e1 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java
@@ -926,7 +926,7 @@ public class Scribe implements IJavaDocTagConstants {
if (indent == 0)
return this.indentationLevel;
if (this.tabChar == DefaultCodeFormatterOptions.TAB) {
- if (this.useTabsOnlyForLeadingIndents) {
+ if (this.indentationSize == 0 || this.useTabsOnlyForLeadingIndents) {
return indent;
}
int rem = indent % this.indentationSize;
@@ -2359,7 +2359,7 @@ public class Scribe implements IJavaDocTagConstants {
int indentationsAsTab = 0;
if (useTabsForLeadingIndents) {
while (this.column <= this.indentationLevel) {
- if (indentationsAsTab < numberOfLeadingIndents) {
+ if (this.tabLength > 0 && indentationsAsTab < numberOfLeadingIndents) {
if (buffer != null) buffer.append('\t');
indentationsAsTab++;
int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space
@@ -2371,7 +2371,7 @@ public class Scribe implements IJavaDocTagConstants {
this.needSpace = false;
}
}
- } else {
+ } else if (this.tabLength > 0) {
while (this.column <= this.indentationLevel) {
if (buffer != null) buffer.append('\t');
int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space
@@ -2395,11 +2395,13 @@ public class Scribe implements IJavaDocTagConstants {
final int columnForLeadingIndents = numberOfLeadingIndents * this.indentationSize;
while (this.column <= this.indentationLevel) {
if (this.column <= columnForLeadingIndents) {
- if ((this.column - 1 + this.tabLength) <= this.indentationLevel) {
+ if (this.tabLength > 0 && (this.column - 1 + this.tabLength) <= this.indentationLevel) {
if (buffer != null) buffer.append('\t');
this.column += this.tabLength;
} else if ((this.column - 1 + this.indentationSize) <= this.indentationLevel) {
// print one indentation
+ // note that this.indentationSize > 0 when entering in the following loop
+ // hence this.column will be incremented and then avoid endless loop (see bug 290905)
for (int i = 0, max = this.indentationSize; i < max; i++) {
if (buffer != null) buffer.append(' ');
this.column++;
@@ -2418,10 +2420,10 @@ public class Scribe implements IJavaDocTagConstants {
}
} else {
while (this.column <= this.indentationLevel) {
- if ((this.column - 1 + this.tabLength) <= this.indentationLevel) {
+ if (this.tabLength > 0 && (this.column - 1 + this.tabLength) <= this.indentationLevel) {
if (buffer != null) buffer.append('\t');
this.column += this.tabLength;
- } else if ((this.column - 1 + this.indentationSize) <= this.indentationLevel) {
+ } else if (this.indentationSize > 0 && (this.column - 1 + this.indentationSize) <= this.indentationLevel) {
// print one indentation
for (int i = 0, max = this.indentationSize; i < max; i++) {
if (buffer != null) buffer.append(' ');
@@ -4141,7 +4143,9 @@ public class Scribe implements IJavaDocTagConstants {
.append(this.lineSeparator)
.append("==================================================================================") //$NON-NLS-1$
.append(this.lineSeparator);
- printRule(stringBuffer);
+ if (this.tabLength >= 0) {
+ printRule(stringBuffer);
+ }
return stringBuffer.toString();
}

Back to the top