View | Details | Raw Unified | Return to bug 311617
Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (-2 / +2 lines)
Lines 873-879 Link Here
873
	 * FORMATTER / Option to define the tag to put in a comment to disable the formatting.
873
	 * FORMATTER / Option to define the tag to put in a comment to disable the formatting.
874
	 *     - option id:         "org.eclipse.jdt.core.formatter.disabling_tag"
874
	 *     - option id:         "org.eclipse.jdt.core.formatter.disabling_tag"
875
	 *     - possible values:   String, with constraints mentioned below
875
	 *     - possible values:   String, with constraints mentioned below
876
	 *     - default:           ""
876
	 *     - default:           "@formatter:off"
877
	 * 
877
	 * 
878
	 * See the {@link #FORMATTER_ENABLING_TAG} option to re-enable it.
878
	 * See the {@link #FORMATTER_ENABLING_TAG} option to re-enable it.
879
	 * </pre>
879
	 * </pre>
Lines 962-968 Link Here
962
	 * FORMATTER / Option to define the tag to put in a comment to re-enable the formatting after it has been disabled (see {@link #FORMATTER_DISABLING_TAG})
962
	 * FORMATTER / Option to define the tag to put in a comment to re-enable the formatting after it has been disabled (see {@link #FORMATTER_DISABLING_TAG})
963
	 *     - option id:         "org.eclipse.jdt.core.formatter.enabling_tag"
963
	 *     - option id:         "org.eclipse.jdt.core.formatter.enabling_tag"
964
	 *     - possible values:   String, with constraints mentioned below
964
	 *     - possible values:   String, with constraints mentioned below
965
	 *     - default:           ""
965
	 *     - default:           "@formatter:on"
966
	 * </pre>
966
	 * </pre>
967
	 * 
967
	 * 
968
	 * <p>
968
	 * <p>
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-2 / +8 lines)
Lines 120-125 Link Here
120
	public boolean use_tags;
120
	public boolean use_tags;
121
	public char[] disabling_tag;
121
	public char[] disabling_tag;
122
	public char[] enabling_tag;
122
	public char[] enabling_tag;
123
	private final static char[] DEFAULT_DISABLING_TAG = "@formatter:off".toCharArray(); //$NON-NLS-1$
124
	private final static char[] DEFAULT_ENABLING_TAG = "@formatter:on".toCharArray(); //$NON-NLS-1$
123
125
124
	public boolean indent_statements_compare_to_block;
126
	public boolean indent_statements_compare_to_block;
125
	public boolean indent_statements_compare_to_body;
127
	public boolean indent_statements_compare_to_body;
Lines 1973-1979 Link Here
1973
					if (tag.length() == 0) {
1975
					if (tag.length() == 0) {
1974
						this.disabling_tag = null;
1976
						this.disabling_tag = null;
1975
					} else {
1977
					} else {
1976
					this.disabling_tag = tag.toCharArray();
1978
						this.disabling_tag = tag.toCharArray();
1977
					}
1979
					}
1978
				}
1980
				}
1979
			}
1981
			}
Lines 1990-1996 Link Here
1990
					if (tag.length() == 0) {
1992
					if (tag.length() == 0) {
1991
						this.enabling_tag = null;
1993
						this.enabling_tag = null;
1992
					} else {
1994
					} else {
1993
					this.enabling_tag = tag.toCharArray();
1995
						this.enabling_tag = tag.toCharArray();
1994
					}
1996
					}
1995
				}
1997
				}
1996
			}
1998
			}
Lines 2306-2311 Link Here
2306
		this.use_tabs_only_for_leading_indentations = false;
2308
		this.use_tabs_only_for_leading_indentations = false;
2307
		this.wrap_before_binary_operator = true;
2309
		this.wrap_before_binary_operator = true;
2308
		this.use_tags = false;
2310
		this.use_tags = false;
2311
		this.disabling_tag = DEFAULT_DISABLING_TAG;
2312
		this.enabling_tag = DEFAULT_ENABLING_TAG;
2309
	}
2313
	}
2310
2314
2311
	public void setEclipseDefaultSettings() {
2315
	public void setEclipseDefaultSettings() {
Lines 2578-2582 Link Here
2578
		this.use_tabs_only_for_leading_indentations = false;
2582
		this.use_tabs_only_for_leading_indentations = false;
2579
		this.wrap_before_binary_operator = true;
2583
		this.wrap_before_binary_operator = true;
2580
		this.use_tags = false;
2584
		this.use_tags = false;
2585
		this.disabling_tag = DEFAULT_DISABLING_TAG;
2586
		this.enabling_tag = DEFAULT_ENABLING_TAG;
2581
	}
2587
	}
2582
}
2588
}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+46 lines)
Lines 6063-6066 Link Here
6063
	);
6063
	);
6064
}
6064
}
6065
6065
6066
/**
6067
 * @bug 311617: [formatter] Master switch to enable/disable on/off tags
6068
 * @test Ensure that the formatter does not take care of formatting tags by default
6069
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311617"
6070
 */
6071
public void testBug0311617() throws JavaModelException {
6072
	this.formatterPrefs.use_tags = true;
6073
	String source =
6074
		"public class X01 {\n" + 
6075
		"\n" + 
6076
		"/* @formatter:off */\n" + 
6077
		"void     foo(    )      {	\n" + 
6078
		"				//      unformatted       comment\n" + 
6079
		"}\n" + 
6080
		"/* @formatter:on */\n" + 
6081
		"void     bar(    )      {	\n" + 
6082
		"				//      formatted       comment\n" + 
6083
		"}\n" + 
6084
		"}\n";
6085
	formatSource(source,
6086
		"public class X01 {\n" + 
6087
		"\n" + 
6088
		"/* @formatter:off */\n" + 
6089
		"void     foo(    )      {	\n" + 
6090
		"				//      unformatted       comment\n" + 
6091
		"}\n" + 
6092
		"/* @formatter:on */\n" + 
6093
		"	void bar() {\n" + 
6094
		"		// formatted comment\n" + 
6095
		"	}\n" + 
6096
		"}\n"
6097
	);
6098
}
6099
public void testBug0311617b() {
6100
	this.formatterPrefs = null;
6101
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE);
6102
	String source =
6103
		"/* @formatter:off */\n" + 
6104
		"public class X01 {\n" + 
6105
		"void     foo(    )      {	\n" + 
6106
		"				//      unformatted       area\n" + 
6107
		"}\n" + 
6108
		"}\n";
6109
	formatSource(source);
6110
}
6111
6066
}
6112
}

Return to bug 311617