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

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-4 / +10 lines)
Lines 1298-1305 Link Here
1298
		this.disablingTag = preferences.disabling_tag;
1298
		this.disablingTag = preferences.disabling_tag;
1299
		this.enablingTag = preferences.enabling_tag;
1299
		this.enablingTag = preferences.enabling_tag;
1300
		char[][] taskTags;
1300
		char[][] taskTags;
1301
		if (this.disablingTag == null && this.enablingTag == null) {
1301
		if (this.disablingTag == null) {
1302
			taskTags = null;
1302
			if (this.enablingTag == null) {
1303
				taskTags = null;
1304
			} else {
1305
				taskTags = new char[][] { this.enablingTag };
1306
			}
1307
		} else if (this.enablingTag == null) {
1308
			taskTags = new char[][] { this.disablingTag };
1303
		} else {
1309
		} else {
1304
			taskTags = new char[][] { this.disablingTag, this.enablingTag };
1310
			taskTags = new char[][] { this.disablingTag, this.enablingTag };
1305
		}
1311
		}
Lines 4742-4751 Link Here
4742
	 */
4748
	 */
4743
	private void setEditsEnabled(int count, int previous) {
4749
	private void setEditsEnabled(int count, int previous) {
4744
		for (int i=previous; i<count; i++) {
4750
		for (int i=previous; i<count; i++) {
4745
			if (CharOperation.equals(this.scanner.foundTaskTags[i], this.disablingTag)) {
4751
			if (this.disablingTag != null && CharOperation.equals(this.scanner.foundTaskTags[i], this.disablingTag)) {
4746
				this.editsEnabled = false;
4752
				this.editsEnabled = false;
4747
			}
4753
			}
4748
			if (CharOperation.equals(this.scanner.foundTaskTags[i], this.enablingTag)) {
4754
			if (this.enablingTag != null && CharOperation.equals(this.scanner.foundTaskTags[i], this.enablingTag)) {
4749
				this.editsEnabled = true;
4755
				this.editsEnabled = true;
4750
			}
4756
			}
4751
		}
4757
		}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+98 lines)
Lines 5275-5278 Link Here
5275
	);
5275
	);
5276
}
5276
}
5277
5277
5278
/**
5279
 * @bug 304529: [formatter] NPE when either the disabling or the enabling tag is not defined
5280
 * @test Verify that having an empty disabling or enabling is now accepted by the formatter
5281
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304529"
5282
 */
5283
public void testBug304529() {
5284
	this.formatterPrefs.disabling_tag = "off".toCharArray();
5285
	this.formatterPrefs.enabling_tag = null;
5286
	String source =
5287
		"/* off */\n" + 
5288
		"public class X01 {\n" + 
5289
		"void     foo(    )      {	\n" + 
5290
		"				//      unformatted       area\n" + 
5291
		"}\n" + 
5292
		"}\n";
5293
	formatSource(source);
5294
}
5295
public void testBug304529b() {
5296
	this.formatterPrefs.disabling_tag = null;
5297
	this.formatterPrefs.enabling_tag = "on".toCharArray();
5298
	String source =
5299
		"/* on */\n" + 
5300
		"public class X01 {\n" + 
5301
		"void     foo(    )      {	\n" + 
5302
		"				//      formatted       area\n" + 
5303
		"}\n" + 
5304
		"}\n";
5305
	formatSource(source,
5306
		"/* on */\n" + 
5307
		"public class X01 {\n" + 
5308
		"	void foo() {\n" + 
5309
		"		// formatted area\n" + 
5310
		"	}\n" + 
5311
		"}\n"
5312
	);
5313
}
5314
public void testBug304529c() {
5315
	this.formatterPrefs = null;
5316
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off");
5317
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "");
5318
	String source =
5319
		"/* off */\n" + 
5320
		"public class X01 {\n" + 
5321
		"void     foo(    )      {	\n" + 
5322
		"				//      unformatted       area\n" + 
5323
		"}\n" + 
5324
		"}\n";
5325
	formatSource(source);
5326
}
5327
public void testBug304529d() {
5328
	this.formatterPrefs = null;
5329
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "");
5330
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on");
5331
	String source =
5332
		"/* on */\n" + 
5333
		"public class X01 {\n" + 
5334
		"void     foo(    )      {	\n" + 
5335
		"				//      formatted       area\n" + 
5336
		"}\n" + 
5337
		"}\n";
5338
	formatSource(source,
5339
		"/* on */\n" + 
5340
		"public class X01 {\n" + 
5341
		"	void foo() {\n" + 
5342
		"		// formatted area\n" + 
5343
		"	}\n" + 
5344
		"}\n"
5345
	);
5346
}
5347
public void testBug304529e() {
5348
	this.formatterPrefs = null;
5349
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off");
5350
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on");
5351
	String source =
5352
		"public class X01 {\n" + 
5353
		"/* off */\n" + 
5354
		"void     foo(    )      {	\n" + 
5355
		"				//      unformatted       area\n" + 
5356
		"}\n" + 
5357
		"/* on */\n" + 
5358
		"void     bar(    )      {	\n" + 
5359
		"				//      formatted       area\n" + 
5360
		"}\n" + 
5361
		"}\n";
5362
	formatSource(source,
5363
		"public class X01 {\n" + 
5364
		"/* off */\n" + 
5365
		"void     foo(    )      {	\n" + 
5366
		"				//      unformatted       area\n" + 
5367
		"}\n" + 
5368
		"/* on */\n" + 
5369
		"	void bar() {\n" + 
5370
		"		// formatted area\n" + 
5371
		"	}\n" + 
5372
		"}\n"
5373
	);
5374
}
5375
5278
}
5376
}

Return to bug 304529