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 (-3 / +10 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 21-27 Link Here
21
 * <p>
22
 * <p>
22
 * This class is not intended to be instantiated or subclassed by clients.
23
 * This class is not intended to be instantiated or subclassed by clients.
23
 * </p>
24
 * </p>
24
 * 
25
 *
25
 * @since 3.0
26
 * @since 3.0
26
 */
27
 */
27
public class DefaultCodeFormatterConstants {
28
public class DefaultCodeFormatterConstants {
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_HONOR_NEVER_INDENT_COMMENT_OPTIONS} 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_HONOR_NEVER_INDENT_COMMENT_OPTIONS} 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++) {
(-)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() {
(-)model/org/eclipse/jdt/core/ToolFactory.java (-1 / +51 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 honor the options that
53
	 * never indent comments on first column. Note that if these options are disabled,
54
	 * then they remain disabled even if this mode is set.
55
	 * If this mode is not set, these options are ignored, even if they are enabled.
56
	 *
57
	 * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN
58
	 * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN
59
	 * @see #createCodeFormatter(Map, int)
60
	 * @since 3.3
61
	 */
62
	public static final int M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS = 0x01;
48
63
49
	/**
64
	/**
50
	 * Create an instance of a code formatter. A code formatter implementation can be contributed via the 
65
	 * 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
104
	 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
90
	 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
105
	 * ({@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.
106
	 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
107
	 * </p><p>
108
	 * Note this is equivalent to <code>createCodeFormatter(options, 0)</code>. Thus some code formatter options
109
	 * may be ignored since the corresponding mode is not set.
92
	 * </p>
110
	 * </p>
93
	 * @param options - the options map to use for formatting with the default code formatter. Recognized options
111
	 * @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 
112
	 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use 
Lines 99-106 Link Here
99
	 * @since 3.0
117
	 * @since 3.0
100
	 */
118
	 */
101
	public static CodeFormatter createCodeFormatter(Map options){
119
	public static CodeFormatter createCodeFormatter(Map options){
120
		return createCodeFormatter(options, 0);
121
	}
122
123
	/**
124
	 * Create an instance of the built-in code formatter.
125
	 * <p>The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}),
126
	 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
127
	 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
128
	 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
129
	 * </p>
130
	 * <p>The given mode is a bitwise value. It is used to determine what options should be enabled when
131
	 * formatting the code.</p>
132
	 * <p>The list of bits used to set the mode includes only {@link #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS}, but
133
	 * other bits are left for future use.</p>
134
	 * 
135
	 * @param options the options map to use for formatting with the default code formatter. Recognized options
136
	 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use 
137
	 * 	the current settings from <code>JavaCore#getOptions</code>.
138
	 * @param mode the given mode to modify the given options.
139
	 *
140
	 * @return an instance of the built-in code formatter
141
	 * @see CodeFormatter
142
	 * @see JavaCore#getOptions()
143
	 * @since 3.3
144
	 */
145
	public static CodeFormatter createCodeFormatter(Map options, int mode) {
102
		if (options == null) options = JavaCore.getOptions();
146
		if (options == null) options = JavaCore.getOptions();
103
		return new DefaultCodeFormatter(options);
147
		Map currentOptions = new HashMap(options);
148
		if ((mode & M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS) == 0) {
149
			// disable the option for not indenting comments starting on first column
150
			currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
151
			currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
152
		}
153
		return new DefaultCodeFormatter(currentOptions);
104
	}
154
	}
105
155
106
	/**
156
	/**

Return to bug 185928