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 101863 Details for
Bug 232768
[formatter] does not format block and single line comment if too much selected
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v03.txt (text/plain), 40.22 KB, created by
Frederic Fusier
on 2008-05-24 16:52:43 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2008-05-24 16:52:43 EDT
Size:
40.22 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.213 >diff -u -r1.213 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 12 May 2008 10:10:52 -0000 1.213 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 24 May 2008 18:49:27 -0000 >@@ -600,6 +600,7 @@ > } > actual = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(actual); > if (!actual.equals(expected)) { >+ System.out.println("Expected formatted output in "+getName()+":"); > System.out.print(org.eclipse.jdt.core.tests.util.Util.displayString(actual.toString(), 2)); > System.out.println(this.endChar); > } >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsMassiveTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsMassiveTests.java,v >retrieving revision 1.19 >diff -u -r1.19 FormatterCommentsMassiveTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsMassiveTests.java 21 May 2008 10:59:13 -0000 1.19 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsMassiveTests.java 24 May 2008 18:49:19 -0000 >@@ -515,7 +515,7 @@ > if (!expected.equals(actual)) { > String actualResult = runFormatter(codeFormatter, source, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, 0, source.length(), null); > String expectedResult = expectedFormattedSource(source); >- assertEquals("Unexpected difference with formatted comment "+(i+1), expectedResult, actualResult); >+ assertEquals("Unexpected difference with formatted comment "+(i+1), Util.convertToIndependantLineDelimiter(expectedResult), Util.convertToIndependantLineDelimiter(actualResult)); > } > } > } >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.9 >diff -u -r1.9 FormatterCommentsBugsTest.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 22 May 2008 20:07:55 -0000 1.9 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 24 May 2008 18:49:19 -0000 >@@ -204,6 +204,629 @@ > } > > /** >+ * @bug 232768: [formatter] does not format block and single line comment if too much selected >+ * @test Ensure that the new comment formatter formats comments touched by the selection >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232768" >+ */ >+public void testBug232768a() throws JavaModelException { >+ String source = "public class A {\r\n" + >+ "[#\r\n" + >+ " /*\r\n" + >+ " * A block comment \r\n" + >+ " * on two lines\r\n" + >+ " */\r\n" + >+ "\r\n#]" + >+ "}\r\n" + >+ ""; >+ // TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6) >+ formatSource(source, >+ "public class A {\n" + >+ "\n" + >+ " /*\n" + >+ " * A block comment on two lines\n" + >+ " */\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug232768b() throws JavaModelException { >+ String source = "public class B {\r\n" + >+ "[#\r\n" + >+ " public void \r\n" + >+ " foo() {}\r\n" + >+ "#]\r\n" + >+ " /*\r\n" + >+ " * A block comment \r\n" + >+ " * on two lines\r\n" + >+ " */\r\n" + >+ "\r\n" + >+ "}\r\n"; >+ formatSource(source, >+ "public class B {\n" + >+ "\n" + >+ " public void foo() {\n" + >+ " }\n" + >+ "\n" + >+ " /*\n" + >+ " * A block comment \n" + >+ " * on two lines\n" + >+ " */\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug232768_Javadoc01() throws JavaModelException { >+ // Selection starts before and ends after the javadoc comment >+ String source = "public class C {\n" + >+ " \n" + >+ "[# /**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "#]\n" + >+ "\n" + >+ "}"; >+ // TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6) >+ formatSource(source, >+ "public class C {\n" + >+ " \n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1() {\n" + >+ "\n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Javadoc02() throws JavaModelException { >+ // Selection starts at javadoc comment begin and ends after it >+ String source = "public class C {\n" + >+ " \n" + >+ " [#/**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " #]\n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class C {\n" + >+ "\n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1() {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Javadoc03() throws JavaModelException { >+ // Selection starts inside the javadoc comment and ends after it >+ String source = "public class C {\n" + >+ " \n" + >+ " /**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * [#c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void #]m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class C {\n" + >+ "\n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Javadoc04() throws JavaModelException { >+ // Selection starts before the javadoc comment and ends at its end >+ String source = "public class C {\n" + >+ "[# \n" + >+ " /**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */#]\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6) >+ formatSource(source, >+ "public class C {\n" + >+ " \n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Javadoc05() throws JavaModelException { >+ // Selection starts before the javadoc comment and ends inside it >+ String source = "[# public class C{\n" + >+ " \n" + >+ " /**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c#]\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class C {\n" + >+ "\n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Javadoc06() throws JavaModelException { >+ // Selection starts and ends inside the javadoc comment >+ String source = " public class C{ \n" + >+ " \n" + >+ " /**\n" + >+ " * a\n" + >+ " * b\n" + >+ " * [#c#]\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ " public class C{\n" + >+ "\n" + >+ " /**\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m1 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block01() throws JavaModelException { >+ // Selection starts before and ends after the block comment >+ String source = "public class D {\n" + >+ " \n" + >+ "[# /*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "#]\n" + >+ "\n" + >+ "}"; >+ // TODO fix the incorrect indentation before the block comment (also in 3.3 and 3.4M6) >+ formatSource(source, >+ "public class D {\n" + >+ " \n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2() {\n" + >+ "\n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block02() throws JavaModelException { >+ // Selection starts at block comment begin and ends after it >+ String source = "public class D {\n" + >+ " \n" + >+ " [#/*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " #]\n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class D {\n" + >+ "\n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2() {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block03() throws JavaModelException { >+ // Selection starts inside the block comment and ends after it >+ String source = "public class D {\n" + >+ " \n" + >+ " /*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * [#c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void #]m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class D {\n" + >+ "\n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block04() throws JavaModelException { >+ // Selection starts before the block comment and ends at its end >+ String source = "public class D {\n" + >+ "[# \n" + >+ " /*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c\n" + >+ " * d\n" + >+ " * .\n" + >+ " */#]\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // TODO fix the incorrect indentation before the block comment (also in 3.3 and 3.4M6) >+ formatSource(source, >+ "public class D {\n" + >+ " \n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block05() throws JavaModelException { >+ // Selection starts before the block comment and ends inside it >+ String source = "[# public class D{\n" + >+ " \n" + >+ " /*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * c#]\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ "public class D {\n" + >+ "\n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Block06() throws JavaModelException { >+ // Selection starts and ends inside the block comment >+ String source = " public class D{ \n" + >+ " \n" + >+ " /*\n" + >+ " * a\n" + >+ " * b\n" + >+ " * [#c#]\n" + >+ " * d\n" + >+ " * .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}"; >+ // Note that the incorrect indentation before the javadoc is fixed in this test case... >+ // This is due to the fact that the region is adapted to include the edit just before the comment >+ formatSource(source, >+ " public class D{\n" + >+ "\n" + >+ " /*\n" + >+ " * a b c d .\n" + >+ " */\n" + >+ " void m2 ( ) {\n" + >+ " \n" + >+ " } \n" + >+ "\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Line01() throws JavaModelException { >+ // Selection starts before and ends after the line comment >+ String source = "public class E {\n" + >+ " \n" + >+ "\n" + >+ "[# void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ "#] \n" + >+ "}"; >+ // TODO fix the incorrect indentation before the method declaration (also in 3.3 and 3.4M6) >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ "}" >+ ); >+} >+public void testBug232768_Line02() throws JavaModelException { >+ // Selection starts at line comment begin and ends after it >+ String source = "public class E {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { [#// this is a bug\n" + >+ "\n#]" + >+ " }\n" + >+ " \n" + >+ "}"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ "}" >+ ); >+} >+public void testBug232768_Line03() throws JavaModelException { >+ // Selection starts inside line comment and ends after it >+ String source = "public class E {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this [#is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }#]"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ "\n" + >+ "}" >+ ); >+} >+public void testBug232768_Line04() throws JavaModelException { >+ // Selection starts before the line comment and ends at its end >+ String source = "public class E {[# \n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug#]\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E {\n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }" >+ ); >+} >+public void testBug232768_Line05() throws JavaModelException { >+ // Selection starts before the line comment and ends inside it >+ String source = "public class E { \n" + >+ " \n" + >+ "\n[#" + >+ " void m3() { // this #] is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E { \n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }" >+ ); >+} >+public void testBug232768_Line06() throws JavaModelException { >+ // Selection starts and ends inside the line comment >+ String source = "public class E { \n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is [#a#] bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class E { \n" + >+ " \n" + >+ "\n" + >+ " void m3() { // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ " }" >+ ); >+} >+public void testBug232768_Line07() throws JavaModelException { >+ // Selection starts and ends inside the line comment >+ String source = "public class F {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { \n" + >+ "[# // this is a bug\n" + >+ "#]\n" + >+ " }\n" + >+ " \n" + >+ "}"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class F {\n" + >+ " \n" + >+ "\n" + >+ " void m3() { \n" + >+ " // this is a bug\n" + >+ "\n" + >+ " }\n" + >+ " \n" + >+ "}" >+ ); >+} >+public void testBug232768_Line08() throws JavaModelException { >+ // Selection starts and ends inside the line comment >+ String source = "public class G {\n" + >+ " void foo() {\n" + >+ " \n" + >+ " // Now we parse one of 'CustomActionTagDependent',\n" + >+ " // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.\n" + >+ " // depending on body-content in TLD.\n" + >+ " }\n" + >+ "}"; >+ // Note that the line comment wasn't formatted using 3.3 and 3.4 M6 >+ formatSource(source, >+ "public class G {\n" + >+ " void foo() {\n" + >+ "\n" + >+ " // Now we parse one of 'CustomActionTagDependent',\n" + >+ " // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.\n" + >+ " // depending on body-content in TLD.\n" + >+ " }\n" + >+ "}" >+ ); >+} >+ >+/** > * @bug 232788: [formatter] Formatter misaligns stars when formatting block comments > * @test Ensure that block comment formatting is correct even with indentation size=1 > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232788" >@@ -270,6 +893,38 @@ > } > > /** >+ * @bug 233011: [formatter] Formatting edited lines has problems (esp. with comments) >+ * @test Ensure that new comment formatter format all comments concerned by selections >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233011" >+ */ >+public void testBug233011() throws JavaModelException { >+ String source = "\n" + >+ "public class E01 {\n" + >+ " /** \n" + >+ " * Javadoc [# #] \n" + >+ " * comment\n" + >+ " */\n" + >+ " /*\n" + >+ " * block [# #] \n" + >+ " * comment\n" + >+ " */\n" + >+ " // single [# #] line comment\n" + >+ "}"; >+ formatSource(source, >+ "\n" + >+ "public class E01 {\n" + >+ " /**\n" + >+ " * Javadoc comment\n" + >+ " */\n" + >+ " /*\n" + >+ " * block comment\n" + >+ " */\n" + >+ " // single line comment\n" + >+ "}" >+ ); >+} >+ >+/** > * @bug 233228: [formatter] line comments which contains \\u are not correctly formatted > * @test Ensure that the new formatter is not screwed up by invalid unicode value inside comments > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233228" >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.230 >diff -u -r1.230 FormatterRegressionTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 14 Apr 2008 21:52:14 -0000 1.230 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 24 May 2008 18:49:26 -0000 >@@ -139,7 +139,7 @@ > return result; > } > >- private String runFormatter(CodeFormatter codeFormatter, String source, int kind, int indentationLevel, IRegion[] regions, String lineSeparator) { >+ String runFormatter(CodeFormatter codeFormatter, String source, int kind, int indentationLevel, IRegion[] regions, String lineSeparator) { > // long time = System.currentTimeMillis(); > TextEdit edit = codeFormatter.format(kind, source, regions, indentationLevel, lineSeparator);//$NON-NLS-1$ > // System.out.println((System.currentTimeMillis() - time) + " ms"); >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java,v >retrieving revision 1.19 >diff -u -r1.19 FormatterCommentsTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java 20 May 2008 13:12:48 -0000 1.19 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java 24 May 2008 18:49:20 -0000 >@@ -39,6 +39,8 @@ > import org.eclipse.jdt.internal.core.util.SimpleDocument; > import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; > import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.Region; > > /** > * Javadoc formatter test suite using the Eclipse default settings. >@@ -109,7 +111,30 @@ > } > > void formatSource(String source, String formattedOutput) { >- formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, false, 0, -1, null); >+ int regionStart = source.indexOf("[#"); >+ if (regionStart != -1) { >+ IRegion[] regions = new Region[10]; >+ int idx = 0; >+ int start = 0; >+ int delta = 0; >+ StringBuffer buffer = new StringBuffer(); >+ while (regionStart != -1) { >+ buffer.append(source.substring(start, regionStart)); >+ int regionEnd = source.indexOf("#]", regionStart+2); >+ buffer.append(source.substring(regionStart+2, regionEnd)); >+ regions[idx++] = new Region(regionStart-delta, regionEnd-(regionStart+2)); >+ delta += 4; >+ start = regionEnd + 2; >+ regionStart = source.indexOf("[#", start); >+ } >+ System.arraycopy(regions, 0, regions = new Region[idx], 0, idx); >+ buffer.append(source.substring(start, source.length())); >+ String newSource = buffer.toString(); >+ String result = runFormatter(codeFormatter(), newSource, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, regions, Util.LINE_SEPARATOR); >+ assertLineEquals(result, newSource, formattedOutput, false); >+ } else { >+ formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, false, 0, -1, null); >+ } > } > > void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean checkNull, int offset, int length, String lineSeparator) { >Index: src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java,v >retrieving revision 1.6 >diff -u -r1.6 SingleLineTestCase.java >--- src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java 27 Apr 2008 16:28:49 -0000 1.6 >+++ src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java 24 May 2008 18:49:27 -0000 >@@ -53,7 +53,7 @@ > setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE); > setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); > String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT >- ? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test" >+ ? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test" > : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER; > assertEquals(expected, testFormat("//test\t\ttest" + DELIMITER + PREFIX + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ > } >@@ -227,7 +227,7 @@ > String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT > ? "// test test" + DELIMITER + > "// test" + DELIMITER + >- "//" + DELIMITER + >+ "// " + DELIMITER + > "// test test" + DELIMITER + > "// test test" > : PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test" + DELIMITER; >@@ -267,8 +267,7 @@ > > public void testNoChange1() { > String content= PREFIX; >- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT ? "//" : content; >- assertEquals(expected, testFormat(content)); >+ assertEquals(content, testFormat(content)); > } > > public void testNoFormat1() { >#P org.eclipse.jdt.core >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.141 >diff -u -r1.141 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 22 May 2008 20:08:01 -0000 1.141 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 24 May 2008 18:49:31 -0000 >@@ -83,7 +83,7 @@ > public int scannerEndPosition; > public int tabLength; > public int indentationSize; >- private IRegion[] regions; >+ private final IRegion[] regions; > private IRegion[] adaptedRegions; > public int tabChar; > public int numberOfIndentations; >@@ -96,6 +96,8 @@ > private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; > private static final int INCLUDE_JAVA_DOC = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_JAVA_DOC; > private static final int INCLUDE_LINE_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_SINGLE_LINE_COMMENT; >+ private static final int SKIP_FIRST_WHITESPACE_TOKEN = -2; >+ private static final int INVALID_TOKEN = 2000; > private int formatComments = 0; > private int headerEndPosition = -1; > String commentIndentation; // indentation requested in comments (usually in javadoc root tags description) >@@ -134,19 +136,68 @@ > if (includeComments) this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS; > reset(); > } >- >+ > /** > * This method will adapt the selected regions if needed. > * If a region should be adapted (see isAdaptableRegion(IRegion)) > * retrieve correct upper and lower bounds and replace the region. > */ > private void adaptRegions() { >- this.adaptedRegions = new IRegion[this.regions.length]; >- for (int i = 0, max = this.regions.length; i < max; i++) { >+ int max = this.regions.length; >+ if (max == 1) { >+ // It's not necessary to adapt the single region which covers all the source >+ if (this.regions[0].getOffset() == 0 && this.regions[0].getLength() == this.scannerEndPosition) { >+ this.adaptedRegions = this.regions; >+ return; >+ } >+ } >+ this.adaptedRegions = new IRegion[max]; >+ int commentIndex = 0; >+ for (int i = 0; i < max; i++) { > IRegion aRegion = this.regions[i]; > int offset = aRegion.getOffset(); >+ int length = aRegion.getLength(); >+ >+ // First look if the region starts or ends inside a comment >+ int index = getCommentIndex(commentIndex, offset); >+ int adaptedOffset = offset; >+ int adaptedLength = length; >+ if (index >= 0) { >+ // the offset of the region is inside a comment => restart the region from the comment start >+ adaptedOffset = this.commentPositions[index][0]; >+ if (adaptedOffset < 0) adaptedOffset = -adaptedOffset; >+ adaptedLength = length + offset - adaptedOffset; >+ commentIndex = index; >+ // include also the indentation edit just before the comment if any >+ for (int j=0; j<this.editsIndex; j++) { >+ int editOffset = this.edits[j].offset; >+ int editEnd = editOffset + this.edits[j].length; >+ if (editEnd == adaptedOffset) { >+ if (j > 0 && this.edits[j].replacement.trim().length() == 0) { >+ adaptedLength += adaptedOffset - this.edits[j].offset; >+ adaptedOffset = editOffset; >+ break; >+ } >+ } else if (editEnd > adaptedOffset) { >+ break; >+ } >+ } >+ } >+ index = getCommentIndex(commentIndex, offset+length-1); >+ if (index >= 0) { >+ // the region end is inside a comment => set the region end at the comment end >+ int commentEnd = this.commentPositions[index][1]; >+ if (commentEnd < 0) commentEnd = -commentEnd; >+ adaptedLength = commentEnd - adaptedOffset; >+ commentIndex = index; >+ } >+ if (adaptedLength != length) { >+ // adapt the region and jump to next one >+ this.adaptedRegions[i] = new Region(adaptedOffset, adaptedLength); >+ continue; >+ } >+ > if (offset > 0) { >- int length = aRegion.getLength(); > if (isAdaptableRegion(offset, length)) { > // if we have a selection, search for overlapping edits > int upperBound = offset; >@@ -333,16 +384,17 @@ > } > int previousPosition = this.scanner.currentPosition; > char ch = (char) this.scanner.getNextChar(); >+ if (this.scanner.atEnd()) { >+ // avoid infinite loop >+ return INVALID_TOKEN; >+ } > while (!this.scanner.atEnd() && ch != '*' && !ScannerHelper.isWhitespace(ch)) { > previousPosition = this.scanner.currentPosition; > ch = (char) this.scanner.getNextChar(); > } >- if (this.scanner.atEnd()) { >- return TerminalTokens.TokenNameEOF; >- } > // restore last whitespace > this.scanner.currentPosition = previousPosition; >- return 2000; // invalid token >+ return INVALID_TOKEN; > } > > public Alignment createAlignment(String name, int mode, int count, int sourceRestart){ >@@ -515,8 +567,48 @@ > return -(g + 1); > } > >- private IRegion getCoveringRegion(int offset, int end) { >- int index = getIndexOfRegionAt(offset); >+ /* >+ * Returns the index of the comment including the given offset position >+ * starting the search from the given start index. >+ * >+ * @param start The start index for the research >+ * @param position The position >+ * @return The index of the comment if the given position is located inside it, -1 otherwise >+ */ >+ private int getCommentIndex(int start, int position) { >+ int commentsLength = this.commentPositions == null ? 0 : this.commentPositions.length; >+ if (commentsLength == 0) return -1; >+ if (position == 0) { >+ if (commentsLength > 0 && this.commentPositions[0][0]== 0) { >+ return 0; >+ } >+ return -1; >+ } >+ int bottom = start, top = commentsLength - 1; >+ int i = 0; >+ int[] comment = null; >+ while (bottom <= top) { >+ i = bottom + (top - bottom) /2; >+ comment = this.commentPositions[i]; >+ int commentStart = comment[0]; >+ if (commentStart < 0) commentStart = -commentStart; >+ if (position < commentStart) { >+ top = i-1; >+ } else { >+ int commentEnd = comment[1]; >+ if (commentEnd < 0) commentEnd = -commentEnd; >+ if (position >= commentEnd) { >+ bottom = i+1; >+ } else { >+ return i; >+ } >+ } >+ } >+ return -1; >+ } >+ >+ private IRegion getCoveringAdaptedRegion(int offset, int end) { >+ int index = getIndexOfAdaptedRegionAt(offset); > > if (index < 0) { > index = -(index + 1); >@@ -616,7 +708,7 @@ > return String.valueOf(buffer); > } > >- private int getIndexOfRegionAt(int offset) { >+ private int getIndexOfAdaptedRegionAt(int offset) { > if (this.adaptedRegions.length == 1) { > int offset2 = this.adaptedRegions[0].getOffset(); > if (offset2 == offset) { >@@ -701,13 +793,13 @@ > return Util.EMPTY_STRING; > } > >- private IRegion getRegionAt(int offset) { >- int index = getIndexOfRegionAt(offset); >+ private IRegion getAdaptedRegionAt(int offset) { >+ int index = getIndexOfAdaptedRegionAt(offset); > if (index < 0) { > return null; > } > >- return this.regions[index]; >+ return this.adaptedRegions[index]; > } > > public TextEdit getRootEdit() { >@@ -846,7 +938,6 @@ > this.maxLines = this.lineEnds == null ? -1 : this.lineEnds.length - 1; > this.scanner.lineEnds = this.lineEnds; > this.scanner.linePtr = this.maxLines; >- // Comment following line to de-activate new Javadoc formatter > initFormatterCommentParser(); > } > >@@ -924,7 +1015,7 @@ > final int editOffset= edit.offset; > if (editLength != 0) { > >- IRegion covering = getCoveringRegion(editOffset, (editOffset + editLength - 1)); >+ IRegion covering = getCoveringAdaptedRegion(editOffset, (editOffset + editLength - 1)); > if (covering != null) { > if (editReplacementLength != 0 && editLength == editReplacementLength) { > for (int i = editOffset, max = editOffset + editLength; i < max; i++) { >@@ -937,7 +1028,7 @@ > return true; > } > >- IRegion starting = getRegionAt(editOffset + editLength); >+ IRegion starting = getAdaptedRegionAt(editOffset + editLength); > if (starting != null) { > int i = editOffset; > for (int max = editOffset + editLength; i < max; i++) { >@@ -957,7 +1048,7 @@ > return false; > } > >- IRegion covering = getCoveringRegion(editOffset, editOffset); >+ IRegion covering = getCoveringAdaptedRegion(editOffset, editOffset); > if (covering != null) { > return true; > } >@@ -1210,6 +1301,8 @@ > this.column += 2; > this.scanner.skipComments = true; > StringBuffer tokensBuffer = new StringBuffer(); >+ int editStart = this.scanner.currentPosition; >+ int editEnd = -1; > > // Consume text token per token > int previousToken = -1; >@@ -1252,7 +1345,7 @@ > } > if (previousToken == -1) { > // do not remember the first whitespace >- previousToken = -2; >+ previousToken = SKIP_FIRST_WHITESPACE_TOKEN; > } else { > previousToken = token; > } >@@ -1267,6 +1360,7 @@ > previousToken = token; > lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); > if (this.scanner.currentCharacter == '/') { >+ editEnd = this.scanner.startPosition - 1; > // Add remaining buffered tokens > if (tokensBuffer.length() > 0) { > buffer.append(tokensBuffer); >@@ -1279,8 +1373,7 @@ > printIndentationIfNecessary(buffer); > } > buffer.append(' '); >- buffer.append(BLOCK_FOOTER); >- this.column += BLOCK_FOOTER_LENGTH + 1; >+ this.column += BLOCK_FOOTER_LENGTH + 1; > this.scanner.getNextChar(); // reach the end of scanner > continue; > } >@@ -1416,7 +1509,7 @@ > > // Replace block comment text > if (hasTokens || multiLines) { >- StringBuffer replacement = new StringBuffer(BLOCK_HEADER); >+ StringBuffer replacement = new StringBuffer(); > if (hasTextOnFirstLine == 1) { > if ((hasMultiLines || multiLines)) { > int col = this.column; >@@ -1430,7 +1523,7 @@ > } > } > replacement.append(buffer); >- addReplaceEdit(currentTokenStartPosition, currentTokenEndPosition-1, replacement.toString()); >+ addReplaceEdit(editStart, editEnd, replacement.toString()); > } > > // Reset >@@ -1803,6 +1896,7 @@ > // Set scanner > initializeScanner(source.toCharArray()); > this.scanner.resetTo(start, end); >+ this.scannerEndPosition = end; > > // Set indentation level > this.numberOfIndentations = level; >@@ -1822,7 +1916,7 @@ > break; > } > } >- >+ > private void printLineComment() { > int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition(); > int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1; >@@ -1907,10 +2001,9 @@ > this.scanner.resetTo(commentStart, commentEnd); > StringBuffer buffer = new StringBuffer(); > this.scanner.getNextChar(); >- buffer.append(this.scanner.currentCharacter); > this.scanner.getNextChar(); >- buffer.append(this.scanner.currentCharacter); > this.column += 2; >+ int editStart = this.scanner.currentPosition; > StringBuffer tokensBuffer = new StringBuffer(); > boolean bufferHasTokens = false; > >@@ -1918,7 +2011,6 @@ > int maxColumn = this.formatter.preferences.comment_line_length + 1; > int previousToken = -1; > int previousPosition = commentStart; >- char previousChar = 0; > boolean firstWord = true; > this.scanner.skipComments = true; > >@@ -1939,8 +2031,6 @@ > tokensBuffer.setLength(0); > bufferHasTokens = true; > } >- previousPosition = this.scanner.currentPosition; >- previousChar = this.scanner.currentCharacter; > continue; > case TerminalTokens.TokenNameEOF: > continue; >@@ -1995,9 +2085,9 @@ > } > previousToken = token; > previousPosition = this.scanner.currentPosition; >- previousChar = this.scanner.currentCharacter; > firstWord = false; > } >+ this.scanner.skipComments = false; > > // Add remaining buffered tokens > if (tokensBuffer.length() > 0) { >@@ -2009,30 +2099,23 @@ > this.indentationLevel = indentLevel; > this.numberOfIndentations = indentations; > this.lastNumberOfNewLines = 0; >- if (previousChar == '\n' || previousChar == '\r') { >- // line comment is normally ended with new line >- this.column = 1; >- buffer.append(this.lineSeparator); >- this.line++; >- this.lastNumberOfNewLines++; >- } else { >- this.scanner.resetTo(previousPosition, commentEnd); >- while (!this.scanner.atEnd()) { >- this.scanner.getNextChar(); >- if (this.scanner.currentCharacter == '\n' || this.scanner.currentCharacter == '\r') { >- // line comment is normally ended with new line >- buffer.append(this.lineSeparator); >- this.column = 1; >- this.line++; >- this.lastNumberOfNewLines++; >- break; >- } >+ this.scanner.resetTo(previousPosition, commentEnd); >+ while (!this.scanner.atEnd()) { >+ previousPosition = this.scanner.currentPosition; >+ this.scanner.getNextChar(); >+ if (this.scanner.currentCharacter == '\n' || this.scanner.currentCharacter == '\r') { >+ // line comment is normally ended with new line >+ this.column = 1; >+ this.line++; >+ this.lastNumberOfNewLines++; >+ break; > } > } > > // Replace the existing comment with new one >- addReplaceEdit(commentStart, commentEnd, buffer.toString()); >- this.scanner.skipComments = false; >+ if (buffer.length() > 0) { >+ addReplaceEdit(editStart, previousPosition - 1, buffer.toString()); >+ } > } > > public void printEmptyLines(int linesNumber) {
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 232768
:
101017
|
101021
| 101863