View | Details | Raw Unified | Return to bug 185928 | Differences between
and this patch

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (-2 / +9 lines)
Lines 13-18 Link Here
13
import java.util.Map;
13
import java.util.Map;
14
14
15
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jdt.core.JavaCore;
16
import org.eclipse.jdt.core.ToolFactory;
16
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
17
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
17
import org.eclipse.jdt.internal.formatter.align.Alignment;
18
import org.eclipse.jdt.internal.formatter.align.Alignment;
18
19
Lines 3035-3044 Link Here
3035
	 * FORMATTER / Option to indent block comments that start on the first column
3036
	 * FORMATTER / Option to indent block comments that start on the first column
3036
	 *     - option id:         "org.eclipse.jdt.core.formatter.formatter.never_indent_block_comments_on_first_column"
3037
	 *     - option id:         "org.eclipse.jdt.core.formatter.formatter.never_indent_block_comments_on_first_column"
3037
	 *     - possible values:   { TRUE, FALSE }
3038
	 *     - possible values:   { TRUE, FALSE }
3038
	 *     - default:           TRUE
3039
	 *     - default:           FALSE
3039
	 * </pre>
3040
	 * </pre>
3041
	 * Note that if the formatter is created without {@link ToolFactory#M_FORMAT_USE_EXISTING_COMMENT_POSITIONS} set,
3042
	 * this option is ignored.
3040
	 * @see #TRUE
3043
	 * @see #TRUE
3041
	 * @see #FALSE
3044
	 * @see #FALSE
3045
	 * @see ToolFactory#createCodeFormatter(Map, int)
3042
	 * @since 3.3
3046
	 * @since 3.3
3043
	 */
3047
	 */
3044
	public static final String FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_block_comments_on_first_column"; //$NON-NLS-1$	
3048
	public static final String FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_block_comments_on_first_column"; //$NON-NLS-1$	
Lines 3047-3056 Link Here
3047
	 * FORMATTER / Option to indent line comments that start on the first column
3051
	 * FORMATTER / Option to indent line comments that start on the first column
3048
	 *     - option id:         "org.eclipse.jdt.core.formatter.formatter.never_indent_line_comments_on_first_column"
3052
	 *     - option id:         "org.eclipse.jdt.core.formatter.formatter.never_indent_line_comments_on_first_column"
3049
	 *     - possible values:   { TRUE, FALSE }
3053
	 *     - possible values:   { TRUE, FALSE }
3050
	 *     - default:           TRUE
3054
	 *     - default:           FALSE
3051
	 * </pre>
3055
	 * </pre>
3056
	 * Note that if the formatter is created without {@link ToolFactory#M_FORMAT_USE_EXISTING_COMMENT_POSITIONS} set,
3057
	 * this option is ignored.
3052
	 * @see #TRUE
3058
	 * @see #TRUE
3053
	 * @see #FALSE
3059
	 * @see #FALSE
3060
	 * @see ToolFactory#createCodeFormatter(Map, int)
3054
	 * @since 3.3
3061
	 * @since 3.3
3055
	 */
3062
	 */
3056
	public static final String FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_line_comments_on_first_column"; //$NON-NLS-1$	
3063
	public static final String FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_line_comments_on_first_column"; //$NON-NLS-1$	
(-)formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java (-25 lines)
Lines 27-33 Link Here
27
27
28
import org.eclipse.equinox.app.IApplication;
28
import org.eclipse.equinox.app.IApplication;
29
import org.eclipse.equinox.app.IApplicationContext;
29
import org.eclipse.equinox.app.IApplicationContext;
30
import org.eclipse.jdt.core.JavaCore;
31
import org.eclipse.jdt.core.ToolFactory;
30
import org.eclipse.jdt.core.ToolFactory;
32
import org.eclipse.jdt.internal.core.util.Util;
31
import org.eclipse.jdt.internal.core.util.Util;
33
import org.eclipse.jface.text.BadLocationException;
32
import org.eclipse.jface.text.BadLocationException;
Lines 376-405 Link Here
376
			System.out.println(Messages.bind(Messages.CommandLineStart));
375
			System.out.println(Messages.bind(Messages.CommandLineStart));
377
		}
376
		}
378
377
379
		// preserve existing default behavior
380
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=20793
381
		if (this.options == null) {
382
			this.options = JavaCore.getOptions();
383
			this.options.put(
384
				DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN,
385
				DefaultCodeFormatterConstants.FALSE);
386
			this.options.put(
387
					DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
388
					DefaultCodeFormatterConstants.FALSE);
389
		} else {
390
			Object option = this.options.get(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN);
391
			if (option == null) {
392
				this.options.put(
393
						DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN,
394
						DefaultCodeFormatterConstants.FALSE);
395
			}
396
			option = this.options.get(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN);
397
			if (option == null) {
398
				this.options.put(
399
						DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
400
						DefaultCodeFormatterConstants.FALSE);
401
			}
402
		}
403
		final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(this.options);
378
		final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(this.options);
404
		// format the list of files and/or directories
379
		// format the list of files and/or directories
405
		for (int i = 0, max = filesToFormat.length; i < max; i++) {
380
		for (int i = 0, max = filesToFormat.length; i < max; i++) {
(-)model/org/eclipse/jdt/core/ToolFactory.java (-1 / +50 lines)
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.InputStream;
15
import java.io.InputStream;
16
import java.util.HashMap;
16
import java.util.Map;
17
import java.util.Map;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipFile;
19
import java.util.zip.ZipFile;
Lines 21-26 Link Here
21
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.*;
22
import org.eclipse.jdt.core.compiler.IScanner;
23
import org.eclipse.jdt.core.compiler.IScanner;
23
import org.eclipse.jdt.core.formatter.CodeFormatter;
24
import org.eclipse.jdt.core.formatter.CodeFormatter;
25
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
24
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
26
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
25
import org.eclipse.jdt.core.util.ClassFormatException;
27
import org.eclipse.jdt.core.util.ClassFormatException;
26
import org.eclipse.jdt.core.util.IClassFileReader;
28
import org.eclipse.jdt.core.util.IClassFileReader;
Lines 45-50 Link Here
45
 * @since 2.0
47
 * @since 2.0
46
 */
48
 */
47
public class ToolFactory {
49
public class ToolFactory {
50
	
51
	/**
52
	 * If set, this mode tells the default code formatter to use the existing comment positions
53
	 * in order to format the code. If not set, the options that format the code keeping existing
54
	 * comment positions are ignored.
55
	 *
56
	 * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN
57
	 * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN
58
	 * @see #createCodeFormatter(Map, int)
59
	 * @since 3.3
60
	 */
61
	public static int M_FORMAT_USE_EXISTING_COMMENT_POSITIONS = 0x01;
48
62
49
	/**
63
	/**
50
	 * Create an instance of a code formatter. A code formatter implementation can be contributed via the 
64
	 * Create an instance of a code formatter. A code formatter implementation can be contributed via the 
Lines 89-94 Link Here
89
	 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
103
	 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
90
	 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
104
	 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
91
	 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
105
	 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
106
	 * </p><p>
107
	 * Note this is equivalent to <code>createCodeFormatter(options, 0)</code>. Thus some code formatter options
108
	 * may be ignored since the corresponding mode is not set.
92
	 * </p>
109
	 * </p>
93
	 * @param options - the options map to use for formatting with the default code formatter. Recognized options
110
	 * @param options - the options map to use for formatting with the default code formatter. Recognized options
94
	 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use 
111
	 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use 
Lines 99-106 Link Here
99
	 * @since 3.0
116
	 * @since 3.0
100
	 */
117
	 */
101
	public static CodeFormatter createCodeFormatter(Map options){
118
	public static CodeFormatter createCodeFormatter(Map options){
119
		return createCodeFormatter(options, 0);
120
	}
121
122
	/**
123
	 * Create an instance of the built-in code formatter.
124
	 * <p>The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}),
125
	 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
126
	 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
127
	 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
128
	 * </p>
129
	 * <p>The given mode is a bitwise value. It is used to determine what options should be enabled when
130
	 * formatting the code.</p>
131
	 * <p>The list of bits used to set the mode includes only {@link #M_FORMAT_USE_EXISTING_COMMENT_POSITIONS}, but
132
	 * other bits are left for future use.</p>
133
	 * 
134
	 * @param options the options map to use for formatting with the default code formatter. Recognized options
135
	 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use 
136
	 * 	the current settings from <code>JavaCore#getOptions</code>.
137
	 * @param mode the given mode to modify the given options.
138
	 *
139
	 * @return an instance of the built-in code formatter
140
	 * @see CodeFormatter
141
	 * @see JavaCore#getOptions()
142
	 * @since 3.3
143
	 */
144
	public static CodeFormatter createCodeFormatter(Map options, int mode) {
102
		if (options == null) options = JavaCore.getOptions();
145
		if (options == null) options = JavaCore.getOptions();
103
		return new DefaultCodeFormatter(options);
146
		Map currentOptions = new HashMap(options);
147
		if ((mode & M_FORMAT_USE_EXISTING_COMMENT_POSITIONS) == 0) {
148
			// disable the option for not indenting comments starting on first column
149
			currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
150
			currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
151
		}
152
		return new DefaultCodeFormatter(currentOptions);
104
	}
153
	}
105
154
106
	/**
155
	/**
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-2 lines)
Lines 2172-2179 Link Here
2172
		setJavaConventionsSettings();
2172
		setJavaConventionsSettings();
2173
		this.tab_char = TAB;
2173
		this.tab_char = TAB;
2174
		this.tab_size = 4;
2174
		this.tab_size = 4;
2175
		this.never_indent_block_comments_on_first_column = true;
2176
		this.never_indent_line_comments_on_first_column = true;
2177
	}
2175
	}
2178
2176
2179
	public void setJavaConventionsSettings() {
2177
	public void setJavaConventionsSettings() {

Return to bug 185928