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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-46 / +125 lines)
Lines 108-113 Link Here
108
	/** disabling */
108
	/** disabling */
109
	boolean editsEnabled;
109
	boolean editsEnabled;
110
	boolean useTags;
110
	boolean useTags;
111
	int tagsKind;
111
112
112
	/* Comments formatting */
113
	/* Comments formatting */
113
	private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT;
114
	private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT;
Lines 1419-1424 Link Here
1419
1420
1420
	private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) {
1421
	private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) {
1421
		this.useTags = preferences.use_tags;
1422
		this.useTags = preferences.use_tags;
1423
		this.tagsKind = 0;
1422
		char[][] taskTags = null;
1424
		char[][] taskTags = null;
1423
		if (this.useTags) {
1425
		if (this.useTags) {
1424
			this.disablingTag = preferences.disabling_tag;
1426
			this.disablingTag = preferences.disabling_tag;
Lines 1433-1438 Link Here
1433
				taskTags = new char[][] { this.disablingTag, this.enablingTag };
1435
				taskTags = new char[][] { this.disablingTag, this.enablingTag };
1434
			}
1436
			}
1435
		}
1437
		}
1438
		if (taskTags != null) {
1439
			loop: for (int i=0,length=taskTags.length; i<length; i++) {
1440
				if (taskTags[i].length > 2 && taskTags[i][0] == '/') {
1441
					switch (taskTags[i][1]) {
1442
						case '/':
1443
							this.tagsKind = TerminalTokens.TokenNameCOMMENT_LINE;
1444
							break loop;
1445
						case '*':
1446
							if (taskTags[i][2] != '*') {
1447
								this.tagsKind = TerminalTokens.TokenNameCOMMENT_BLOCK;
1448
								break loop;
1449
							}
1450
							break;
1451
					}
1452
				}
1453
			}
1454
		}
1436
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/);
1455
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/);
1437
		this.editsEnabled = true;
1456
		this.editsEnabled = true;
1438
	}
1457
	}
Lines 2368-2378 Link Here
2368
			int lines = 0;
2387
			int lines = 0;
2369
			while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
2388
			while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
2370
				int foundTaskCount = this.scanner.foundTaskCount;
2389
				int foundTaskCount = this.scanner.foundTaskCount;
2390
				int tokenStartPosition = this.scanner.getCurrentTokenStartPosition();
2391
				int tokenEndPosition = this.scanner.getCurrentTokenEndPosition();
2371
				switch(this.currentToken) {
2392
				switch(this.currentToken) {
2372
					case TerminalTokens.TokenNameWHITESPACE :
2393
					case TerminalTokens.TokenNameWHITESPACE :
2373
						char[] whiteSpaces = this.scanner.getCurrentTokenSource();
2394
						char[] whiteSpaces = this.scanner.getCurrentTokenSource();
2374
						int whitespacesStartPosition = this.scanner.getCurrentTokenStartPosition();
2375
						int whitespacesEndPosition = this.scanner.getCurrentTokenEndPosition();
2376
						lines = 0;
2395
						lines = 0;
2377
						for (int i = 0, max = whiteSpaces.length; i < max; i++) {
2396
						for (int i = 0, max = whiteSpaces.length; i < max; i++) {
2378
							switch(whiteSpaces[i]) {
2397
							switch(whiteSpaces[i]) {
Lines 2445-2453 Link Here
2445
							// if a line comment is consumed, no other comment can be on the same line after
2464
							// if a line comment is consumed, no other comment can be on the same line after
2446
							if (hasLineComment) {
2465
							if (hasLineComment) {
2447
								if (lines >= 1) {
2466
								if (lines >= 1) {
2448
									currentTokenStartPosition = whitespacesStartPosition;
2467
									currentTokenStartPosition = tokenStartPosition;
2449
									preserveEmptyLines(lines, currentTokenStartPosition);
2468
									preserveEmptyLines(lines, currentTokenStartPosition);
2450
									addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
2469
									addDeleteEdit(currentTokenStartPosition, tokenEndPosition);
2451
									this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
2470
									this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
2452
									return;
2471
									return;
2453
								}
2472
								}
Lines 2457-2463 Link Here
2457
							// if one or several new lines are consumed, following comments cannot be considered as trailing ones
2476
							// if one or several new lines are consumed, following comments cannot be considered as trailing ones
2458
							if (lines >= 1) {
2477
							if (lines >= 1) {
2459
								if (hasComment) {
2478
								if (hasComment) {
2460
									this.printNewLine(whitespacesStartPosition);
2479
									this.printNewLine(tokenStartPosition);
2461
								}
2480
								}
2462
								this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
2481
								this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
2463
								return;
2482
								return;
Lines 2465-2501 Link Here
2465
							// delete consumed white spaces
2484
							// delete consumed white spaces
2466
							hasWhitespaces = true;
2485
							hasWhitespaces = true;
2467
							currentTokenStartPosition = this.scanner.currentPosition;
2486
							currentTokenStartPosition = this.scanner.currentPosition;
2468
							addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
2487
							addDeleteEdit(tokenStartPosition, tokenEndPosition);
2469
						} else {
2488
						} else {
2470
							if (lines == 0) {
2489
							if (lines == 0) {
2471
								hasWhitespaces = true;
2490
								hasWhitespaces = true;
2472
								addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
2491
								addDeleteEdit(tokenStartPosition, tokenEndPosition);
2473
							} else if (hasLineComment) {
2492
							} else if (hasLineComment) {
2474
								currentTokenStartPosition = whitespacesStartPosition;
2493
								currentTokenStartPosition = tokenStartPosition;
2475
								preserveEmptyLines(lines, currentTokenStartPosition);
2494
								preserveEmptyLines(lines, currentTokenStartPosition);
2476
								addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
2495
								addDeleteEdit(currentTokenStartPosition, tokenEndPosition);
2477
							} else if (hasComment) {
2496
							} else if (hasComment) {
2478
								if (lines == 1) {
2497
								if (lines == 1) {
2479
									this.printNewLine(whitespacesStartPosition);
2498
									this.printNewLine(tokenStartPosition);
2480
								} else {
2499
								} else {
2481
									preserveEmptyLines(lines - 1, whitespacesStartPosition);
2500
									preserveEmptyLines(lines - 1, tokenStartPosition);
2482
								}
2501
								}
2483
								addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
2502
								addDeleteEdit(tokenStartPosition, tokenEndPosition);
2484
							} else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) {
2503
							} else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) {
2485
								addReplaceEdit(whitespacesStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1));
2504
								addReplaceEdit(tokenStartPosition, tokenEndPosition, getPreserveEmptyLines(lines-1));
2486
							} else {
2505
							} else {
2487
								addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
2506
								addDeleteEdit(tokenStartPosition, tokenEndPosition);
2488
							}
2507
							}
2489
						}
2508
						}
2490
						currentTokenStartPosition = this.scanner.currentPosition;
2509
						currentTokenStartPosition = this.scanner.currentPosition;
2491
						break;
2510
						break;
2492
					case TerminalTokens.TokenNameCOMMENT_LINE :
2511
					case TerminalTokens.TokenNameCOMMENT_LINE :
2493
						if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
2512
						tokenEndPosition = -this.scanner.commentStops[this.scanner.commentPtr];
2494
							setEditsEnabled(foundTaskCount);
2513
						if (this.useTags && this.editsEnabled) {
2495
							if (!this.editsEnabled && this.editsIndex > 1) {
2514
							boolean turnOff = false;
2496
								OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
2515
							if (foundTaskCount > 0) {
2497
								if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
2516
								setEditsEnabled(foundTaskCount);
2498
									printNewLinesBeforeDisablingComment();
2517
								turnOff = true;
2518
							} else if (this.tagsKind == this.currentToken
2519
								&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition)) {
2520
    							this.editsEnabled = false;
2521
								turnOff = true;
2522
					    	}
2523
							if (turnOff) {
2524
								if (!this.editsEnabled && this.editsIndex > 1) {
2525
									OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
2526
									if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
2527
										printNewLinesBeforeDisablingComment();
2528
									}
2499
								}
2529
								}
2500
							}
2530
							}
2501
						}
2531
						}
Lines 2514-2530 Link Here
2514
						currentTokenStartPosition = this.scanner.currentPosition;
2544
						currentTokenStartPosition = this.scanner.currentPosition;
2515
						hasLineComment = true;
2545
						hasLineComment = true;
2516
						lines = 0;
2546
						lines = 0;
2517
						if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
2547
						if (this.useTags && !this.editsEnabled) {
2518
							setEditsEnabled(foundTaskCount);
2548
							if (foundTaskCount > 0) {
2549
								setEditsEnabled(foundTaskCount);
2550
							} else if (this.tagsKind == this.currentToken) {
2551
	    						this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition);
2552
					    	}
2519
						}
2553
						}
2520
						break;
2554
						break;
2521
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2555
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2522
						if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
2556
						if (this.useTags && this.editsEnabled) {
2523
							setEditsEnabled(foundTaskCount);
2557
							boolean turnOff = false;
2524
							if (!this.editsEnabled && this.editsIndex > 1) {
2558
							if (foundTaskCount > 0) {
2525
								OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
2559
								setEditsEnabled(foundTaskCount);
2526
								if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
2560
								turnOff = true;
2527
									printNewLinesBeforeDisablingComment();
2561
							} else if (this.tagsKind == this.currentToken
2562
								&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1)) {
2563
    							this.editsEnabled = false;
2564
								turnOff = true;
2565
					    	}
2566
							if (turnOff) {
2567
								if (!this.editsEnabled && this.editsIndex > 1) {
2568
									OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
2569
									if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
2570
										printNewLinesBeforeDisablingComment();
2571
									}
2528
								}
2572
								}
2529
							}
2573
							}
2530
						}
2574
						}
Lines 2550-2557 Link Here
2550
						hasLineComment = false;
2594
						hasLineComment = false;
2551
						hasComment = true;
2595
						hasComment = true;
2552
						lines = 0;
2596
						lines = 0;
2553
						if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
2597
						if (this.useTags && !this.editsEnabled) {
2554
							setEditsEnabled(foundTaskCount);
2598
							if (foundTaskCount > 0) {
2599
								setEditsEnabled(foundTaskCount);
2600
							} else if (this.tagsKind == this.currentToken) {
2601
	    						this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1);
2602
					    	}
2555
						}
2603
						}
2556
						break;
2604
						break;
2557
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
2605
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
Lines 4430-4435 Link Here
4430
			boolean hasModifiers = false;
4478
			boolean hasModifiers = false;
4431
			while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4479
			while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4432
				int foundTaskCount = this.scanner.foundTaskCount;
4480
				int foundTaskCount = this.scanner.foundTaskCount;
4481
				int tokenStartPosition = this.scanner.getCurrentTokenStartPosition();
4482
				int tokenEndPosition = this.scanner.getCurrentTokenEndPosition();
4433
				switch(this.currentToken) {
4483
				switch(this.currentToken) {
4434
					case TerminalTokens.TokenNamepublic :
4484
					case TerminalTokens.TokenNamepublic :
4435
					case TerminalTokens.TokenNameprotected :
4485
					case TerminalTokens.TokenNameprotected :
Lines 4494-4528 Link Here
4494
						break;
4544
						break;
4495
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
4545
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
4496
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
4546
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
4497
						if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
4547
						if (this.useTags && this.editsEnabled) {
4498
							setEditsEnabled(foundTaskCount);
4548
							boolean turnOff = false;
4499
							if (!this.editsEnabled && this.editsIndex > 1) {
4549
							if (foundTaskCount > 0) {
4500
								OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
4550
								setEditsEnabled(foundTaskCount);
4501
								if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
4551
								turnOff = true;
4502
									printNewLinesBeforeDisablingComment();
4552
							} else if (this.tagsKind == this.currentToken
4553
								&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1)) {
4554
    							this.editsEnabled = false;
4555
								turnOff = true;
4556
					    	}
4557
							if (turnOff) {
4558
								if (!this.editsEnabled && this.editsIndex > 1) {
4559
									OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
4560
									if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
4561
										printNewLinesBeforeDisablingComment();
4562
									}
4503
								}
4563
								}
4504
							}
4564
							}
4505
						}
4565
						}
4506
						printBlockComment(this.currentToken == TerminalTokens.TokenNameCOMMENT_JAVADOC);
4566
						printBlockComment(this.currentToken == TerminalTokens.TokenNameCOMMENT_JAVADOC);
4507
						if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
4567
						if (this.useTags && !this.editsEnabled) {
4508
							setEditsEnabled(foundTaskCount);
4568
							if (foundTaskCount > 0) {
4569
								setEditsEnabled(foundTaskCount);
4570
							} else if (this.tagsKind == this.currentToken) {
4571
	    						this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1);
4572
					    	}
4509
						}
4573
						}
4510
						currentTokenStartPosition = this.scanner.currentPosition;
4574
						currentTokenStartPosition = this.scanner.currentPosition;
4511
						hasComment = true;
4575
						hasComment = true;
4512
						break;
4576
						break;
4513
					case TerminalTokens.TokenNameCOMMENT_LINE :
4577
					case TerminalTokens.TokenNameCOMMENT_LINE :
4514
						if (this.useTags && this.editsEnabled && foundTaskCount > 0) {
4578
						tokenEndPosition = -this.scanner.commentStops[this.scanner.commentPtr];
4515
							setEditsEnabled(foundTaskCount);
4579
						if (this.useTags && this.editsEnabled) {
4516
							if (!this.editsEnabled && this.editsIndex > 1) {
4580
							boolean turnOff = false;
4517
								OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
4581
							if (foundTaskCount > 0) {
4518
								if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
4582
								setEditsEnabled(foundTaskCount);
4519
									printNewLinesBeforeDisablingComment();
4583
								turnOff = true;
4584
							} else if (this.tagsKind == this.currentToken
4585
								&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition)) {
4586
    							this.editsEnabled = false;
4587
								turnOff = true;
4588
					    	}
4589
							if (turnOff) {
4590
								if (!this.editsEnabled && this.editsIndex > 1) {
4591
									OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1];
4592
									if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) {
4593
										printNewLinesBeforeDisablingComment();
4594
									}
4520
								}
4595
								}
4521
							}
4596
							}
4522
						}
4597
						}
4523
						printLineComment();
4598
						printLineComment();
4524
						if (this.useTags && !this.editsEnabled && foundTaskCount > 0) {
4599
						if (this.useTags && !this.editsEnabled) {
4525
							setEditsEnabled(foundTaskCount);
4600
							if (foundTaskCount > 0) {
4601
								setEditsEnabled(foundTaskCount);
4602
							} else if (this.tagsKind == this.currentToken) {
4603
	    						this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition);
4604
					    	}
4526
						}
4605
						}
4527
						currentTokenStartPosition = this.scanner.currentPosition;
4606
						currentTokenStartPosition = this.scanner.currentPosition;
4528
						break;
4607
						break;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (-3 / +346 lines)
Lines 6046-6051 Link Here
6046
}
6046
}
6047
6047
6048
/**
6048
/**
6049
 * @bug 311578: [formatter] Enable/disable tag detection should include comment start/end tokens
6050
 * @test Ensure that the formatter now accepts tags with comment start/end tokens
6051
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311578"
6052
 */
6053
public void testBug311578a() throws JavaModelException {
6054
	this.formatterPrefs.use_tags = true;
6055
	this.formatterPrefs.disabling_tag = "//J-".toCharArray();
6056
	this.formatterPrefs.enabling_tag = "//J+".toCharArray();
6057
	String source =
6058
		"package a;\n" + 
6059
		"public class Bug {\n" + 
6060
		"int a      =  -     1  +    42;\n" + 
6061
		"\n" + 
6062
		"//J-\n" + 
6063
		"int b      =  -     1  +    42;\n" + 
6064
		"//J+\n" + 
6065
		"\n" + 
6066
		"char                       x;\n" + 
6067
		"\n" + 
6068
		"////J-\n" + 
6069
		"int c      =  -     1  +    42;\n" + 
6070
		"////J+\n" + 
6071
		"\n" + 
6072
		"char                       y;\n" + 
6073
		"\n" + 
6074
		"/* J- */\n" + 
6075
		"int d      =  -     1  +    42;\n" + 
6076
		"/* J+ */\n" + 
6077
		"\n" + 
6078
		"char                       z;\n" + 
6079
		"\n" + 
6080
		"/* //J- */\n" + 
6081
		"int e      =  -     1  +    42;\n" + 
6082
		"/* //J+ */\n" + 
6083
		"\n" + 
6084
		"/** J-1 blabla */\n" + 
6085
		"char                       t;\n" + 
6086
		"}\n";
6087
	formatSource(source,
6088
		"package a;\n" + 
6089
		"\n" + 
6090
		"public class Bug {\n" + 
6091
		"	int a = -1 + 42;\n" + 
6092
		"\n" + 
6093
		"//J-\n" + 
6094
		"int b      =  -     1  +    42;\n" + 
6095
		"//J+\n" + 
6096
		"\n" + 
6097
		"	char x;\n" + 
6098
		"\n" + 
6099
		"////J-\n" + 
6100
		"int c      =  -     1  +    42;\n" + 
6101
		"////J+\n" + 
6102
		"\n" + 
6103
		"	char y;\n" + 
6104
		"\n" + 
6105
		"	/* J- */\n" + 
6106
		"	int d = -1 + 42;\n" + 
6107
		"	/* J+ */\n" + 
6108
		"\n" + 
6109
		"	char z;\n" + 
6110
		"\n" + 
6111
		"/* //J- */\n" + 
6112
		"int e      =  -     1  +    42;\n" + 
6113
		"/* //J+ */\n" + 
6114
		"\n" + 
6115
		"	/** J-1 blabla */\n" + 
6116
		"	char t;\n" + 
6117
		"}\n"
6118
	);
6119
}
6120
public void testBug311578b() throws JavaModelException {
6121
	this.formatterPrefs.use_tags = true;
6122
	this.formatterPrefs.disabling_tag = "/* J- */".toCharArray();
6123
	this.formatterPrefs.enabling_tag = "/* J+ */".toCharArray();
6124
	String source =
6125
		"package a;\n" + 
6126
		"public class Bug {\n" + 
6127
		"int a      =  -     1  +    42;\n" + 
6128
		"\n" + 
6129
		"//J-\n" + 
6130
		"int b      =  -     1  +    42;\n" + 
6131
		"//J+\n" + 
6132
		"\n" + 
6133
		"char                       x;\n" + 
6134
		"\n" + 
6135
		"////J-\n" + 
6136
		"int c      =  -     1  +    42;\n" + 
6137
		"////J+\n" + 
6138
		"\n" + 
6139
		"char                       y;\n" + 
6140
		"\n" + 
6141
		"/* J- */\n" + 
6142
		"int d      =  -     1  +    42;\n" + 
6143
		"/* J+ */\n" + 
6144
		"\n" + 
6145
		"char                       z;\n" + 
6146
		"\n" + 
6147
		"/* //J- */\n" + 
6148
		"int e      =  -     1  +    42;\n" + 
6149
		"/* //J+ */\n" + 
6150
		"\n" + 
6151
		"/** J-1 blabla */\n" + 
6152
		"char                       t;\n" + 
6153
		"}\n";
6154
	formatSource(source,
6155
		"package a;\n" + 
6156
		"\n" + 
6157
		"public class Bug {\n" + 
6158
		"	int a = -1 + 42;\n" + 
6159
		"\n" + 
6160
		"	// J-\n" + 
6161
		"	int b = -1 + 42;\n" + 
6162
		"	// J+\n" + 
6163
		"\n" + 
6164
		"	char x;\n" + 
6165
		"\n" + 
6166
		"	// //J-\n" + 
6167
		"	int c = -1 + 42;\n" + 
6168
		"	// //J+\n" + 
6169
		"\n" + 
6170
		"	char y;\n" + 
6171
		"\n" + 
6172
		"/* J- */\n" + 
6173
		"int d      =  -     1  +    42;\n" + 
6174
		"/* J+ */\n" + 
6175
		"\n" + 
6176
		"	char z;\n" + 
6177
		"\n" + 
6178
		"	/* //J- */\n" + 
6179
		"	int e = -1 + 42;\n" + 
6180
		"	/* //J+ */\n" + 
6181
		"\n" + 
6182
		"	/** J-1 blabla */\n" + 
6183
		"	char t;\n" + 
6184
		"}\n"
6185
	);
6186
}
6187
public void testBug311578c() throws JavaModelException {
6188
	this.formatterPrefs = null;
6189
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE);
6190
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "//F--");
6191
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "//F++");
6192
	String source =
6193
		"package a;\n" + 
6194
		"public class Bug {\n" + 
6195
		"int a      =  -     1  +    42;\n" + 
6196
		"\n" + 
6197
		"//F--\n" + 
6198
		"int b      =  -     1  +    42;\n" + 
6199
		"//F++\n" + 
6200
		"\n" + 
6201
		"char                       x;\n" + 
6202
		"\n" + 
6203
		"////F--\n" + 
6204
		"int c      =  -     1  +    42;\n" + 
6205
		"////F++\n" + 
6206
		"\n" + 
6207
		"char                       y;\n" + 
6208
		"\n" + 
6209
		"/* F-- */\n" + 
6210
		"int d      =  -     1  +    42;\n" + 
6211
		"/* F++ */\n" + 
6212
		"\n" + 
6213
		"char                       z;\n" + 
6214
		"\n" + 
6215
		"/* //F-- */\n" + 
6216
		"int e      =  -     1  +    42;\n" + 
6217
		"/* //F++ */\n" + 
6218
		"\n" + 
6219
		"/** F--1 blabla */\n" + 
6220
		"char                       t;\n" + 
6221
		"}\n";
6222
	formatSource(source,
6223
		"package a;\n" + 
6224
		"\n" + 
6225
		"public class Bug {\n" + 
6226
		"	int a = -1 + 42;\n" + 
6227
		"\n" + 
6228
		"//F--\n" + 
6229
		"int b      =  -     1  +    42;\n" + 
6230
		"//F++\n" + 
6231
		"\n" + 
6232
		"	char x;\n" + 
6233
		"\n" + 
6234
		"////F--\n" + 
6235
		"int c      =  -     1  +    42;\n" + 
6236
		"////F++\n" + 
6237
		"\n" + 
6238
		"	char y;\n" + 
6239
		"\n" + 
6240
		"	/* F-- */\n" + 
6241
		"	int d = -1 + 42;\n" + 
6242
		"	/* F++ */\n" + 
6243
		"\n" + 
6244
		"	char z;\n" + 
6245
		"\n" + 
6246
		"/* //F-- */\n" + 
6247
		"int e      =  -     1  +    42;\n" + 
6248
		"/* //F++ */\n" + 
6249
		"\n" + 
6250
		"	/** F--1 blabla */\n" + 
6251
		"	char t;\n" + 
6252
		"}\n"
6253
	);
6254
}
6255
public void testBug311578d() throws JavaModelException {
6256
	this.formatterPrefs = null;
6257
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE);
6258
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "/*F--*/");
6259
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "/*F++*/");
6260
	String source =
6261
		"package a;\n" + 
6262
		"public class Bug {\n" + 
6263
		"int a      =  -     1  +    42;\n" + 
6264
		"\n" + 
6265
		"//F--\n" + 
6266
		"int b      =  -     1  +    42;\n" + 
6267
		"//F++\n" + 
6268
		"\n" + 
6269
		"char                       x;\n" + 
6270
		"\n" + 
6271
		"////F--\n" + 
6272
		"int c      =  -     1  +    42;\n" + 
6273
		"////F++\n" + 
6274
		"\n" + 
6275
		"char                       y;\n" + 
6276
		"\n" + 
6277
		"/* F-- */\n" + 
6278
		"int d      =  -     1  +    42;\n" + 
6279
		"/* F++ */\n" + 
6280
		"\n" + 
6281
		"char                       y2;\n" + 
6282
		"\n" + 
6283
		"/*F--*/\n" + 
6284
		"int d2      =  -     1  +    42;\n" + 
6285
		"/*F++*/\n" + 
6286
		"\n" + 
6287
		"char                       z;\n" + 
6288
		"\n" + 
6289
		"/* //F-- */\n" + 
6290
		"int e      =  -     1  +    42;\n" + 
6291
		"/* //F++ */\n" + 
6292
		"\n" + 
6293
		"/** F--1 blabla */\n" + 
6294
		"char                       t;\n" + 
6295
		"}\n";
6296
	formatSource(source,
6297
		"package a;\n" + 
6298
		"\n" + 
6299
		"public class Bug {\n" + 
6300
		"	int a = -1 + 42;\n" + 
6301
		"\n" + 
6302
		"	// F--\n" + 
6303
		"	int b = -1 + 42;\n" + 
6304
		"	// F++\n" + 
6305
		"\n" + 
6306
		"	char x;\n" + 
6307
		"\n" + 
6308
		"	// //F--\n" + 
6309
		"	int c = -1 + 42;\n" + 
6310
		"	// //F++\n" + 
6311
		"\n" + 
6312
		"	char y;\n" + 
6313
		"\n" + 
6314
		"	/* F-- */\n" + 
6315
		"	int d = -1 + 42;\n" + 
6316
		"	/* F++ */\n" + 
6317
		"\n" + 
6318
		"	char y2;\n" + 
6319
		"\n" + 
6320
		"/*F--*/\n" + 
6321
		"int d2      =  -     1  +    42;\n" + 
6322
		"/*F++*/\n" + 
6323
		"\n" + 
6324
		"	char z;\n" + 
6325
		"\n" + 
6326
		"	/* //F-- */\n" + 
6327
		"	int e = -1 + 42;\n" + 
6328
		"	/* //F++ */\n" + 
6329
		"\n" + 
6330
		"	/** F--1 blabla */\n" + 
6331
		"	char t;\n" + 
6332
		"}\n"
6333
	);
6334
}
6335
public void testBug311578_320754a() throws JavaModelException {
6336
	this.formatterPrefs.use_tags = true;
6337
	this.formatterPrefs.disabling_tag = "//J-".toCharArray();
6338
	this.formatterPrefs.enabling_tag = "//J+".toCharArray();
6339
	String source =
6340
		"//J-\n" + 
6341
		"@MyAnnot (\n" + 
6342
		"  testAttribute = {\"test1\", \"test2\", \"test3\"}\n" + 
6343
		")\n" + 
6344
		"//J+\n" + 
6345
		"public class X\n" + 
6346
		"{\n" + 
6347
		"    public void foo()\n" + 
6348
		"    {\n" + 
6349
		"    }\n" + 
6350
		"}\n";
6351
	formatSource(source,
6352
		"//J-\n" + 
6353
		"@MyAnnot (\n" + 
6354
		"  testAttribute = {\"test1\", \"test2\", \"test3\"}\n" + 
6355
		")\n" + 
6356
		"//J+\n" + 
6357
		"public class X {\n" + 
6358
		"	public void foo() {\n" + 
6359
		"	}\n" + 
6360
		"}\n"
6361
	);
6362
}
6363
public void testBug311578_320754b() throws JavaModelException {
6364
	this.formatterPrefs.use_tags = true;
6365
	this.formatterPrefs.disabling_tag = "/*J-*/".toCharArray();
6366
	this.formatterPrefs.enabling_tag = "/*J+*/".toCharArray();
6367
	String source =
6368
		"/*J-*/\n" + 
6369
		"@MyAnnot (\n" + 
6370
		"  testAttribute = {\"test1\", \"test2\", \"test3\"}\n" + 
6371
		")\n" + 
6372
		"/*J+*/\n" + 
6373
		"public class X\n" + 
6374
		"{\n" + 
6375
		"    public void foo()\n" + 
6376
		"    {\n" + 
6377
		"    }\n" + 
6378
		"}\n";
6379
	formatSource(source,
6380
		"/*J-*/\n" + 
6381
		"@MyAnnot (\n" + 
6382
		"  testAttribute = {\"test1\", \"test2\", \"test3\"}\n" + 
6383
		")\n" + 
6384
		"/*J+*/\n" + 
6385
		"public class X {\n" + 
6386
		"	public void foo() {\n" + 
6387
		"	}\n" + 
6388
		"}\n"
6389
	);
6390
}
6391
6392
/**
6049
 * @bug 311582: [formatter] Master switch to enable/disable on/off tags
6393
 * @bug 311582: [formatter] Master switch to enable/disable on/off tags
6050
 * @test Ensure that the formatter does not take care of formatting tags by default
6394
 * @test Ensure that the formatter does not take care of formatting tags by default
6051
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311582"
6395
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311582"
Lines 6693-6701 Link Here
6693
}
7037
}
6694
7038
6695
/**
7039
/**
6696
 * @bug 320754: [formatter] Add preference for improved lines wrapping in nested method calls
7040
 * @bug 320754: [formatter] formatter:off/on tags does not work correctly
6697
 * @test Ensure that the formatter keep previous eclipse versions behavior when
7041
 * @test Ensure disabling/enabling tags work properly around annotations
6698
 * 		the "Try to keep nested expressions on one line" preference is set.
6699
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=320754"
7042
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=320754"
6700
 */
7043
 */
6701
public void testBug320754_00() throws JavaModelException {
7044
public void testBug320754_00() throws JavaModelException {

Return to bug 311578