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

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-222 / +309 lines)
Lines 172-181 Link Here
172
		TerminalTokens.TokenNameGREATER
172
		TerminalTokens.TokenNameGREATER
173
	};
173
	};
174
	public int lastLocalDeclarationSourceStart;
174
	public int lastLocalDeclarationSourceStart;
175
	int lastBinaryExpressionAlignmentBreakIndentation;
175
	private Scanner localScanner;
176
	private Scanner localScanner;
176
	public DefaultCodeFormatterOptions preferences;
177
	public DefaultCodeFormatterOptions preferences;
177
	public Scribe scribe;
178
	public Scribe scribe;
178
179
180
	// Binary expression positions storage
181
	final static long  EXPRESSIONS_POS_ENTER_EQUALITY = 1;
182
	final static long  EXPRESSIONS_POS_ENTER_TWO = 2;
183
	final static long  EXPRESSIONS_POS_BETWEEN_TWO = 3;
184
	final static long  EXPRESSIONS_POS_MASK = EXPRESSIONS_POS_BETWEEN_TWO;
185
	long expressionsPos;
186
	int expressionsDepth = -1;
187
188
	// Array initializers information
189
	int arrayInitializersDepth = -1;
190
179
	public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) {
191
	public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) {
180
		long sourceLevel = settings == null
192
		long sourceLevel = settings == null
181
			? ClassFileConstants.JDK1_3
193
			? ClassFileConstants.JDK1_3
Lines 421-482 Link Here
421
		BinaryExpressionFragmentBuilder builder = buildFragments(binaryExpression, scope);
433
		BinaryExpressionFragmentBuilder builder = buildFragments(binaryExpression, scope);
422
		final int fragmentsSize = builder.size();
434
		final int fragmentsSize = builder.size();
423
435
424
		if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) {
436
		if (this.expressionsDepth < 0) {
425
			this.scribe.printComment();
437
			this.expressionsDepth = 0;
426
			Alignment binaryExpressionAlignment = this.scribe.createAlignment(
438
		} else {
427
					Alignment.BINARY_EXPRESSION,
439
			this.expressionsDepth++;
428
					this.preferences.alignment_for_binary_expression,
440
			this.expressionsPos <<= 2;
429
					Alignment.R_OUTERMOST,
441
		}
430
					fragmentsSize,
442
		try {
431
					this.scribe.scanner.currentPosition);
443
			this.lastBinaryExpressionAlignmentBreakIndentation = 0;
432
			this.scribe.enterAlignment(binaryExpressionAlignment);
444
			if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) {
433
			boolean ok = false;
445
				int scribeLine = this.scribe.line;
434
			ASTNode[] fragments = builder.fragments();
446
				this.scribe.printComment();
435
			int[] operators = builder.operators();
447
				Alignment binaryExpressionAlignment = this.scribe.createAlignment(
436
			do {
448
						Alignment.BINARY_EXPRESSION,
437
				try {
449
						this.preferences.alignment_for_binary_expression,
438
					for (int i = 0; i < fragmentsSize - 1; i++) {
450
						Alignment.R_OUTERMOST,
439
						ASTNode fragment = fragments[i];
451
						fragmentsSize,
440
						fragment.traverse(this, scope);
452
						this.scribe.scanner.currentPosition);
441
						this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
453
				this.scribe.enterAlignment(binaryExpressionAlignment);
442
						if (this.scribe.lastNumberOfNewLines == 1) {
454
				boolean ok = false;
443
							// a new line has been inserted by printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT)
455
				ASTNode[] fragments = builder.fragments();
444
							this.scribe.indentationLevel = binaryExpressionAlignment.breakIndentationLevel;
456
				int[] operators = builder.operators();
445
						}
457
				do {
446
						if (this.preferences.wrap_before_binary_operator) {
458
					try {
447
							this.scribe.alignFragment(binaryExpressionAlignment, i);
459
						final int max = fragmentsSize - 1;
448
							this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator);
460
						for (int i = 0; i < max; i++) {
449
						} else {
461
							ASTNode fragment = fragments[i];
450
							this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator);
462
							fragment.traverse(this, scope);
451
							this.scribe.alignFragment(binaryExpressionAlignment, i);
463
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
452
						}
464
							if (this.scribe.lastNumberOfNewLines == 1) {
453
						if (operators[i] == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) {
465
								// a new line has been inserted while printing the comment
454
							// the next character is a minus (unary operator)
466
								// hence we need to use the break indentation level before printing next token...
455
							this.scribe.space();
467
								this.scribe.indentationLevel = binaryExpressionAlignment.breakIndentationLevel;
456
						}
468
							}
457
						if (this.preferences.insert_space_after_binary_operator) {
469
							if (this.preferences.wrap_before_binary_operator) {
458
							this.scribe.space();
470
								this.scribe.alignFragment(binaryExpressionAlignment, i);
471
								this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator);
472
							} else {
473
								this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator);
474
								this.scribe.alignFragment(binaryExpressionAlignment, i);
475
							}
476
							if (operators[i] == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) {
477
								// the next character is a minus (unary operator)
478
								this.scribe.space();
479
							}
480
							if (this.preferences.insert_space_after_binary_operator) {
481
								this.scribe.space();
482
							}
459
						}
483
						}
484
						fragments[max].traverse(this, scope);
485
						this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
486
						ok = true;
487
					} catch(AlignmentException e){
488
						this.scribe.redoAlignment(e);
460
					}
489
					}
461
					fragments[fragmentsSize - 1].traverse(this, scope);
490
				} while (!ok);
462
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
491
				this.scribe.exitAlignment(binaryExpressionAlignment, true);
463
					ok = true;
492
				if (this.scribe.line == scribeLine) {
464
				} catch(AlignmentException e){
493
					// The expression was not broken => reset last break indentation
465
					this.scribe.redoAlignment(e);
494
					this.lastBinaryExpressionAlignmentBreakIndentation = 0;
495
				} else {
496
					this.lastBinaryExpressionAlignmentBreakIndentation = binaryExpressionAlignment.breakIndentationLevel;
466
				}
497
				}
467
			} while (!ok);
498
			} else {
468
			this.scribe.exitAlignment(binaryExpressionAlignment, true);
499
				this.expressionsPos |= EXPRESSIONS_POS_ENTER_TWO;
469
		} else {
500
				binaryExpression.left.traverse(this, scope);
470
			binaryExpression.left.traverse(this, scope);
501
				this.expressionsPos &= ~EXPRESSIONS_POS_MASK;
471
			this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator);
502
				this.expressionsPos |= EXPRESSIONS_POS_BETWEEN_TWO;
472
			if (operator == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) {
503
				this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator, Scribe.PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION);
473
				// the next character is a minus (unary operator)
504
				if (operator == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) {
474
				this.scribe.space();
505
					// the next character is a minus (unary operator)
506
					this.scribe.space();
507
				}
508
				if (this.preferences.insert_space_after_binary_operator) {
509
					this.scribe.space();
510
				}
511
				binaryExpression.right.traverse(this, scope);
475
			}
512
			}
476
			if (this.preferences.insert_space_after_binary_operator) {
513
		}
477
				this.scribe.space();
514
		finally {
515
			this.expressionsDepth--;
516
			this.expressionsPos >>= 2;
517
			if (this.expressionsDepth < 0) {
518
				this.lastBinaryExpressionAlignmentBreakIndentation = 0;
478
			}
519
			}
479
			binaryExpression.right.traverse(this, scope);
480
		}
520
		}
481
		if (numberOfParens > 0) {
521
		if (numberOfParens > 0) {
482
			manageClosingParenthesizedExpression(binaryExpression, numberOfParens);
522
			manageClosingParenthesizedExpression(binaryExpression, numberOfParens);
Lines 494-506 Link Here
494
		if (numberOfParens > 0) {
534
		if (numberOfParens > 0) {
495
			manageOpeningParenthesizedExpression(binaryExpression, numberOfParens);
535
			manageOpeningParenthesizedExpression(binaryExpression, numberOfParens);
496
		}
536
		}
497
		binaryExpression.left.traverse(this, scope);
537
		if (this.expressionsDepth < 0) {
498
		this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator);
538
			this.expressionsDepth = 0;
499
		if (this.preferences.insert_space_after_binary_operator) {
539
		} else {
500
			this.scribe.space();
540
			this.expressionsDepth++;
541
			this.expressionsPos <<= 2;
542
		}
543
		try {
544
			this.expressionsPos |= EXPRESSIONS_POS_ENTER_EQUALITY;
545
			binaryExpression.left.traverse(this, scope);
546
			this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator, Scribe.PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION);
547
			if (this.preferences.insert_space_after_binary_operator) {
548
				this.scribe.space();
549
			}
550
			binaryExpression.right.traverse(this, scope);
551
		}
552
		finally {
553
			this.expressionsDepth--;
554
			this.expressionsPos >>= 2;
501
		}
555
		}
502
		binaryExpression.right.traverse(this, scope);
503
504
		if (numberOfParens > 0) {
556
		if (numberOfParens > 0) {
505
			manageClosingParenthesizedExpression(binaryExpression, numberOfParens);
557
			manageClosingParenthesizedExpression(binaryExpression, numberOfParens);
506
		}
558
		}
Lines 1254-1260 Link Here
1254
				this.scribe.indent();
1306
				this.scribe.indent();
1255
			}
1307
			}
1256
			formatStatements(scope, statements, true);
1308
			formatStatements(scope, statements, true);
1257
			this.scribe.printComment();
1309
			this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK);
1258
1310
1259
			if (this.preferences.indent_statements_compare_to_block) {
1311
			if (this.preferences.indent_statements_compare_to_block) {
1260
				this.scribe.unIndent();
1312
				this.scribe.unIndent();
Lines 1264-1270 Link Here
1264
			if (this.preferences.indent_statements_compare_to_block) {
1316
			if (this.preferences.indent_statements_compare_to_block) {
1265
				this.scribe.indent();
1317
				this.scribe.indent();
1266
			}
1318
			}
1267
			this.scribe.printComment();
1319
			this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK);
1268
1320
1269
			if (this.preferences.indent_statements_compare_to_block) {
1321
			if (this.preferences.indent_statements_compare_to_block) {
1270
				this.scribe.unIndent();
1322
				this.scribe.unIndent();
Lines 1273-1279 Link Here
1273
			if (this.preferences.indent_statements_compare_to_block) {
1325
			if (this.preferences.indent_statements_compare_to_block) {
1274
				this.scribe.indent();
1326
				this.scribe.indent();
1275
			}
1327
			}
1276
			this.scribe.printComment();
1328
			this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK);
1277
1329
1278
			if (this.preferences.indent_statements_compare_to_block) {
1330
			if (this.preferences.indent_statements_compare_to_block) {
1279
				this.scribe.unIndent();
1331
				this.scribe.unIndent();
Lines 1582-1601 Link Here
1582
	}
1634
	}
1583
1635
1584
	private void formatLeftCurlyBrace(final int line, final String bracePosition) {
1636
	private void formatLeftCurlyBrace(final int line, final String bracePosition) {
1585
		this.scribe.formatBrace = true;
1586
		/*
1637
		/*
1587
		 * deal with (quite unexpected) comments right before lcurly
1638
		 * deal with (quite unexpected) comments right before lcurly
1588
		 */
1639
		 */
1589
		try {
1640
		this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE);
1590
			this.scribe.printComment();
1641
		if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition)
1591
			if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition)
1642
				&& (this.scribe.line > line || this.scribe.column >= this.preferences.page_width))
1592
					&& (this.scribe.line > line || this.scribe.column >= this.preferences.page_width))
1643
		{
1593
			{
1644
			this.scribe.printNewLine();
1594
				this.scribe.printNewLine();
1595
			}
1596
		}
1597
		finally {
1598
			this.scribe.formatBrace = false;
1599
		}
1645
		}
1600
	}
1646
	}
1601
1647
Lines 1736-1741 Link Here
1736
							if (i > 0) {
1782
							if (i > 0) {
1737
								this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
1783
								this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
1738
								this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1784
								this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1785
								if (this.scribe.lastNumberOfNewLines == 1) {
1786
									// a new line has been inserted while printing the comment
1787
									// hence we need to use the break indentation level before printing next token...
1788
									this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel;
1789
								}
1739
							}
1790
							}
1740
							this.scribe.alignFragment(argumentsAlignment, i);
1791
							this.scribe.alignFragment(argumentsAlignment, i);
1741
							if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1792
							if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
Lines 1806-1811 Link Here
1806
						if (i > 0) {
1857
						if (i > 0) {
1807
							this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma);
1858
							this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma);
1808
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1859
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1860
							if (this.scribe.lastNumberOfNewLines == 1) {
1861
								// a new line has been inserted while printing the comment
1862
								// hence we need to use the break indentation level before printing next token...
1863
								this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel;
1864
							}
1809
						}
1865
						}
1810
						this.scribe.alignFragment(argumentsAlignment, i);
1866
						this.scribe.alignFragment(argumentsAlignment, i);
1811
						if (i == 0) {
1867
						if (i == 0) {
Lines 1907-1913 Link Here
1907
				this.scribe.printNewLine();
1963
				this.scribe.printNewLine();
1908
				this.scribe.indent();
1964
				this.scribe.indent();
1909
			}
1965
			}
1910
			this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace);
1966
			this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace, Scribe.PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE);
1911
			this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT);
1967
			this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT);
1912
	}
1968
	}
1913
	private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) {
1969
	private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) {
Lines 2111-2117 Link Here
2111
			this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
2167
			this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
2112
			this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2168
			this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2113
		}
2169
		}
2114
		this.scribe.printComment();
2170
		this.scribe.printComment(Scribe.DO_NOT_PRESERVE_EMPTY_LINES);
2115
		this.scribe.exitMemberAlignment(memberAlignment);
2171
		this.scribe.exitMemberAlignment(memberAlignment);
2116
	}
2172
	}
2117
2173
Lines 2581-2696 Link Here
2581
	/**
2637
	/**
2582
	 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
2638
	 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
2583
	 */
2639
	 */
2584
	public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) {		final int numberOfParens = (arrayInitializer.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
2640
	public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) {
2641
		final int numberOfParens = (arrayInitializer.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
2585
		if (numberOfParens > 0) {
2642
		if (numberOfParens > 0) {
2586
			manageOpeningParenthesizedExpression(arrayInitializer, numberOfParens);
2643
			manageOpeningParenthesizedExpression(arrayInitializer, numberOfParens);
2587
		}
2644
		}
2588
2645
2589
		final Expression[] expressions = arrayInitializer.expressions;
2646
		if (this.arrayInitializersDepth < 0) {
2590
		if (expressions != null) {
2647
			this.arrayInitializersDepth = 0;
2591
			String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer;
2648
		} else {
2592
			formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2649
			this.arrayInitializersDepth++;
2593
2650
		}
2594
			int expressionsLength = expressions.length;
2651
		int arrayInitializerIndentationLevel = this.scribe.indentationLevel;
2595
			final boolean insert_new_line_after_opening_brace = this.preferences.insert_new_line_after_opening_brace_in_array_initializer;
2652
		try {
2596
			if (expressionsLength > 1) {
2653
			final Expression[] expressions = arrayInitializer.expressions;
2597
				if (insert_new_line_after_opening_brace) {
2654
			if (expressions != null) {
2598
					this.scribe.printNewLine();
2655
				String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer;
2599
				}
2656
				formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2600
				Alignment arrayInitializerAlignment =this.scribe.createAlignment(
2601
						Alignment.ARRAY_INITIALIZER,
2602
						this.preferences.alignment_for_expressions_in_array_initializer,
2603
						Alignment.R_OUTERMOST,
2604
						expressionsLength,
2605
						this.scribe.scanner.currentPosition,
2606
						this.preferences.continuation_indentation_for_array_initializer,
2607
						true);
2608
2609
				if (insert_new_line_after_opening_brace) {
2610
					arrayInitializerAlignment.fragmentIndentations[0] = arrayInitializerAlignment.breakIndentationLevel;
2611
				}
2612
2657
2613
				this.scribe.enterAlignment(arrayInitializerAlignment);
2658
				int expressionsLength = expressions.length;
2659
				final boolean insert_new_line_after_opening_brace = this.preferences.insert_new_line_after_opening_brace_in_array_initializer;
2614
				boolean ok = false;
2660
				boolean ok = false;
2615
				do {
2661
				Alignment arrayInitializerAlignment = null;
2616
					try {
2662
				if (expressionsLength > 1) {
2617
						this.scribe.alignFragment(arrayInitializerAlignment, 0);
2663
					if (insert_new_line_after_opening_brace) {
2618
						if (this.preferences.insert_space_after_opening_brace_in_array_initializer) {
2664
						this.scribe.printNewLine();
2619
							this.scribe.space();
2665
					}
2620
						}
2666
					arrayInitializerAlignment = this.scribe.createAlignment(
2621
						expressions[0].traverse(this, scope);
2667
							Alignment.ARRAY_INITIALIZER,
2622
						for (int i = 1; i < expressionsLength; i++) {
2668
							this.preferences.alignment_for_expressions_in_array_initializer,
2623
							this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2669
							Alignment.R_OUTERMOST,
2624
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2670
							expressionsLength,
2625
							this.scribe.alignFragment(arrayInitializerAlignment, i);
2671
							this.scribe.scanner.currentPosition,
2626
							if (this.preferences.insert_space_after_comma_in_array_initializer) {
2672
							this.preferences.continuation_indentation_for_array_initializer,
2673
							true);
2674
	
2675
					if (insert_new_line_after_opening_brace) {
2676
						arrayInitializerAlignment.fragmentIndentations[0] = arrayInitializerAlignment.breakIndentationLevel;
2677
					}
2678
	
2679
					this.scribe.enterAlignment(arrayInitializerAlignment);
2680
					do {
2681
						try {
2682
							this.scribe.alignFragment(arrayInitializerAlignment, 0);
2683
							if (this.preferences.insert_space_after_opening_brace_in_array_initializer) {
2627
								this.scribe.space();
2684
								this.scribe.space();
2628
							}
2685
							}
2629
							expressions[i].traverse(this, scope);
2686
							expressions[0].traverse(this, scope);
2630
							if (i == expressionsLength - 1) {
2687
							for (int i = 1; i < expressionsLength; i++) {
2631
								if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2688
								this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2632
									this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2689
								this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2633
									this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2690
								this.scribe.alignFragment(arrayInitializerAlignment, i);
2691
								if (this.preferences.insert_space_after_comma_in_array_initializer) {
2692
									this.scribe.space();
2693
								}
2694
								expressions[i].traverse(this, scope);
2695
								if (i == expressionsLength - 1) {
2696
									if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2697
										this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2698
										this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2699
									}
2634
								}
2700
								}
2635
							}
2701
							}
2702
							ok = true;
2703
						} catch (AlignmentException e) {
2704
							this.scribe.redoAlignment(e);
2636
						}
2705
						}
2637
						ok = true;
2706
					} while (!ok);
2638
					} catch (AlignmentException e) {
2707
					this.scribe.exitAlignment(arrayInitializerAlignment, true);
2639
						this.scribe.redoAlignment(e);
2708
				} else {
2709
					// Use an alignment with no break in case when the array initializer
2710
					// is not inside method arguments alignments
2711
					if (this.scribe.currentAlignment == null || this.scribe.currentAlignment.kind != Alignment.MESSAGE_ARGUMENTS) {
2712
						arrayInitializerAlignment = this.scribe.createAlignment(
2713
								Alignment.ARRAY_INITIALIZER,
2714
								this.preferences.alignment_for_expressions_in_array_initializer,
2715
								Alignment.R_OUTERMOST,
2716
								0,
2717
								this.scribe.scanner.currentPosition,
2718
								this.preferences.continuation_indentation_for_array_initializer,
2719
								true);
2720
						this.scribe.enterAlignment(arrayInitializerAlignment);
2721
					}
2722
					do {
2723
						try {
2724
							if (insert_new_line_after_opening_brace) {
2725
								this.scribe.printNewLine();
2726
								this.scribe.indent();
2727
							}
2728
							// we don't need to use an alignment
2729
							if (this.preferences.insert_space_after_opening_brace_in_array_initializer) {
2730
								this.scribe.space();
2731
							} else {
2732
								this.scribe.needSpace = false;
2733
							}
2734
							expressions[0].traverse(this, scope);
2735
							if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2736
								this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2737
								this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2738
							}
2739
							if (insert_new_line_after_opening_brace) {
2740
								this.scribe.unIndent();
2741
							}
2742
							ok = true;
2743
						} catch (AlignmentException e) {
2744
							if (arrayInitializerAlignment == null) throw e;
2745
							this.scribe.redoAlignment(e);
2746
						}
2747
					} while (!ok);
2748
					if (arrayInitializerAlignment != null) {
2749
						this.scribe.exitAlignment(arrayInitializerAlignment, true);
2640
					}
2750
					}
2641
				} while (!ok);
2642
				this.scribe.exitAlignment(arrayInitializerAlignment, true);
2643
			} else {
2644
				if (insert_new_line_after_opening_brace) {
2645
					this.scribe.printNewLine();
2646
					this.scribe.indent();
2647
				}
2751
				}
2648
				// we don't need to use an alignment
2752
				if (this.preferences.insert_new_line_before_closing_brace_in_array_initializer) {
2649
				if (this.preferences.insert_space_after_opening_brace_in_array_initializer) {
2753
					this.scribe.printNewLine();
2754
				} else if (this.preferences.insert_space_before_closing_brace_in_array_initializer) {
2650
					this.scribe.space();
2755
					this.scribe.space();
2651
				} else {
2652
					this.scribe.needSpace = false;
2653
				}
2654
				expressions[0].traverse(this, scope);
2655
				if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2656
					this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2657
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2658
				}
2756
				}
2659
				if (insert_new_line_after_opening_brace) {
2757
				this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, false, Scribe.PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER + (arrayInitializerIndentationLevel << 16));
2758
				if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
2660
					this.scribe.unIndent();
2759
					this.scribe.unIndent();
2661
				}
2760
				}
2662
			}
2663
			if (this.preferences.insert_new_line_before_closing_brace_in_array_initializer) {
2664
				this.scribe.printNewLine();
2665
			} else if (this.preferences.insert_space_before_closing_brace_in_array_initializer) {
2666
				this.scribe.space();
2667
			}
2668
			this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, false);
2669
			if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
2670
				this.scribe.unIndent();
2671
			}
2672
		} else {
2673
			boolean keepEmptyArrayInitializerOnTheSameLine = this.preferences.keep_empty_array_initializer_on_one_line;
2674
			String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer;
2675
			if (keepEmptyArrayInitializerOnTheSameLine) {
2676
				this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2677
				if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2678
					this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2679
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2680
				}
2681
				this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
2682
			} else {
2761
			} else {
2683
				formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2762
				boolean keepEmptyArrayInitializerOnTheSameLine = this.preferences.keep_empty_array_initializer_on_one_line;
2684
				if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2763
				String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer;
2685
					this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2764
				if (keepEmptyArrayInitializerOnTheSameLine) {
2686
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2765
					this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2687
				}
2766
					if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2688
				this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
2767
						this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2689
				if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
2768
						this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2690
					this.scribe.unIndent();
2769
					}
2770
					this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
2771
				} else {
2772
					formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer);
2773
					if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
2774
						this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
2775
						this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
2776
					}
2777
					this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
2778
					if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
2779
						this.scribe.unIndent();
2780
					}
2691
				}
2781
				}
2692
			}
2782
			}
2783
		} finally {
2784
			this.arrayInitializersDepth--;
2693
		}
2785
		}
2786
		
2694
2787
2695
		if (numberOfParens > 0) {
2788
		if (numberOfParens > 0) {
2696
			manageClosingParenthesizedExpression(arrayInitializer, numberOfParens);
2789
			manageClosingParenthesizedExpression(arrayInitializer, numberOfParens);
Lines 3958-3966 Link Here
3958
4051
3959
		if (elseStatement != null) {
4052
		if (elseStatement != null) {
3960
			if (thenStatementIsBlock) {
4053
			if (thenStatementIsBlock) {
3961
				this.scribe.printNextToken(TerminalTokens.TokenNameelse, this.preferences.insert_space_after_closing_brace_in_block);
4054
				this.scribe.printNextToken(TerminalTokens.TokenNameelse, this.preferences.insert_space_after_closing_brace_in_block, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE);
3962
			} else {
4055
			} else {
3963
				this.scribe.printNextToken(TerminalTokens.TokenNameelse, true);
4056
				this.scribe.printNextToken(TerminalTokens.TokenNameelse, true, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE);
3964
			}
4057
			}
3965
			if (elseStatement instanceof Block) {
4058
			if (elseStatement instanceof Block) {
3966
				elseStatement.traverse(this, scope);
4059
				elseStatement.traverse(this, scope);
Lines 4125-4130 Link Here
4125
		pair.value.traverse(this, scope);
4218
		pair.value.traverse(this, scope);
4126
		return false;
4219
		return false;
4127
	}
4220
	}
4221
4128
	/**
4222
	/**
4129
	 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
4223
	 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
4130
	 */
4224
	 */
Lines 4328-4334 Link Here
4328
					this.scribe.indent();
4422
					this.scribe.indent();
4329
				}
4423
				}
4330
				formatStatements(methodDeclarationScope, statements, true);
4424
				formatStatements(methodDeclarationScope, statements, true);
4331
				this.scribe.printComment();
4425
				this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION);
4332
				if (this.preferences.indent_statements_compare_to_body) {
4426
				if (this.preferences.indent_statements_compare_to_body) {
4333
					this.scribe.unIndent();
4427
					this.scribe.unIndent();
4334
				}
4428
				}
Lines 4339-4345 Link Here
4339
				if (this.preferences.indent_statements_compare_to_body) {
4433
				if (this.preferences.indent_statements_compare_to_body) {
4340
					this.scribe.indent();
4434
					this.scribe.indent();
4341
				}
4435
				}
4342
				this.scribe.printComment();
4436
				this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION);
4343
				if (this.preferences.indent_statements_compare_to_body) {
4437
				if (this.preferences.indent_statements_compare_to_body) {
4344
					this.scribe.unIndent();
4438
					this.scribe.unIndent();
4345
				}
4439
				}
Lines 4975-4981 Link Here
4975
			manageOpeningParenthesizedExpression(stringLiteral, numberOfParens);
5069
			manageOpeningParenthesizedExpression(stringLiteral, numberOfParens);
4976
		}
5070
		}
4977
5071
4978
		this.scribe.printComment();
5072
		this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_STRING_LITERAL_CONCATENATION);
4979
		ASTNode[] fragments = stringLiteral.literals;
5073
		ASTNode[] fragments = stringLiteral.literals;
4980
		int fragmentsSize = stringLiteral.counter;
5074
		int fragmentsSize = stringLiteral.counter;
4981
		Alignment binaryExpressionAlignment = this.scribe.createAlignment(
5075
		Alignment binaryExpressionAlignment = this.scribe.createAlignment(
Lines 5044-5050 Link Here
5044
		if (this.preferences.insert_space_after_opening_paren_in_switch) {
5138
		if (this.preferences.insert_space_after_opening_paren_in_switch) {
5045
			this.scribe.space();
5139
			this.scribe.space();
5046
		}
5140
		}
5047
5048
		switchStatement.expression.traverse(this, scope);
5141
		switchStatement.expression.traverse(this, scope);
5049
		this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_switch);
5142
		this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_switch);
5050
		/*
5143
		/*
Lines 5054-5130 Link Here
5054
		formatOpeningBrace(switch_brace, this.preferences.insert_space_before_opening_brace_in_switch);
5147
		formatOpeningBrace(switch_brace, this.preferences.insert_space_before_opening_brace_in_switch);
5055
		this.scribe.printNewLine();
5148
		this.scribe.printNewLine();
5056
5149
5150
		final Statement[] statements = switchStatement.statements;
5151
		int switchIndentationLevel = this.scribe.indentationLevel;
5152
		int caseIndentation = 0;
5153
		int statementIndentation = 0;
5154
		int breakIndentation = 0;
5057
		if (this.preferences.indent_switchstatements_compare_to_switch) {
5155
		if (this.preferences.indent_switchstatements_compare_to_switch) {
5058
			this.scribe.indent();
5156
			caseIndentation++;
5157
			statementIndentation++;
5158
			breakIndentation++;
5159
		}
5160
		if (this.preferences.indent_switchstatements_compare_to_cases) {
5161
			statementIndentation++;
5162
		}
5163
		if (this.preferences.indent_breaks_compare_to_cases) {
5164
			breakIndentation++;
5059
		}
5165
		}
5060
		final Statement[] statements = switchStatement.statements;
5061
		boolean wasACase = false;
5166
		boolean wasACase = false;
5062
		boolean wasAStatement = false;
5167
		boolean wasABreak = false;
5063
		if (statements != null) {
5168
		if (statements != null) {
5064
			int statementsLength = statements.length;
5169
			int statementsLength = statements.length;
5065
			for (int i = 0; i < statementsLength; i++) {
5170
			for (int i = 0; i < statementsLength; i++) {
5066
				final Statement statement = statements[i];
5171
				final Statement statement = statements[i];
5067
				if (statement instanceof CaseStatement) {
5172
				if (statement instanceof CaseStatement) {
5173
					if (wasABreak) {
5174
						this.scribe.setIndentation(switchIndentationLevel, caseIndentation);
5175
						this.scribe.printComment();
5176
					} else {
5177
						if (wasACase) {
5178
							this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_SWITCH_CASE);
5179
						} else {
5180
							this.scribe.printComment();
5181
						}
5182
						this.scribe.setIndentation(switchIndentationLevel, caseIndentation);
5183
					}
5068
					if (wasACase) {
5184
					if (wasACase) {
5069
						this.scribe.printNewLine();
5185
						this.scribe.printNewLine();
5070
					}
5186
					}
5071
					if ((wasACase && this.preferences.indent_switchstatements_compare_to_cases)
5072
						|| (wasAStatement && this.preferences.indent_switchstatements_compare_to_cases)) {
5073
						this.scribe.unIndent();
5074
					}
5075
					statement.traverse(this, scope);
5187
					statement.traverse(this, scope);
5076
					wasACase = true;
5188
					// Print following trailing (if any) comment at statement indentation
5077
					wasAStatement = false;
5189
					this.scribe.setIndentation(switchIndentationLevel, statementIndentation);
5078
					if (this.preferences.indent_switchstatements_compare_to_cases) {
5079
						this.scribe.indent();
5080
					}
5081
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT);
5190
					this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT);
5191
					wasACase = true;
5192
					wasABreak = false;
5082
				} else if (statement instanceof BreakStatement) {
5193
				} else if (statement instanceof BreakStatement) {
5083
					if (this.preferences.indent_breaks_compare_to_cases) {
5194
					this.scribe.setIndentation(switchIndentationLevel, breakIndentation);
5084
						if (wasAStatement && !this.preferences.indent_switchstatements_compare_to_cases) {
5085
							this.scribe.indent();
5086
						}
5087
					} else {
5088
						if (wasAStatement) {
5089
							if (this.preferences.indent_switchstatements_compare_to_cases) {
5090
								this.scribe.unIndent();
5091
							}
5092
						}
5093
						if (wasACase && this.preferences.indent_switchstatements_compare_to_cases) {
5094
							this.scribe.unIndent();
5095
						}
5096
					}
5097
					if (wasACase) {
5195
					if (wasACase) {
5098
						this.scribe.printNewLine();
5196
						this.scribe.printNewLine();
5099
					}
5197
					}
5198
					this.scribe.printComment();
5100
					statement.traverse(this, scope);
5199
					statement.traverse(this, scope);
5101
					if (this.preferences.indent_breaks_compare_to_cases) {
5102
						this.scribe.unIndent();
5103
					}
5104
					wasACase = false;
5200
					wasACase = false;
5105
					wasAStatement = false;
5201
					wasABreak = true;
5106
				} else if (statement instanceof Block) {
5202
				} else if (statement instanceof Block) {
5107
					String bracePosition;
5203
					this.scribe.setIndentation(switchIndentationLevel, wasACase ? caseIndentation : statementIndentation);
5108
					if (wasACase) {
5204
					this.scribe.printComment();
5109
						if (this.preferences.indent_switchstatements_compare_to_cases) {
5205
					String bracePosition = wasACase ? this.preferences.brace_position_for_block_in_case : this.preferences.brace_position_for_block;
5110
							this.scribe.unIndent();
5206
					formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_before_opening_brace_in_block);
5111
						}
5112
						bracePosition =	this.preferences.brace_position_for_block_in_case;
5113
						formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_after_colon_in_case);
5114
						if (this.preferences.indent_switchstatements_compare_to_cases) {
5115
							this.scribe.indent();
5116
						}
5117
					} else {
5118
						bracePosition =	this.preferences.brace_position_for_block;
5119
						formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_before_opening_brace_in_block);
5120
					}
5121
					wasAStatement = true;
5122
					wasACase = false;
5207
					wasACase = false;
5208
					wasABreak = false;
5123
				} else {
5209
				} else {
5210
					this.scribe.setIndentation(switchIndentationLevel, statementIndentation);
5124
					this.scribe.printNewLine();
5211
					this.scribe.printNewLine();
5212
					this.scribe.printComment();
5125
					statement.traverse(this, scope);
5213
					statement.traverse(this, scope);
5126
					wasAStatement = true;
5127
					wasACase = false;
5214
					wasACase = false;
5215
					wasABreak = false;
5128
				}
5216
				}
5129
				if (statement instanceof Expression) {
5217
				if (statement instanceof Expression) {
5130
					/*
5218
					/*
Lines 5168-5184 Link Here
5168
				} else if (!wasACase) {
5256
				} else if (!wasACase) {
5169
					this.scribe.printNewLine();
5257
					this.scribe.printNewLine();
5170
				}
5258
				}
5171
				this.scribe.printComment();
5172
			}
5259
			}
5173
		}
5260
		}
5174
5175
		if ((wasACase || wasAStatement) && this.preferences.indent_switchstatements_compare_to_cases) {
5176
			this.scribe.unIndent();
5177
		}
5178
		if (this.preferences.indent_switchstatements_compare_to_switch) {
5179
			this.scribe.unIndent();
5180
		}
5181
		this.scribe.printNewLine();
5261
		this.scribe.printNewLine();
5262
		if (wasABreak) {
5263
			this.scribe.setIndentation(switchIndentationLevel, 0);
5264
			this.scribe.printComment();
5265
		} else {
5266
			this.scribe.printComment();
5267
			this.scribe.setIndentation(switchIndentationLevel, 0);
5268
		}
5182
		this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
5269
		this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
5183
		this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
5270
		this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
5184
		if (switch_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
5271
		if (switch_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-116 / +186 lines)
Lines 73-79 Link Here
73
	public int indentationLevel;
73
	public int indentationLevel;
74
	public int lastNumberOfNewLines;
74
	public int lastNumberOfNewLines;
75
	private boolean preserveLineBreakIndentation = false;
75
	private boolean preserveLineBreakIndentation = false;
76
	boolean formatBrace;
77
	public int line;
76
	public int line;
78
77
79
	private int[] lineEnds;
78
	private int[] lineEnds;
Lines 105-110 Link Here
105
	private final boolean indentEmptyLines;
104
	private final boolean indentEmptyLines;
106
	int blank_lines_between_import_groups = -1;
105
	int blank_lines_between_import_groups = -1;
107
106
107
	// Preserve empty lines constants
108
	public static final int DO_NOT_PRESERVE_EMPTY_LINES = -1;
109
	public static final int PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION = 1;
110
	public static final int PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE = 2;
111
	public static final int PRESERVE_EMPTY_LINES_IN_STRING_LITERAL_CONCATENATION = 3;
112
	public static final int PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER = 4;
113
	public static final int PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE = 5;
114
	public static final int PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION = 6;
115
	public static final int PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION = 7;
116
	public static final int PRESERVE_EMPTY_LINES_BEFORE_ELSE = 8;
117
	public static final int PRESERVE_EMPTY_LINES_IN_SWITCH_CASE = 9;
118
	public static final int PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION = 10;
119
	public static final int PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK = 11;
120
	final static int PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION = -1;
121
	final static int PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION = 0;
122
	final static int PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION = 1;
123
108
	/** disabling */
124
	/** disabling */
109
	boolean editsEnabled;
125
	boolean editsEnabled;
110
	boolean useTags;
126
	boolean useTags;
Lines 696-701 Link Here
696
712
697
	public Alignment createAlignment(int kind, int mode, int tieBreakRule, int count, int sourceRestart, int continuationIndent, boolean adjust){
713
	public Alignment createAlignment(int kind, int mode, int tieBreakRule, int count, int sourceRestart, int continuationIndent, boolean adjust){
698
		Alignment alignment = new Alignment(kind, mode, tieBreakRule, this, count, sourceRestart, continuationIndent);
714
		Alignment alignment = new Alignment(kind, mode, tieBreakRule, this, count, sourceRestart, continuationIndent);
715
		// specific break indentation for message arguments inside binary expressions
716
		if ((this.currentAlignment == null && this.formatter.expressionsDepth >= 0) ||
717
			(this.currentAlignment != null && this.currentAlignment.kind == Alignment.BINARY_EXPRESSION &&
718
				(this.formatter.expressionsPos & CodeFormatterVisitor.EXPRESSIONS_POS_MASK) == CodeFormatterVisitor.EXPRESSIONS_POS_BETWEEN_TWO)) {
719
			switch (kind) {
720
				case Alignment.CONDITIONAL_EXPRESSION:
721
				case Alignment.MESSAGE_ARGUMENTS:
722
				case Alignment.MESSAGE_SEND:
723
					if (this.formatter.lastBinaryExpressionAlignmentBreakIndentation == alignment.breakIndentationLevel) {
724
						alignment.breakIndentationLevel += this.indentationSize;
725
						alignment.shiftBreakIndentationLevel += this.indentationSize;
726
						this.formatter.lastBinaryExpressionAlignmentBreakIndentation = 0;
727
					}
728
					break;
729
			}
730
		}
699
		// adjust break indentation
731
		// adjust break indentation
700
		if (adjust && this.memberAlignment != null) {
732
		if (adjust && this.memberAlignment != null) {
701
			Alignment current = this.memberAlignment;
733
			Alignment current = this.memberAlignment;
Lines 1137-1244 Link Here
1137
	/*
1169
	/*
1138
	 * Preserve empty lines depending on given count and preferences.
1170
	 * Preserve empty lines depending on given count and preferences.
1139
	 */
1171
	 */
1140
	private String getPreserveEmptyLines(int count) {
1172
	private String getPreserveEmptyLines(int count, int emptyLinesRules) {
1141
		if (count == 0) {
1173
		if (count == 0) {
1142
			// preserve line breaks in wrapping if specified
1174
			int currentIndentationLevel = this.indentationLevel;
1143
			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
1175
			int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules);
1144
			if (this.currentAlignment != null && !this.formatter.preferences.join_wrapped_lines) {
1176
			switch (useAlignmentBreakIndentation) {
1145
				// Insert a new line only if it has not been already done before
1177
				case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION:
1146
				// (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476)
1178
					return Util.EMPTY_STRING;
1147
				// or when there's no direct member alignment
1179
				default:
1148
				// (additional fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286601)
1180
					// Return the new indented line
1149
				if (this.lastNumberOfNewLines == 0 || this.memberAlignment == null || this.memberAlignment.location.inputOffset < this.currentAlignment.location.inputOffset) {
1181
					StringBuffer buffer = new StringBuffer(getNewLine());
1150
					
1182
					printIndentationIfNecessary(buffer);
1151
					// Debug
1183
					if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) {
1152
					if (DefaultCodeFormatter.DEBUG) {
1184
						this.indentationLevel = currentIndentationLevel;
1153
						System.out.println("Preserve empty lines:"); //$NON-NLS-1$
1154
						System.out.println(" - indentation level = "+this.indentationLevel); //$NON-NLS-1$
1155
						System.out.println(" - current alignment: "); //$NON-NLS-1$
1156
						System.out.print(this.currentAlignment.toString(new StringBuffer(), 1));
1157
						if (this.memberAlignment != null) {
1158
							System.out.println(" - member alignment: "); //$NON-NLS-1$
1159
							System.out.print(this.memberAlignment.toString(new StringBuffer(), 1));
1160
						}
1161
					}
1162
1163
					// Reset indentation level to the location output
1164
					this.indentationLevel = this.currentAlignment.location.outputIndentationLevel;
1165
1166
					// Create new line
1167
					this.tempBuffer.setLength(0);
1168
					this.tempBuffer.append(getNewLine());
1169
					
1170
					// Look for current indentation
1171
					int currentIndentation = getCurrentIndentation(this.scanner.currentPosition);
1172
					
1173
					// Determine whether the alignment indentation can be used or not
1174
					// So far, the best algorithm is to use it when
1175
					// 1. this is not the opening brace of a local declaration assignment
1176
					// 2. this is not the first opening brace
1177
					//     or this is an array initializer alignment 
1178
					//     or this is an binary expression alignment
1179
					// 3. the indentation level is below the alignment break indentation
1180
					int currentTokenStartPosition = this.scanner.currentPosition;
1181
					int nextToken = -1;
1182
					try {
1183
						nextToken = this.scanner.getNextToken();
1184
					} catch (InvalidInputException e) {
1185
						// skip
1186
					}
1187
					this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
1188
					boolean canUseAlignmentIndentation = (nextToken != TerminalTokens.TokenNameLBRACE || this.currentAlignment.kind != Alignment.LOCAL_DECLARATION_ASSIGNMENT);
1189
					if (canUseAlignmentIndentation &&
1190
							(!this.formatBrace ||
1191
									this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER ||
1192
									this.currentAlignment.kind == Alignment.BINARY_EXPRESSION) &&
1193
							this.indentationLevel < this.currentAlignment.breakIndentationLevel) {
1194
						this.indentationLevel = this.currentAlignment.breakIndentationLevel;
1195
					}
1185
					}
1196
					
1186
					return buffer.toString();
1197
					// Use the current indentation if over the computed indentation
1198
					if (this.indentationLevel < currentIndentation) {
1199
						this.indentationLevel = currentIndentation;
1200
					}
1201
					
1202
					// Debug
1203
					if (DefaultCodeFormatter.DEBUG) {
1204
						System.out.println(" - format brace = "+this.formatBrace); //$NON-NLS-1$
1205
						System.out.println(" - current column = "+(currentIndentation+1)); //$NON-NLS-1$
1206
						System.out.println(" - current position = "+this.scanner.currentPosition); //$NON-NLS-1$
1207
						System.out.print(" - current line = "); //$NON-NLS-1$
1208
						int linePtr = Arrays.binarySearch(this.lineEnds, this.scanner.currentPosition);
1209
						if (linePtr < 0) {
1210
							linePtr = -linePtr - 1;
1211
						}
1212
						int i = getLineEnd(linePtr)+1;
1213
						char[] source = this.scanner.source;
1214
						int sourceLength = source.length;
1215
						while (i < sourceLength && source[i] != '\r') {
1216
							System.out.print(source[i++]);
1217
						}
1218
						System.out.println();
1219
						System.out.println(" - indentation level = "+this.indentationLevel); //$NON-NLS-1$
1220
						System.out.println();
1221
					}
1222
					
1223
					// Set the flag to indicate that a specific indentation is currently in used
1224
					this.preserveLineBreakIndentation = true;
1225
					
1226
					// Print the computed indentation in the buffer
1227
					printIndentationIfNecessary(this.tempBuffer);
1228
					return this.tempBuffer.toString();
1229
				}
1230
			}
1187
			}
1231
			return Util.EMPTY_STRING;
1232
		}
1188
		}
1233
		if (this.blank_lines_between_import_groups >= 0) {
1189
		if (this.blank_lines_between_import_groups >= 0) {
1190
			useAlignmentBreakIndentation(emptyLinesRules);
1234
			return getEmptyLines(this.blank_lines_between_import_groups);
1191
			return getEmptyLines(this.blank_lines_between_import_groups);
1235
		}
1192
		}
1236
		if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
1193
		if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
1194
			useAlignmentBreakIndentation(emptyLinesRules);
1237
			int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve);
1195
			int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve);
1238
			return getEmptyLines(linesToPreserve);
1196
			return getEmptyLines(linesToPreserve);
1239
		}
1197
		}
1240
		return getNewLine();
1198
		return getNewLine();
1241
	}
1199
	}
1200
	private int useAlignmentBreakIndentation(int emptyLinesRules) {
1201
		// preserve line breaks in wrapping if specified
1202
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
1203
		boolean specificEmptyLinesRule = emptyLinesRules != PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION;
1204
		if ((this.currentAlignment != null || specificEmptyLinesRule) && !this.formatter.preferences.join_wrapped_lines) {
1205
			// insert a new line only if it has not been already done before
1206
			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476
1207
			if (this.lastNumberOfNewLines == 0 || specificEmptyLinesRule || this.formatter.arrayInitializersDepth >= 0) {
1208
				
1209
				// Do not use alignment break indentation in specific circumstances
1210
				boolean useAlignmentBreakIndentation;
1211
				boolean useAlignmentShiftBreakIndentation = false;
1212
				boolean useLastBinaryExpressionAlignmentBreakIndentation = false;
1213
				switch (emptyLinesRules) {
1214
					case DO_NOT_PRESERVE_EMPTY_LINES:
1215
					case PRESERVE_EMPTY_LINES_IN_SWITCH_CASE:
1216
					case PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION:
1217
					case PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK:
1218
						return PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION;
1219
					case PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION:
1220
						useAlignmentBreakIndentation = true;
1221
						if ((this.formatter.expressionsPos & CodeFormatterVisitor.EXPRESSIONS_POS_MASK) == CodeFormatterVisitor.EXPRESSIONS_POS_BETWEEN_TWO) {
1222
							// we're just before the left expression, try to use the last
1223
							// binary expression break indentation if any
1224
							useLastBinaryExpressionAlignmentBreakIndentation = true;
1225
						}
1226
						break;
1227
					case PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION:
1228
						useAlignmentShiftBreakIndentation = this.currentAlignment == null || this.currentAlignment.kind == Alignment.BINARY_EXPRESSION;
1229
						useAlignmentBreakIndentation = !useAlignmentShiftBreakIndentation;
1230
						break;
1231
					case PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE:
1232
						useAlignmentBreakIndentation = this.formatter.arrayInitializersDepth <= 1
1233
							&& this.currentAlignment != null
1234
							&& this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER;
1235
						break;
1236
					case PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE:
1237
						useAlignmentBreakIndentation = false;
1238
						break;
1239
					default:
1240
						if ((emptyLinesRules & 0xFFFF) == PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER && this.scanner.currentCharacter == '}' ) {
1241
							// last array initializer closing brace
1242
							this.indentationLevel = emptyLinesRules >> 16;
1243
							this.preserveLineBreakIndentation = true;
1244
							return PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION;
1245
						}
1246
						useAlignmentBreakIndentation = true;
1247
						break;
1248
				}
1249
1250
				// If there's an alignment try to align on its break indentation level
1251
				Alignment alignment = this.currentAlignment;
1252
				if (alignment == null) {
1253
					if (useLastBinaryExpressionAlignmentBreakIndentation) {
1254
						if (this.indentationLevel < this.formatter.lastBinaryExpressionAlignmentBreakIndentation) {
1255
							this.indentationLevel = this.formatter.lastBinaryExpressionAlignmentBreakIndentation;
1256
						}
1257
					}
1258
					if (useAlignmentShiftBreakIndentation && this.memberAlignment != null) {
1259
						if (this.indentationLevel < this.memberAlignment.shiftBreakIndentationLevel) {
1260
							this.indentationLevel = this.memberAlignment.shiftBreakIndentationLevel;
1261
						}
1262
					}
1263
				} else {
1264
					// Use the member alignment break indentation level when
1265
					// it's closer from the wrapped line than the current alignment
1266
					if (this.memberAlignment != null && this.memberAlignment.location.inputOffset > alignment.location.inputOffset) {
1267
						alignment = this.memberAlignment;
1268
					}
1269
1270
					// Use the break indentation level if possible...
1271
					if (useLastBinaryExpressionAlignmentBreakIndentation) {
1272
						if (this.indentationLevel < this.formatter.lastBinaryExpressionAlignmentBreakIndentation) {
1273
							this.indentationLevel = this.formatter.lastBinaryExpressionAlignmentBreakIndentation;
1274
						}
1275
					}
1276
					if (useAlignmentBreakIndentation) {
1277
						if (this.indentationLevel < alignment.breakIndentationLevel) {
1278
							this.indentationLevel = alignment.breakIndentationLevel;
1279
						}
1280
					} else if (useAlignmentShiftBreakIndentation) {
1281
						if (this.indentationLevel < alignment.shiftBreakIndentationLevel) {
1282
							this.indentationLevel = alignment.shiftBreakIndentationLevel;
1283
						}
1284
					}
1285
				}
1286
				this.preserveLineBreakIndentation = true;
1287
				if (useLastBinaryExpressionAlignmentBreakIndentation || useAlignmentShiftBreakIndentation) {
1288
					return PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION;
1289
				}
1290
				return PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION;
1291
			}
1292
		}
1293
		return PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION;
1294
	}
1242
1295
1243
	public TextEdit getRootEdit() {
1296
	public TextEdit getRootEdit() {
1244
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
1297
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
Lines 1446-1451 Link Here
1446
		this.numberOfIndentations++;
1499
		this.numberOfIndentations++;
1447
	}
1500
	}
1448
1501
1502
	void setIndentation(int level, int n) {
1503
		this.indentationLevel = level + n * this.indentationSize;
1504
		this.numberOfIndentations = this.indentationLevel / this.indentationSize;
1505
	}
1506
1449
	private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) {
1507
	private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) {
1450
		this.useTags = preferences.use_tags;
1508
		this.useTags = preferences.use_tags;
1451
		this.tagsKind = 0;
1509
		this.tagsKind = 0;
Lines 2344-2356 Link Here
2344
	}
2402
	}
2345
2403
2346
	void printComment() {
2404
	void printComment() {
2347
		printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
2405
		printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION);
2406
	}
2407
2408
	void printComment(int emptyLinesRules) {
2409
		printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, emptyLinesRules);
2410
	}
2411
2412
	void printComment(int kind, int trailing) {
2413
		printComment(kind, trailing, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION);
2348
	}
2414
	}
2349
2415
2350
	/*
2416
	/*
2351
	 * Main method to print and format comments (javadoc, block and single line comments)
2417
	 * Main method to print and format comments (javadoc, block and single line comments)
2352
	 */
2418
	 */
2353
	void printComment(int kind, int trailing) {
2419
	void printComment(int kind, int trailing, int emptyLinesRules) {
2354
		final boolean rejectLineComment = kind  == CodeFormatter.K_MULTI_LINE_COMMENT || kind == CodeFormatter.K_JAVA_DOC;
2420
		final boolean rejectLineComment = kind  == CodeFormatter.K_MULTI_LINE_COMMENT || kind == CodeFormatter.K_JAVA_DOC;
2355
		final boolean rejectBlockComment = kind  == CodeFormatter.K_SINGLE_LINE_COMMENT || kind  == CodeFormatter.K_JAVA_DOC;
2421
		final boolean rejectBlockComment = kind  == CodeFormatter.K_SINGLE_LINE_COMMENT || kind  == CodeFormatter.K_JAVA_DOC;
2356
		final boolean rejectJavadocComment = kind  == CodeFormatter.K_SINGLE_LINE_COMMENT || kind  == CodeFormatter.K_MULTI_LINE_COMMENT;
2422
		final boolean rejectJavadocComment = kind  == CodeFormatter.K_SINGLE_LINE_COMMENT || kind  == CodeFormatter.K_MULTI_LINE_COMMENT;
Lines 2464-2475 Link Here
2464
						} else {
2530
						} else {
2465
							if (lines == 0) {
2531
							if (lines == 0) {
2466
								hasWhitespaces = true;
2532
								hasWhitespaces = true;
2467
								addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2533
								if (hasLineComment && emptyLinesRules != PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION) {
2534
									addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(0, emptyLinesRules));
2535
								} else {
2536
									addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2537
								}
2468
							} else if (hasLineComment) {
2538
							} else if (hasLineComment) {
2539
								useAlignmentBreakIndentation(emptyLinesRules);
2469
								currentTokenStartPosition = tokenStartPosition;
2540
								currentTokenStartPosition = tokenStartPosition;
2470
								preserveEmptyLines(lines, currentTokenStartPosition);
2541
								preserveEmptyLines(lines, currentTokenStartPosition);
2471
								addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
2542
								addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
2472
							} else if (hasComment) {
2543
							} else if (hasComment) {
2544
								useAlignmentBreakIndentation(emptyLinesRules);
2473
								if (lines == 1) {
2545
								if (lines == 1) {
2474
									this.printNewLine(tokenStartPosition);
2546
									this.printNewLine(tokenStartPosition);
2475
								} else {
2547
								} else {
Lines 2477-2484 Link Here
2477
								}
2549
								}
2478
								addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2550
								addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2479
							} 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)) {
2551
							} 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)) {
2480
								addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1));
2552
								addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1, emptyLinesRules));
2481
							} else {
2553
							} else {
2554
								useAlignmentBreakIndentation(emptyLinesRules);
2482
								addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2555
								addDeleteEdit(tokenStartPosition, whitespacesEndPosition);
2483
							}
2556
							}
2484
						}
2557
						}
Lines 2712-2717 Link Here
2712
					}
2785
					}
2713
				} else {
2786
				} else {
2714
					if (this.currentAlignment != null && this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER &&
2787
					if (this.currentAlignment != null && this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER &&
2788
						this.currentAlignment.fragmentCount > 0 &&
2715
						this.indentationLevel < this.currentAlignment.breakIndentationLevel &&
2789
						this.indentationLevel < this.currentAlignment.breakIndentationLevel &&
2716
						this.lastLineComment.lines > 0)
2790
						this.lastLineComment.lines > 0)
2717
					{
2791
					{
Lines 2782-2787 Link Here
2782
    		} else if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
2856
    		} else if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) {
2783
    			this.currentAlignment.performFragmentEffect();
2857
    			this.currentAlignment.performFragmentEffect();
2784
    		}
2858
    		}
2859
    		if (this.currentAlignment.kind == Alignment.BINARY_EXPRESSION &&
2860
    			this.currentAlignment.enclosing != null &&
2861
    			this.currentAlignment.enclosing.kind == Alignment.BINARY_EXPRESSION &&
2862
    			this.indentationLevel < this.currentAlignment.breakIndentationLevel)
2863
    		{
2864
    			this.indentationLevel = this.currentAlignment.breakIndentationLevel;
2865
    		}
2785
    	}
2866
    	}
2786
    	this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
2867
    	this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
2787
    }
2868
    }
Lines 4800-4830 Link Here
4800
	}
4881
	}
4801
4882
4802
	public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny) {
4883
	public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny) {
4884
		printNextToken(expectedTokenType, considerSpaceIfAny, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION);
4885
	}
4886
4887
	public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny, int emptyLineRules) {
4803
		// Set brace flag, it's useful for the scribe while preserving line breaks
4888
		// Set brace flag, it's useful for the scribe while preserving line breaks
4804
		switch (expectedTokenType) {
4889
		printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, emptyLineRules);
4805
			case TerminalTokens.TokenNameRBRACE:
4806
			case TerminalTokens.TokenNameLBRACE:
4807
				this.formatBrace = true;
4808
		}
4809
		try {
4890
		try {
4810
			printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
4891
			this.currentToken = this.scanner.getNextToken();
4811
			try {
4892
			if (expectedTokenType != this.currentToken) {
4812
				this.currentToken = this.scanner.getNextToken();
4893
				throw new AbortFormatting("unexpected token type, expecting:"+expectedTokenType+", actual:"+this.currentToken);//$NON-NLS-1$//$NON-NLS-2$
4813
				if (expectedTokenType != this.currentToken) {
4814
					throw new AbortFormatting("unexpected token type, expecting:"+expectedTokenType+", actual:"+this.currentToken);//$NON-NLS-1$//$NON-NLS-2$
4815
				}
4816
				print(this.scanner.currentPosition - this.scanner.startPosition, considerSpaceIfAny);
4817
			} catch (InvalidInputException e) {
4818
				throw new AbortFormatting(e);
4819
			}
4820
		}
4821
		finally {
4822
			// Flush brace flag
4823
			switch (expectedTokenType) {
4824
				case TerminalTokens.TokenNameRBRACE:
4825
				case TerminalTokens.TokenNameLBRACE:
4826
					this.formatBrace = false;
4827
			}
4894
			}
4895
			print(this.scanner.currentPosition - this.scanner.startPosition, considerSpaceIfAny);
4896
		} catch (InvalidInputException e) {
4897
			throw new AbortFormatting(e);
4828
		}
4898
		}
4829
	}
4899
	}
4830
4900
(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (-2 / +5 lines)
Lines 252-258 Link Here
252
	}
252
	}
253
253
254
	public void checkColumn() {
254
	public void checkColumn() {
255
		if ((this.mode & M_MULTICOLUMN) != 0) {
255
		if ((this.mode & M_MULTICOLUMN) != 0 && this.fragmentCount > 0) {
256
			int currentIndentation = this.scribe.getNextIndentationLevel(this.scribe.column+(this.scribe.needSpace ? 1 : 0));
256
			int currentIndentation = this.scribe.getNextIndentationLevel(this.scribe.column+(this.scribe.needSpace ? 1 : 0));
257
			int fragmentIndentation = this.fragmentIndentations[this.fragmentIndex];
257
			int fragmentIndentation = this.fragmentIndentations[this.fragmentIndex];
258
			if (currentIndentation > fragmentIndentation) {
258
			if (currentIndentation > fragmentIndentation) {
Lines 351-356 Link Here
351
	}
351
	}
352
352
353
	public boolean couldBreak(){
353
	public boolean couldBreak(){
354
		if (this.fragmentCount == 0) return false;
354
		int i;
355
		int i;
355
		switch(this.mode & SPLIT_MASK){
356
		switch(this.mode & SPLIT_MASK){
356
357
Lines 445-452 Link Here
445
		}
446
		}
446
		return false; // cannot split better
447
		return false; // cannot split better
447
	}
448
	}
448
449
	
449
	public boolean isWrapped() {
450
	public boolean isWrapped() {
451
		if (this.fragmentCount == 0) return false;
450
		return this.fragmentBreaks[this.fragmentIndex] == BREAK;
452
		return this.fragmentBreaks[this.fragmentIndex] == BREAK;
451
	}
453
	}
452
454
Lines 461-466 Link Here
461
463
462
	// perform alignment effect for current fragment
464
	// perform alignment effect for current fragment
463
	public void performFragmentEffect(){
465
	public void performFragmentEffect(){
466
		if (this.fragmentCount == 0) return;
464
		if ((this.mode & M_MULTICOLUMN) == 0) {
467
		if ((this.mode & M_MULTICOLUMN) == 0) {
465
			switch(this.mode & SPLIT_MASK) {
468
			switch(this.mode & SPLIT_MASK) {
466
				case Alignment.M_COMPACT_SPLIT :
469
				case Alignment.M_COMPACT_SPLIT :
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (-362 / +3047 lines)
Lines 1242-1248 Link Here
1242
		"public class Test {\n" +
1242
		"public class Test {\n" +
1243
		"\n" +
1243
		"\n" +
1244
		"	String foo(boolean enabled) {\n" +
1244
		"	String foo(boolean enabled) {\n" +
1245
		"		if (enabled) {\n" +
1245
		"		if (enabled)\n" +
1246
		"		{\n" +
1246
		"			// we need x\n" +
1247
		"			// we need x\n" +
1247
		"			// we need a select\n" +
1248
		"			// we need a select\n" +
1248
		"			return \"select x \"\n" +
1249
		"			return \"select x \"\n" +
Lines 1272-1278 Link Here
1272
		"public class Test {\n" +
1273
		"public class Test {\n" +
1273
		"\n" +
1274
		"\n" +
1274
		"    String foo(boolean enabled) {\n" +
1275
		"    String foo(boolean enabled) {\n" +
1275
		"        if (enabled) {\n" +
1276
		"        if (enabled)\n" +
1277
		"        {\n" +
1276
		"            // we need x\n" +
1278
		"            // we need x\n" +
1277
		"            // we need a select\n" +
1279
		"            // we need a select\n" +
1278
		"            return \"select x \"\n" +
1280
		"            return \"select x \"\n" +
Lines 1897-1904 Link Here
1897
	formatSource(source,
1899
	formatSource(source,
1898
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
1900
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
1899
		"		activationConfig = {\n" + 
1901
		"		activationConfig = {\n" + 
1900
		"			@ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
1902
		"				@ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
1901
		"					propertyValue = \"0/10 * * * * ?\")\n" + 
1903
		"						propertyValue = \"0/10 * * * * ?\")\n" + 
1902
		"		})\n" + 
1904
		"		})\n" + 
1903
		"@RunAs(\"admin\")\n" + 
1905
		"@RunAs(\"admin\")\n" + 
1904
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
1906
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
Lines 2621-2628 Link Here
2621
		"    }\n" +
2623
		"    }\n" +
2622
		"}\n";
2624
		"}\n";
2623
	formatSource(source,
2625
	formatSource(source,
2624
		"public class Test {\n" +
2626
		"public class Test\n" +
2625
		"	public void aMethod() {\n" +
2627
		"{\n" +
2628
		"	public void aMethod()\n" +
2629
		"	{\n" +
2626
		"		Object anObject = new Object()\n" +
2630
		"		Object anObject = new Object()\n" +
2627
		"		{\n" +
2631
		"		{\n" +
2628
		"			boolean aVariable;\n" +
2632
		"			boolean aVariable;\n" +
Lines 2689-2696 Link Here
2689
		"    }\n" +
2693
		"    }\n" +
2690
		"}\n";
2694
		"}\n";
2691
	formatSource(source,
2695
	formatSource(source,
2692
		"public class Test {\n" +
2696
		"public class Test\n" +
2693
		"	public void aMethod() {\n" +
2697
		"{\n" +
2698
		"	public void aMethod()\n" +
2699
		"	{\n" +
2694
		"		Object anObject = new Object()\n" +
2700
		"		Object anObject = new Object()\n" +
2695
		"		{\n" +
2701
		"		{\n" +
2696
		"			boolean aVariable;\n" +
2702
		"			boolean aVariable;\n" +
Lines 2721-3118 Link Here
2721
		"    }\n" +
2727
		"    }\n" +
2722
		"}\n";
2728
		"}\n";
2723
	formatSource(source,
2729
	formatSource(source,
2724
		"public class Test {\n" +
2725
		"	public void aMethod() {\n" +
2726
		"		Object anObject = new Object() /* comment */\n" +
2727
		"		{\n" +
2728
		"			boolean aVariable;\n" +
2729
		"\n" +
2730
		"			void foo() /* comment */\n" +
2731
		"			{\n" +
2732
		"			}\n" +
2733
		"		};\n" +
2734
		"	}\n" +
2735
		"}\n"
2736
	);
2737
}
2738
public void testBug286601e() {
2739
	this.formatterPrefs.join_wrapped_lines = false;
2740
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2741
	String source =
2742
		"public class Test\n" +
2743
		"{\n" +
2744
		"    public void build(String href) {\n" +
2745
		"        // set the href on the related topic\n" +
2746
		"        if (href == null)\n" +
2747
		"            setHref(\"\"); //$NON-NLS-1$\n" +
2748
		"        else {\n" +
2749
		"            if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" +
2750
		"                    && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" +
2751
		"                    && href.indexOf(\':\') == -1) // no other protocols\n" +
2752
		"            {\n" +
2753
		"                setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" +
2754
		"            }\n" +
2755
		"        }\n" +
2756
		"    }\n" +
2757
		"}\n";
2758
	formatSource(source,
2759
		"public class Test\n" +
2730
		"public class Test\n" +
2760
		"{\n" +
2731
		"{\n" +
2761
		"	public void build(String href)\n" +
2732
		"	public void aMethod()\n" +
2762
		"	{\n" +
2733
		"	{\n" +
2763
		"		// set the href on the related topic\n" +
2734
		"		Object anObject = new Object() /* comment */\n" +
2764
		"		if (href == null)\n" +
2765
		"			setHref(\"\"); //$NON-NLS-1$\n" +
2766
		"		else\n" +
2767
		"		{\n" +
2735
		"		{\n" +
2768
		"			if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" +
2736
		"			boolean aVariable;\n" +
2769
		"					&& !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" +
2770
		"					&& href.indexOf(\':\') == -1) // no other protocols\n" +
2771
		"			{\n" +
2772
		"				setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" +
2773
		"			}\n" +
2774
		"		}\n" +
2775
		"	}\n" +
2776
		"}\n"
2777
	);
2778
}
2779
public void testBug286601f() {
2780
	this.formatterPrefs.join_wrapped_lines = false;
2781
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2782
	String source =
2783
		"public class Test\n" +
2784
		"{\n" +
2785
		"    \n" +
2786
		"    private AntModel getAntModel(final File buildFile) {\n" +
2787
		"        AntModel model= new AntModel(XMLCore.getDefault(), doc, null, new LocationProvider(null) {\n" +
2788
		"            /* (non-Javadoc)\n" +
2789
		"             * @see org.eclipse.ant.internal.ui.editor.outline.ILocationProvider#getLocation()\n" +
2790
		"             */\n" +
2791
		"            public IPath getLocation() {\n" +
2792
		"                return new Path(buildFile.getAbsolutePath());\n" +
2793
		"            }\n" +
2794
		"        });\n" +
2795
		"        model.reconcile(null);\n" +
2796
		"        return model;\n" +
2797
		"    }\n" +
2798
		"}\n";
2799
	formatSource(source,
2800
		"public class Test\n" +
2801
		"{\n" +
2802
		"\n" +
2803
		"	private AntModel getAntModel(final File buildFile)\n" +
2804
		"	{\n" +
2805
		"		AntModel model = new AntModel(XMLCore.getDefault(), doc, null,\n" +
2806
		"				new LocationProvider(null)\n" +
2807
		"				{\n" +
2808
		"					/*\n" +
2809
		"					 * (non-Javadoc)\n" +
2810
		"					 * \n" +
2811
		"					 * @see\n" +
2812
		"					 * org.eclipse.ant.internal.ui.editor.outline.ILocationProvider\n" +
2813
		"					 * #getLocation()\n" +
2814
		"					 */\n" +
2815
		"					public IPath getLocation()\n" +
2816
		"					{\n" +
2817
		"						return new Path(buildFile.getAbsolutePath());\n" +
2818
		"					}\n" +
2819
		"				});\n" +
2820
		"		model.reconcile(null);\n" +
2821
		"		return model;\n" +
2822
		"	}\n" +
2823
		"}\n"
2824
	);
2825
}
2826
public void testBug286601g() {
2827
	this.formatterPrefs.join_wrapped_lines = false;
2828
	String source =
2829
		"package massive;\n" +
2830
		"\n" +
2831
		"public class X05\n" +
2832
		"{\n" +
2833
		"\n" +
2834
		"    public void foo() throws NullPointerException {\n" +
2835
		"\n" +
2836
		"        Object body = new Object() {\n" +
2837
		"            public void run(StringBuffer monitor) throws IllegalArgumentException {\n" +
2838
		"                IResourceVisitor visitor = new IResourceVisitor() {\n" +
2839
		"                    public boolean visit(String resource) throws IllegalArgumentException {\n" +
2840
		"                        return true;\n" +
2841
		"                    }\n" +
2842
		"                };\n" +
2843
		"            }\n" +
2844
		"        };\n" +
2845
		"    }\n" +
2846
		"\n" +
2847
		"}\n" +
2848
		"interface IResourceVisitor {\n" +
2849
		"}\n";
2850
	formatSource(source,
2851
		"package massive;\n" +
2852
		"\n" +
2853
		"public class X05 {\n" +
2854
		"\n" +
2855
		"	public void foo() throws NullPointerException {\n" +
2856
		"\n" +
2857
		"		Object body = new Object() {\n" +
2858
		"			public void run(StringBuffer monitor)\n" +
2859
		"					throws IllegalArgumentException {\n" +
2860
		"				IResourceVisitor visitor = new IResourceVisitor() {\n" +
2861
		"					public boolean visit(String resource)\n" +
2862
		"							throws IllegalArgumentException {\n" +
2863
		"						return true;\n" +
2864
		"					}\n" +
2865
		"				};\n" +
2866
		"			}\n" +
2867
		"		};\n" +
2868
		"	}\n" +
2869
		"\n" +
2870
		"}\n" +
2871
		"\n" +
2872
		"interface IResourceVisitor {\n" +
2873
		"}\n"
2874
	);
2875
}
2876
public void testBug286601h() {
2877
	this.formatterPrefs.join_wrapped_lines = false;
2878
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2879
	String source =
2880
		"package massive;\n" +
2881
		"\n" +
2882
		"public class X05\n" +
2883
		"{\n" +
2884
		"\n" +
2885
		"    public void foo() throws NullPointerException {\n" +
2886
		"\n" +
2887
		"        Object body = new Object() {\n" +
2888
		"            public void run(StringBuffer monitor) throws IllegalArgumentException {\n" +
2889
		"                IResourceVisitor visitor = new IResourceVisitor() {\n" +
2890
		"                    public boolean visit(String resource) throws IllegalArgumentException {\n" +
2891
		"                        return true;\n" +
2892
		"                    }\n" +
2893
		"                };\n" +
2894
		"            }\n" +
2895
		"        };\n" +
2896
		"    }\n" +
2897
		"\n" +
2898
		"}\n" +
2899
		"interface IResourceVisitor {\n" +
2900
		"}\n";
2901
	formatSource(source,
2902
		"package massive;\n" +
2903
		"\n" +
2904
		"public class X05\n" +
2905
		"{\n" +
2906
		"\n" +
2907
		"	public void foo() throws NullPointerException\n" +
2908
		"	{\n" +
2909
		"\n" +
2737
		"\n" +
2910
		"		Object body = new Object()\n" +
2738
		"			void foo() /* comment */\n" +
2911
		"		{\n" +
2912
		"			public void run(StringBuffer monitor)\n" +
2913
		"					throws IllegalArgumentException\n" +
2914
		"			{\n" +
2739
		"			{\n" +
2915
		"				IResourceVisitor visitor = new IResourceVisitor()\n" +
2916
		"				{\n" +
2917
		"					public boolean visit(String resource)\n" +
2918
		"							throws IllegalArgumentException\n" +
2919
		"					{\n" +
2920
		"						return true;\n" +
2921
		"					}\n" +
2922
		"				};\n" +
2923
		"			}\n" +
2740
		"			}\n" +
2924
		"		};\n" +
2741
		"		};\n" +
2925
		"	}\n" +
2742
		"	}\n" +
2926
		"\n" +
2927
		"}\n" +
2928
		"\n" +
2929
		"interface IResourceVisitor\n" +
2930
		"{\n" +
2931
		"}\n"
2932
	);
2933
}
2934
public void testBug286601i1() {
2935
	this.formatterPrefs.join_wrapped_lines = false;
2936
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE;
2937
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2938
	String source =
2939
		"package massive;\n" +
2940
		"\n" +
2941
		"public class X06a {\n" +
2942
		"\n" +
2943
		"    \n" +
2944
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" +
2945
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" +
2946
		"    /* Comment 1 */\n" +
2947
		"    /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2948
		"    /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2949
		"    };\n" +
2950
		"\n" +
2951
		"}\n";
2952
	formatSource(source,
2953
		"package massive;\n" +
2954
		"\n" +
2955
		"public class X06a\n" +
2956
		"{\n" +
2957
		"\n" +
2958
		"	// Table to merge access modes for condition statements (e.g branch[x] ||\n" +
2959
		"	// branch[y]).\n" +
2960
		"	private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" +
2961
		"	{\n" +
2962
		"		/* Comment 1 */\n" +
2963
		"		/* Comment 2 */{ \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2964
		"		/* Comment 3 */{ \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2965
		"	};\n" +
2966
		"\n" +
2967
		"}\n"
2743
		"}\n"
2968
	);
2744
	);
2969
}
2745
}
2970
public void testBug286601i2() {
2746
public void testBug286601_massive_01() {
2971
	this.formatterPrefs.join_wrapped_lines = false;
2747
	this.formatterPrefs.join_wrapped_lines = false;
2972
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
2973
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE;
2974
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2748
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2975
	String source =
2749
	String source =
2976
		"package massive;\n" +
2750
		"package massive;\n" + 
2977
		"\n" +
2751
		"public class X01 {\n" + 
2978
		"public class X06a {\n" +
2752
		"    public void build(String href) {\n" + 
2979
		"\n" +
2753
		"        // set the href on the related topic\n" + 
2980
		"    \n" +
2754
		"        if (href == null)\n" + 
2981
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" +
2755
		"            setHref(\"\"); //$NON-NLS-1$\n" + 
2982
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" +
2756
		"        else {\n" + 
2983
		"    /* Comment 1 */\n" +
2757
		"            if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + 
2984
		"    /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2758
		"                    && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + 
2985
		"    /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2759
		"                    && href.indexOf(\':\') == -1) // no other protocols\n" + 
2986
		"    };\n" +
2760
		"            {\n" + 
2987
		"\n" +
2761
		"                setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
2762
		"            }\n" + 
2763
		"        }\n" + 
2764
		"    }\n" + 
2765
		"\n" + 
2766
		"    private void setHref(String string)\n" + 
2767
		"    {\n" + 
2768
		"        \n" + 
2769
		"    }\n" + 
2988
		"}\n";
2770
		"}\n";
2989
	formatSource(source,
2771
	formatSource(source,
2990
		"package massive;\n" +
2772
		"package massive;\n" + 
2991
		"\n" +
2773
		"\n" + 
2992
		"public class X06a\n" +
2774
		"public class X01\n" + 
2993
		"{\n" +
2775
		"{\n" + 
2994
		"\n" +
2776
		"	public void build(String href)\n" + 
2995
		"    // Table to merge access modes for condition statements (e.g branch[x] ||\n" +
2777
		"	{\n" + 
2996
		"    // branch[y]).\n" +
2778
		"		// set the href on the related topic\n" + 
2997
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" +
2779
		"		if (href == null)\n" + 
2998
		"    {\n" +
2780
		"			setHref(\"\"); //$NON-NLS-1$\n" + 
2999
		"     /* Comment 1 */\n" +
2781
		"		else\n" + 
3000
		"     /* Comment 2 */{ \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2782
		"		{\n" + 
3001
		"     /* Comment 3 */{ \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2783
		"			if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + 
3002
		"    };\n" +
2784
		"					&& !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + 
3003
		"\n" +
2785
		"					&& href.indexOf(\':\') == -1) // no other protocols\n" + 
2786
		"			{\n" + 
2787
		"				setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
2788
		"			}\n" + 
2789
		"		}\n" + 
2790
		"	}\n" + 
2791
		"\n" + 
2792
		"	private void setHref(String string)\n" + 
2793
		"	{\n" + 
2794
		"\n" + 
2795
		"	}\n" + 
3004
		"}\n"
2796
		"}\n"
3005
	);
2797
	);
3006
}
2798
}
3007
public void testBug286601j1() {
2799
public void testBug286601_massive_02() {
3008
	this.formatterPrefs.join_wrapped_lines = false;
2800
	this.formatterPrefs.join_wrapped_lines = false;
3009
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE;
3010
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2801
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
3011
	String source =
2802
	String source =
3012
		"package massive;\n" +
2803
		"package massive;\n" + 
3013
		"\n" +
2804
		"\n" + 
3014
		"public class X06b {\n" +
2805
		"public class X02\n" + 
3015
		"\n" +
2806
		"{\n" + 
3016
		"    \n" +
2807
		"    \n" + 
3017
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" +
2808
		"    private AntModel getAntModel(final File buildFile) {\n" + 
3018
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" +
2809
		"        AntModel model= new AntModel(XMLCore.getDefault(), doc, null, new LocationProvider(null) {\n" + 
3019
		"    { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2810
		"            /* (non-Javadoc)\n" + 
3020
		"    { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2811
		"             * @see org.eclipse.ant.internal.ui.editor.outline.ILocationProvider#getLocation()\n" + 
3021
		"    };\n" +
2812
		"             */\n" + 
3022
		"\n" +
2813
		"            public IPath getLocation() {\n" + 
2814
		"                return new Path(buildFile.getAbsolutePath());\n" + 
2815
		"            }\n" + 
2816
		"        });\n" + 
2817
		"        model.reconcile(null);\n" + 
2818
		"        return model;\n" + 
2819
		"    }\n" + 
3023
		"}\n";
2820
		"}\n";
3024
	formatSource(source,
2821
	formatSource(source,
3025
		"package massive;\n" +
2822
		"package massive;\n" + 
3026
		"\n" +
2823
		"\n" + 
3027
		"public class X06b\n" +
2824
		"public class X02\n" + 
3028
		"{\n" +
2825
		"{\n" + 
3029
		"\n" +
2826
		"\n" + 
3030
		"	// Table to merge access modes for condition statements (e.g branch[x] ||\n" +
2827
		"	private AntModel getAntModel(final File buildFile)\n" + 
3031
		"	// branch[y]).\n" +
2828
		"	{\n" + 
3032
		"	private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" +
2829
		"		AntModel model = new AntModel(XMLCore.getDefault(), doc, null,\n" + 
3033
		"	{\n" +
2830
		"				new LocationProvider(null)\n" + 
3034
		"		{ \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2831
		"				{\n" + 
3035
		"		{ \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2832
		"					/*\n" + 
3036
		"	};\n" +
2833
		"					 * (non-Javadoc)\n" + 
3037
		"\n" +
2834
		"					 * \n" + 
2835
		"					 * @see\n" + 
2836
		"					 * org.eclipse.ant.internal.ui.editor.outline.ILocationProvider\n" + 
2837
		"					 * #getLocation()\n" + 
2838
		"					 */\n" + 
2839
		"					public IPath getLocation()\n" + 
2840
		"					{\n" + 
2841
		"						return new Path(buildFile.getAbsolutePath());\n" + 
2842
		"					}\n" + 
2843
		"				});\n" + 
2844
		"		model.reconcile(null);\n" + 
2845
		"		return model;\n" + 
2846
		"	}\n" + 
3038
		"}\n"
2847
		"}\n"
3039
	);
2848
	);
3040
}
2849
}
3041
public void testBug286601j2() {
2850
public void testBug286601_massive_03() {
3042
	this.formatterPrefs.join_wrapped_lines = false;
2851
	this.formatterPrefs.join_wrapped_lines = false;
3043
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
3044
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE;
3045
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
3046
	String source =
2852
	String source =
3047
		"package massive;\n" +
2853
		"package massive;\n" + 
3048
		"\n" +
2854
		"\n" + 
3049
		"public class X06b {\n" +
2855
		"public class X03\n" + 
3050
		"\n" +
2856
		"{\n" + 
3051
		"    \n" +
2857
		"\n" + 
3052
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" +
2858
		"    public void foo() throws NullPointerException {\n" + 
3053
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" +
2859
		"\n" + 
3054
		"    { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2860
		"        Object body = new Object() {\n" + 
3055
		"    { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2861
		"            public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + 
3056
		"    };\n" +
2862
		"                IResourceVisitor visitor = new IResourceVisitor() {\n" + 
3057
		"\n" +
2863
		"                    public boolean visit(String resource) throws IllegalArgumentException {\n" + 
2864
		"                        return true;\n" + 
2865
		"                    }\n" + 
2866
		"                };\n" + 
2867
		"            }\n" + 
2868
		"        };\n" + 
2869
		"    }\n" + 
2870
		"\n" + 
2871
		"}\n" + 
2872
		"interface IResourceVisitor {\n" + 
3058
		"}\n";
2873
		"}\n";
3059
	formatSource(source,
2874
	formatSource(source,
3060
		"package massive;\n" +
2875
		"package massive;\n" + 
3061
		"\n" +
2876
		"\n" + 
3062
		"public class X06b\n" +
2877
		"public class X03\n" +
3063
		"{\n" +
2878
		"{\n" + 
3064
		"\n" +
2879
		"\n" + 
3065
		"    // Table to merge access modes for condition statements (e.g branch[x] ||\n" +
2880
		"	public void foo() throws NullPointerException {\n" + 
3066
		"    // branch[y]).\n" +
2881
		"\n" + 
3067
		"    private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" +
2882
		"		Object body = new Object() {\n" + 
3068
		"    {\n" +
2883
		"			public void run(StringBuffer monitor)\n" + 
3069
		"     { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" +
2884
		"					throws IllegalArgumentException {\n" + 
3070
		"     { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" +
2885
		"				IResourceVisitor visitor = new IResourceVisitor() {\n" + 
3071
		"    };\n" +
2886
		"					public boolean visit(String resource)\n" + 
3072
		"\n" +
2887
		"							throws IllegalArgumentException {\n" + 
2888
		"						return true;\n" + 
2889
		"					}\n" + 
2890
		"				};\n" + 
2891
		"			}\n" + 
2892
		"		};\n" + 
2893
		"	}\n" + 
2894
		"\n" + 
2895
		"}\n" + 
2896
		"\n" + 
2897
		"interface IResourceVisitor {\n" + 
3073
		"}\n"
2898
		"}\n"
3074
	);
2899
	);
3075
}
2900
}
3076
public void testBug286601k() {
2901
public void testBug286601_wksp_03b() {
3077
	this.formatterPrefs.join_wrapped_lines = false;
2902
	this.formatterPrefs.join_wrapped_lines = false;
3078
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
3079
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE;
3080
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
2903
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
3081
	String source =
2904
	String source =
3082
		"package massive;\n" +
2905
		"package massive;\n" + 
3083
		"\n" +
2906
		"\n" + 
3084
		"public class X07 {\n" +
2907
		"public class X03\n" + 
3085
		"    private MinimizedFileSystemElement selectFiles(final Object rootFileSystemObject, final IImportStructureProvider structureProvider) {\n" +
2908
		"{\n" + 
3086
		"\n" +
2909
		"\n" + 
3087
		"        BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {\n" +
2910
		"    public void foo() throws NullPointerException {\n" + 
3088
		"            public void run() {\n" +
2911
		"\n" + 
3089
		"                //Create the root element from the supplied file system object\n" +
2912
		"        Object body = new Object() {\n" + 
3090
		"            }\n" +
2913
		"            public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + 
3091
		"        });\n" +
2914
		"                IResourceVisitor visitor = new IResourceVisitor() {\n" + 
3092
		"\n" +
2915
		"                    public boolean visit(String resource) throws IllegalArgumentException {\n" + 
3093
		"        return null;\n" +
2916
		"                        return true;\n" + 
3094
		"    }\n" +
2917
		"                    }\n" + 
2918
		"                };\n" + 
2919
		"            }\n" + 
2920
		"        };\n" + 
2921
		"    }\n" + 
2922
		"\n" + 
2923
		"}\n" + 
2924
		"interface IResourceVisitor {\n" + 
3095
		"}\n";
2925
		"}\n";
3096
	formatSource(source,
2926
	formatSource(source,
3097
		"package massive;\n" +
2927
		"package massive;\n" + 
3098
		"\n" +
2928
		"\n" + 
3099
		"public class X07\n" +
2929
		"public class X03\n" + 
3100
		"{\n" +
2930
		"{\n" + 
3101
		"    private MinimizedFileSystemElement selectFiles(\n" +
2931
		"\n" + 
3102
		"            final Object rootFileSystemObject,\n" +
2932
		"	public void foo() throws NullPointerException\n" + 
3103
		"            final IImportStructureProvider structureProvider)\n" +
2933
		"	{\n" + 
3104
		"    {\n" +
2934
		"\n" + 
3105
		"\n" +
2935
		"		Object body = new Object()\n" + 
3106
		"        BusyIndicator.showWhile(getShell().getDisplay(), new Runnable()\n" +
2936
		"		{\n" + 
3107
		"        {\n" +
2937
		"			public void run(StringBuffer monitor)\n" + 
3108
		"            public void run()\n" +
2938
		"					throws IllegalArgumentException\n" + 
3109
		"            {\n" +
2939
		"			{\n" + 
3110
		"                // Create the root element from the supplied file system object\n" +
2940
		"				IResourceVisitor visitor = new IResourceVisitor()\n" + 
3111
		"            }\n" +
2941
		"				{\n" + 
3112
		"        });\n" +
2942
		"					public boolean visit(String resource)\n" + 
3113
		"\n" +
2943
		"							throws IllegalArgumentException\n" + 
3114
		"        return null;\n" +
2944
		"					{\n" + 
3115
		"    }\n" +
2945
		"						return true;\n" + 
2946
		"					}\n" + 
2947
		"				};\n" + 
2948
		"			}\n" + 
2949
		"		};\n" + 
2950
		"	}\n" + 
2951
		"\n" + 
2952
		"}\n" + 
2953
		"\n" + 
2954
		"interface IResourceVisitor\n" + 
2955
		"{\n" + 
3116
		"}\n"
2956
		"}\n"
3117
	);
2957
	);
3118
}
2958
}
Lines 7019-7032 Link Here
7019
		"					MessageFormat\n" + 
6859
		"					MessageFormat\n" + 
7020
		"							.format(InternalAntMessages\n" + 
6860
		"							.format(InternalAntMessages\n" + 
7021
		"									.getString(\"InternalAntRunner.Buildfile__{0}_does_not_exist_!_1\"), //$NON-NLS-1$\n" + 
6861
		"									.getString(\"InternalAntRunner.Buildfile__{0}_does_not_exist_!_1\"), //$NON-NLS-1$\n" + 
7022
		"							new String[] { buildFile.getAbsolutePath() }));\n" + 
6862
		"									new String[] { buildFile.getAbsolutePath() }));\n" + 
7023
		"		}\n" + 
6863
		"		}\n" + 
7024
		"		if (!buildFile.isFile()) {\n" + 
6864
		"		if (!buildFile.isFile()) {\n" + 
7025
		"			throw new BuildException(\n" + 
6865
		"			throw new BuildException(\n" + 
7026
		"					MessageFormat\n" + 
6866
		"					MessageFormat\n" + 
7027
		"							.format(InternalAntMessages\n" + 
6867
		"							.format(InternalAntMessages\n" + 
7028
		"									.getString(\"InternalAntRunner.Buildfile__{0}_is_not_a_file_1\"), //$NON-NLS-1$\n" + 
6868
		"									.getString(\"InternalAntRunner.Buildfile__{0}_is_not_a_file_1\"), //$NON-NLS-1$\n" + 
7029
		"							new String[] { buildFile.getAbsolutePath() }));\n" + 
6869
		"									new String[] { buildFile.getAbsolutePath() }));\n" + 
7030
		"		}\n" + 
6870
		"		}\n" + 
7031
		"	}\n" + 
6871
		"	}\n" + 
7032
		"}\n"
6872
		"}\n"
Lines 7630-7635 Link Here
7630
}
7470
}
7631
7471
7632
/**
7472
/**
7473
 * @bug 330313: [formatter] 'Never join already wrapped lines' formatter option does correctly indent
7474
 * @test Ensure that indentation is correct when 'Never join already wrapped lines' is set
7475
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=330313"
7476
 */
7477
public void testBug330313() {
7478
	this.formatterPrefs.join_wrapped_lines = false;
7479
	String source =
7480
		"public class Test {\n" + 
7481
		"	private void helper2(\n" + 
7482
		"			 boolean[] booleans) {\n" + 
7483
		"		if (booleans[0]) {\n" + 
7484
		"\n" + 
7485
		"		}\n" + 
7486
		"	}\n" + 
7487
		"}\n";
7488
	formatSource(source,
7489
		"public class Test {\n" + 
7490
		"	private void helper2(\n" + 
7491
		"			boolean[] booleans) {\n" + 
7492
		"		if (booleans[0]) {\n" + 
7493
		"\n" + 
7494
		"		}\n" + 
7495
		"	}\n" + 
7496
		"}\n"
7497
	);
7498
}
7499
public void testBug330313a() {
7500
	this.formatterPrefs.join_wrapped_lines = false;
7501
	String source =
7502
		"public class Test {\n" + 
7503
		"	private void helper2(\n" + 
7504
		"			boolean[] booleans) {\n" + 
7505
		"		if (booleans[0]) {\n" + 
7506
		"\n" + 
7507
		"		}\n" + 
7508
		"	}\n" + 
7509
		"}\n";
7510
	formatSource(source);
7511
}
7512
public void testBug330313b() {
7513
	this.formatterPrefs.join_wrapped_lines = false;
7514
	String source =
7515
		"public class Test {\n" + 
7516
		"	private void helper2(\n" + 
7517
		"                boolean[] booleans) {\n" + 
7518
		"		if (booleans[0]) {\n" + 
7519
		"\n" + 
7520
		"		}\n" + 
7521
		"	}\n" + 
7522
		"}\n";
7523
	formatSource(source,
7524
		"public class Test {\n" + 
7525
		"	private void helper2(\n" + 
7526
		"			boolean[] booleans) {\n" + 
7527
		"		if (booleans[0]) {\n" + 
7528
		"\n" + 
7529
		"		}\n" + 
7530
		"	}\n" + 
7531
		"}\n"
7532
	);
7533
}
7534
public void testBug330313c() {
7535
	this.formatterPrefs.join_wrapped_lines = false;
7536
	String source =
7537
		"public class Test {\n" + 
7538
		"	private void helper2(\n" + 
7539
		"boolean[] booleans) {\n" + 
7540
		"		if (booleans[0]) {\n" + 
7541
		"\n" + 
7542
		"		}\n" + 
7543
		"	}\n" + 
7544
		"}\n";
7545
	formatSource(source,
7546
		"public class Test {\n" + 
7547
		"	private void helper2(\n" + 
7548
		"			boolean[] booleans) {\n" + 
7549
		"		if (booleans[0]) {\n" + 
7550
		"\n" + 
7551
		"		}\n" + 
7552
		"	}\n" + 
7553
		"}\n"
7554
	);
7555
}
7556
public void testBug330313d() {
7557
	this.formatterPrefs.join_wrapped_lines = false;
7558
	String source =
7559
		"public class Test {\n" + 
7560
		"	private void helper2(\n" + 
7561
		"			boolean[] booleans) {\n" + 
7562
		"		if (booleans[0]) {\n" + 
7563
		"\n" + 
7564
		"		}\n" + 
7565
		"	}\n" + 
7566
		"}\n";
7567
	formatSource(source,
7568
		"public class Test {\n" + 
7569
		"	private void helper2(\n" + 
7570
		"			boolean[] booleans) {\n" + 
7571
		"		if (booleans[0]) {\n" + 
7572
		"\n" + 
7573
		"		}\n" + 
7574
		"	}\n" + 
7575
		"}\n"
7576
	);
7577
}
7578
public void testBug330313_regression_187a() {
7579
	String source =
7580
		"import java.io.File;\n" + 
7581
		"\n" + 
7582
		"public class RegressionTest_187 {\n" + 
7583
		"\n" + 
7584
		"	private String createC42PDFCommandLine(String documentName) {\n" + 
7585
		"		return (Registry.getConvertToolPath() + File.separator +\n" + 
7586
		"			   Registry.getConvertToolName() +\n" + 
7587
		"			   \" -o \" + _workingDir + File.separator + documentName +\n" + 
7588
		"			   \" -l \" + _workingDir + File.separator + _fileList);\n" + 
7589
		"	}\n" + 
7590
		"}\n";
7591
	formatSource(source,
7592
		"import java.io.File;\n" + 
7593
		"\n" + 
7594
		"public class RegressionTest_187 {\n" + 
7595
		"\n" + 
7596
		"	private String createC42PDFCommandLine(String documentName) {\n" + 
7597
		"		return (Registry.getConvertToolPath() + File.separator\n" + 
7598
		"				+ Registry.getConvertToolName() + \" -o \" + _workingDir\n" + 
7599
		"				+ File.separator + documentName + \" -l \" + _workingDir\n" + 
7600
		"				+ File.separator + _fileList);\n" + 
7601
		"	}\n" + 
7602
		"}\n"
7603
	);
7604
}
7605
public void testBug330313_regression_187b() {
7606
	String source =
7607
		"import java.io.File;\n" + 
7608
		"\n" + 
7609
		"public class RegressionTest_187 {\n" + 
7610
		"\n" + 
7611
		"	private String createC42PDFCommandLine(String documentName) {\n" + 
7612
		"		return (Registry.getConvertToolPath() + File.separator +\n" + 
7613
		"			   Registry.getConvertToolName() +\n" + 
7614
		"			   (\" -o \" + _workingDir + File.separator + documentName +\n" + 
7615
		"			   (\" -l \" + _workingDir + File.separator + _fileList)));\n" + 
7616
		"	}\n" + 
7617
		"}\n";
7618
	formatSource(source,
7619
		"import java.io.File;\n" + 
7620
		"\n" + 
7621
		"public class RegressionTest_187 {\n" + 
7622
		"\n" + 
7623
		"	private String createC42PDFCommandLine(String documentName) {\n" + 
7624
		"		return (Registry.getConvertToolPath() + File.separator\n" + 
7625
		"				+ Registry.getConvertToolName() + (\" -o \" + _workingDir\n" + 
7626
		"				+ File.separator + documentName + (\" -l \" + _workingDir\n" + 
7627
		"				+ File.separator + _fileList)));\n" + 
7628
		"	}\n" + 
7629
		"}\n"
7630
	);
7631
}
7632
//static { TESTS_PREFIX = "testBug330313_wksp1"; }
7633
public void testBug330313_wksp1_01_njl() {
7634
	this.formatterPrefs.join_wrapped_lines = false;
7635
	String source =
7636
		"package wksp1;\n" + 
7637
		"\n" + 
7638
		"public class X01 {\n" + 
7639
		"\n" + 
7640
		"    protected String getPrefixFromDocument(String aDocumentText, int anOffset) {\n" + 
7641
		"        int startOfWordToken = anOffset;\n" + 
7642
		"        \n" + 
7643
		"        char token= \'a\';\n" + 
7644
		"        if (startOfWordToken > 0) {\n" + 
7645
		"			token= aDocumentText.charAt(startOfWordToken - 1);\n" + 
7646
		"        }\n" + 
7647
		"        \n" + 
7648
		"        while (startOfWordToken > 0 \n" + 
7649
		"                && (Character.isJavaIdentifierPart(token) \n" + 
7650
		"                    || \'.\' == token\n" + 
7651
		"					|| \'-\' == token\n" + 
7652
		"        			|| \';\' == token)\n" + 
7653
		"                && !(\'$\' == token)) {\n" + 
7654
		"            startOfWordToken--;\n" + 
7655
		"            if (startOfWordToken == 0) {\n" + 
7656
		"            	break; //word goes right to the beginning of the doc\n" + 
7657
		"            }\n" + 
7658
		"			token= aDocumentText.charAt(startOfWordToken - 1);\n" + 
7659
		"        }\n" + 
7660
		"        return \"\";\n" + 
7661
		"    }\n" + 
7662
		"}\n";
7663
	formatSource(source,
7664
		"package wksp1;\n" + 
7665
		"\n" + 
7666
		"public class X01 {\n" + 
7667
		"\n" + 
7668
		"	protected String getPrefixFromDocument(String aDocumentText, int anOffset) {\n" + 
7669
		"		int startOfWordToken = anOffset;\n" + 
7670
		"\n" + 
7671
		"		char token = \'a\';\n" + 
7672
		"		if (startOfWordToken > 0) {\n" + 
7673
		"			token = aDocumentText.charAt(startOfWordToken - 1);\n" + 
7674
		"		}\n" + 
7675
		"\n" + 
7676
		"		while (startOfWordToken > 0\n" + 
7677
		"				&& (Character.isJavaIdentifierPart(token)\n" + 
7678
		"						|| \'.\' == token\n" + 
7679
		"						|| \'-\' == token\n" + 
7680
		"						|| \';\' == token)\n" + 
7681
		"				&& !(\'$\' == token)) {\n" + 
7682
		"			startOfWordToken--;\n" + 
7683
		"			if (startOfWordToken == 0) {\n" + 
7684
		"				break; // word goes right to the beginning of the doc\n" + 
7685
		"			}\n" + 
7686
		"			token = aDocumentText.charAt(startOfWordToken - 1);\n" + 
7687
		"		}\n" + 
7688
		"		return \"\";\n" + 
7689
		"	}\n" + 
7690
		"}\n"
7691
	);
7692
}
7693
public void testBug330313_wksp1_02_njl() {
7694
	this.formatterPrefs.join_wrapped_lines = false;
7695
	String source =
7696
		"package wksp1;\n" + 
7697
		"\n" + 
7698
		"public class X02 {\n" + 
7699
		"  public void testMethod(String currentTokenVal,\n" + 
7700
		"                         int[][] expectedTokenSequencesVal,\n" + 
7701
		"                         String[] tokenImageVal\n" + 
7702
		"                        )\n" + 
7703
		"  {\n" + 
7704
		"  }\n" + 
7705
		"}\n";
7706
	formatSource(source,
7707
		"package wksp1;\n" + 
7708
		"\n" + 
7709
		"public class X02 {\n" + 
7710
		"	public void testMethod(String currentTokenVal,\n" + 
7711
		"			int[][] expectedTokenSequencesVal,\n" + 
7712
		"			String[] tokenImageVal\n" + 
7713
		"			)\n" +
7714
		"	{\n" + 
7715
		"	}\n" + 
7716
		"}\n"
7717
	);
7718
}
7719
public void testBug330313_wksp1_03_njl() {
7720
	this.formatterPrefs.join_wrapped_lines = false;
7721
	String source =
7722
		"package wksp1;\n" + 
7723
		"\n" + 
7724
		"public class X03 {\n" + 
7725
		"\n" + 
7726
		"	void foo() {\n" + 
7727
		"			if (declaringClass.isNestedType()){\n" + 
7728
		"				NestedTypeBinding nestedType = (NestedTypeBinding) declaringClass;\n" + 
7729
		"				this.scope.extraSyntheticArguments = nestedType.syntheticOuterLocalVariables();\n" + 
7730
		"				scope.computeLocalVariablePositions(// consider synthetic arguments if any\n" + 
7731
		"					nestedType.enclosingInstancesSlotSize + 1,\n" + 
7732
		"					codeStream);\n" + 
7733
		"				argSlotSize += nestedType.enclosingInstancesSlotSize;\n" + 
7734
		"				argSlotSize += nestedType.outerLocalVariablesSlotSize;\n" + 
7735
		"			} else {\n" + 
7736
		"				scope.computeLocalVariablePositions(1,  codeStream);\n" + 
7737
		"			}\n" + 
7738
		"	}\n" + 
7739
		"}\n";
7740
	formatSource(source,
7741
		"package wksp1;\n" + 
7742
		"\n" + 
7743
		"public class X03 {\n" + 
7744
		"\n" + 
7745
		"	void foo() {\n" + 
7746
		"		if (declaringClass.isNestedType()) {\n" + 
7747
		"			NestedTypeBinding nestedType = (NestedTypeBinding) declaringClass;\n" + 
7748
		"			this.scope.extraSyntheticArguments = nestedType\n" + 
7749
		"					.syntheticOuterLocalVariables();\n" + 
7750
		"			scope.computeLocalVariablePositions(// consider synthetic arguments\n" + 
7751
		"												// if any\n" + 
7752
		"					nestedType.enclosingInstancesSlotSize + 1,\n" + 
7753
		"					codeStream);\n" + 
7754
		"			argSlotSize += nestedType.enclosingInstancesSlotSize;\n" + 
7755
		"			argSlotSize += nestedType.outerLocalVariablesSlotSize;\n" + 
7756
		"		} else {\n" + 
7757
		"			scope.computeLocalVariablePositions(1, codeStream);\n" + 
7758
		"		}\n" + 
7759
		"	}\n" + 
7760
		"}\n"
7761
	);
7762
}
7763
public void testBug330313_wksp1_04() {
7764
	String source =
7765
		"package wksp1;\n" + 
7766
		"\n" + 
7767
		"public class X04 {\n" + 
7768
		"\n" + 
7769
		"	void foo() {\n" + 
7770
		"		for (;;) {\n" + 
7771
		"			if (act <= NUM_RULES) {               // reduce action\n" + 
7772
		"				tempStackTop--;\n" + 
7773
		"			} else if (act < ACCEPT_ACTION ||     // shift action\n" + 
7774
		"					 act > ERROR_ACTION) {        // shift-reduce action\n" + 
7775
		"				if (indx == MAX_DISTANCE)\n" + 
7776
		"					return indx;\n" + 
7777
		"				indx++;\n" + 
7778
		"			}\n" + 
7779
		"		}\n" + 
7780
		"	}\n" + 
7781
		"}\n";
7782
	formatSource(source,
7783
		"package wksp1;\n" + 
7784
		"\n" + 
7785
		"public class X04 {\n" + 
7786
		"\n" + 
7787
		"	void foo() {\n" + 
7788
		"		for (;;) {\n" + 
7789
		"			if (act <= NUM_RULES) { // reduce action\n" + 
7790
		"				tempStackTop--;\n" + 
7791
		"			} else if (act < ACCEPT_ACTION || // shift action\n" + 
7792
		"					act > ERROR_ACTION) { // shift-reduce action\n" + 
7793
		"				if (indx == MAX_DISTANCE)\n" + 
7794
		"					return indx;\n" + 
7795
		"				indx++;\n" + 
7796
		"			}\n" + 
7797
		"		}\n" + 
7798
		"	}\n" + 
7799
		"}\n"
7800
	);
7801
}
7802
public void testBug330313_wksp1_04_njl() {
7803
	this.formatterPrefs.join_wrapped_lines = false;
7804
	String source =
7805
		"package wksp1;\n" + 
7806
		"\n" + 
7807
		"public class X04 {\n" + 
7808
		"\n" + 
7809
		"	void foo() {\n" + 
7810
		"		for (;;) {\n" + 
7811
		"			if (act <= NUM_RULES) {               // reduce action\n" + 
7812
		"				tempStackTop--;\n" + 
7813
		"			} else if (act < ACCEPT_ACTION ||     // shift action\n" + 
7814
		"					 act > ERROR_ACTION) {        // shift-reduce action\n" + 
7815
		"				if (indx == MAX_DISTANCE)\n" + 
7816
		"					return indx;\n" + 
7817
		"				indx++;\n" + 
7818
		"			}\n" + 
7819
		"		}\n" + 
7820
		"	}\n" + 
7821
		"}\n";
7822
	formatSource(source,
7823
		"package wksp1;\n" + 
7824
		"\n" + 
7825
		"public class X04 {\n" + 
7826
		"\n" + 
7827
		"	void foo() {\n" + 
7828
		"		for (;;) {\n" + 
7829
		"			if (act <= NUM_RULES) { // reduce action\n" + 
7830
		"				tempStackTop--;\n" + 
7831
		"			} else if (act < ACCEPT_ACTION || // shift action\n" + 
7832
		"					act > ERROR_ACTION) { // shift-reduce action\n" + 
7833
		"				if (indx == MAX_DISTANCE)\n" + 
7834
		"					return indx;\n" + 
7835
		"				indx++;\n" + 
7836
		"			}\n" + 
7837
		"		}\n" + 
7838
		"	}\n" + 
7839
		"}\n"
7840
	);
7841
}
7842
public void testBug330313_wksp1_05_njl() {
7843
	this.formatterPrefs.join_wrapped_lines = false;
7844
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
7845
	String source =
7846
		"package wksp1;\n" + 
7847
		"\n" + 
7848
		"public class X05 {\n" + 
7849
		"\n" + 
7850
		"	private void foo() {\n" + 
7851
		"		setBuildFileLocation.invoke(runner, new Object[] { buildFileLocation });\n" + 
7852
		"	}\n" + 
7853
		"}\n";
7854
	formatSource(source,
7855
		"package wksp1;\n" + 
7856
		"\n" + 
7857
		"public class X05\n" + 
7858
		"{\n" + 
7859
		"\n" + 
7860
		"	private void foo()\n" + 
7861
		"	{\n" + 
7862
		"		setBuildFileLocation.invoke(runner, new Object[]\n" + 
7863
		"		{ buildFileLocation });\n" + 
7864
		"	}\n" + 
7865
		"}\n"
7866
	);
7867
}
7868
public void testBug330313_wksp1_06_njl() {
7869
	this.formatterPrefs.join_wrapped_lines = false;
7870
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
7871
	String source =
7872
		"package wksp1;\n" + 
7873
		"\n" + 
7874
		"public class X06 {\n" + 
7875
		"\n" + 
7876
		"	public void foo(Object index) {\n" + 
7877
		"\n" + 
7878
		"		try {\n" + 
7879
		"			index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);\n" + 
7880
		"		}\n" + 
7881
		"		finally {}\n" + 
7882
		"	}\n" + 
7883
		"}\n";
7884
	formatSource(source,
7885
		"package wksp1;\n" + 
7886
		"\n" + 
7887
		"public class X06\n" + 
7888
		"{\n" + 
7889
		"\n" + 
7890
		"	public void foo(Object index)\n" + 
7891
		"	{\n" + 
7892
		"\n" + 
7893
		"		try\n" + 
7894
		"		{\n" + 
7895
		"			index = this.manager.getIndexForUpdate(this.containerPath, true, /*\n" + 
7896
		"																			 * reuse\n" + 
7897
		"																			 * index\n" + 
7898
		"																			 * file\n" + 
7899
		"																			 */\n" + 
7900
		"					true /* create if none */);\n" + 
7901
		"		} finally\n" + 
7902
		"		{\n" + 
7903
		"		}\n" + 
7904
		"	}\n" + 
7905
		"}\n"
7906
	);
7907
}
7908
public void testBug330313_wksp1_07() {
7909
	String source =
7910
		"package wksp1;\n" + 
7911
		"\n" + 
7912
		"public class X07 {\n" + 
7913
		"\n" + 
7914
		"static final long[] jjtoToken = {\n" + 
7915
		"   0x7fbfecffL, \n" + 
7916
		"};\n" + 
7917
		"static final long[] jjtoSkip = {\n" + 
7918
		"   0x400000L, \n" + 
7919
		"};\n" + 
7920
		"\n" + 
7921
		"}\n";
7922
	formatSource(source,
7923
		"package wksp1;\n" + 
7924
		"\n" + 
7925
		"public class X07 {\n" + 
7926
		"\n" + 
7927
		"	static final long[] jjtoToken = { 0x7fbfecffL, };\n" + 
7928
		"	static final long[] jjtoSkip = { 0x400000L, };\n" + 
7929
		"\n" + 
7930
		"}\n"
7931
	);
7932
}
7933
public void testBug330313_wksp1_07_bnl() {
7934
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
7935
	String source =
7936
		"package wksp1;\n" + 
7937
		"\n" + 
7938
		"public class X07 {\n" + 
7939
		"\n" + 
7940
		"static final long[] jjtoToken = {\n" + 
7941
		"   0x7fbfecffL, \n" + 
7942
		"};\n" + 
7943
		"static final long[] jjtoSkip = {\n" + 
7944
		"   0x400000L, \n" + 
7945
		"};\n" + 
7946
		"\n" + 
7947
		"}\n";
7948
	formatSource(source,
7949
		"package wksp1;\n" + 
7950
		"\n" + 
7951
		"public class X07\n" + 
7952
		"{\n" + 
7953
		"\n" + 
7954
		"	static final long[] jjtoToken =\n" + 
7955
		"	{ 0x7fbfecffL, };\n" + 
7956
		"	static final long[] jjtoSkip =\n" + 
7957
		"	{ 0x400000L, };\n" + 
7958
		"\n" + 
7959
		"}\n"
7960
	);
7961
}
7962
public void testBug330313_wksp1_07_njl() {
7963
	this.formatterPrefs.join_wrapped_lines = false;
7964
	String source =
7965
		"package wksp1;\n" + 
7966
		"\n" + 
7967
		"public class X07 {\n" + 
7968
		"\n" + 
7969
		"static final long[] jjtoToken = {\n" + 
7970
		"   0x7fbfecffL, \n" + 
7971
		"};\n" + 
7972
		"static final long[] jjtoSkip = {\n" + 
7973
		"   0x400000L, \n" + 
7974
		"};\n" + 
7975
		"\n" + 
7976
		"}\n";
7977
	formatSource(source,
7978
		"package wksp1;\n" + 
7979
		"\n" + 
7980
		"public class X07 {\n" + 
7981
		"\n" + 
7982
		"	static final long[] jjtoToken = {\n" + 
7983
		"			0x7fbfecffL,\n" + 
7984
		"	};\n" + 
7985
		"	static final long[] jjtoSkip = {\n" + 
7986
		"			0x400000L,\n" + 
7987
		"	};\n" + 
7988
		"\n" + 
7989
		"}\n"
7990
	);
7991
}
7992
public void testBug330313_wksp1_07_njl_bnl() {
7993
	this.formatterPrefs.join_wrapped_lines = false;
7994
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
7995
	String source =
7996
		"package wksp1;\n" + 
7997
		"\n" + 
7998
		"public class X07 {\n" + 
7999
		"\n" + 
8000
		"static final long[] jjtoToken = {\n" + 
8001
		"   0x7fbfecffL, \n" + 
8002
		"};\n" + 
8003
		"static final long[] jjtoSkip = {\n" + 
8004
		"   0x400000L, \n" + 
8005
		"};\n" + 
8006
		"\n" + 
8007
		"}\n";
8008
	formatSource(source,
8009
		"package wksp1;\n" + 
8010
		"\n" + 
8011
		"public class X07\n" + 
8012
		"{\n" + 
8013
		"\n" + 
8014
		"	static final long[] jjtoToken =\n" + 
8015
		"	{\n" + 
8016
		"			0x7fbfecffL,\n" + 
8017
		"	};\n" + 
8018
		"	static final long[] jjtoSkip =\n" + 
8019
		"	{\n" + 
8020
		"			0x400000L,\n" + 
8021
		"	};\n" + 
8022
		"\n" + 
8023
		"}\n"
8024
	);
8025
}
8026
public void testBug330313_wksp1_08_njl() {
8027
	this.formatterPrefs.join_wrapped_lines = false;
8028
	String source =
8029
		"package wksp1;\n" + 
8030
		"\n" + 
8031
		"public class X08 {\n" + 
8032
		"\n" + 
8033
		"	void foo() {\n" + 
8034
		"		MinimizedFileSystemElement dummyParent =\n" + 
8035
		"			new MinimizedFileSystemElement(\"\", null, true);//$NON-NLS-1$\n" + 
8036
		"	}\n" + 
8037
		"}\n";
8038
	formatSource(source,
8039
		"package wksp1;\n" + 
8040
		"\n" + 
8041
		"public class X08 {\n" + 
8042
		"\n" + 
8043
		"	void foo() {\n" + 
8044
		"		MinimizedFileSystemElement dummyParent =\n" + 
8045
		"				new MinimizedFileSystemElement(\"\", null, true);//$NON-NLS-1$\n" + 
8046
		"	}\n" + 
8047
		"}\n"
8048
	);
8049
}
8050
// testCompare1159_1: org.eclipse.debug.internal.ui.DebugUIPropertiesAdapterFactory
8051
public void testBug330313_wksp1_09_njl() {
8052
	this.formatterPrefs.join_wrapped_lines = false;
8053
	String source =
8054
		"package wksp1;\n" + 
8055
		"\n" + 
8056
		"public class X09 {\n" + 
8057
		"	public Class[] getAdapterList() {\n" + 
8058
		"		return new Class[] {\n" + 
8059
		"			IWorkbenchAdapter.class\n" + 
8060
		"		};\n" + 
8061
		"	}\n" + 
8062
		"}\n";
8063
	formatSource(source,
8064
		"package wksp1;\n" + 
8065
		"\n" + 
8066
		"public class X09 {\n" + 
8067
		"	public Class[] getAdapterList() {\n" + 
8068
		"		return new Class[] {\n" + 
8069
		"				IWorkbenchAdapter.class\n" + 
8070
		"		};\n" + 
8071
		"	}\n" + 
8072
		"}\n"
8073
	);
8074
}
8075
// testCompare1723_1: org.eclipse.jdt.internal.compiler.ast.DoubleLiteral
8076
public void testBug330313_wksp1_10_njl() {
8077
	this.formatterPrefs.join_wrapped_lines = false;
8078
	String source =
8079
		"package wksp1;\n" + 
8080
		"\n" + 
8081
		"public class X10 {\n" + 
8082
		"\n" + 
8083
		"public void computeConstant() {\n" + 
8084
		"\n" + 
8085
		"	if (true)\n" + 
8086
		"	{	//only a true 0 can be made of zeros\n" + 
8087
		"		//2.00000000000000000e-324 is illegal .... \n" + 
8088
		"	}}\n" + 
8089
		"}\n";
8090
	formatSource(source,
8091
		"package wksp1;\n" + 
8092
		"\n" + 
8093
		"public class X10 {\n" + 
8094
		"\n" + 
8095
		"	public void computeConstant() {\n" + 
8096
		"\n" + 
8097
		"		if (true)\n" + 
8098
		"		{ // only a true 0 can be made of zeros\n" + 
8099
		"			// 2.00000000000000000e-324 is illegal ....\n" + 
8100
		"		}\n" + 
8101
		"	}\n" + 
8102
		"}\n"
8103
	);
8104
}
8105
// testCompare1794_1: org.eclipse.jdt.internal.compiler.ast.ClassFile
8106
public void testBug330313_wksp1_11_njl() {
8107
	this.formatterPrefs.join_wrapped_lines = false;
8108
	String source =
8109
		"package wksp1;\n" + 
8110
		"\n" + 
8111
		"public class X11 {\n" + 
8112
		"	X11() {\n" + 
8113
		"		accessFlags\n" + 
8114
		"			&= ~(\n" + 
8115
		"				AccStrictfp\n" + 
8116
		"					| AccProtected\n" + 
8117
		"					| AccPrivate\n" + 
8118
		"					| AccStatic\n" + 
8119
		"					| AccSynchronized\n" + 
8120
		"					| AccNative);\n" + 
8121
		"	}\n" + 
8122
		"}\n";
8123
	formatSource(source,
8124
		"package wksp1;\n" + 
8125
		"\n" + 
8126
		"public class X11 {\n" + 
8127
		"	X11() {\n" + 
8128
		"		accessFlags &= ~(\n" + 
8129
		"				AccStrictfp\n" + 
8130
		"						| AccProtected\n" + 
8131
		"						| AccPrivate\n" + 
8132
		"						| AccStatic\n" + 
8133
		"						| AccSynchronized\n" + 
8134
		"						| AccNative);\n" + 
8135
		"	}\n" + 
8136
		"}\n"
8137
	);
8138
}
8139
// rg.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlFormatter.java
8140
public void testBug330313_wksp1_12() {
8141
	String source =
8142
		"package wksp1;\n" + 
8143
		"\n" + 
8144
		"public class X12 {\n" + 
8145
		"\n" + 
8146
		"    private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {\n" + 
8147
		"		Document doc= new Document(string);\n" + 
8148
		"		try {\n" + 
8149
		"			if (positions != null) {\n" + 
8150
		"				doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + 
8151
		"					protected boolean notDeleted() {\n" + 
8152
		"						if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {\n" + 
8153
		"							return false;\n" + 
8154
		"						}\n" + 
8155
		"						return true;\n" + 
8156
		"					}\n" + 
8157
		"				});\n" + 
8158
		"			}\n" + 
8159
		"		} catch (BadPositionCategoryException cannotHappen) {\n" + 
8160
		"			// can not happen: category is correctly set up\n" + 
8161
		"		}\n" + 
8162
		"		return doc;\n" + 
8163
		"	}\n" + 
8164
		"}\n";
8165
	formatSource(source,
8166
		"package wksp1;\n" + 
8167
		"\n" + 
8168
		"public class X12 {\n" + 
8169
		"\n" + 
8170
		"	private static Document createDocument(String string, Position[] positions)\n" + 
8171
		"			throws IllegalArgumentException {\n" + 
8172
		"		Document doc = new Document(string);\n" + 
8173
		"		try {\n" + 
8174
		"			if (positions != null) {\n" + 
8175
		"				doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + 
8176
		"					protected boolean notDeleted() {\n" + 
8177
		"						if (fOffset < fPosition.offset\n" + 
8178
		"								&& (fPosition.offset + fPosition.length < fOffset\n" + 
8179
		"										+ fLength)) {\n" + 
8180
		"							return false;\n" + 
8181
		"						}\n" + 
8182
		"						return true;\n" + 
8183
		"					}\n" + 
8184
		"				});\n" + 
8185
		"			}\n" + 
8186
		"		} catch (BadPositionCategoryException cannotHappen) {\n" + 
8187
		"			// can not happen: category is correctly set up\n" + 
8188
		"		}\n" + 
8189
		"		return doc;\n" + 
8190
		"	}\n" + 
8191
		"}\n"
8192
	);
8193
}
8194
public void testBug330313_wksp1_12_njl() {
8195
	this.formatterPrefs.join_wrapped_lines = false;
8196
	String source =
8197
		"package wksp1;\n" + 
8198
		"\n" + 
8199
		"public class X12 {\n" + 
8200
		"\n" + 
8201
		"    private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {\n" + 
8202
		"		Document doc= new Document(string);\n" + 
8203
		"		try {\n" + 
8204
		"			if (positions != null) {\n" + 
8205
		"				doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + 
8206
		"					protected boolean notDeleted() {\n" + 
8207
		"						if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {\n" + 
8208
		"							return false;\n" + 
8209
		"						}\n" + 
8210
		"						return true;\n" + 
8211
		"					}\n" + 
8212
		"				});\n" + 
8213
		"			}\n" + 
8214
		"		} catch (BadPositionCategoryException cannotHappen) {\n" + 
8215
		"			// can not happen: category is correctly set up\n" + 
8216
		"		}\n" + 
8217
		"		return doc;\n" + 
8218
		"	}\n" + 
8219
		"}\n";
8220
	formatSource(source,
8221
		"package wksp1;\n" + 
8222
		"\n" + 
8223
		"public class X12 {\n" + 
8224
		"\n" + 
8225
		"	private static Document createDocument(String string, Position[] positions)\n" + 
8226
		"			throws IllegalArgumentException {\n" + 
8227
		"		Document doc = new Document(string);\n" + 
8228
		"		try {\n" + 
8229
		"			if (positions != null) {\n" + 
8230
		"				doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + 
8231
		"					protected boolean notDeleted() {\n" + 
8232
		"						if (fOffset < fPosition.offset\n" + 
8233
		"								&& (fPosition.offset + fPosition.length < fOffset\n" + 
8234
		"										+ fLength)) {\n" + 
8235
		"							return false;\n" + 
8236
		"						}\n" + 
8237
		"						return true;\n" + 
8238
		"					}\n" + 
8239
		"				});\n" + 
8240
		"			}\n" + 
8241
		"		} catch (BadPositionCategoryException cannotHappen) {\n" + 
8242
		"			// can not happen: category is correctly set up\n" + 
8243
		"		}\n" + 
8244
		"		return doc;\n" + 
8245
		"	}\n" + 
8246
		"}\n"
8247
	);
8248
}
8249
// Test case extracted from org.eclipse.ant.ui/org/eclipse/core/internal/dtree/NodeInfo.java
8250
public void testBug330313_wksp1_13() {
8251
	String source =
8252
		"package wksp1;\n" + 
8253
		"\n" + 
8254
		"public class X13 {\n" + 
8255
		"\n" + 
8256
		"	public boolean isEmptyDelta() {\n" + 
8257
		"		return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE && this.getNamesOfChildren().length == 0 && this.getNamesOfDeletedChildren().length == 0);\n" + 
8258
		"	}\n" + 
8259
		"}\n";
8260
	formatSource(source,
8261
		"package wksp1;\n" + 
8262
		"\n" + 
8263
		"public class X13 {\n" + 
8264
		"\n" + 
8265
		"	public boolean isEmptyDelta() {\n" + 
8266
		"		return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE\n" + 
8267
		"				&& this.getNamesOfChildren().length == 0 && this\n" + 
8268
		"					.getNamesOfDeletedChildren().length == 0);\n" + 
8269
		"	}\n" + 
8270
		"}\n"
8271
	);
8272
}
8273
public void testBug330313_wksp1_13_njl() {
8274
	this.formatterPrefs.join_wrapped_lines = false;
8275
	String source =
8276
		"package wksp1;\n" + 
8277
		"\n" + 
8278
		"public class X13 {\n" + 
8279
		"\n" + 
8280
		"	public boolean isEmptyDelta() {\n" + 
8281
		"		return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE && this.getNamesOfChildren().length == 0 && this.getNamesOfDeletedChildren().length == 0);\n" + 
8282
		"	}\n" + 
8283
		"}\n";
8284
	formatSource(source,
8285
		"package wksp1;\n" + 
8286
		"\n" + 
8287
		"public class X13 {\n" + 
8288
		"\n" + 
8289
		"	public boolean isEmptyDelta() {\n" + 
8290
		"		return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE\n" + 
8291
		"				&& this.getNamesOfChildren().length == 0 && this\n" + 
8292
		"					.getNamesOfDeletedChildren().length == 0);\n" + 
8293
		"	}\n" + 
8294
		"}\n"
8295
	);
8296
}
8297
// Test case extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java
8298
public void testBug330313_wksp1_14() {
8299
	String source =
8300
		"package wksp1;\n" + 
8301
		"\n" + 
8302
		"public class X14 {\n" + 
8303
		"	public void foo() {\n" + 
8304
		"		if (true) {\n" + 
8305
		"			if (((bits & DepthMASK) != 0)\n" + 
8306
		"				&& (fieldBinding.isPrivate() // private access\n" + 
8307
		"					|| (fieldBinding.isProtected() // implicit protected access\n" + 
8308
		"							&& fieldBinding.declaringClass.getPackage() \n" + 
8309
		"								!= currentScope.enclosingSourceType().getPackage()))) {\n" + 
8310
		"				return;\n" + 
8311
		"			}\n" + 
8312
		"		}\n" + 
8313
		"	}\n" + 
8314
		"}\n";
8315
	formatSource(source,
8316
		"package wksp1;\n" + 
8317
		"\n" + 
8318
		"public class X14 {\n" + 
8319
		"	public void foo() {\n" + 
8320
		"		if (true) {\n" + 
8321
		"			if (((bits & DepthMASK) != 0) && (fieldBinding.isPrivate() // private\n" + 
8322
		"																		// access\n" + 
8323
		"					|| (fieldBinding.isProtected() // implicit protected access\n" + 
8324
		"					&& fieldBinding.declaringClass.getPackage() != currentScope\n" + 
8325
		"							.enclosingSourceType().getPackage()))) {\n" + 
8326
		"				return;\n" + 
8327
		"			}\n" + 
8328
		"		}\n" + 
8329
		"	}\n" + 
8330
		"}\n"
8331
	);
8332
}
8333
public void testBug330313_wksp1_14_njl() {
8334
	this.formatterPrefs.join_wrapped_lines = false;
8335
	String source =
8336
		"package wksp1;\n" + 
8337
		"\n" + 
8338
		"public class X14 {\n" + 
8339
		"	public void foo() {\n" + 
8340
		"		if (true) {\n" + 
8341
		"			if (((bits & DepthMASK) != 0)\n" + 
8342
		"				&& (fieldBinding.isPrivate() // private access\n" + 
8343
		"					|| (fieldBinding.isProtected() // implicit protected access\n" + 
8344
		"							&& fieldBinding.declaringClass.getPackage() \n" + 
8345
		"								!= currentScope.enclosingSourceType().getPackage()))) {\n" + 
8346
		"				return;\n" + 
8347
		"			}\n" + 
8348
		"		}\n" + 
8349
		"	}\n" + 
8350
		"}\n";
8351
	formatSource(source,
8352
		"package wksp1;\n" + 
8353
		"\n" + 
8354
		"public class X14 {\n" + 
8355
		"	public void foo() {\n" + 
8356
		"		if (true) {\n" + 
8357
		"			if (((bits & DepthMASK) != 0)\n" + 
8358
		"					&& (fieldBinding.isPrivate() // private access\n" + 
8359
		"					|| (fieldBinding.isProtected() // implicit protected access\n" + 
8360
		"					&& fieldBinding.declaringClass.getPackage()\n" + 
8361
		"						!= currentScope.enclosingSourceType().getPackage()))) {\n" + 
8362
		"				return;\n" + 
8363
		"			}\n" + 
8364
		"		}\n" + 
8365
		"	}\n" + 
8366
		"}\n"
8367
	);
8368
}
8369
// Test case extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java
8370
public void testBug330313_wksp1_15_njl() {
8371
	this.formatterPrefs.join_wrapped_lines = false;
8372
	String source =
8373
		"package wksp1;\n" + 
8374
		"\n" + 
8375
		"public class X15 {\n" + 
8376
		"	public void foo() {\n" + 
8377
		"		if (true) {\n" + 
8378
		"			if (fieldBinding.declaringClass != this.actualReceiverType\n" + 
8379
		"				&& !this.actualReceiverType.isArrayType()	\n" + 
8380
		"				&& fieldBinding.declaringClass != null\n" + 
8381
		"				&& fieldBinding.constant == NotAConstant\n" + 
8382
		"				&& ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2 \n" + 
8383
		"						&& !fieldBinding.isStatic()\n" + 
8384
		"						&& fieldBinding.declaringClass.id != T_Object) // no change for Object fields (if there was any)\n" + 
8385
		"					|| !fieldBinding.declaringClass.canBeSeenBy(currentScope))){\n" + 
8386
		"				this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)this.actualReceiverType);\n" + 
8387
		"			}\n" + 
8388
		"		}\n" + 
8389
		"	}\n" + 
8390
		"}\n";
8391
	formatSource(source,
8392
		"package wksp1;\n" + 
8393
		"\n" + 
8394
		"public class X15 {\n" + 
8395
		"	public void foo() {\n" + 
8396
		"		if (true) {\n" + 
8397
		"			if (fieldBinding.declaringClass != this.actualReceiverType\n" + 
8398
		"					&& !this.actualReceiverType.isArrayType()\n" + 
8399
		"					&& fieldBinding.declaringClass != null\n" + 
8400
		"					&& fieldBinding.constant == NotAConstant\n" + 
8401
		"					&& ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + 
8402
		"							&& !fieldBinding.isStatic()\n" + 
8403
		"							&& fieldBinding.declaringClass.id != T_Object) // no\n" + 
8404
		"																			// change\n" + 
8405
		"																			// for\n" + 
8406
		"																			// Object\n" + 
8407
		"																			// fields\n" + 
8408
		"																			// (if\n" + 
8409
		"																			// there\n" + 
8410
		"																			// was\n" + 
8411
		"																			// any)\n" + 
8412
		"							|| !fieldBinding.declaringClass\n" + 
8413
		"								.canBeSeenBy(currentScope))) {\n" + 
8414
		"				this.codegenBinding = currentScope.enclosingSourceType()\n" + 
8415
		"						.getUpdatedFieldBinding(fieldBinding,\n" + 
8416
		"								(ReferenceBinding) this.actualReceiverType);\n" + 
8417
		"			}\n" + 
8418
		"		}\n" + 
8419
		"	}\n" + 
8420
		"}\n"
8421
	);
8422
}
8423
// Test case 1941_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/Parser.java)
8424
public void testBug330313_wksp1_16() {
8425
	String source =
8426
		"package wksp1;\n" + 
8427
		"\n" + 
8428
		"public class X16 {\n" + 
8429
		"void foo() {\n" + 
8430
		"	// recovery\n" + 
8431
		"	if (this.currentElement != null) {\n" + 
8432
		"		if (!(this.currentElement instanceof RecoveredType)\n" + 
8433
		"			&& (this.currentToken == TokenNameDOT\n" + 
8434
		"				//|| declaration.modifiers != 0\n" + 
8435
		"				|| (this.scanner.getLineNumber(declaration.type.sourceStart)\n" + 
8436
		"						!= this.scanner.getLineNumber((int) (namePosition >>> 32))))){\n" + 
8437
		"			return;\n" + 
8438
		"		}\n" + 
8439
		"	}\n" + 
8440
		"}\n" + 
8441
		"}\n";
8442
	formatSource(source,
8443
		"package wksp1;\n" + 
8444
		"\n" + 
8445
		"public class X16 {\n" + 
8446
		"	void foo() {\n" + 
8447
		"		// recovery\n" + 
8448
		"		if (this.currentElement != null) {\n" + 
8449
		"			if (!(this.currentElement instanceof RecoveredType)\n" + 
8450
		"					&& (this.currentToken == TokenNameDOT\n" + 
8451
		"					// || declaration.modifiers != 0\n" + 
8452
		"					|| (this.scanner\n" + 
8453
		"							.getLineNumber(declaration.type.sourceStart) != this.scanner\n" + 
8454
		"							.getLineNumber((int) (namePosition >>> 32))))) {\n" + 
8455
		"				return;\n" + 
8456
		"			}\n" + 
8457
		"		}\n" + 
8458
		"	}\n" + 
8459
		"}\n"
8460
	);
8461
}
8462
public void testBug330313_wksp1_16_njl() {
8463
	this.formatterPrefs.join_wrapped_lines = false;
8464
	String source =
8465
		"package wksp1;\n" + 
8466
		"\n" + 
8467
		"public class X16 {\n" + 
8468
		"void foo() {\n" + 
8469
		"	// recovery\n" + 
8470
		"	if (this.currentElement != null) {\n" + 
8471
		"		if (!(this.currentElement instanceof RecoveredType)\n" + 
8472
		"			&& (this.currentToken == TokenNameDOT\n" + 
8473
		"				//|| declaration.modifiers != 0\n" + 
8474
		"				|| (this.scanner.getLineNumber(declaration.type.sourceStart)\n" + 
8475
		"						!= this.scanner.getLineNumber((int) (namePosition >>> 32))))){\n" + 
8476
		"			return;\n" + 
8477
		"		}\n" + 
8478
		"	}\n" + 
8479
		"}\n" + 
8480
		"}\n";
8481
	formatSource(source,
8482
		"package wksp1;\n" + 
8483
		"\n" + 
8484
		"public class X16 {\n" + 
8485
		"	void foo() {\n" + 
8486
		"		// recovery\n" + 
8487
		"		if (this.currentElement != null) {\n" + 
8488
		"			if (!(this.currentElement instanceof RecoveredType)\n" + 
8489
		"					&& (this.currentToken == TokenNameDOT\n" + 
8490
		"					// || declaration.modifiers != 0\n" + 
8491
		"					|| (this.scanner\n" + 
8492
		"							.getLineNumber(declaration.type.sourceStart)\n" + 
8493
		"						!= this.scanner\n" + 
8494
		"							.getLineNumber((int) (namePosition >>> 32))))) {\n" + 
8495
		"				return;\n" + 
8496
		"			}\n" + 
8497
		"		}\n" + 
8498
		"	}\n" + 
8499
		"}\n"
8500
	);
8501
}
8502
// Test case 1872_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java)
8503
public void testBug330313_wksp1_17_njl() {
8504
	this.formatterPrefs.join_wrapped_lines = false;
8505
	String source =
8506
		"package wksp1;\n" + 
8507
		"\n" + 
8508
		"public class X17 {\n" + 
8509
		"	void foo() {\n" + 
8510
		"		if ((currentMethodScope = this.methodScope())\n" + 
8511
		"			!= outerLocalVariable.declaringScope.methodScope()) {\n" + 
8512
		"			return;\n" + 
8513
		"		}\n" + 
8514
		"	}\n" + 
8515
		"}\n";
8516
	formatSource(source	,
8517
		"package wksp1;\n" + 
8518
		"\n" + 
8519
		"public class X17 {\n" + 
8520
		"	void foo() {\n" + 
8521
		"		if ((currentMethodScope = this.methodScope())\n" + 
8522
		"				!= outerLocalVariable.declaringScope.methodScope()) {\n" + 
8523
		"			return;\n" + 
8524
		"		}\n" + 
8525
		"	}\n" + 
8526
		"}\n"
8527
	);
8528
}
8529
// Test case 1964_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/core/dom/ASTMatcher.java)
8530
public void testBug330313_wksp1_18_njl() {
8531
	this.formatterPrefs.join_wrapped_lines = false;
8532
	String source =
8533
		"package wksp1;\n" + 
8534
		"\n" + 
8535
		"public class X18 {\n" + 
8536
		"	public boolean foo() {\n" + 
8537
		"		return (\n" + 
8538
		"			safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8539
		"				&& safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + 
8540
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" + 
8541
		"				&& safeSubtreeListMatch(node.arguments(), o.arguments())\n" + 
8542
		"				&& safeSubtreeListMatch(\n" + 
8543
		"					node.bodyDeclarations(),\n" + 
8544
		"					o.bodyDeclarations()));\n" + 
8545
		"	}\n" + 
8546
		"}\n";
8547
	formatSource(source	,
8548
		"package wksp1;\n" + 
8549
		"\n" + 
8550
		"public class X18 {\n" + 
8551
		"	public boolean foo() {\n" + 
8552
		"		return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8553
		"				&& safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + 
8554
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" + 
8555
		"				&& safeSubtreeListMatch(node.arguments(), o.arguments())\n" + 
8556
		"				&& safeSubtreeListMatch(\n" + 
8557
		"					node.bodyDeclarations(),\n" + 
8558
		"					o.bodyDeclarations()));\n" + 
8559
		"	}\n" + 
8560
		"}\n"
8561
	);
8562
}
8563
public void testBug330313_wksp1_19_njl() {
8564
	this.formatterPrefs.join_wrapped_lines = false;
8565
	String source =
8566
		"package wksp1;\n" + 
8567
		"\n" + 
8568
		"public class X19 {\n" + 
8569
		"	public boolean foo() {\n" + 
8570
		"		return (\n" + 
8571
		"			safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8572
		"				&& safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + 
8573
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" + 
8574
		"				&& safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes())\n" + 
8575
		"				&& safeSubtreeListMatch(\n" + 
8576
		"					node.bodyDeclarations(),\n" + 
8577
		"					o.bodyDeclarations()));\n" + 
8578
		"	}\n" + 
8579
		"}\n";
8580
	formatSource(source	,
8581
		"package wksp1;\n" + 
8582
		"\n" + 
8583
		"public class X19 {\n" + 
8584
		"	public boolean foo() {\n" + 
8585
		"		return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8586
		"				&& safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + 
8587
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" + 
8588
		"				&& safeSubtreeListMatch(node.superInterfaceTypes(),\n" + 
8589
		"						o.superInterfaceTypes())\n" + 
8590
		"				&& safeSubtreeListMatch(\n" + 
8591
		"					node.bodyDeclarations(),\n" + 
8592
		"					o.bodyDeclarations()));\n" + 
8593
		"	}\n" + 
8594
		"}\n"
8595
	);
8596
}
8597
// Test case extracted from org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java
8598
public void testBug330313_wksp1_20_njl() {
8599
	this.formatterPrefs.join_wrapped_lines = false;
8600
	String source =
8601
		"package wksp1;\n" + 
8602
		"\n" + 
8603
		"public class X20 {\n" + 
8604
		"\n" + 
8605
		"  static final String decode(String entity) {\n" + 
8606
		"    if (true) {\n" + 
8607
		"      if (entity.charAt(2) == \'X\' || entity.charAt(2) == \'x\') {\n" + 
8608
		"      }\n" + 
8609
		"      Character c =\n" + 
8610
		"	new Character((char)Integer.parseInt(entity.substring(start), radix));\n" + 
8611
		"      return c.toString();\n" + 
8612
		"    }\n" + 
8613
		"	return \"\";\n" + 
8614
		"  }\n" + 
8615
		"}\n";
8616
	formatSource(source	,
8617
		"package wksp1;\n" + 
8618
		"\n" + 
8619
		"public class X20 {\n" + 
8620
		"\n" + 
8621
		"	static final String decode(String entity) {\n" + 
8622
		"		if (true) {\n" + 
8623
		"			if (entity.charAt(2) == \'X\' || entity.charAt(2) == \'x\') {\n" + 
8624
		"			}\n" + 
8625
		"			Character c =\n" + 
8626
		"					new Character((char) Integer.parseInt(\n" + 
8627
		"							entity.substring(start), radix));\n" + 
8628
		"			return c.toString();\n" + 
8629
		"		}\n" + 
8630
		"		return \"\";\n" + 
8631
		"	}\n" + 
8632
		"}\n"
8633
	);
8634
}
8635
// Test case extracted from org.apache.lucene/src/org/apache/lucene/demo/html/Entities.java
8636
public void testBug330313_wksp1_21_njl() {
8637
	this.formatterPrefs.join_wrapped_lines = false;
8638
	String source =
8639
		"package wksp1;\n" + 
8640
		"\n" + 
8641
		"public class X21 {\n" + 
8642
		"	public boolean isAvailable() {\n" + 
8643
		"		return !(getViewer() == null || getViewer().getControl() == null || getViewer().getControl().isDisposed());\n" + 
8644
		"	}	\n" + 
8645
		"}\n";
8646
	formatSource(source	,
8647
		"package wksp1;\n" + 
8648
		"\n" + 
8649
		"public class X21 {\n" + 
8650
		"	public boolean isAvailable() {\n" + 
8651
		"		return !(getViewer() == null || getViewer().getControl() == null || getViewer()\n" + 
8652
		"				.getControl().isDisposed());\n" + 
8653
		"	}\n" + 
8654
		"}\n"
8655
	);
8656
}
8657
// Test case extracted from differences noticed with patch v27.txt
8658
public void testBug330313_wksp1_22_njl() {
8659
	this.formatterPrefs.join_wrapped_lines = false;
8660
	String source =
8661
		"package wksp1;\n" + 
8662
		"\n" + 
8663
		"public class X22 {\n" + 
8664
		"	public boolean foo() {\n" + 
8665
		"		return (\n" + 
8666
		"				(node.isInterface() == o.isInterface())\n" + 
8667
		"				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8668
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" + 
8669
		"				&& safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations()));\n" + 
8670
		"	}\n" + 
8671
		"}\n";
8672
	formatSource(source	,
8673
		"package wksp1;\n" + 
8674
		"\n" + 
8675
		"public class X22 {\n" + 
8676
		"	public boolean foo() {\n" + 
8677
		"		return ((node.isInterface() == o.isInterface())\n" + 
8678
		"				&& safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + 
8679
		"				&& safeSubtreeMatch(node.getName(), o.getName())\n" +
8680
		"				&& safeSubtreeListMatch(node.bodyDeclarations(),\n" + 
8681
		"					o.bodyDeclarations()));\n" + 
8682
		"	}\n" + 
8683
		"}\n"
8684
	);
8685
}
8686
public void testBug330313_wksp1_23_njl() {
8687
	this.formatterPrefs.join_wrapped_lines = false;
8688
	String source =
8689
		"package wksp1;\n" + 
8690
		"\n" + 
8691
		"public class X23 {\n" + 
8692
		"	void foo() {\n" + 
8693
		"		boolean wasError = IMarker.SEVERITY_ERROR\n" + 
8694
		"				== pb.getAttribute(IMarker.SEVERITY,\n" + 
8695
		"						IMarker.SEVERITY_ERROR);\n" + 
8696
		"	}\n" + 
8697
		"}\n";
8698
	formatSource(source	);
8699
}
8700
public void testBug330313_wksp1_24_njl() {
8701
	this.formatterPrefs.join_wrapped_lines = false;
8702
	String source =
8703
		"package wksp1;\n" + 
8704
		"\n" + 
8705
		"public class X24 {\n" + 
8706
		"\n" + 
8707
		"	protected boolean canRunEvaluation() {\n" + 
8708
		"		// NOTE similar to #canStep, except a quiet suspend state is OK\n" + 
8709
		"		try {\n" + 
8710
		"			return isSuspendedQuiet() || (isSuspended()\n" + 
8711
		"					&& !(isPerformingEvaluation() || isInvokingMethod())\n" + 
8712
		"					&& !isStepping()\n" + 
8713
		"					&& getTopStackFrame() != null\n" + 
8714
		"					&& !getJavaDebugTarget().isPerformingHotCodeReplace());\n" + 
8715
		"		} catch (DebugException e) {\n" + 
8716
		"			return false;\n" + 
8717
		"		}\n" + 
8718
		"	}\n" + 
8719
		"}\n";
8720
	formatSource(source	);
8721
}
8722
public void testBug330313_wksp1_25_njl() {
8723
	this.formatterPrefs.join_wrapped_lines = false;
8724
	String source =
8725
		"package wksp1;\n" + 
8726
		"\n" + 
8727
		"public class X25 {\n" + 
8728
		"\n" + 
8729
		"	void unloadIcon(ImageData icon) {\n" + 
8730
		"		int sizeImage = (((icon.width * icon.depth + 31) / 32 * 4) +\n" + 
8731
		"				((icon.width + 31) / 32 * 4)) * icon.height;\n" + 
8732
		"	}\n" + 
8733
		"}\n";
8734
	formatSource(source	);
8735
}
8736
public void testBug330313_wksp1_26_njl() {
8737
	this.formatterPrefs.join_wrapped_lines = false;
8738
	String source =
8739
		"package wksp1;\n" + 
8740
		"\n" + 
8741
		"public class X26 {\n" + 
8742
		"\n" + 
8743
		"void foo() {\n" + 
8744
		"	for (int i = 0; i < data.length; i++) {\n" + 
8745
		"		byte s = data[i];\n" + 
8746
		"		sourceData[i] = (byte)(((s & 0x80) >> 7) |\n" + 
8747
		"			((s & 0x40) >> 5) |\n" + 
8748
		"			((s & 0x20) >> 3) |\n" + 
8749
		"			((s & 0x10) >> 1) |\n" + 
8750
		"			((s & 0x08) << 1) |\n" + 
8751
		"			((s & 0x04) << 3) |\n" + 
8752
		"			((s & 0x02) << 5) |\n" + 
8753
		"			((s & 0x01) << 7));\n" + 
8754
		"	}\n" + 
8755
		"}\n" + 
8756
		"}\n";
8757
	formatSource(source	,
8758
		"package wksp1;\n" + 
8759
		"\n" + 
8760
		"public class X26 {\n" + 
8761
		"\n" + 
8762
		"	void foo() {\n" + 
8763
		"		for (int i = 0; i < data.length; i++) {\n" + 
8764
		"			byte s = data[i];\n" + 
8765
		"			sourceData[i] = (byte) (((s & 0x80) >> 7) |\n" + 
8766
		"					((s & 0x40) >> 5) |\n" + 
8767
		"					((s & 0x20) >> 3) |\n" + 
8768
		"					((s & 0x10) >> 1) |\n" + 
8769
		"					((s & 0x08) << 1) |\n" + 
8770
		"					((s & 0x04) << 3) |\n" + 
8771
		"					((s & 0x02) << 5) |\n" + 
8772
		"					((s & 0x01) << 7));\n" + 
8773
		"		}\n" + 
8774
		"	}\n" + 
8775
		"}\n"
8776
	);
8777
}
8778
public void testBug330313_wksp1_27_njl() {
8779
	this.formatterPrefs.join_wrapped_lines = false;
8780
	String source =
8781
		"package wksp1;\n" + 
8782
		"\n" + 
8783
		"public class X27 {\n" + 
8784
		"	private void foo() {\n" + 
8785
		"\n" + 
8786
		"		if (_VerificationResult.getVerificationCode()\n" + 
8787
		"			== IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED\n" + 
8788
		"			|| _VerificationResult.getVerificationCode()\n" + 
8789
		"				== IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED) {\n" + 
8790
		"			// Group box\n" + 
8791
		"		}\n" + 
8792
		"	}\n" + 
8793
		"\n" + 
8794
		"}\n";
8795
	formatSource(source	,
8796
		"package wksp1;\n" + 
8797
		"\n" + 
8798
		"public class X27 {\n" + 
8799
		"	private void foo() {\n" + 
8800
		"\n" + 
8801
		"		if (_VerificationResult.getVerificationCode()\n" + 
8802
		"					== IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED\n" + 
8803
		"				|| _VerificationResult.getVerificationCode()\n" + 
8804
		"					== IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED) {\n" + 
8805
		"			// Group box\n" + 
8806
		"		}\n" + 
8807
		"	}\n" + 
8808
		"\n" + 
8809
		"}\n"
8810
	);
8811
}
8812
public void testBug330313_wksp1_28_njl() {
8813
	this.formatterPrefs.join_wrapped_lines = false;
8814
	String source =
8815
		"package wksp1;\n" + 
8816
		"\n" + 
8817
		"public class X28 {\n" + 
8818
		"\n" + 
8819
		"	void foo() {\n" + 
8820
		"		if (fieldBinding.declaringClass != lastReceiverType\n" + 
8821
		"			&& !lastReceiverType.isArrayType()			\n" + 
8822
		"			&& fieldBinding.declaringClass != null\n" + 
8823
		"			&& fieldBinding.constant == NotAConstant\n" + 
8824
		"			&& ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + 
8825
		"					&& (fieldBinding != this.binding || this.indexOfFirstFieldBinding > 1 || !fieldBinding.isStatic())\n" + 
8826
		"					&& fieldBinding.declaringClass.id != T_Object)\n" + 
8827
		"				|| !(useDelegate\n" + 
8828
		"						? new CodeSnippetScope(currentScope).canBeSeenByForCodeSnippet(fieldBinding.declaringClass, (ReferenceBinding) this.delegateThis.type)\n" + 
8829
		"						: fieldBinding.declaringClass.canBeSeenBy(currentScope)))){\n" + 
8830
		"			// code\n" + 
8831
		"		}\n" + 
8832
		"	}\n" + 
8833
		"}\n";
8834
	formatSource(source	,
8835
		"package wksp1;\n" + 
8836
		"\n" + 
8837
		"public class X28 {\n" + 
8838
		"\n" + 
8839
		"	void foo() {\n" + 
8840
		"		if (fieldBinding.declaringClass != lastReceiverType\n" + 
8841
		"				&& !lastReceiverType.isArrayType()\n" + 
8842
		"				&& fieldBinding.declaringClass != null\n" + 
8843
		"				&& fieldBinding.constant == NotAConstant\n" + 
8844
		"				&& ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + 
8845
		"						&& (fieldBinding != this.binding\n" + 
8846
		"								|| this.indexOfFirstFieldBinding > 1 || !fieldBinding\n" + 
8847
		"									.isStatic())\n" + 
8848
		"						&& fieldBinding.declaringClass.id != T_Object)\n" + 
8849
		"						|| !(useDelegate\n" + 
8850
		"							? new CodeSnippetScope(currentScope)\n" + 
8851
		"									.canBeSeenByForCodeSnippet(\n" + 
8852
		"											fieldBinding.declaringClass,\n" + 
8853
		"											(ReferenceBinding) this.delegateThis.type)\n" + 
8854
		"							: fieldBinding.declaringClass\n" +
8855
		"									.canBeSeenBy(currentScope)))) {\n" + 
8856
		"			// code\n" + 
8857
		"		}\n" + 
8858
		"	}\n" + 
8859
		"}\n"
8860
	);
8861
}
8862
public void testBug330313_wksp1_29_njl() {
8863
	this.formatterPrefs.join_wrapped_lines = false;
8864
	String source =
8865
		"package wksp1;\n" + 
8866
		"\n" + 
8867
		"public class X29 {\n" + 
8868
		"\n" + 
8869
		"	boolean foo() {\n" + 
8870
		"		return (pack != null && otherpack != null && isSamePackage(pack, otherpack));\n" + 
8871
		"	}\n" + 
8872
		"}\n";
8873
	formatSource(source	,
8874
		"package wksp1;\n" + 
8875
		"\n" + 
8876
		"public class X29 {\n" + 
8877
		"\n" + 
8878
		"	boolean foo() {\n" + 
8879
		"		return (pack != null && otherpack != null && isSamePackage(pack,\n" + 
8880
		"				otherpack));\n" + 
8881
		"	}\n" + 
8882
		"}\n"
8883
	);
8884
}
8885
public void testBug330313_wksp1_30_njl() {
8886
	this.formatterPrefs.join_wrapped_lines = false;
8887
	String source =
8888
		"package wksp1;\n" + 
8889
		"\n" + 
8890
		"public class X30 {\n" + 
8891
		"	private boolean isInTypeNestedInInputType(ASTNode node, TypeDeclaration inputType){\n" + 
8892
		"		return (isInAnonymousTypeInsideInputType(node, inputType) ||\n" + 
8893
		"				isInLocalTypeInsideInputType(node, inputType) ||\n" + 
8894
		"				isInNonStaticMemberTypeInsideInputType(node, inputType));\n" + 
8895
		"	}\n" + 
8896
		"}\n";
8897
	formatSource(source	,
8898
		"package wksp1;\n" + 
8899
		"\n" + 
8900
		"public class X30 {\n" + 
8901
		"	private boolean isInTypeNestedInInputType(ASTNode node,\n" + 
8902
		"			TypeDeclaration inputType) {\n" + 
8903
		"		return (isInAnonymousTypeInsideInputType(node, inputType) ||\n" + 
8904
		"				isInLocalTypeInsideInputType(node, inputType) || isInNonStaticMemberTypeInsideInputType(\n" + 
8905
		"					node, inputType));\n" + 
8906
		"	}\n" + 
8907
		"}\n"
8908
	);
8909
}
8910
public void testBug330313_wksp1_31_njl() {
8911
	this.formatterPrefs.join_wrapped_lines = false;
8912
	String source =
8913
		"package wksp1;\n" + 
8914
		"\n" + 
8915
		"public class X31 {\n" + 
8916
		"	void foo(int i) {\n" + 
8917
		"		if (true) {\n" + 
8918
		"			switch (i) {\n" + 
8919
		"				case 0:\n" + 
8920
		"					if (!((offset == (hashable.length - 1)) && !has95 && hasOneOf(meta63, hashable, offset - 2, 2) && !hasOneOf(meta64, hashable, offset - 4, 2)))\n" + 
8921
		"						buffer.append(\'R\');\n" + 
8922
		"					break;\n" + 
8923
		"			}\n" + 
8924
		"		}\n" + 
8925
		"	}\n" + 
8926
		"}\n";
8927
	formatSource(source	,
8928
		"package wksp1;\n" + 
8929
		"\n" + 
8930
		"public class X31 {\n" + 
8931
		"	void foo(int i) {\n" + 
8932
		"		if (true) {\n" + 
8933
		"			switch (i) {\n" + 
8934
		"			case 0:\n" + 
8935
		"				if (!((offset == (hashable.length - 1)) && !has95\n" + 
8936
		"						&& hasOneOf(meta63, hashable, offset - 2, 2) && !hasOneOf(\n" + 
8937
		"							meta64, hashable, offset - 4, 2)))\n" + 
8938
		"					buffer.append(\'R\');\n" + 
8939
		"				break;\n" + 
8940
		"			}\n" + 
8941
		"		}\n" + 
8942
		"	}\n" + 
8943
		"}\n"
8944
	);
8945
}
8946
public void testBug330313_wksp1_32_njl() {
8947
	this.formatterPrefs.join_wrapped_lines = false;
8948
	String source =
8949
		"package wksp1;\n" + 
8950
		"\n" + 
8951
		"public class X32 {\n" + 
8952
		"	public boolean equals(Object object) {\n" + 
8953
		"		TextAttribute a= (TextAttribute) object;\n" + 
8954
		"		return (a.style == style && equals(a.foreground, foreground) && equals(a.background, background));\n" + 
8955
		"	}\n" + 
8956
		"}\n";
8957
	formatSource(source	,
8958
		"package wksp1;\n" + 
8959
		"\n" + 
8960
		"public class X32 {\n" + 
8961
		"	public boolean equals(Object object) {\n" + 
8962
		"		TextAttribute a = (TextAttribute) object;\n" + 
8963
		"		return (a.style == style && equals(a.foreground, foreground) && equals(\n" + 
8964
		"				a.background, background));\n" + 
8965
		"	}\n" + 
8966
		"}\n"
8967
	);
8968
}
8969
// Test case extracted from differences noticed with patch v29.txt
8970
public void testBug330313_wksp1_33() {
8971
	String source =
8972
		"package wksp1;\n" + 
8973
		"\n" + 
8974
		"public class X33 {\n" + 
8975
		"	void foo() {\n" + 
8976
		"        if(inMetaTag &&\n" + 
8977
		"                        (  t1.image.equalsIgnoreCase(\"name\") ||\n" + 
8978
		"                           t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + 
8979
		"                        )\n" + 
8980
		"           && t2 != null)\n" + 
8981
		"        {\n" + 
8982
		"                currentMetaTag=t2.image.toLowerCase();\n" + 
8983
		"        }\n" + 
8984
		"	}\n" + 
8985
		"}\n";
8986
	formatSource(source	,
8987
		"package wksp1;\n" + 
8988
		"\n" + 
8989
		"public class X33 {\n" + 
8990
		"	void foo() {\n" + 
8991
		"		if (inMetaTag\n" + 
8992
		"				&& (t1.image.equalsIgnoreCase(\"name\") || t1.image\n" + 
8993
		"						.equalsIgnoreCase(\"HTTP-EQUIV\")) && t2 != null) {\n" + 
8994
		"			currentMetaTag = t2.image.toLowerCase();\n" + 
8995
		"		}\n" + 
8996
		"	}\n" + 
8997
		"}\n"
8998
	);
8999
}
9000
public void testBug330313_wksp1_33_njl() {
9001
	this.formatterPrefs.join_wrapped_lines = false;
9002
	String source =
9003
		"package wksp1;\n" + 
9004
		"\n" + 
9005
		"public class X33 {\n" + 
9006
		"	void foo() {\n" + 
9007
		"        if(inMetaTag &&\n" + 
9008
		"                        (  t1.image.equalsIgnoreCase(\"name\") ||\n" + 
9009
		"                           t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + 
9010
		"                        )\n" + 
9011
		"           && t2 != null)\n" + 
9012
		"        {\n" + 
9013
		"                currentMetaTag=t2.image.toLowerCase();\n" + 
9014
		"        }\n" + 
9015
		"	}\n" + 
9016
		"}\n";
9017
	formatSource(source	,
9018
		"package wksp1;\n" + 
9019
		"\n" + 
9020
		"public class X33 {\n" + 
9021
		"	void foo() {\n" + 
9022
		"		if (inMetaTag &&\n" + 
9023
		"				(t1.image.equalsIgnoreCase(\"name\") ||\n" + 
9024
		"				t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + 
9025
		"				)\n" + 
9026
		"				&& t2 != null)\n" + 
9027
		"		{\n" + 
9028
		"			currentMetaTag = t2.image.toLowerCase();\n" + 
9029
		"		}\n" + 
9030
		"	}\n" + 
9031
		"}\n"
9032
	);
9033
}
9034
public void testBug330313_wksp1_34_njl() {
9035
	this.formatterPrefs.join_wrapped_lines = false;
9036
	String source =
9037
		"package wksp1;\n" + 
9038
		"\n" + 
9039
		"public class X34 {\n" + 
9040
		"	private boolean compareMarkers(ResourceInfo oldElement, ResourceInfo newElement) {\n" + 
9041
		"		boolean bothNull = oldElement.getMarkers(false) == null && newElement.getMarkers(false) == null;\n" + 
9042
		"		return bothNull || oldElement.getMarkerGenerationCount() == newElement.getMarkerGenerationCount();\n" + 
9043
		"	}\n" + 
9044
		"	private boolean compareSync(ResourceInfo oldElement, ResourceInfo newElement) {\n" + 
9045
		"		return oldElement.getSyncInfoGenerationCount() == newElement.getSyncInfoGenerationCount();\n" + 
9046
		"	}\n" + 
9047
		"}\n";
9048
	formatSource(source	,
9049
		"package wksp1;\n" + 
9050
		"\n" + 
9051
		"public class X34 {\n" + 
9052
		"	private boolean compareMarkers(ResourceInfo oldElement,\n" + 
9053
		"			ResourceInfo newElement) {\n" + 
9054
		"		boolean bothNull = oldElement.getMarkers(false) == null\n" + 
9055
		"				&& newElement.getMarkers(false) == null;\n" + 
9056
		"		return bothNull\n" + 
9057
		"				|| oldElement.getMarkerGenerationCount() == newElement\n" + 
9058
		"						.getMarkerGenerationCount();\n" + 
9059
		"	}\n" + 
9060
		"\n" + 
9061
		"	private boolean compareSync(ResourceInfo oldElement, ResourceInfo newElement) {\n" + 
9062
		"		return oldElement.getSyncInfoGenerationCount() == newElement\n" + 
9063
		"				.getSyncInfoGenerationCount();\n" + 
9064
		"	}\n" + 
9065
		"}\n"
9066
	);
9067
}
9068
// Test case extracted from differences noticed with patch v30.txt
9069
public void testBug330313_wksp1_35_njl() {
9070
	this.formatterPrefs.join_wrapped_lines = false;
9071
	String source =
9072
		"package wksp1;\n" + 
9073
		"\n" + 
9074
		"public class X35 {\n" + 
9075
		"	void foo() {\n" + 
9076
		"		if (true) {\n" + 
9077
		"			if (20+lineNum*printGC.getFontMetrics().getHeight() > printer.getClientArea().height) {\n" + 
9078
		"				//\n" + 
9079
		"			}\n" + 
9080
		"		}\n" + 
9081
		"	}\n" + 
9082
		"}\n";
9083
	formatSource(source	,
9084
		"package wksp1;\n" + 
9085
		"\n" + 
9086
		"public class X35 {\n" + 
9087
		"	void foo() {\n" + 
9088
		"		if (true) {\n" + 
9089
		"			if (20 + lineNum * printGC.getFontMetrics().getHeight() > printer\n" + 
9090
		"					.getClientArea().height) {\n" + 
9091
		"				//\n" + 
9092
		"			}\n" + 
9093
		"		}\n" + 
9094
		"	}\n" + 
9095
		"}\n"
9096
	);
9097
}
9098
// Test case extracted from differences noticed with patch v32.txt
9099
public void testBug330313_wksp1_36_njl() {
9100
	this.formatterPrefs.join_wrapped_lines = false;
9101
	String source =
9102
		"package wksp1;\n" + 
9103
		"\n" + 
9104
		"public class X36 {\n" + 
9105
		"	public static boolean isRuntimeException(ITypeBinding thrownException) {\n" + 
9106
		"		if (thrownException == null || thrownException.isPrimitive() || thrownException.isArray())\n" + 
9107
		"			return false;\n" + 
9108
		"		return findTypeInHierarchy(thrownException, \"java.lang.RuntimeException\") != null; //$NON-NLS-1$\n" + 
9109
		"	}\n" + 
9110
		"}\n";
9111
	formatSource(source	,
9112
		"package wksp1;\n" + 
9113
		"\n" + 
9114
		"public class X36 {\n" + 
9115
		"	public static boolean isRuntimeException(ITypeBinding thrownException) {\n" + 
9116
		"		if (thrownException == null || thrownException.isPrimitive()\n" + 
9117
		"				|| thrownException.isArray())\n" + 
9118
		"			return false;\n" + 
9119
		"		return findTypeInHierarchy(thrownException,\n" + 
9120
		"				\"java.lang.RuntimeException\") != null; //$NON-NLS-1$\n" + 
9121
		"	}\n" + 
9122
		"}\n"
9123
	);
9124
}
9125
public void testBug330313_wksp1_37_njl() {
9126
	this.formatterPrefs.join_wrapped_lines = false;
9127
	String source =
9128
		"package wksp1;\n" + 
9129
		"\n" + 
9130
		"public class X37 {\n" + 
9131
		"	void foo() {\n" + 
9132
		"		if (true) {\n" + 
9133
		"			if (ignoreQuickDiffPrefPage && (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffChange\") //$NON-NLS-1$\n" + 
9134
		"					|| (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffAddition\")) //$NON-NLS-1$\n" + 
9135
		"					|| (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffDeletion\")) //$NON-NLS-1$\n" + 
9136
		"				)) \n" + 
9137
		"				continue;\n" + 
9138
		"		}\n" + 
9139
		"	}\n" + 
9140
		"}\n";
9141
	formatSource(source	,
9142
		"package wksp1;\n" + 
9143
		"\n" + 
9144
		"public class X37 {\n" + 
9145
		"	void foo() {\n" + 
9146
		"		if (true) {\n" + 
9147
		"			if (ignoreQuickDiffPrefPage\n" + 
9148
		"					&& (info.getAnnotationType()\n" + 
9149
		"							.equals(\"org.eclipse.ui.workbench.texteditor.quickdiffChange\") //$NON-NLS-1$\n" + 
9150
		"							|| (info.getAnnotationType()\n" + 
9151
		"									.equals(\"org.eclipse.ui.workbench.texteditor.quickdiffAddition\")) //$NON-NLS-1$\n" + 
9152
		"					|| (info.getAnnotationType()\n" + 
9153
		"							.equals(\"org.eclipse.ui.workbench.texteditor.quickdiffDeletion\")) //$NON-NLS-1$\n" + 
9154
		"					))\n" + 
9155
		"				continue;\n" + 
9156
		"		}\n" + 
9157
		"	}\n" + 
9158
		"}\n"
9159
	);
9160
}
9161
// Test case extracted from differences noticed with patch v33.txt
9162
public void testBug330313_wksp1_38_njl() {
9163
	this.formatterPrefs.join_wrapped_lines = false;
9164
	String source =
9165
		"package wksp1;\n" + 
9166
		"\n" + 
9167
		"public class X38 {\n" + 
9168
		"	void foo(boolean condition) {\n" + 
9169
		"		if (condition)\n" + 
9170
		"		{\n" + 
9171
		"			// block 1\n" + 
9172
		"		}\n" + 
9173
		"		else\n" + 
9174
		"		{\n" + 
9175
		"			// block 2\n" + 
9176
		"		}\n" + 
9177
		"	}\n" + 
9178
		"}\n";
9179
	formatSource(source	);
9180
}
9181
public void testBug330313_wksp1_39_njl() {
9182
	this.formatterPrefs.join_wrapped_lines = false;
9183
	String source =
9184
		"package wksp1;\n" + 
9185
		"\n" + 
9186
		"public class X39 {\n" + 
9187
		"/**\n" + 
9188
		" * <pre>\n" + 
9189
		" *		RadioGroupFieldEditor editor= new RadioGroupFieldEditor(\n" + 
9190
		" *			\"GeneralPage.DoubleClick\", resName, 1,\n" + 
9191
		" *			new String[][] {\n" + 
9192
		" *				{\"Open Browser\", \"open\"},\n" + 
9193
		" *				{\"Expand Tree\", \"expand\"}\n" + 
9194
		" *			},\n" + 
9195
		" *          parent);	\n" + 
9196
		" * </pre>\n" + 
9197
		" */\n" + 
9198
		"public void foo() {\n" + 
9199
		"}\n" + 
9200
		"}\n";
9201
	formatSource(source	,
9202
		"package wksp1;\n" + 
9203
		"\n" + 
9204
		"public class X39 {\n" + 
9205
		"	/**\n" + 
9206
		"	 * <pre>\n" + 
9207
		"	 * RadioGroupFieldEditor editor = new RadioGroupFieldEditor(\n" + 
9208
		"	 * 		&quot;GeneralPage.DoubleClick&quot;, resName, 1,\n" + 
9209
		"	 * 		new String[][] {\n" + 
9210
		"	 * 				{ &quot;Open Browser&quot;, &quot;open&quot; },\n" + 
9211
		"	 * 				{ &quot;Expand Tree&quot;, &quot;expand&quot; }\n" + 
9212
		"	 * 		},\n" + 
9213
		"	 * 		parent);\n" + 
9214
		"	 * </pre>\n" + 
9215
		"	 */\n" + 
9216
		"	public void foo() {\n" + 
9217
		"	}\n" + 
9218
		"}\n"
9219
	);
9220
}
9221
public void testBug330313_wksp1_40_njl() {
9222
	this.formatterPrefs.join_wrapped_lines = false;
9223
	String source =
9224
		"package wksp1;\n" + 
9225
		"\n" + 
9226
		"public class X40 {\n" + 
9227
		"	protected final static String[][] TABLE= new String[][] {\n" + 
9228
		"								/*INACTIVE*/	/*PARTLY_ACTIVE */	/*ACTIVE */\n" + 
9229
		"		/* INACTIVE */		{	\"INACTIVE\",		\"PARTLY_ACTIVE\",		\"PARTLY_ACTIVE\" },\n" + 
9230
		"		/* PARTLY_ACTIVE*/	{	\"PARTLY_ACTIVE\", 	\"PARTLY_ACTIVE\",		\"PARTLY_ACTIVE\" },\n" + 
9231
		"		/* ACTIVE */		{	\"PARTLY_ACTIVE\", 	\"PARTLY_ACTIVE\",		\"ACTIVE\"}\n" + 
9232
		"	};\n" + 
9233
		"}\n";
9234
	formatSource(source	,
9235
		"package wksp1;\n" + 
9236
		"\n" + 
9237
		"public class X40 {\n" + 
9238
		"	protected final static String[][] TABLE = new String[][] {\n" + 
9239
		"			/* INACTIVE *//* PARTLY_ACTIVE *//* ACTIVE */\n" + 
9240
		"			/* INACTIVE */{ \"INACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + 
9241
		"			/* PARTLY_ACTIVE */{ \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\",\n" + 
9242
		"					\"PARTLY_ACTIVE\" },\n" + 
9243
		"			/* ACTIVE */{ \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"ACTIVE\" }\n" + 
9244
		"	};\n" + 
9245
		"}\n"
9246
	);
9247
}
9248
public void testBug330313_wksp1_41_njl() {
9249
	this.formatterPrefs.join_wrapped_lines = false;
9250
	String source =
9251
		"package wksp1;\n" + 
9252
		"\n" + 
9253
		"public class X41 {\n" + 
9254
		"	static final int [][] TABLE = {\n" + 
9255
		"		\n" + 
9256
		"		/* First */\n" + 
9257
		"		{1,	2},\n" + 
9258
		"		{3,	4},\n" + 
9259
		"		{5,	6},\n" + 
9260
		"//		{7????,	8},\n" + 
9261
		"\n" + 
9262
		"		/* Second */		\n" + 
9263
		"//		{11, 12},\n" + 
9264
		"//		{13, 14},\n" + 
9265
		"//		{15, 16},\n" + 
9266
		"		\n" + 
9267
		"		\n" + 
9268
		"		/* Third */\n" + 
9269
		"		{21,	22},\n" + 
9270
		"		{23,	24},\n" + 
9271
		"		{25,	26},\n" + 
9272
		"//		{27????,	28},\n" + 
9273
		"\n" + 
9274
		"		/* Others */\n" + 
9275
		"		{31,	32},\n" + 
9276
		"		{33,	34},\n" + 
9277
		"		{35,	36},\n" + 
9278
		"//		{37????,	38},\n" + 
9279
		"		\n" + 
9280
		"	};\n" + 
9281
		"}\n";
9282
	formatSource(source	,
9283
		"package wksp1;\n" + 
9284
		"\n" + 
9285
		"public class X41 {\n" + 
9286
		"	static final int[][] TABLE = {\n" + 
9287
		"\n" + 
9288
		"			/* First */\n" + 
9289
		"			{ 1, 2 },\n" + 
9290
		"			{ 3, 4 },\n" + 
9291
		"			{ 5, 6 },\n" + 
9292
		"			// {7????, 8},\n" + 
9293
		"\n" + 
9294
		"			/* Second */\n" + 
9295
		"			// {11, 12},\n" + 
9296
		"			// {13, 14},\n" + 
9297
		"			// {15, 16},\n" + 
9298
		"\n" + 
9299
		"			/* Third */\n" + 
9300
		"			{ 21, 22 },\n" + 
9301
		"			{ 23, 24 },\n" + 
9302
		"			{ 25, 26 },\n" + 
9303
		"			// {27????, 28},\n" + 
9304
		"\n" + 
9305
		"			/* Others */\n" + 
9306
		"			{ 31, 32 },\n" + 
9307
		"			{ 33, 34 },\n" + 
9308
		"			{ 35, 36 },\n" + 
9309
		"			// {37????, 38},\n" + 
9310
		"\n" + 
9311
		"	};\n" + 
9312
		"}\n"
9313
	);
9314
}
9315
public void testBug330313_wksp1_42_njl() {
9316
	this.formatterPrefs.join_wrapped_lines = false;
9317
	String source =
9318
		"package wksp1;\n" + 
9319
		"\n" + 
9320
		"public class X42 {\n" + 
9321
		"	static final byte[][] DashList = {\n" + 
9322
		"		{ },                   // SWT.LINE_SOLID\n" + 
9323
		"		{ 10, 4 },             // SWT.LINE_DASH\n" + 
9324
		"		{ 2, 2 },              // SWT.LINE_DOT\n" + 
9325
		"		{ 10, 4, 2, 4 },       // SWT.LINE_DASHDOT\n" + 
9326
		"		{ 10, 4, 2, 4, 2, 4 }  // SWT.LINE_DASHDOTDOT\n" + 
9327
		"	};\n" + 
9328
		"}\n";
9329
	formatSource(source	,
9330
		"package wksp1;\n" + 
9331
		"\n" + 
9332
		"public class X42 {\n" + 
9333
		"	static final byte[][] DashList = {\n" + 
9334
		"			{}, // SWT.LINE_SOLID\n" + 
9335
		"			{ 10, 4 }, // SWT.LINE_DASH\n" + 
9336
		"			{ 2, 2 }, // SWT.LINE_DOT\n" + 
9337
		"			{ 10, 4, 2, 4 }, // SWT.LINE_DASHDOT\n" + 
9338
		"			{ 10, 4, 2, 4, 2, 4 } // SWT.LINE_DASHDOTDOT\n" + 
9339
		"	};\n" + 
9340
		"}\n"
9341
	);
9342
}
9343
public void testBug330313_wksp1_43_njl() {
9344
	this.formatterPrefs.join_wrapped_lines = false;
9345
	String source =
9346
		"package wksp1;\n" + 
9347
		"\n" + 
9348
		"public class X43 {\n" + 
9349
		"	Cloneable clone;\n" + 
9350
		"X43() {\n" + 
9351
		"	this.clone = new Cloneable() {\n" + 
9352
		"		void foo(int x) {\n" + 
9353
		"			switch (x) {\n" + 
9354
		"				case 1:\n" + 
9355
		"				case 2:\n" + 
9356
		"					if (true) break;\n" + 
9357
		"					// FALL THROUGH\n" + 
9358
		"				case 3:\n" + 
9359
		"				case 4:\n" + 
9360
		"					break;\n" + 
9361
		"			}\n" + 
9362
		"		}\n" + 
9363
		"	};\n" + 
9364
		"}\n" + 
9365
		"}\n";
9366
	formatSource(source	,
9367
		"package wksp1;\n" + 
9368
		"\n" + 
9369
		"public class X43 {\n" + 
9370
		"	Cloneable clone;\n" + 
9371
		"\n" + 
9372
		"	X43() {\n" + 
9373
		"		this.clone = new Cloneable() {\n" + 
9374
		"			void foo(int x) {\n" + 
9375
		"				switch (x) {\n" + 
9376
		"				case 1:\n" + 
9377
		"				case 2:\n" + 
9378
		"					if (true)\n" + 
9379
		"						break;\n" + 
9380
		"					// FALL THROUGH\n" + 
9381
		"				case 3:\n" + 
9382
		"				case 4:\n" + 
9383
		"					break;\n" + 
9384
		"				}\n" + 
9385
		"			}\n" + 
9386
		"		};\n" + 
9387
		"	}\n" + 
9388
		"}\n"
9389
	);
9390
}
9391
public void testBug330313_wksp1_44_njl() {
9392
	// TODO Could be improved to put the all array statements at the same indentation...
9393
	this.formatterPrefs.join_wrapped_lines = false;
9394
	String source =
9395
		"package wksp1;\n" + 
9396
		"\n" + 
9397
		"public class X44 {\n" + 
9398
		"	String foo() {\n" + 
9399
		"		return Policy.bind(\"CVSAnnotateBlock.6\", new Object[] { //$NON-NLS-1$\n" + 
9400
		"			user,\n" + 
9401
		"			revision,\n" + 
9402
		"			String.valueOf(delta),\n" + 
9403
		"			line\n" + 
9404
		"		});\n" + 
9405
		"	}\n" + 
9406
		"}\n";
9407
	formatSource(source	,
9408
		"package wksp1;\n" + 
9409
		"\n" + 
9410
		"public class X44 {\n" + 
9411
		"	String foo() {\n" + 
9412
		"		return Policy.bind(\"CVSAnnotateBlock.6\", new Object[] { //$NON-NLS-1$\n" + 
9413
		"				user,\n" + 
9414
		"						revision,\n" + 
9415
		"						String.valueOf(delta),\n" + 
9416
		"						line\n" + 
9417
		"		});\n" + 
9418
		"	}\n" + 
9419
		"}\n"
9420
	);
9421
}
9422
public void testBug330313_wksp1_45_njl() {
9423
	this.formatterPrefs.join_wrapped_lines = false;
9424
	String source =
9425
		"package wksp1;\n" + 
9426
		"\n" + 
9427
		"public class X45 {\n" + 
9428
		"		private String[][] TABLE  = {\n" + 
9429
		"			{\"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\", \"COL_TAGS\"},	/* revision */ \n" + 
9430
		"			{\"COL_TAGS\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\"},	/* tags */\n" + 
9431
		"			{\"COL_DATE\", \"COL_REVISION\", \"COL_AUTHOR\", \"COL_COMMENT\", \"COL_TAGS\"},	/* date */\n" + 
9432
		"			{\"COL_AUTHOR\", \"COL_REVISION\", \"COL_DATE\", \"COL_COMMENT\", \"COL_TAGS\"},	/* author */\n" + 
9433
		"			{\"COL_COMMENT\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_TAGS\"}		/* comment */\n" + 
9434
		"		};\n" + 
9435
		"}\n";
9436
	formatSource(source	,
9437
		"package wksp1;\n" + 
9438
		"\n" + 
9439
		"public class X45 {\n" + 
9440
		"	private String[][] TABLE = {\n" + 
9441
		"			{ \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\",\n" + 
9442
		"					\"COL_TAGS\" }, /* revision */\n" + 
9443
		"			{ \"COL_TAGS\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\",\n" + 
9444
		"					\"COL_COMMENT\" }, /* tags */\n" + 
9445
		"			{ \"COL_DATE\", \"COL_REVISION\", \"COL_AUTHOR\", \"COL_COMMENT\",\n" + 
9446
		"					\"COL_TAGS\" }, /* date */\n" + 
9447
		"			{ \"COL_AUTHOR\", \"COL_REVISION\", \"COL_DATE\", \"COL_COMMENT\",\n" + 
9448
		"					\"COL_TAGS\" }, /* author */\n" + 
9449
		"			{ \"COL_COMMENT\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\",\n" + 
9450
		"					\"COL_TAGS\" } /* comment */\n" + 
9451
		"	};\n" + 
9452
		"}\n"
9453
	);
9454
}
9455
public void testBug330313_wksp1_46_njl() {
9456
	this.formatterPrefs.join_wrapped_lines = false;
9457
	String source =
9458
		"package wksp1;\n" + 
9459
		"\n" + 
9460
		"public class X46 {\n" + 
9461
		"	void foo() {\n" + 
9462
		"	    if (getActive() == StackPresentation.AS_ACTIVE_NOFOCUS) {\n" + 
9463
		"	        drawGradient(\n" + 
9464
		"	                colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR), \n" + 
9465
		"	                new Color [] {\n" + 
9466
		"	                        colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START) \n" + 
9467
		"	                }, \n" + 
9468
		"	                new int [0],\n" + 
9469
		"	                true);	        \n" + 
9470
		"	    }\n" + 
9471
		"	}\n" + 
9472
		"}\n";
9473
	formatSource(source	,
9474
		"package wksp1;\n" + 
9475
		"\n" + 
9476
		"public class X46 {\n" + 
9477
		"	void foo() {\n" + 
9478
		"		if (getActive() == StackPresentation.AS_ACTIVE_NOFOCUS) {\n" + 
9479
		"			drawGradient(\n" + 
9480
		"					colorRegistry\n" + 
9481
		"							.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR),\n" + 
9482
		"					new Color[] {\n" + 
9483
		"					colorRegistry\n" + 
9484
		"							.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START)\n" + 
9485
		"					},\n" + 
9486
		"					new int[0],\n" + 
9487
		"					true);\n" + 
9488
		"		}\n" + 
9489
		"	}\n" + 
9490
		"}\n"
9491
	);
9492
}
9493
public void testBug330313_wksp1_47_njl() {
9494
	this.formatterPrefs.join_wrapped_lines = false;
9495
	String source =
9496
		"package wksp1;\n" + 
9497
		"\n" + 
9498
		"public class X47 {\n" + 
9499
		"	void foo(int x) {\n" + 
9500
		"		switch (x) {\n" + 
9501
		"			case 0 :\n" + 
9502
		"				// case 0\n" + 
9503
		"				break;\n" + 
9504
		"			case 3 :\n" + 
9505
		"				// case 3\n" + 
9506
		"				break;\n" + 
9507
		"			//case -1 :\n" + 
9508
		"			// internal failure: trying to load variable not supposed to be generated\n" + 
9509
		"			//	break;\n" + 
9510
		"			default :\n" + 
9511
		"				// default\n" + 
9512
		"		}\n" + 
9513
		"		// last comment\n" + 
9514
		"	}\n" + 
9515
		"}\n";
9516
	formatSource(source	,
9517
		"package wksp1;\n" + 
9518
		"\n" + 
9519
		"public class X47 {\n" + 
9520
		"	void foo(int x) {\n" + 
9521
		"		switch (x) {\n" + 
9522
		"		case 0:\n" + 
9523
		"			// case 0\n" + 
9524
		"			break;\n" + 
9525
		"		case 3:\n" + 
9526
		"			// case 3\n" + 
9527
		"			break;\n" + 
9528
		"		// case -1 :\n" + 
9529
		"		// internal failure: trying to load variable not supposed to be\n" + 
9530
		"		// generated\n" + 
9531
		"		// break;\n" + 
9532
		"		default:\n" + 
9533
		"			// default\n" + 
9534
		"		}\n" + 
9535
		"		// last comment\n" + 
9536
		"	}\n" + 
9537
		"}\n"
9538
	);
9539
}
9540
public void testBug330313_wksp1_48_njl() {
9541
	this.formatterPrefs.join_wrapped_lines = false;
9542
	String source =
9543
		"package wksp1;\n" + 
9544
		"\n" + 
9545
		"public class X48 {\n" + 
9546
		"	void foo(int x) {\n" + 
9547
		"		switch (x) {\n" + 
9548
		"			case 0 :\n" + 
9549
		"				// case 0\n" + 
9550
		"				break;\n" + 
9551
		"			case 3 :\n" + 
9552
		"				// case 3\n" + 
9553
		"				break;\n" + 
9554
		"			//case -1 :\n" + 
9555
		"			// internal failure: trying to load variable not supposed to be generated\n" + 
9556
		"			//	break;\n" + 
9557
		"		}\n" + 
9558
		"		// last comment\n" + 
9559
		"	}\n" + 
9560
		"}\n";
9561
	formatSource(source	,
9562
		"package wksp1;\n" + 
9563
		"\n" + 
9564
		"public class X48 {\n" + 
9565
		"	void foo(int x) {\n" + 
9566
		"		switch (x) {\n" + 
9567
		"		case 0:\n" + 
9568
		"			// case 0\n" + 
9569
		"			break;\n" + 
9570
		"		case 3:\n" + 
9571
		"			// case 3\n" + 
9572
		"			break;\n" + 
9573
		"		// case -1 :\n" + 
9574
		"		// internal failure: trying to load variable not supposed to be\n" + 
9575
		"		// generated\n" + 
9576
		"		// break;\n" + 
9577
		"		}\n" + 
9578
		"		// last comment\n" + 
9579
		"	}\n" + 
9580
		"}\n"
9581
	);
9582
}
9583
public void testBug330313_wksp1_49_njl() {
9584
	this.formatterPrefs.join_wrapped_lines = false;
9585
	String source =
9586
		"package wksp1;\n" + 
9587
		"\n" + 
9588
		"public class X49 {\n" + 
9589
		"	void foo(int i) {\n" + 
9590
		"		if (true) {\n" + 
9591
		"			if (true) {\n" + 
9592
		"				this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };\n" + 
9593
		"			}\n" + 
9594
		"		}\n" + 
9595
		"	}\n" + 
9596
		"}\n";
9597
	formatSource(source	,
9598
		"package wksp1;\n" + 
9599
		"\n" + 
9600
		"public class X49 {\n" + 
9601
		"	void foo(int i) {\n" + 
9602
		"		if (true) {\n" + 
9603
		"			if (true) {\n" + 
9604
		"				this.foundTaskPositions[this.foundTaskCount] = new int[] { i,\n" + 
9605
		"						i + tagLength - 1 };\n" + 
9606
		"			}\n" + 
9607
		"		}\n" + 
9608
		"	}\n" + 
9609
		"}\n"
9610
	);
9611
}
9612
public void testBug330313_wksp1_50_njl() {
9613
	this.formatterPrefs.join_wrapped_lines = false;
9614
	String source =
9615
		"package wksp1;\n" + 
9616
		"\n" + 
9617
		"public class X50 {\n" + 
9618
		"private void deployCodeSnippetClassIfNeeded(IRequestor requestor) {\n" + 
9619
		"	if (this.codeSnippetBinary == null) {\n" + 
9620
		"		// Deploy CodeSnippet class (only once)\n" + 
9621
		"		requestor.acceptClassFiles(\n" + 
9622
		"			new ClassFile[] {\n" + 
9623
		"				new ClassFile() {\n" + 
9624
		"					public byte[] getBytes() {\n" + 
9625
		"						return getCodeSnippetBytes();\n" + 
9626
		"					}\n" + 
9627
		"					public char[][] getCompoundName() {\n" + 
9628
		"						return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + 
9629
		"					}\n" + 
9630
		"				}\n" + 
9631
		"			}, \n" + 
9632
		"			null);\n" + 
9633
		"	}\n" + 
9634
		"}\n" + 
9635
		"}\n";
9636
	formatSource(source	,
9637
		"package wksp1;\n" + 
9638
		"\n" + 
9639
		"public class X50 {\n" + 
9640
		"	private void deployCodeSnippetClassIfNeeded(IRequestor requestor) {\n" + 
9641
		"		if (this.codeSnippetBinary == null) {\n" + 
9642
		"			// Deploy CodeSnippet class (only once)\n" + 
9643
		"			requestor.acceptClassFiles(\n" + 
9644
		"					new ClassFile[] {\n" + 
9645
		"					new ClassFile() {\n" + 
9646
		"						public byte[] getBytes() {\n" + 
9647
		"							return getCodeSnippetBytes();\n" + 
9648
		"						}\n" + 
9649
		"\n" + 
9650
		"						public char[][] getCompoundName() {\n" + 
9651
		"							return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + 
9652
		"						}\n" + 
9653
		"					}\n" + 
9654
		"					},\n" + 
9655
		"					null);\n" + 
9656
		"		}\n" + 
9657
		"	}\n" + 
9658
		"}\n"
9659
	);
9660
}
9661
public void testBug330313_wksp1_51_njl() {
9662
	this.formatterPrefs.join_wrapped_lines = false;
9663
	String source =
9664
		"package wksp1;\n" + 
9665
		"\n" + 
9666
		"public class X51 {\n" + 
9667
		"\n" + 
9668
		"protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {\n" + 
9669
		"	for (int i = 0, l = sourceLocations.length; i < l; i++) {\n" + 
9670
		"		sourceLocation.sourceFolder.accept(\n" + 
9671
		"			new IResourceProxyVisitor() {\n" + 
9672
		"				public boolean visit(IResourceProxy proxy) throws CoreException {\n" + 
9673
		"					IResource resource = null;\n" + 
9674
		"					switch(proxy.getType()) {\n" + 
9675
		"						case IResource.FILE :\n" + 
9676
		"							if (exclusionPatterns != null || inclusionPatterns != null) {\n" + 
9677
		"								resource = proxy.requestResource();\n" + 
9678
		"								if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return false;\n" + 
9679
		"							}\n" + 
9680
		"							if (org.eclipse.jdt.internal.compiler.util.Util.isJavaFileName(proxy.getName())) {\n" + 
9681
		"								if (resource == null)\n" + 
9682
		"									resource = proxy.requestResource();\n" + 
9683
		"								sourceFiles.add(new SourceFile((IFile) resource, sourceLocation));\n" + 
9684
		"							}\n" + 
9685
		"							return false;\n" + 
9686
		"						case IResource.FOLDER :\n" + 
9687
		"							if (exclusionPatterns != null && inclusionPatterns == null) {\n" + 
9688
		"								// if there are inclusion patterns then we must walk the children\n" + 
9689
		"								resource = proxy.requestResource();\n" + 
9690
		"								if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return false;\n" + 
9691
		"							}\n" + 
9692
		"							if (isAlsoProject && isExcludedFromProject(proxy.requestFullPath())) return false;\n" + 
9693
		"					}\n" + 
9694
		"					return true;\n" + 
9695
		"				}\n" + 
9696
		"			},\n" + 
9697
		"			IResource.NONE\n" + 
9698
		"		);\n" + 
9699
		"		notifier.checkCancel();\n" + 
9700
		"	}\n" + 
9701
		"}\n" + 
9702
		"}\n";
9703
	formatSource(source	,
9704
		"package wksp1;\n" + 
9705
		"\n" + 
9706
		"public class X51 {\n" + 
9707
		"\n" + 
9708
		"	protected void addAllSourceFiles(final ArrayList sourceFiles)\n" + 
9709
		"			throws CoreException {\n" + 
9710
		"		for (int i = 0, l = sourceLocations.length; i < l; i++) {\n" + 
9711
		"			sourceLocation.sourceFolder.accept(\n" + 
9712
		"					new IResourceProxyVisitor() {\n" + 
9713
		"						public boolean visit(IResourceProxy proxy)\n" + 
9714
		"								throws CoreException {\n" + 
9715
		"							IResource resource = null;\n" + 
9716
		"							switch (proxy.getType()) {\n" + 
9717
		"							case IResource.FILE:\n" + 
9718
		"								if (exclusionPatterns != null\n" + 
9719
		"										|| inclusionPatterns != null) {\n" + 
9720
		"									resource = proxy.requestResource();\n" + 
9721
		"									if (Util.isExcluded(resource,\n" + 
9722
		"											inclusionPatterns,\n" + 
9723
		"											exclusionPatterns))\n" + 
9724
		"										return false;\n" + 
9725
		"								}\n" + 
9726
		"								if (org.eclipse.jdt.internal.compiler.util.Util\n" + 
9727
		"										.isJavaFileName(proxy.getName())) {\n" + 
9728
		"									if (resource == null)\n" + 
9729
		"										resource = proxy.requestResource();\n" + 
9730
		"									sourceFiles.add(new SourceFile(\n" + 
9731
		"											(IFile) resource, sourceLocation));\n" + 
9732
		"								}\n" + 
9733
		"								return false;\n" + 
9734
		"							case IResource.FOLDER:\n" + 
9735
		"								if (exclusionPatterns != null\n" + 
9736
		"										&& inclusionPatterns == null) {\n" + 
9737
		"									// if there are inclusion patterns then we\n" + 
9738
		"									// must walk the children\n" + 
9739
		"									resource = proxy.requestResource();\n" + 
9740
		"									if (Util.isExcluded(resource,\n" + 
9741
		"											inclusionPatterns,\n" + 
9742
		"											exclusionPatterns))\n" + 
9743
		"										return false;\n" + 
9744
		"								}\n" + 
9745
		"								if (isAlsoProject\n" + 
9746
		"										&& isExcludedFromProject(proxy\n" + 
9747
		"												.requestFullPath()))\n" + 
9748
		"									return false;\n" + 
9749
		"							}\n" + 
9750
		"							return true;\n" + 
9751
		"						}\n" + 
9752
		"					},\n" + 
9753
		"					IResource.NONE\n" + 
9754
		"					);\n" + 
9755
		"			notifier.checkCancel();\n" + 
9756
		"		}\n" + 
9757
		"	}\n" + 
9758
		"}\n"
9759
	);
9760
}
9761
public void testBug330313_wksp1_52_njl() {
9762
	this.formatterPrefs.join_wrapped_lines = false;
9763
	String source =
9764
		"package wksp1;\n" + 
9765
		"\n" + 
9766
		"public class X52 {\n" + 
9767
		"	protected FastSyncInfoFilter getKnownFailureCases() {\n" + 
9768
		"		return new OrSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9769
		"			// Conflicting additions of files will fail\n" + 
9770
		"			new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9771
		"				FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.ADDITION),\n" + 
9772
		"				new FastSyncInfoFilter() {\n" + 
9773
		"					public boolean select(SyncInfo info) {\n" + 
9774
		"						return info.getLocal().getType() == IResource.FILE;\n" + 
9775
		"					}\n" + 
9776
		"				}\n" + 
9777
		"			}),\n" + 
9778
		"			// Conflicting changes of files will fail if the local is not managed\n" + 
9779
		"			// or is an addition\n" + 
9780
		"			new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9781
		"				FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9782
		"				new FastSyncInfoFilter() {\n" + 
9783
		"					public boolean select(SyncInfo info) {\n" + 
9784
		"						if (info.getLocal().getType() == IResource.FILE) {\n" + 
9785
		"							try {\n" + 
9786
		"								ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile)info.getLocal());\n" + 
9787
		"								byte[] syncBytes = cvsFile.getSyncBytes();\n" + 
9788
		"								return (syncBytes == null || ResourceSyncInfo.isAddition(syncBytes));\n" + 
9789
		"							} catch (CVSException e) {\n" + 
9790
		"								CVSUIPlugin.log(e);\n" + 
9791
		"								// Fall though and try to update\n" + 
9792
		"							}\n" + 
9793
		"						}\n" + 
9794
		"						return false;\n" + 
9795
		"					}\n" + 
9796
		"				}\n" + 
9797
		"			}),\n" + 
9798
		"			// Conflicting changes involving a deletion on one side will aways fail\n" + 
9799
		"			new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9800
		"				FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9801
		"				new FastSyncInfoFilter() {\n" + 
9802
		"					public boolean select(SyncInfo info) {\n" + 
9803
		"						IResourceVariant remote = info.getRemote();\n" + 
9804
		"						IResourceVariant base = info.getBase();\n" + 
9805
		"						if (info.getLocal().exists()) {\n" + 
9806
		"							// local != base and no remote will fail\n" + 
9807
		"							return (base != null && remote == null);\n" + 
9808
		"						} else {\n" + 
9809
		"							// no local and base != remote\n" + 
9810
		"							return (base != null && remote != null && !base.equals(remote));\n" + 
9811
		"						}\n" + 
9812
		"					}\n" + 
9813
		"				}\n" + 
9814
		"			}),\n" + 
9815
		"			// Conflicts where the file type is binary will work but are not merged\n" + 
9816
		"			// so they should be skipped\n" + 
9817
		"			new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9818
		"				FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9819
		"				new FastSyncInfoFilter() {\n" + 
9820
		"					public boolean select(SyncInfo info) {\n" + 
9821
		"						IResource local = info.getLocal();\n" + 
9822
		"						if (local.getType() == IResource.FILE) {\n" + 
9823
		"							try {\n" + 
9824
		"								ICVSFile file = CVSWorkspaceRoot.getCVSFileFor((IFile)local);\n" + 
9825
		"								byte[] syncBytes = file.getSyncBytes();\n" + 
9826
		"								if (syncBytes != null) {\n" + 
9827
		"									return ResourceSyncInfo.isBinary(syncBytes);\n" + 
9828
		"								}\n" + 
9829
		"							} catch (CVSException e) {\n" + 
9830
		"								// There was an error obtaining or interpreting the sync bytes\n" + 
9831
		"								// Log it and skip the file\n" + 
9832
		"								CVSProviderPlugin.log(e);\n" + 
9833
		"								return true;\n" + 
9834
		"							}\n" + 
9835
		"						}\n" + 
9836
		"						return false;\n" + 
9837
		"					}\n" + 
9838
		"				}\n" + 
9839
		"			}),\n" + 
9840
		"			// Outgoing changes may not fail but they are skipped as well\n" + 
9841
		"			new SyncInfoDirectionFilter(SyncInfo.OUTGOING)\n" + 
9842
		"		});\n" + 
9843
		"	}\n" + 
9844
		"}\n";
9845
	formatSource(source	,
9846
		"package wksp1;\n" + 
9847
		"\n" + 
9848
		"public class X52 {\n" + 
9849
		"	protected FastSyncInfoFilter getKnownFailureCases() {\n" + 
9850
		"		return new OrSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9851
		"				// Conflicting additions of files will fail\n" + 
9852
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9853
		"						FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + 
9854
		"								SyncInfo.CONFLICTING, SyncInfo.ADDITION),\n" + 
9855
		"						new FastSyncInfoFilter() {\n" + 
9856
		"							public boolean select(SyncInfo info) {\n" + 
9857
		"								return info.getLocal().getType() == IResource.FILE;\n" + 
9858
		"							}\n" + 
9859
		"						}\n" + 
9860
		"				}),\n" + 
9861
		"				// Conflicting changes of files will fail if the local is not\n" + 
9862
		"				// managed\n" + 
9863
		"				// or is an addition\n" + 
9864
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9865
		"						FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + 
9866
		"								SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9867
		"						new FastSyncInfoFilter() {\n" + 
9868
		"							public boolean select(SyncInfo info) {\n" + 
9869
		"								if (info.getLocal().getType() == IResource.FILE) {\n" + 
9870
		"									try {\n" + 
9871
		"										ICVSFile cvsFile = CVSWorkspaceRoot\n" + 
9872
		"												.getCVSFileFor((IFile) info\n" + 
9873
		"														.getLocal());\n" + 
9874
		"										byte[] syncBytes = cvsFile\n" + 
9875
		"												.getSyncBytes();\n" + 
9876
		"										return (syncBytes == null || ResourceSyncInfo\n" + 
9877
		"												.isAddition(syncBytes));\n" + 
9878
		"									} catch (CVSException e) {\n" + 
9879
		"										CVSUIPlugin.log(e);\n" + 
9880
		"										// Fall though and try to update\n" + 
9881
		"									}\n" + 
9882
		"								}\n" + 
9883
		"								return false;\n" + 
9884
		"							}\n" + 
9885
		"						}\n" + 
9886
		"				}),\n" + 
9887
		"				// Conflicting changes involving a deletion on one side will\n" + 
9888
		"				// aways fail\n" + 
9889
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9890
		"						FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + 
9891
		"								SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9892
		"						new FastSyncInfoFilter() {\n" + 
9893
		"							public boolean select(SyncInfo info) {\n" + 
9894
		"								IResourceVariant remote = info.getRemote();\n" + 
9895
		"								IResourceVariant base = info.getBase();\n" + 
9896
		"								if (info.getLocal().exists()) {\n" + 
9897
		"									// local != base and no remote will fail\n" + 
9898
		"									return (base != null && remote == null);\n" + 
9899
		"								} else {\n" + 
9900
		"									// no local and base != remote\n" + 
9901
		"									return (base != null && remote != null && !base\n" + 
9902
		"											.equals(remote));\n" + 
9903
		"								}\n" + 
9904
		"							}\n" + 
9905
		"						}\n" + 
9906
		"				}),\n" + 
9907
		"				// Conflicts where the file type is binary will work but are not\n" + 
9908
		"				// merged\n" + 
9909
		"				// so they should be skipped\n" + 
9910
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
9911
		"						FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + 
9912
		"								SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + 
9913
		"						new FastSyncInfoFilter() {\n" + 
9914
		"							public boolean select(SyncInfo info) {\n" + 
9915
		"								IResource local = info.getLocal();\n" + 
9916
		"								if (local.getType() == IResource.FILE) {\n" + 
9917
		"									try {\n" + 
9918
		"										ICVSFile file = CVSWorkspaceRoot\n" + 
9919
		"												.getCVSFileFor((IFile) local);\n" + 
9920
		"										byte[] syncBytes = file.getSyncBytes();\n" + 
9921
		"										if (syncBytes != null) {\n" + 
9922
		"											return ResourceSyncInfo\n" + 
9923
		"													.isBinary(syncBytes);\n" + 
9924
		"										}\n" + 
9925
		"									} catch (CVSException e) {\n" + 
9926
		"										// There was an error obtaining or\n" + 
9927
		"										// interpreting the sync bytes\n" + 
9928
		"										// Log it and skip the file\n" + 
9929
		"										CVSProviderPlugin.log(e);\n" + 
9930
		"										return true;\n" + 
9931
		"									}\n" + 
9932
		"								}\n" + 
9933
		"								return false;\n" + 
9934
		"							}\n" + 
9935
		"						}\n" + 
9936
		"				}),\n" + 
9937
		"				// Outgoing changes may not fail but they are skipped as well\n" + 
9938
		"				new SyncInfoDirectionFilter(SyncInfo.OUTGOING)\n" + 
9939
		"		});\n" + 
9940
		"	}\n" + 
9941
		"}\n"
9942
	);
9943
}
9944
public void testBug330313_wksp1_53_njl_bnl() {
9945
	this.formatterPrefs.join_wrapped_lines = false;
9946
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
9947
	String source =
9948
		"package wksp1;\n" + 
9949
		"\n" + 
9950
		"public class X53 {\n" + 
9951
		"	static final short[][][] BLACK_CODE = {\n" + 
9952
		"		/* 9 bits  */\n" + 
9953
		"		{{24, 15}},\n" + 
9954
		"		/* 10 bits */\n" + 
9955
		"		{{8, 18}, {15, 64}, {23, 16}, {24, 17}, {55, 0}},\n" + 
9956
		"		/* 11 bits */\n" + 
9957
		"		{/* EOL */{0, -1}, {8, 1792}, {23, 24}, {24, 25}, {40, 23}, {55, 22}, {103, 19},\n" + 
9958
		"		{104, 20}, {108, 21}, {12, 1856}, {13, 1920}},\n" + 
9959
		"	};\n" + 
9960
		"}\n";
9961
	formatSource(source	,
9962
		"package wksp1;\n" + 
9963
		"\n" + 
9964
		"public class X53\n" + 
9965
		"{\n" + 
9966
		"	static final short[][][] BLACK_CODE =\n" + 
9967
		"	{\n" + 
9968
		"			/* 9 bits */\n" + 
9969
		"			{\n" + 
9970
		"			{ 24, 15 } },\n" + 
9971
		"			/* 10 bits */\n" + 
9972
		"			{\n" + 
9973
		"			{ 8, 18 },\n" + 
9974
		"			{ 15, 64 },\n" + 
9975
		"			{ 23, 16 },\n" + 
9976
		"			{ 24, 17 },\n" + 
9977
		"			{ 55, 0 } },\n" + 
9978
		"			/* 11 bits */\n" + 
9979
		"			{/* EOL */\n" + 
9980
		"			{ 0, -1 },\n" + 
9981
		"			{ 8, 1792 },\n" + 
9982
		"			{ 23, 24 },\n" + 
9983
		"			{ 24, 25 },\n" + 
9984
		"			{ 40, 23 },\n" + 
9985
		"			{ 55, 22 },\n" + 
9986
		"			{ 103, 19 },\n" + 
9987
		"			{ 104, 20 },\n" + 
9988
		"			{ 108, 21 },\n" + 
9989
		"			{ 12, 1856 },\n" + 
9990
		"			{ 13, 1920 } },\n" + 
9991
		"	};\n" + 
9992
		"}\n"
9993
	);
9994
}
9995
public void testBug330313_wksp2_01 () {
9996
	String source =
9997
		"package wksp2;\n" + 
9998
		"\n" + 
9999
		"public class X01 {\n" + 
10000
		"\n" + 
10001
		"    static final Object[][] contents = {\n" + 
10002
		"        // comment\n" + 
10003
		"        { \"STR1\",\n" + 
10004
		"        	// comment\n" + 
10005
		"            new String[] { \"STR\",     // comment\n" + 
10006
		"                           \"STR\",     // comment\n" + 
10007
		"                           \"STR\"}     // comment\n" + 
10008
		"        }\n" + 
10009
		"\n" + 
10010
		"    };\n" + 
10011
		"\n" + 
10012
		"}\n";
10013
	formatSource(source,
10014
		"package wksp2;\n" + 
10015
		"\n" + 
10016
		"public class X01 {\n" + 
10017
		"\n" + 
10018
		"	static final Object[][] contents = {\n" + 
10019
		"	// comment\n" + 
10020
		"	{ \"STR1\",\n" + 
10021
		"			// comment\n" + 
10022
		"			new String[] { \"STR\", // comment\n" + 
10023
		"					\"STR\", // comment\n" + 
10024
		"					\"STR\" } // comment\n" + 
10025
		"	}\n" + 
10026
		"\n" + 
10027
		"	};\n" + 
10028
		"\n" + 
10029
		"}\n"
10030
	);
10031
}
10032
public void testBug330313_wksp3_X01_njl() {
10033
	this.formatterPrefs.join_wrapped_lines = false;
10034
	String source =
10035
		"package wksp3;\n" + 
10036
		"\n" + 
10037
		"public class X01 {\n" + 
10038
		"    private static final String foo[][] = {\n" + 
10039
		"        // line 1\n" + 
10040
		"        // line 2\n" + 
10041
		"        {\"A\", \"B\", \"C\", \"D\", \"E\"} // comment\n" + 
10042
		"    };\n" + 
10043
		"}\n";
10044
	formatSource(source	,
10045
		"package wksp3;\n" + 
10046
		"\n" + 
10047
		"public class X01 {\n" + 
10048
		"	private static final String foo[][] = {\n" + 
10049
		"			// line 1\n" + 
10050
		"			// line 2\n" + 
10051
		"			{ \"A\", \"B\", \"C\", \"D\", \"E\" } // comment\n" + 
10052
		"	};\n" + 
10053
		"}\n"
10054
	);
10055
}
10056
// Test cases added from bug 286601
10057
public void testBug330313_b286601_04() {
10058
	this.formatterPrefs.join_wrapped_lines = false;
10059
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT;
10060
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
10061
	String source =
10062
		"package b286601;\n" + 
10063
		"\n" + 
10064
		"public class X04 {\n" + 
10065
		"\n" + 
10066
		"    \n" + 
10067
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + 
10068
		"    private static final int[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + 
10069
		"    /*                        UNUSED           READ             READ_POTENTIAL   WRTIE            WRITE_POTENTIAL  UNKNOWN */\n" + 
10070
		"    /* UNUSED */            { UNUSED,          READ_POTENTIAL,  READ_POTENTIAL,  WRITE_POTENTIAL, WRITE_POTENTIAL, UNKNOWN },\n" + 
10071
		"    /* READ */              { READ_POTENTIAL,  READ,            READ_POTENTIAL,  UNKNOWN,         UNKNOWN,         UNKNOWN },\n" + 
10072
		"    /* READ_POTENTIAL */    { READ_POTENTIAL,  READ_POTENTIAL,  READ_POTENTIAL,  UNKNOWN,         UNKNOWN,         UNKNOWN },\n" + 
10073
		"    /* WRITE */             { WRITE_POTENTIAL, UNKNOWN,         UNKNOWN,         WRITE,           WRITE_POTENTIAL, UNKNOWN },\n" + 
10074
		"    /* WRITE_POTENTIAL */   { WRITE_POTENTIAL, UNKNOWN,         UNKNOWN,         WRITE_POTENTIAL, WRITE_POTENTIAL, UNKNOWN },\n" + 
10075
		"    /* UNKNOWN */           { UNKNOWN,         UNKNOWN,         UNKNOWN,         UNKNOWN,         UNKNOWN,         UNKNOWN }\n" + 
10076
		"    };\n" + 
10077
		"\n" + 
10078
		"}\n";
10079
	formatSource(source,
10080
		"package b286601;\n" + 
10081
		"\n" + 
10082
		"public class X04\n" + 
10083
		"{\n" + 
10084
		"\n" + 
10085
		"	// Table to merge access modes for condition statements (e.g branch[x] ||\n" + 
10086
		"	// branch[y]).\n" + 
10087
		"	private static final int[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + 
10088
		"	{\n" + 
10089
		"			/* UNUSED READ READ_POTENTIAL WRTIE WRITE_POTENTIAL UNKNOWN */\n" + 
10090
		"			/* UNUSED */{\n" + 
10091
		"					UNUSED,\n" + 
10092
		"					READ_POTENTIAL,\n" + 
10093
		"					READ_POTENTIAL,\n" + 
10094
		"					WRITE_POTENTIAL,\n" + 
10095
		"					WRITE_POTENTIAL,\n" + 
10096
		"					UNKNOWN },\n" + 
10097
		"			/* READ */{\n" + 
10098
		"					READ_POTENTIAL,\n" + 
10099
		"					READ,\n" + 
10100
		"					READ_POTENTIAL,\n" + 
10101
		"					UNKNOWN,\n" + 
10102
		"					UNKNOWN,\n" + 
10103
		"					UNKNOWN },\n" + 
10104
		"			/* READ_POTENTIAL */{\n" + 
10105
		"					READ_POTENTIAL,\n" + 
10106
		"					READ_POTENTIAL,\n" + 
10107
		"					READ_POTENTIAL,\n" + 
10108
		"					UNKNOWN,\n" + 
10109
		"					UNKNOWN,\n" + 
10110
		"					UNKNOWN },\n" + 
10111
		"			/* WRITE */{\n" + 
10112
		"					WRITE_POTENTIAL,\n" + 
10113
		"					UNKNOWN,\n" + 
10114
		"					UNKNOWN,\n" + 
10115
		"					WRITE,\n" + 
10116
		"					WRITE_POTENTIAL,\n" + 
10117
		"					UNKNOWN },\n" + 
10118
		"			/* WRITE_POTENTIAL */{\n" + 
10119
		"					WRITE_POTENTIAL,\n" + 
10120
		"					UNKNOWN,\n" + 
10121
		"					UNKNOWN,\n" + 
10122
		"					WRITE_POTENTIAL,\n" + 
10123
		"					WRITE_POTENTIAL,\n" + 
10124
		"					UNKNOWN },\n" + 
10125
		"			/* UNKNOWN */{ UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }\n" + 
10126
		// Should be slip but that has been broken since 3.4.2 (i.e. 3.3.2 is OK)
10127
//		"			/* UNKNOWN */{\n" + 
10128
//		"					UNKNOWN,\n" + 
10129
//		"					UNKNOWN,\n" + 
10130
//		"					UNKNOWN,\n" + 
10131
//		"					UNKNOWN,\n" + 
10132
//		"					UNKNOWN,\n" + 
10133
//		"					UNKNOWN }\n" + 
10134
		"	};\n" + 
10135
		"\n" + 
10136
		"}\n"
10137
	);
10138
}
10139
public void testBug330313_b286601_05() {
10140
	this.formatterPrefs.join_wrapped_lines = false;
10141
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT;
10142
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
10143
	String source =
10144
		"package b286601;\n" + 
10145
		"\n" + 
10146
		"public class X05 {\n" + 
10147
		"\n" + 
10148
		"    \n" + 
10149
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + 
10150
		"    static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + 
10151
		"    { \"UNUSED\",          \"READ_POTENTIAL\",  \"READ_POTENTIAL\",  \"WRITE_POTENTIAL\", \"WRITE_POTENTIAL\", \"UNKNOWN\" },\n" + 
10152
		"    { \"READ_POTENTIAL\",  \"READ\",            \"READ_POTENTIAL\",  \"UNKNOWN\",         \"UNKNOWN\",         \"UNKNOWN\" },\n" + 
10153
		"    };\n" + 
10154
		"\n" + 
10155
		"}\n";
10156
	formatSource(source,
10157
		"package b286601;\n" + 
10158
		"\n" + 
10159
		"public class X05\n" + 
10160
		"{\n" + 
10161
		"\n" + 
10162
		"	// Table to merge access modes for condition statements (e.g branch[x] ||\n" + 
10163
		"	// branch[y]).\n" + 
10164
		"	static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + 
10165
		"	{\n" + 
10166
		"			{\n" + 
10167
		"					\"UNUSED\",\n" + 
10168
		"					\"READ_POTENTIAL\",\n" + 
10169
		"					\"READ_POTENTIAL\",\n" + 
10170
		"					\"WRITE_POTENTIAL\",\n" + 
10171
		"					\"WRITE_POTENTIAL\",\n" + 
10172
		"					\"UNKNOWN\" },\n" + 
10173
		"			{\n" + 
10174
		"					\"READ_POTENTIAL\",\n" + 
10175
		"					\"READ\",\n" + 
10176
		"					\"READ_POTENTIAL\",\n" + 
10177
		"					\"UNKNOWN\",\n" + 
10178
		"					\"UNKNOWN\",\n" + 
10179
		"					\"UNKNOWN\" },\n" + 
10180
		"	};\n" + 
10181
		"\n" + 
10182
		"}\n"
10183
	);
10184
}
10185
public void testBug330313_b286601_06() {
10186
	this.formatterPrefs.join_wrapped_lines = false;
10187
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT;
10188
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
10189
	String source =
10190
		"package b286601;\n" + 
10191
		"\n" + 
10192
		"public class X06 {\n" + 
10193
		"\n" + 
10194
		"    \n" + 
10195
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + 
10196
		"    static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + 
10197
		"    /* Comment 1 */\n" + 
10198
		"    /* Comment 2 */ { \"UNUSED\",          \"READ_POTENTIAL\",  \"READ_POTENTIAL\",  \"WRITE_POTENTIAL\", \"WRITE_POTENTIAL\", \"UNKNOWN\" },\n" + 
10199
		"    /* Comment 3 */ { \"READ_POTENTIAL\",  \"READ\",            \"READ_POTENTIAL\",  \"UNKNOWN\",         \"UNKNOWN\",         \"UNKNOWN\" },\n" + 
10200
		"    };\n" + 
10201
		"\n" + 
10202
		"}\n";
10203
	formatSource(source,
10204
		"package b286601;\n" + 
10205
		"\n" + 
10206
		"public class X06\n" + 
10207
		"{\n" + 
10208
		"\n" + 
10209
		"	// Table to merge access modes for condition statements (e.g branch[x] ||\n" + 
10210
		"	// branch[y]).\n" + 
10211
		"	static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + 
10212
		"	{\n" + 
10213
		"			/* Comment 1 */\n" + 
10214
		"			/* Comment 2 */{\n" + 
10215
		"					\"UNUSED\",\n" + 
10216
		"					\"READ_POTENTIAL\",\n" + 
10217
		"					\"READ_POTENTIAL\",\n" + 
10218
		"					\"WRITE_POTENTIAL\",\n" + 
10219
		"					\"WRITE_POTENTIAL\",\n" + 
10220
		"					\"UNKNOWN\" },\n" + 
10221
		"			/* Comment 3 */{\n" + 
10222
		"					\"READ_POTENTIAL\",\n" + 
10223
		"					\"READ\",\n" + 
10224
		"					\"READ_POTENTIAL\",\n" + 
10225
		"					\"UNKNOWN\",\n" + 
10226
		"					\"UNKNOWN\",\n" + 
10227
		"					\"UNKNOWN\" },\n" + 
10228
		"	};\n" + 
10229
		"\n" + 
10230
		"}\n"
10231
	);
10232
}
10233
public void testBug330313_b286601_07() {
10234
	this.formatterPrefs.join_wrapped_lines = false;
10235
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
10236
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT;
10237
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
10238
	String source =
10239
		"package b286601;\n" + 
10240
		"\n" + 
10241
		"public class X07 {\n" + 
10242
		"\n" + 
10243
		"    \n" + 
10244
		"    // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + 
10245
		"    static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + 
10246
		"    /* Comment 1 */\n" + 
10247
		"    /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + 
10248
		"    /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + 
10249
		"    };\n" + 
10250
		"\n" + 
10251
		"}\n";
10252
	formatSource(source,
10253
		"package b286601;\n" + 
10254
		"\n" + 
10255
		"public class X07\n" + 
10256
		"{\n" + 
10257
		"\n" + 
10258
		"    // Table to merge access modes for condition statements (e.g branch[x] ||\n" + 
10259
		"    // branch[y]).\n" + 
10260
		"    static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + 
10261
		"    {\n" + 
10262
		"            /* Comment 1 */\n" + 
10263
		"            /* Comment 2 */{\n" + 
10264
		"                    \"1234567890123456789012345678901234567890\",\n" + 
10265
		"                    \"1234567890123456789012345678901234567890\" },\n" + 
10266
		"            /* Comment 3 */{\n" + 
10267
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\",\n" + 
10268
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + 
10269
		"    };\n" + 
10270
		"\n" + 
10271
		"}\n"
10272
	);
10273
}
10274
public void testBug330313_b286601_08() {
10275
	this.formatterPrefs.join_wrapped_lines = false;
10276
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT;
10277
	setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE);
10278
	String source =
10279
		"package b286601;\n" + 
10280
		"\n" + 
10281
		"public class X08 {\n" + 
10282
		"    private MinimizedFileSystemElement selectFiles(final Object rootFileSystemObject, final IImportStructureProvider structureProvider) {\n" + 
10283
		"\n" + 
10284
		"        BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {\n" + 
10285
		"            public void run() {\n" + 
10286
		"                //Create the root element from the supplied file system object\n" + 
10287
		"            }\n" + 
10288
		"        });\n" + 
10289
		"\n" + 
10290
		"        return null;\n" + 
10291
		"    }\n" + 
10292
		"}\n";
10293
	formatSource(source,
10294
		"package b286601;\n" + 
10295
		"\n" + 
10296
		"public class X08\n" + 
10297
		"{\n" + 
10298
		"	private MinimizedFileSystemElement selectFiles(\n" + 
10299
		"			final Object rootFileSystemObject,\n" + 
10300
		"			final IImportStructureProvider structureProvider)\n" + 
10301
		"	{\n" + 
10302
		"\n" + 
10303
		"		BusyIndicator.showWhile(getShell().getDisplay(), new Runnable()\n" + 
10304
		"		{\n" + 
10305
		"			public void run()\n" + 
10306
		"			{\n" + 
10307
		"				// Create the root element from the supplied file system object\n" + 
10308
		"			}\n" + 
10309
		"		});\n" + 
10310
		"\n" + 
10311
		"		return null;\n" + 
10312
		"	}\n" + 
10313
		"}\n"
10314
	);
10315
}
10316
10317
/**
7633
 * @bug 332818: [formatter] Java formatter, Blank Lines tab, only 1st line indented when multiple lines is set
10318
 * @bug 332818: [formatter] Java formatter, Blank Lines tab, only 1st line indented when multiple lines is set
7634
 * @test Ensure that the indentation is set on all blank lines
10319
 * @test Ensure that the indentation is set on all blank lines
7635
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=332818"
10320
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=332818"
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java (-33 / +66 lines)
Lines 569-575 Link Here
569
			separator = ",";
569
			separator = ",";
570
		}
570
		}
571
		if (NO_COMMENTS) {
571
		if (NO_COMMENTS) {
572
			buffer.append(separator+"no_comments");
572
			buffer.append(separator+"no_comments=true");
573
			separator = ",";
573
			separator = ",";
574
		}
574
		}
575
		if (BRACES != null) {
575
		if (BRACES != null) {
Lines 660-673 Link Here
660
			} else if (token.equals("list")) {
660
			} else if (token.equals("list")) {
661
				LIST = true;
661
				LIST = true;
662
			} else if (token.equals("tmp")) {
662
			} else if (token.equals("tmp")) {
663
				if (JDT_CORE_HEAD) {
663
				if (PATCH_BUG != null) {
664
					TEMP_OUTPUT = "HEAD";
664
					TEMP_OUTPUT = "patch";
665
				}
666
				else if (JDT_CORE_HEAD) {
667
					TEMP_OUTPUT = "head";
665
				}
668
				}
666
			}
669
			}
667
		}
670
		}
668
		setOutputDir(inputDir, outputDir, profiles);
671
		setOutputDir(inputDir, outputDir, profiles);
669
		if (CLEAN) {
672
		if (CLEAN) {
670
			if (PATCH_BUG != null || (TEMP_OUTPUT == null && JDT_CORE_HEAD)) {
673
			if ((PATCH_BUG != null || JDT_CORE_HEAD) && TEMP_OUTPUT == null) {
671
				System.err.println("Reference can only be updated using a version (i.e. with a closed buildnotes_jdt-core.html)!");
674
				System.err.println("Reference can only be updated using a version (i.e. with a closed buildnotes_jdt-core.html)!");
672
				System.exit(1);
675
				System.exit(1);
673
			}
676
			}
Lines 705-755 Link Here
705
private static void setLogDir(File inputDir, int profiles, boolean verify) throws CoreException {
708
private static void setLogDir(File inputDir, int profiles, boolean verify) throws CoreException {
706
709
707
	// Compute log dir
710
	// Compute log dir
708
	File logDir = new File(System.getProperty("logDir"));
711
	File rootLogDir = new File(System.getProperty("logDir"));
709
	if (!logDir.exists()) {
712
	if (!rootLogDir.exists()) {
710
		if (!logDir.mkdirs()) {
713
		if (!rootLogDir.mkdirs()) {
711
			System.err.println("Cannot create specified log directory: "+logDir+"!!!");
714
			System.err.println("Cannot create specified log directory: "+rootLogDir+"!!!");
712
			return;
715
			return;
713
		}
716
		}
714
	}
717
	}
715
718
716
	// Compute log sub-directories depending on version
719
	// Compute log sub-directories depending on version
717
	logDir = new File(logDir, ECLIPSE_VERSION);
720
	rootLogDir = new File(rootLogDir, ECLIPSE_VERSION);
721
	String subRootDir;
718
	if (PATCH_BUG != null) {
722
	if (PATCH_BUG != null) {
719
		logDir = new File(logDir, "tests");
723
		rootLogDir = new File(rootLogDir, "tests");
720
		logDir = new File(logDir, PATCH_BUG);
724
		rootLogDir = new File(rootLogDir, PATCH_BUG);
721
		logDir = new File(logDir, PATCH_VERSION);
725
		subRootDir = PATCH_VERSION;
722
	} else if (JDT_CORE_HEAD) {
726
	} else if (JDT_CORE_HEAD) {
723
		logDir = new File(logDir, "HEAD");
727
		subRootDir = "HEAD";
724
	} else {
728
	} else {
725
		logDir = new File(logDir, ECLIPSE_MILESTONE);
729
		rootLogDir = new File(rootLogDir, ECLIPSE_MILESTONE);
726
		logDir = new File(logDir, JDT_CORE_VERSION);
730
		subRootDir = JDT_CORE_VERSION;
727
	}
731
	}
728
732
729
	// Compute log sub-directories depending on profiles
733
	// Compute log sub-directories depending on profiles
734
	List subDirs = new ArrayList();
730
	if (profiles > 0) {
735
	if (profiles > 0) {
731
		logDir = new File(logDir, "profiles");
736
		subDirs.add("profiles");
732
		logDir = setProfilesDir(profiles, logDir);
737
		setProfilesDir(profiles, subDirs);
733
	}
738
	}
734
739
735
	if (FILES_FILTER_KIND > 0) {
740
	if (FILES_FILTER_KIND > 0) {
736
		logDir = new File(new File(logDir, "filter"), FILES_FILTER.replace('?', '_').replace('*', '%'));
741
		subDirs.add("filter");
742
		subDirs.add(FILES_FILTER.replace('?', '_').replace('*', '%'));
737
	}
743
	}
738
744
739
	// Create log stream
745
	// Create log stream
740
	logDir.mkdirs();
746
	File logDir = createDir(new File (rootLogDir, subRootDir), subDirs);
741
	String filePrefix = inputDir.getName().replaceAll("\\.", "");
747
	String filePrefix = inputDir.getName().replaceAll("\\.", "");
742
	String logFileName = filePrefix+".txt";
748
	String logFileName = filePrefix+".txt";
743
	LOG_FILE = new File(logDir, logFileName);
749
	LOG_FILE = new File(logDir, logFileName);
744
	if (verify && LOG_FILE.exists()) {
750
	if (verify && LOG_FILE.exists()) {
745
		File saveDir = new File(logDir, "save");
751
		File saveDir = new File(new File(rootLogDir, "save"), subRootDir);
746
		saveDir.mkdir();
752
		saveDir.mkdirs();
747
		int i=0;
753
		int i=0;
748
		while (true) {
754
		while (true) {
749
			String newFileName = filePrefix+"_";
755
			String dirN = Integer.toString(i);
750
			if (i<10) newFileName += "0";
756
			if (i<10) dirN = "0" + dirN;
751
			newFileName += i+".txt";
757
			saveDir = new File(saveDir, dirN);
752
			File renamedFile = new File(saveDir, newFileName);
758
			logDir = createDir(saveDir, subDirs);
759
			File renamedFile = new File(logDir, logFileName);
753
			if (LOG_FILE.renameTo(renamedFile)) break;
760
			if (LOG_FILE.renameTo(renamedFile)) break;
754
			i++;
761
			i++;
755
		}
762
		}
Lines 768-774 Link Here
768
//	LOG_BUFFER = new StringBuffer();
775
//	LOG_BUFFER = new StringBuffer();
769
}
776
}
770
777
778
private static File createDir(File rootDir, List subDirs) {
779
	File dir = rootDir;
780
	for (int i=0, s=subDirs.size(); i<s; i++) {
781
		dir = new File (dir, (String) subDirs.get(i));
782
	}
783
	dir.mkdirs();
784
	return dir;
785
}
786
771
private static File setProfilesDir(int profiles, File dir) {
787
private static File setProfilesDir(int profiles, File dir) {
788
	List subDirs = new ArrayList();
789
	setProfilesDir(profiles, subDirs);
790
	return createDir(dir, subDirs);
791
}
792
793
private static void setProfilesDir(int profiles, List subDirs) {
772
	String joinLines = null;
794
	String joinLines = null;
773
	switch (profiles & PROFILE_JOIN_LINES_MASK) {
795
	switch (profiles & PROFILE_JOIN_LINES_MASK) {
774
		case PROFILE_NEVER_JOIN_LINES:
796
		case PROFILE_NEVER_JOIN_LINES:
Lines 782-791 Link Here
782
			break;
804
			break;
783
	}
805
	}
784
	if (joinLines != null) {
806
	if (joinLines != null) {
785
		dir = new File(new File(dir, "join_lines"), joinLines);
807
		subDirs.add("join_lines");
808
		subDirs.add(joinLines);
786
	}
809
	}
787
	if ((profiles & PROFILE_NO_COMMENTS) != 0) {
810
	if ((profiles & PROFILE_NO_COMMENTS) != 0) {
788
		dir = new File(dir, "no_comments");
811
		subDirs.add("no_comments");
789
	}
812
	}
790
	String braces = null;
813
	String braces = null;
791
	switch (profiles & PROFILE_BRACES_MASK) {
814
	switch (profiles & PROFILE_BRACES_MASK) {
Lines 800-812 Link Here
800
			break;
823
			break;
801
	}
824
	}
802
	if (braces != null) {
825
	if (braces != null) {
803
		dir = new File(new File(dir, "braces"), braces);
826
		subDirs.add("braces");
827
		subDirs.add(braces);
804
	}
828
	}
805
	if ((profiles & PROFILE_PRESERVED_LINES_MASK) != 0) {
829
	if ((profiles & PROFILE_PRESERVED_LINES_MASK) != 0) {
806
		int lines = (profiles & PROFILE_PRESERVED_LINES_MASK) >> 5;
830
		int lines = (profiles & PROFILE_PRESERVED_LINES_MASK) >> 5;
807
		dir = new File(new File(dir, "preserved_lines"), Integer.toString(lines));
831
		subDirs.add("preserved_lines");
832
		subDirs.add(Integer.toString(lines));
808
	}
833
	}
809
	return dir;
810
}
834
}
811
835
812
private static void appendProfiles(int profiles, StringBuffer buffer) {
836
private static void appendProfiles(int profiles, StringBuffer buffer) {
Lines 1135-1143 Link Here
1135
	}
1159
	}
1136
1160
1137
	// Dump the version
1161
	// Dump the version
1138
	File versionFile = new Path(OUTPUT_DIR.getPath()).append("version.txt").toFile();
1162
	if (CLEAN) {
1139
	OUTPUT_DIR.mkdirs();
1163
		File versionFile = new Path(OUTPUT_DIR.getPath()).append("version.txt").toFile();
1140
	Util.writeToFile(JDT_CORE_VERSION, versionFile.getAbsolutePath());
1164
		OUTPUT_DIR.mkdirs();
1165
		String version = JDT_CORE_VERSION;
1166
		if (TEMP_OUTPUT != null) {
1167
				version += " + " + TEMP_OUTPUT;
1168
			if (PATCH_BUG != null) {
1169
				version += " " + PATCH_VERSION + " of " + PATCH_BUG;
1170
			}
1171
		}
1172
		Util.writeToFile(version, versionFile.getAbsolutePath());
1173
	}
1141
1174
1142
	// Init time measuring
1175
	// Init time measuring
1143
	TIME_MEASURES = new TimeMeasuring();
1176
	TIME_MEASURES = new TimeMeasuring();
(-)workspace/Formatter/test488/A_out.java (-2 / +2 lines)
Lines 4-17 Link Here
4
			case VALUE0 :
4
			case VALUE0 :
5
				doCase0();
5
				doCase0();
6
				break;
6
				break;
7
			case VALUE1 :{
7
			case VALUE1 : {
8
				doCase1();
8
				doCase1();
9
				break;
9
				break;
10
			}
10
			}
11
			case VALUE2 :
11
			case VALUE2 :
12
				doCase2();
12
				doCase2();
13
				break;
13
				break;
14
			default :{
14
			default : {
15
				doDefault();
15
				doDefault();
16
			}
16
			}
17
		}
17
		}

Return to bug 330313