### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui Index: core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java,v retrieving revision 1.60 diff -u -r1.60 CodeFormatterUtil.java --- core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java 7 Apr 2006 16:49:15 -0000 1.60 +++ core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java 23 May 2007 14:31:30 -0000 @@ -233,6 +233,17 @@ return format2(kind, string, 0, string.length(), indentationLevel, lineSeparator, options); } + public static TextEdit reFormat(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) { + if (offset < 0 || length < 0 || offset + length > string.length()) { + throw new IllegalArgumentException("offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + } + return ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS).format(kind, string, offset, length, indentationLevel, lineSeparator); + } + + public static TextEdit reFormat(int kind, String string, int indentationLevel, String lineSeparator, Map options) { + return reFormat(kind, string, 0, string.length(), indentationLevel, lineSeparator, options); + } + /** * Creates edits that describe how to format the given string. Returns null if the code could not be formatted for the given kind. * @throws IllegalArgumentException If the offset and length are not inside the string, a Index: ui/org/eclipse/jdt/internal/ui/fix/CodeFormatFix.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/CodeFormatFix.java,v retrieving revision 1.6 diff -u -r1.6 CodeFormatFix.java --- ui/org/eclipse/jdt/internal/ui/fix/CodeFormatFix.java 18 Apr 2007 10:52:55 -0000 1.6 +++ ui/org/eclipse/jdt/internal/ui/fix/CodeFormatFix.java 23 May 2007 14:31:30 -0000 @@ -53,7 +53,7 @@ String content= cu.getBuffer().getContents(); Document document= new Document(content); - TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, content, 0, TextUtilities.getDefaultLineDelimiter(document), fomatterSettings); + TextEdit edit= CodeFormatterUtil.reFormat(CodeFormatter.K_COMPILATION_UNIT, content, 0, TextUtilities.getDefaultLineDelimiter(document), fomatterSettings); if (edit == null || !edit.hasChildren()) return null; Index: ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java,v retrieving revision 1.44 diff -u -r1.44 JavaFormattingStrategy.java --- ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java 28 Mar 2006 16:53:40 -0000 1.44 +++ ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java 23 May 2007 14:31:31 -0000 @@ -61,7 +61,7 @@ Map partitioners= null; try { - final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences()); + final TextEdit edit= CodeFormatterUtil.reFormat(CodeFormatter.K_COMPILATION_UNIT, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences()); if (edit != null) { if (edit.getChildrenSize() > 20) partitioners= TextUtilities.removeDocumentPartitioners(document); 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.48 diff -u -r1.48 CommentFormattingStrategy.java --- ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java 30 Apr 2007 21:24:15 -0000 1.48 +++ ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java 23 May 2007 14:31:31 -0000 @@ -115,7 +115,7 @@ int partitionOffset= position.getOffset() - sourceOffset; int sourceLength= partitionOffset + position.getLength(); String source= document.get(sourceOffset, sourceLength); - CodeFormatter commentFormatter= ToolFactory.createCodeFormatter(preferences); + CodeFormatter commentFormatter= ToolFactory.createCodeFormatter(preferences, ToolFactory.M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS); 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));