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 58454 Details for
Bug 173048
[preferences] Comment formatter prefs: Header can be non-Javadoc comment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fix
fix_173048.txt (text/plain), 11.46 KB, created by
Benno Baumgartner
on 2007-02-07 11:15:51 EST
(
hide
)
Description:
fix
Filename:
MIME Type:
Creator:
Benno Baumgartner
Created:
2007-02-07 11:15:51 EST
Size:
11.46 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java,v >retrieving revision 1.45 >diff -u -r1.45 CommentFormattingStrategy.java >--- ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java 28 Aug 2006 10:46:30 -0000 1.45 >+++ ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java 7 Feb 2007 16:14:04 -0000 >@@ -101,11 +101,12 @@ > return null; > > Map preferences= getPreferences(); >- final boolean isFormattingHeader= Boolean.toString(true).equals(preferences.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER)); >+ final boolean isFormattingHeader= DefaultCodeFormatterConstants.TRUE.equals(preferences.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER)); > int documentsHeaderEnd= computeHeaderEnd(document); > >- TextEdit edit= null; >- if (isFormattingHeader || position.offset >= documentsHeaderEnd) { >+ TextEdit edit= null; >+ if (position.offset >= documentsHeaderEnd) { >+ // not a header > try { > // compute offset in document of region passed to the formatter > int sourceOffset= document.getLineOffset(document.getLineOfOffset(position.getOffset())); >@@ -124,6 +125,45 @@ > } catch (BadLocationException x) { > JavaPlugin.log(x); > } >+ } else if (isFormattingHeader) { >+ boolean wasJavaDoc= DefaultCodeFormatterConstants.TRUE.equals(preferences.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT)); >+ if (!wasJavaDoc) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, DefaultCodeFormatterConstants.TRUE); >+ >+ boolean wasBlockComment= DefaultCodeFormatterConstants.TRUE.equals(preferences.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT)); >+ if (!wasBlockComment) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, DefaultCodeFormatterConstants.TRUE); >+ >+ boolean wasLineComment= DefaultCodeFormatterConstants.TRUE.equals(preferences.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT)); >+ if (!wasLineComment) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, DefaultCodeFormatterConstants.TRUE); >+ >+ try { >+ // compute offset in document of region passed to the formatter >+ int sourceOffset= document.getLineOffset(document.getLineOfOffset(position.getOffset())); >+ >+ // format region >+ int partitionOffset= position.getOffset() - sourceOffset; >+ int sourceLength= partitionOffset + position.getLength(); >+ String source= document.get(sourceOffset, sourceLength); >+ CodeFormatter commentFormatter= ToolFactory.createCodeFormatter(preferences); >+ int indentationLevel= inferIndentationLevel(source.substring(0, partitionOffset), getTabSize(preferences), getIndentSize(preferences)); >+ edit= commentFormatter.format(getKindForPartitionType(position.getType()), source, partitionOffset, position.getLength(), indentationLevel, TextUtilities.getDefaultLineDelimiter(document)); >+ >+ // move edit offset to match document >+ if (edit != null) >+ edit.moveTree(sourceOffset); >+ } catch (BadLocationException x) { >+ JavaPlugin.log(x); >+ } finally { >+ if (!wasJavaDoc) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); >+ if (!wasLineComment) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE); >+ if (!wasLineComment) >+ preferences.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, DefaultCodeFormatterConstants.FALSE); >+ } >+ > } > return edit; > } >Index: ui/org/eclipse/jdt/internal/ui/preferences/formatter/CommentsTabPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/CommentsTabPage.java,v >retrieving revision 1.18 >diff -u -r1.18 CommentsTabPage.java >--- ui/org/eclipse/jdt/internal/ui/preferences/formatter/CommentsTabPage.java 2 Feb 2007 14:48:01 -0000 1.18 >+++ ui/org/eclipse/jdt/internal/ui/preferences/formatter/CommentsTabPage.java 7 Feb 2007 16:14:04 -0000 >@@ -47,68 +47,59 @@ > JavaCore.INSERT > }; > >- >- private final static class AndController implements Observer { >+ private static abstract class Controller implements Observer { > > private final Collection fMasters; > private final Collection fSlaves; > >- public AndController(Collection masters, Collection slaves) { >+ public Controller(Collection masters, Collection slaves) { > fMasters= masters; > fSlaves= slaves; > for (final Iterator iter= fMasters.iterator(); iter.hasNext();) { >- ((CheckboxPreference)iter.next()).addObserver(this); >+ ((CheckboxPreference)iter.next()).addObserver(this); > } >- update(null, null); > } >- >+ > public void update(Observable o, Object arg) { >- boolean enabled= true; >- >- for (final Iterator iter= fMasters.iterator(); iter.hasNext();) { >- enabled &= ((CheckboxPreference)iter.next()).getChecked(); >- } >- >- for (final Iterator iter = fSlaves.iterator(); iter.hasNext();) { >- final Object obj= iter.next(); >- if (obj instanceof Preference) { >- ((Preference)obj).setEnabled(enabled); >- } else if (obj instanceof Control) { >- ((Group)obj).setEnabled(enabled); >- } >+ boolean enabled= areSlavesEnabled(); >+ >+ for (final Iterator iter= fSlaves.iterator(); iter.hasNext();) { >+ final Object obj= iter.next(); >+ if (obj instanceof Preference) { >+ ((Preference)obj).setEnabled(enabled); >+ } else if (obj instanceof Control) { >+ ((Group)obj).setEnabled(enabled); >+ } > } > } >+ >+ public Collection getMasters() { >+ return fMasters; >+ } >+ >+ public Collection getSlaves() { >+ return fSlaves; >+ } >+ >+ protected abstract boolean areSlavesEnabled(); > } > >- private final static class OrController implements Observer { >- >- private final Collection fMasters; >- private final Collection fSlaves; >+ private final static class OrController extends Controller { > > public OrController(Collection masters, Collection slaves) { >- fMasters= masters; >- fSlaves= slaves; >- for (final Iterator iter= fMasters.iterator(); iter.hasNext();) { >- ((CheckboxPreference)iter.next()).addObserver(this); >- } >+ super(masters, slaves); > update(null, null); > } >- >- public void update(Observable o, Object arg) { >- boolean enabled= false; >- >- for (final Iterator iter= fMasters.iterator(); iter.hasNext();) { >- enabled |= ((CheckboxPreference)iter.next()).getChecked(); >- } >- >- for (final Iterator iter = fSlaves.iterator(); iter.hasNext();) { >- final Object obj= iter.next(); >- if (obj instanceof Preference) { >- ((Preference)obj).setEnabled(enabled); >- } else if (obj instanceof Control) { >- ((Group)obj).setEnabled(enabled); >- } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected boolean areSlavesEnabled() { >+ for (final Iterator iter= getMasters().iterator(); iter.hasNext();) { >+ if (((CheckboxPreference)iter.next()).getChecked()) >+ return true; > } >+ return false; > } > } > >@@ -156,12 +147,12 @@ > // global group > final Group globalGroup= createGroup(numColumns, composite, FormatterMessages.CommentsTabPage_group1_title); > final CheckboxPreference javadoc= createPrefTrueFalse(globalGroup, numColumns, FormatterMessages.commentsTabPage_enable_javadoc_comment_formatting, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT); >- final CheckboxPreference blockComment= createPrefTrueFalse(globalGroup, numColumns, FormatterMessages.CommentsTabPage_enable_block_comment_formatting, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT); >+ final CheckboxPreference blockComment= createPrefTrueFalse(globalGroup, numColumns, FormatterMessages.CommentsTabPage_enable_block_comment_formatting, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT); > final CheckboxPreference singleLineComments= createPrefTrueFalse(globalGroup, numColumns, FormatterMessages.CommentsTabPage_enable_line_comment_formatting, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT); >+ final CheckboxPreference header= createPrefTrueFalse(globalGroup, numColumns, FormatterMessages.CommentsTabPage_format_header, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER); > > // javadoc comment formatting settings > final Group settingsGroup= createGroup(numColumns, composite, FormatterMessages.CommentsTabPage_group2_title); >- final CheckboxPreference header= createPrefTrueFalse(settingsGroup, numColumns, FormatterMessages.CommentsTabPage_format_header, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER); > final CheckboxPreference html= createPrefTrueFalse(settingsGroup, numColumns, FormatterMessages.CommentsTabPage_format_html, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HTML); > final CheckboxPreference code= createPrefTrueFalse(settingsGroup, numColumns, FormatterMessages.CommentsTabPage_format_code_snippets, DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE); > final CheckboxPreference blankJavadoc= createPrefInsert(settingsGroup, numColumns, FormatterMessages.CommentsTabPage_blank_line_before_javadoc_tags, DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS); >@@ -180,10 +171,10 @@ > > ArrayList javaDocMaster= new ArrayList(); > javaDocMaster.add(javadoc); >+ javaDocMaster.add(header); > > ArrayList javaDocSlaves= new ArrayList(); > javaDocSlaves.add(settingsGroup); >- javaDocSlaves.add(header); > javaDocSlaves.add(html); > javaDocSlaves.add(code); > javaDocSlaves.add(blankJavadoc); >@@ -191,30 +182,37 @@ > javaDocSlaves.add(nlParam); > javaDocSlaves.add(blankLinesJavadoc); > >- new AndController(javaDocMaster, javaDocSlaves); >+ new OrController(javaDocMaster, javaDocSlaves); > > ArrayList indentMasters= new ArrayList(); > indentMasters.add(javadoc); >+ indentMasters.add(header); > indentMasters.add(indentJavadoc); > > ArrayList indentSlaves= new ArrayList(); > indentSlaves.add(indentDesc); > >- new AndController(indentMasters, indentSlaves); >+ new Controller(indentMasters, indentSlaves) { >+ protected boolean areSlavesEnabled() { >+ return (javadoc.getChecked() || header.getChecked()) && indentJavadoc.getChecked(); >+ } >+ }.update(null, null); > > ArrayList blockMasters= new ArrayList(); > blockMasters.add(blockComment); >+ blockMasters.add(header); > > ArrayList blockSlaves= new ArrayList(); > blockSlaves.add(blockSettingsGroup); > blockSlaves.add(blankLinesBlock); > >- new AndController(blockMasters, blockSlaves); >+ new OrController(blockMasters, blockSlaves); > > ArrayList lineWidthMasters= new ArrayList(); > lineWidthMasters.add(javadoc); > lineWidthMasters.add(blockComment); > lineWidthMasters.add(singleLineComments); >+ lineWidthMasters.add(header); > > ArrayList lineWidthSlaves= new ArrayList(); > lineWidthSlaves.add(widthGroup);
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 173048
:
58435
|
58436
| 58454