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 162152 Details for
Bug 305371
[formatter] Unexpected indentation of line comment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v03.txt (text/plain), 5.76 KB, created by
Frederic Fusier
on 2010-03-16 06:10:39 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2010-03-16 06:10:39 EDT
Size:
5.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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.200 >diff -u -r1.200 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 11 Mar 2010 11:27:29 -0000 1.200 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 16 Mar 2010 09:42:31 -0000 >@@ -2217,15 +2217,12 @@ > // then it becomes not a good idea to change the trailing flag > if (trailing == BASIC_TRAILING_COMMENT && hasLineComment) { > int currentCommentIndentation = getCurrentIndentation(whiteSpaces, 0); >- int lastCommentIndentation = this.lastLineComment.currentIndentation; >- if (this.tabLength > 0) { >- if ((currentCommentIndentation % this.tabLength) == 0) { >- lastCommentIndentation = (lastCommentIndentation / this.tabLength) * this.tabLength; >- } else { >- currentCommentIndentation = ((currentCommentIndentation / this.tabLength) + 1) * this.tabLength; >- } >+ int relativeIndentation = currentCommentIndentation - this.lastLineComment.currentIndentation; >+ if (this.tabLength == 0) { >+ canChangeTrailing = relativeIndentation == 0; >+ } else { >+ canChangeTrailing = relativeIndentation > -this.tabLength; > } >- canChangeTrailing = currentCommentIndentation >= lastCommentIndentation; > } > // if the trailing can be change, then look at the following tokens > if (canChangeTrailing) { >@@ -2494,15 +2491,15 @@ > int currentCommentIndentation = getCurrentIndentation(this.lastLineComment.leadingSpaces, 0); > // Keep the current comment indentation when over the previous contiguous line comment > // and the previous comment has not been reindented >- int lastCommentIndentation = this.lastLineComment.currentIndentation; >- if (this.tabLength > 0) { >- if ((currentCommentIndentation % this.tabLength) == 0) { >- lastCommentIndentation = (lastCommentIndentation / this.tabLength) * this.tabLength; >- } else { >- currentCommentIndentation = ((currentCommentIndentation / this.tabLength) + 1) * this.tabLength; >- } >+ int relativeIndentation = currentCommentIndentation - this.lastLineComment.currentIndentation; >+ boolean similarCommentsIndentation = false; >+ if (this.tabLength == 0) { >+ similarCommentsIndentation = relativeIndentation == 0; >+ } else if (relativeIndentation > -this.tabLength) { >+ similarCommentsIndentation = this.formatter.preferences.comment_format_line_comment_starting_on_first_column || >+ (currentCommentIndentation != 0 && this.lastLineComment.currentIndentation != 0); > } >- if (currentCommentIndentation >= lastCommentIndentation && this.lastLineComment.indentation != this.indentationLevel) { >+ if (similarCommentsIndentation && this.lastLineComment.indentation != this.indentationLevel) { > int currentIndentationLevel = this.indentationLevel; > this.indentationLevel = this.lastLineComment.indentation ; > printIndentationIfNecessary(); >#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.59 >diff -u -r1.59 FormatterCommentsBugsTest.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 11 Mar 2010 11:27:26 -0000 1.59 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 16 Mar 2010 09:42:33 -0000 >@@ -6281,4 +6281,62 @@ > "}\n"); > } > >+/** >+ * @bug 305371: [formatter] Unexpected indentation of line comment >+ * @test Verify that comments with too different indentation are not considered as contiguous >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305371" >+ */ >+public void testBug305371() { >+ this.formatterPrefs = null; >+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); >+ String source = >+ "class X01 {\n" + >+ "// unformatted comment !\n" + >+ " // formatted comment !\n" + >+ "}\n"; >+ formatSource(source, >+ "class X01 {\n" + >+ "// unformatted comment !\n" + >+ " // formatted comment !\n" + >+ "}\n"); >+} >+public void testBug305371b() { >+ this.formatterPrefs = null; >+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); >+ String source = >+ "class X02 {\n" + >+ " // formatted comment !\n" + >+ "// unformatted comment !\n" + >+ "}\n"; >+ formatSource(source, >+ "class X02 {\n" + >+ " // formatted comment !\n" + >+ "// unformatted comment !\n" + >+ "}\n"); >+} >+public void testBug305371c() { >+ String source = >+ "class X03 {\n" + >+ " // formatted comment 1\n" + >+ " // formatted comment 2\n" + >+ "}\n"; >+ formatSource(source, >+ "class X03 {\n" + >+ " // formatted comment 1\n" + >+ " // formatted comment 2\n" + >+ "}\n"); >+} >+public void testBug305371d() { >+ String source = >+ "class X04 {\n" + >+ " // formatted comment 1\n" + >+ " // formatted comment 2\n" + >+ "}\n"; >+ formatSource(source, >+ "class X04 {\n" + >+ " // formatted comment 1\n" + >+ " // formatted comment 2\n" + >+ "}\n"); >+} >+ > }
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 305371
: 162152