Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 119523 Details for
Bug 239130
[formatter] Comment formatter does not keep blank lines after @see references
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Last proposed patch
v04.txt (text/plain), 30.00 KB, created by
Frederic Fusier
on 2008-12-04 11:31:33 EST
(
hide
)
Description:
Last proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2008-12-04 11:31:33 EST
Size:
30.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v >retrieving revision 1.30 >diff -u -r1.30 FormatterCommentsBugsTest.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 4 Dec 2008 11:06:07 -0000 1.30 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 4 Dec 2008 16:27:01 -0000 >@@ -2152,8 +2152,6 @@ > "}\n" > ); > } >-// Output will need to be changed while fixing >-// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=239130 > public void testBug238210_X03() throws JavaModelException { > String source = > "package eclipse30;\n" + >@@ -2178,8 +2176,10 @@ > " /**\n" + > " * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#handleBreakpointEvent(com.sun.jdi.event.Event,\n" + > " * org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget,\n" + >- " * org.eclipse.jdt.internal.debug.core.model.JDIThread) (From\n" + >- " * referenced JavaDoc: Returns whethers the thread should be resumed\n" + >+ " * org.eclipse.jdt.internal.debug.core.model.JDIThread)\n" + >+ " * \n" + >+ " * (From referenced JavaDoc: Returns whethers the thread should be\n" + >+ " * resumed\n" + > " */\n" + > " void foo() {\n" + > " }\n" + >@@ -2292,6 +2292,337 @@ > } > > /** >+ * @bug 239130: [formatter] problem formatting block comments >+ * @test Ensure that the comment formatter preserve line breaks when specified >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=239130" >+ */ >+public void testBug239130_default() throws JavaModelException { >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_clearBlankLines() throws JavaModelException { >+ this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true; >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_preserveLineBreaks() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_clearBlankLines_preserveLineBreaks() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true; >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * \n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * @see java.lang.String\n" + >+ " * Formatter should keep empty line above\n" + >+ " */\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=196124 >+public void testBug239130_196124_default() throws JavaModelException { >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * The foo method.\n" + >+ " * foo is a substitute for bar.\n" + >+ " * \n" + >+ " * @param param1 The first parameter\n" + >+ " * @param param2\n" + >+ " * The second parameter.\n" + >+ " * If <b>null</b>the first parameter is used\n" + >+ " */\n" + >+ " public void foo(Object param1, Object param2) {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * The foo method. foo is a substitute for bar.\n" + >+ " * \n" + >+ " * @param param1\n" + >+ " * The first parameter\n" + >+ " * @param param2\n" + >+ " * The second parameter. If <b>null</b>the first parameter is\n" + >+ " * used\n" + >+ " */\n" + >+ " public void foo(Object param1, Object param2) {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_196124() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ String source = >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * The foo method.\n" + >+ " * foo is a substitute for bar.\n" + >+ " * \n" + >+ " * @param param1 The first parameter\n" + >+ " * @param param2\n" + >+ " * The second parameter.\n" + >+ " * If <b>null</b>the first parameter is used\n" + >+ " */\n" + >+ " public void foo(Object param1, Object param2) {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class X {\n" + >+ "\n" + >+ " /**\n" + >+ " * The foo method.\n" + >+ " * foo is a substitute for bar.\n" + >+ " * \n" + >+ " * @param param1\n" + >+ " * The first parameter\n" + >+ " * @param param2\n" + >+ " * The second parameter.\n" + >+ " * If <b>null</b>the first parameter is used\n" + >+ " */\n" + >+ " public void foo(Object param1, Object param2) {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=96696 >+public void testBug239130_96696_block_default() throws JavaModelException { >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, source); >+} >+public void testBug239130_96696_block_clearBlankLines() throws JavaModelException { >+ this.formatterPrefs.comment_clear_blank_lines_in_block_comment = true; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * Conceptually, all viewers perform two primary tasks: - They help adapt\n" + >+ " * your domain objects into viewable entities - They provide notifications\n" + >+ " * when the viewable entities are selected or changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_96696_block_clearBlankLines_preserveLineBreaks() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ this.formatterPrefs.comment_clear_blank_lines_in_block_comment = true; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_96696_javadoc_default() throws JavaModelException { >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /**\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, source); >+} >+public void testBug239130_96696_javadoc_clearBlankLines() throws JavaModelException { >+ this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /**\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /**\n" + >+ " * Conceptually, all viewers perform two primary tasks: - They help adapt\n" + >+ " * your domain objects into viewable entities - They provide notifications\n" + >+ " * when the viewable entities are selected or changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug239130_96696_javadoc_clearBlankLines_preserveLineBreaks() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /**\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * \n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * \n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /**\n" + >+ " * Conceptually, all viewers perform two primary tasks:\n" + >+ " * - They help adapt your domain objects into viewable entities\n" + >+ " * - They provide notifications when the viewable entities are selected or\n" + >+ " * changed through the UI\n" + >+ " */\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+ >+/** > * @bug 239719: [formatter] Code formatter destroys pre formatted javadoc comments > * @test Ensure that annotations inside <pre>...</pre> tags are not considered as javadoc tags > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=239719" >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.237 >diff -u -r1.237 FormatterRegressionTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 14 Oct 2008 16:26:39 -0000 1.237 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 4 Dec 2008 16:27:04 -0000 >@@ -10568,4 +10568,174 @@ > 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.preserve_existing_line_breaks = true; >+ 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.preserve_existing_line_breaks = true; >+ 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.preserve_existing_line_breaks = true; >+ 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" >+ ); >+} >+// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=201022 >+public void testBug201022() throws JavaModelException { >+ this.formatterPrefs.preserve_existing_line_breaks = true; >+ 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.preserve_existing_line_breaks = true; >+ 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.preserve_existing_line_breaks = true; >+ 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" >+ ); >+} > } >#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.94 >diff -u -r1.94 DefaultCodeFormatterConstants.java >--- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 11 Sep 2008 11:42:25 -0000 1.94 >+++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 4 Dec 2008 16:27:07 -0000 >@@ -3115,6 +3115,16 @@ > public static final String FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE = JavaCore.PLUGIN_ID + ".formatter.number_of_empty_lines_to_preserve"; //$NON-NLS-1$ > /** > * <pre> >+ * FORMATTER / Option to specify whether the formatter should preserve existing line breaks or not >+ * - option id: "org.eclipse.jdt.core.formatter.preserve_existing_line_breaks" >+ * - possible values: { TRUE, FALSE } >+ * - default: FALSE >+ * </pre> >+ * @since 3.5 >+ */ >+ public static final String FORMATTER_PRESERVE_EXISTING_LINE_BREAKS = JavaCore.PLUGIN_ID + ".formatter.preserve_existing_line_breaks"; //$NON-NLS-1$ >+ /** >+ * <pre> > * FORMATTER / Option to specify whether or not empty statement should be on a new line > * - option id: "org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" > * - possible values: { TRUE, FALSE } >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.154 >diff -u -r1.154 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 4 Dec 2008 11:06:05 -0000 1.154 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 4 Dec 2008 16:27:09 -0000 >@@ -929,15 +929,28 @@ > return indent; > } > >+ /* >+ * Preserve empty lines depending on given count and preferences. >+ */ > private String getPreserveEmptyLines(int count) { >- if (count > 0) { >- if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { >- int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); >- return getEmptyLines(linesToPreserve); >+ if (count == 0) { >+ // preserve line breaks in wrapping if specified >+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074 >+ if (this.currentAlignment != null && this.formatter.preferences.preserve_existing_line_breaks) { >+ int savedIndentation = this.indentationLevel; >+ StringBuffer buffer = new StringBuffer(getNewLine()); >+ this.indentationLevel = this.currentAlignment.breakIndentationLevel; >+ printIndentationIfNecessary(buffer); >+ this.indentationLevel = savedIndentation; >+ return buffer.toString(); > } >- return getNewLine(); >+ return Util.EMPTY_STRING; > } >- return Util.EMPTY_STRING; >+ if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { >+ int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); >+ return getEmptyLines(linesToPreserve); >+ } >+ return getNewLine(); > } > > private IRegion getAdaptedRegionAt(int offset) { >@@ -1414,6 +1427,7 @@ > int hasTextOnFirstLine = 0; > boolean firstWord = true; > boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment; >+ boolean preserveBreakLines = this.formatter.preferences.preserve_existing_line_breaks; > int scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, 0, this.maxLines); > int firstLine = scannerLine; > int lineNumber = scannerLine; >@@ -1520,7 +1534,7 @@ > // insert one blank line before root tags > linesGap = 2; > } >- max = 1; >+ max = preserveBreakLines ? 0 : 1; > } > if (linesGap > max) { > if (clearBlankLines) { >@@ -1528,7 +1542,7 @@ > if (token == TerminalTokens.TokenNameAT) { > linesGap = 1; > } else { >- linesGap = max==0 ? 1 : 0; >+ linesGap = max==0 || preserveBreakLines ? 1 : 0; > } > } > for (int i=0; i<linesGap; i++) { >@@ -1922,8 +1936,8 @@ > } else if (hasLineComment) { > preserveEmptyLines(count, this.scanner.getCurrentTokenStartPosition()); > addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition()); >- } else if (count != 0 && this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { >- addReplaceEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition(), getPreserveEmptyLines(count - 1)); >+ } else if (count != 0 && (this.formatter.preferences.preserve_existing_line_breaks || this.formatter.preferences.number_of_empty_lines_to_preserve != 0)) { >+ addReplaceEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition(), getPreserveEmptyLines(count-1)); > } else { > addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition()); > } >@@ -2381,7 +2395,6 @@ > } > > // format tag section if necessary >- boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; > if (!block.isInlined()) { > this.lastNumberOfNewLines = 0; > } >@@ -2429,7 +2442,9 @@ > } > > // tag section: iterate through the blocks composing this tag but the last one >- int previousLine = 0; >+ int previousLine = Util.getLineNumber(previousEnd, this.lineEnds, 0, this.maxLines); >+ boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; >+ boolean preserveBreakLines = this.formatter.preferences.preserve_existing_line_breaks; > for (int i=0; i<=maxNodes; i++) { > FormatJavadocNode node = block.nodes[i]; > int nodeStart = node.sourceStart; >@@ -2439,6 +2454,18 @@ > if (i == 0) { > newLines = this.formatter.preferences.comment_insert_new_line_for_parameter && block.isParamTag() ? 1 : 0; > if (nodeStart > (previousEnd+1)) { >+ if (!clearBlankLines || preserveBreakLines) { >+ int startLine = Util.getLineNumber(nodeStart, this.lineEnds, previousLine-1, this.maxLines); >+ int gapLine = previousLine; >+ if (!preserveBreakLines) gapLine++; // if not preserving line break then gap must be at least of one line >+ if (startLine > gapLine) { >+ newLines = startLine - previousLine; >+ } >+ if (clearBlankLines) { >+ // clearing blank lines in this block means that break lines should be preserved, hence only keep one new line >+ if (newLines > 0) newLines = 1; >+ } >+ } > if (newLines == 0) { > newLines = printJavadocBlockNodesNewLines(block, node, previousEnd); > } >@@ -3297,6 +3324,7 @@ > private void printJavadocText(FormatJavadocText text, FormatJavadocBlock block, boolean textOnNewLine) { > > boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; >+ boolean preserveBreakLines = this.formatter.preferences.preserve_existing_line_breaks; > StringBuffer buffer = new StringBuffer(); > int textStart = text.sourceStart; > int nextStart = textStart; >@@ -3319,14 +3347,18 @@ > > // Replace with current buffer if there are several empty lines between text lines > nextStart = (int) text.separators[idx]; >- if (!clearBlankLines) { >+ if (!clearBlankLines || preserveBreakLines) { > int endLine = Util.getLineNumber(end, this.lineEnds, startLine-1, this.maxLines); > startLine = Util.getLineNumber(nextStart, this.lineEnds, endLine-1, this.maxLines); >- if (startLine > (endLine+1)) { >+ int gapLine = endLine; >+ if (!preserveBreakLines) gapLine++; // if not preserving line break then gap must be at least of one line >+ if (startLine > gapLine) { > addReplaceEdit(textStart, end, buffer.toString()); > textStart = nextStart; > buffer.setLength(0); >- printJavadocGapLines(end+1, nextStart-1, startLine - endLine, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); >+ int newLines = startLine - endLine; >+ if (clearBlankLines) newLines = 1; >+ printJavadocGapLines(end+1, nextStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); > textOnNewLine = true; > } > } >Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v >retrieving revision 1.92 >diff -u -r1.92 DefaultCodeFormatterOptions.java >--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 27 Jun 2008 16:04:07 -0000 1.92 >+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 4 Dec 2008 16:27:08 -0000 >@@ -302,6 +302,7 @@ > public boolean never_indent_block_comments_on_first_column; > public boolean never_indent_line_comments_on_first_column; > public int number_of_empty_lines_to_preserve; >+ public boolean preserve_existing_line_breaks; > public boolean put_empty_statement_on_new_line; > public int tab_size; > public final char filling_space = ' '; >@@ -579,6 +580,7 @@ > options.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, this.never_indent_block_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); > options.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, this.never_indent_line_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); > options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, Integer.toString(this.number_of_empty_lines_to_preserve)); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_PRESERVE_EXISTING_LINE_BREAKS, this.preserve_existing_line_breaks ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); > options.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, this.put_empty_statement_on_new_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); > options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(this.page_width)); > switch(this.tab_char) { >@@ -1846,6 +1848,10 @@ > this.number_of_empty_lines_to_preserve = 0; > } > } >+ final Object preserveExistingLineBreaksOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PRESERVE_EXISTING_LINE_BREAKS); >+ if (preserveExistingLineBreaksOption != null) { >+ this.preserve_existing_line_breaks = DefaultCodeFormatterConstants.TRUE.equals(preserveExistingLineBreaksOption); >+ } > final Object putEmptyStatementOnNewLineOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE); > if (putEmptyStatementOnNewLineOption != null) { > this.put_empty_statement_on_new_line = DefaultCodeFormatterConstants.TRUE.equals(putEmptyStatementOnNewLineOption); >@@ -2185,6 +2191,7 @@ > this.never_indent_block_comments_on_first_column = false; > this.never_indent_line_comments_on_first_column = false; > this.number_of_empty_lines_to_preserve = 1; >+ this.preserve_existing_line_breaks = false; > this.put_empty_statement_on_new_line = false; > this.tab_size = 4; > this.page_width = 80; >@@ -2449,6 +2456,7 @@ > this.never_indent_block_comments_on_first_column = false; > this.never_indent_line_comments_on_first_column = false; > this.number_of_empty_lines_to_preserve = 1; >+ this.preserve_existing_line_breaks = false; > this.put_empty_statement_on_new_line = true; > this.tab_size = 8; > this.page_width = 80;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 239130
:
119368
|
119490
| 119523