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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-48 / +122 lines)
Lines 422-428 Link Here
422
422
423
		if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) {
423
		if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) {
424
			this.scribe.printComment();
424
			this.scribe.printComment();
425
			Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
425
			Alignment binaryExpressionAlignment = this.scribe.createAlignment(
426
					Alignment.BINARY_EXPRESSION,
427
					this.preferences.alignment_for_binary_expression,
428
					Alignment.R_OUTERMOST,
429
					fragmentsSize,
430
					this.scribe.scanner.currentPosition);
426
			this.scribe.enterAlignment(binaryExpressionAlignment);
431
			this.scribe.enterAlignment(binaryExpressionAlignment);
427
			boolean ok = false;
432
			boolean ok = false;
428
			ASTNode[] fragments = builder.fragments();
433
			ASTNode[] fragments = builder.fragments();
Lines 590-596 Link Here
590
			if (this.preferences.insert_space_after_assignment_operator) {
595
			if (this.preferences.insert_space_after_assignment_operator) {
591
				this.scribe.space();
596
				this.scribe.space();
592
			}
597
			}
593
			Alignment assignmentAlignment = this.scribe.createAlignment("fieldDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_INNERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
598
			Alignment assignmentAlignment = this.scribe.createAlignment(
599
					Alignment.FIELD_DECLARATION_ASSIGNMENT,
600
					this.preferences.alignment_for_assignment,
601
					Alignment.R_INNERMOST,
602
					1,
603
					this.scribe.scanner.currentPosition);
594
			this.scribe.enterAlignment(assignmentAlignment);
604
			this.scribe.enterAlignment(assignmentAlignment);
595
			boolean ok = false;
605
			boolean ok = false;
596
			do {
606
			do {
Lines 672-678 Link Here
672
		final int multipleFieldDeclarationsLength = multiFieldDeclaration.declarations.length;
682
		final int multipleFieldDeclarationsLength = multiFieldDeclaration.declarations.length;
673
683
674
		Alignment multiFieldDeclarationsAlignment =this.scribe.createAlignment(
684
		Alignment multiFieldDeclarationsAlignment =this.scribe.createAlignment(
675
				"multiple_field",//$NON-NLS-1$
685
				Alignment.MULTIPLE_FIELD,
676
				this.preferences.alignment_for_multiple_fields,
686
				this.preferences.alignment_for_multiple_fields,
677
				multipleFieldDeclarationsLength - 1,
687
				multipleFieldDeclarationsLength - 1,
678
				this.scribe.scanner.currentPosition);
688
				this.scribe.scanner.currentPosition);
Lines 956-962 Link Here
956
		final TypeReference superclass = typeDeclaration.superclass;
966
		final TypeReference superclass = typeDeclaration.superclass;
957
		if (superclass != null) {
967
		if (superclass != null) {
958
			Alignment superclassAlignment =this.scribe.createAlignment(
968
			Alignment superclassAlignment =this.scribe.createAlignment(
959
					"superclass", //$NON-NLS-1$
969
					Alignment.SUPER_CLASS,
960
					this.preferences.alignment_for_superclass_in_type_declaration,
970
					this.preferences.alignment_for_superclass_in_type_declaration,
961
					2,
971
					2,
962
					this.scribe.scanner.currentPosition);
972
					this.scribe.scanner.currentPosition);
Lines 994-1000 Link Here
994
			}
1004
			}
995
			int superInterfaceLength = superInterfaces.length;
1005
			int superInterfaceLength = superInterfaces.length;
996
			Alignment interfaceAlignment =this.scribe.createAlignment(
1006
			Alignment interfaceAlignment =this.scribe.createAlignment(
997
					"superInterfaces",//$NON-NLS-1$
1007
					Alignment.SUPER_INTERFACES,
998
					alignment_for_superinterfaces,
1008
					alignment_for_superinterfaces,
999
					superInterfaceLength+1,  // implements token is first fragment
1009
					superInterfaceLength+1,  // implements token is first fragment
1000
					this.scribe.scanner.currentPosition);
1010
					this.scribe.scanner.currentPosition);
Lines 1087-1093 Link Here
1087
				hasConstants = enumConstantsLength != 0;
1097
				hasConstants = enumConstantsLength != 0;
1088
				if (enumConstantsLength > 1) {
1098
				if (enumConstantsLength > 1) {
1089
					Alignment enumConstantsAlignment = this.scribe.createAlignment(
1099
					Alignment enumConstantsAlignment = this.scribe.createAlignment(
1090
							"enumConstants",//$NON-NLS-1$
1100
							Alignment.ENUM_CONSTANTS,
1091
							this.preferences.alignment_for_enum_constants,
1101
							this.preferences.alignment_for_enum_constants,
1092
							enumConstantsLength,
1102
							enumConstantsLength,
1093
							this.scribe.scanner.currentPosition,
1103
							this.scribe.scanner.currentPosition,
Lines 1318-1324 Link Here
1318
				}
1328
				}
1319
				int argumentLength = arguments.length;
1329
				int argumentLength = arguments.length;
1320
				Alignment argumentsAlignment = this.scribe.createAlignment(
1330
				Alignment argumentsAlignment = this.scribe.createAlignment(
1321
						"messageArguments", //$NON-NLS-1$
1331
						Alignment.MESSAGE_ARGUMENTS,
1322
						this.preferences.alignment_for_arguments_in_method_invocation,
1332
						this.preferences.alignment_for_arguments_in_method_invocation,
1323
						Alignment.R_OUTERMOST,
1333
						Alignment.R_OUTERMOST,
1324
						argumentLength,
1334
						argumentLength,
Lines 1353-1369 Link Here
1353
			}
1363
			}
1354
			startingPositionInCascade = 2;
1364
			startingPositionInCascade = 2;
1355
		}
1365
		}
1366
		int tieBreakRule = size-startingPositionInCascade > 2 ? Alignment.R_OUTERMOST : Alignment.R_INNERMOST;
1356
		Alignment cascadingMessageSendAlignment =
1367
		Alignment cascadingMessageSendAlignment =
1357
			this.scribe.createAlignment(
1368
			this.scribe.createAlignment(
1358
				"cascadingMessageSendAlignment", //$NON-NLS-1$
1369
				Alignment.CASCADING_MESSAGE_SEND,
1359
				this.preferences.alignment_for_selector_in_method_invocation,
1370
				this.preferences.alignment_for_selector_in_method_invocation,
1360
				Alignment.R_INNERMOST,
1371
				tieBreakRule,
1361
				size,
1372
				size,
1362
				this.scribe.scanner.currentPosition);
1373
				this.scribe.scanner.currentPosition);
1363
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1374
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1364
		boolean ok = false;
1375
		boolean ok = false;
1365
		boolean setStartingColumn = startingPositionInCascade == 1;
1376
		boolean setStartingColumn = true;
1366
		switch (this.preferences.alignment_for_arguments_in_method_invocation) {
1377
		switch (this.preferences.alignment_for_arguments_in_method_invocation & Alignment.SPLIT_MASK) {
1367
			case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
1378
			case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
1368
			case Alignment.M_NEXT_SHIFTED_SPLIT:
1379
			case Alignment.M_NEXT_SHIFTED_SPLIT:
1369
			case Alignment.M_ONE_PER_LINE_SPLIT:
1380
			case Alignment.M_ONE_PER_LINE_SPLIT:
Lines 1413-1427 Link Here
1413
							this.scribe.space();
1424
							this.scribe.space();
1414
						}
1425
						}
1415
						int argumentLength = arguments.length;
1426
						int argumentLength = arguments.length;
1427
						int alignmentMode = this.preferences.alignment_for_arguments_in_method_invocation;
1416
						Alignment argumentsAlignment = this.scribe.createAlignment(
1428
						Alignment argumentsAlignment = this.scribe.createAlignment(
1417
								"messageArguments", //$NON-NLS-1$
1429
								Alignment.MESSAGE_ARGUMENTS,
1418
								this.preferences.alignment_for_arguments_in_method_invocation,
1430
								alignmentMode,
1419
								Alignment.R_OUTERMOST,
1431
								Alignment.R_OUTERMOST,
1420
								argumentLength,
1432
								argumentLength,
1421
								this.scribe.scanner.currentPosition);
1433
								this.scribe.scanner.currentPosition);
1422
						this.scribe.enterAlignment(argumentsAlignment);
1434
						this.scribe.enterAlignment(argumentsAlignment);
1423
						boolean okForArguments = false;
1435
						boolean okForArguments = false;
1424
						do {
1436
						do {
1437
							switch (alignmentMode & Alignment.SPLIT_MASK) {
1438
								case Alignment.M_COMPACT_SPLIT:
1439
								case Alignment.M_NEXT_PER_LINE_SPLIT:
1440
									argumentsAlignment.startingColumn = this.scribe.column;
1441
									break;
1442
							}
1425
							try {
1443
							try {
1426
								for (int j = 0; j < argumentLength; j++) {
1444
								for (int j = 0; j < argumentLength; j++) {
1427
									if (j > 0) {
1445
									if (j > 0) {
Lines 1429-1438 Link Here
1429
										this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1447
										this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1430
									}
1448
									}
1431
									this.scribe.alignFragment(argumentsAlignment, j);
1449
									this.scribe.alignFragment(argumentsAlignment, j);
1432
									if (j > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1450
									if (j == 0) {
1451
										int fragmentIndentation = argumentsAlignment.fragmentIndentations[j];
1452
										if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
1453
											this.scribe.indentationLevel = fragmentIndentation;
1454
										}	
1455
									} else if (this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1433
										this.scribe.space();
1456
										this.scribe.space();
1434
									}
1457
									}
1435
									arguments[j].traverse(this, scope);
1458
									arguments[j].traverse(this, scope);
1459
									argumentsAlignment.startingColumn = -1;
1436
								}
1460
								}
1437
								okForArguments = true;
1461
								okForArguments = true;
1438
							} catch (AlignmentException e) {
1462
							} catch (AlignmentException e) {
Lines 1468-1474 Link Here
1468
		final int FIELD = 1, METHOD = 2, TYPE = 3;
1492
		final int FIELD = 1, METHOD = 2, TYPE = 3;
1469
		this.scribe.lastNumberOfNewLines = 1;
1493
		this.scribe.lastNumberOfNewLines = 1;
1470
		ASTNode[] mergedNodes = computeMergedMemberDeclarations(nodes);
1494
		ASTNode[] mergedNodes = computeMergedMemberDeclarations(nodes);
1471
		Alignment memberAlignment = this.scribe.createMemberAlignment("typeMembers", this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT, 4, this.scribe.scanner.currentPosition); //$NON-NLS-1$
1495
		Alignment memberAlignment = this.scribe.createMemberAlignment(
1496
				Alignment.TYPE_MEMBERS,
1497
				this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
1498
				4,
1499
				this.scribe.scanner.currentPosition);
1472
		this.scribe.enterMemberAlignment(memberAlignment);
1500
		this.scribe.enterMemberAlignment(memberAlignment);
1473
		boolean isChunkStart = false;
1501
		boolean isChunkStart = false;
1474
		boolean ok = false;
1502
		boolean ok = false;
Lines 1612-1618 Link Here
1612
			if (this.preferences.insert_space_after_assignment_operator) {
1640
			if (this.preferences.insert_space_after_assignment_operator) {
1613
				this.scribe.space();
1641
				this.scribe.space();
1614
			}
1642
			}
1615
			Alignment assignmentAlignment = this.scribe.createAlignment("localDeclarationAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
1643
			Alignment assignmentAlignment = this.scribe.createAlignment(
1644
					Alignment.LOCAL_DECLARATION_ASSIGNMENT,
1645
					this.preferences.alignment_for_assignment,
1646
					Alignment.R_OUTERMOST,
1647
					1,
1648
					this.scribe.scanner.currentPosition);
1616
			this.scribe.enterAlignment(assignmentAlignment);
1649
			this.scribe.enterAlignment(assignmentAlignment);
1617
			boolean ok = false;
1650
			boolean ok = false;
1618
			do {
1651
			do {
Lines 1642-1650 Link Here
1642
		Alignment messageAlignment) {
1675
		Alignment messageAlignment) {
1643
1676
1644
		if (messageAlignment != null) {
1677
		if (messageAlignment != null) {
1645
			this.scribe.alignFragment(messageAlignment, 0);
1678
			if (messageAlignment.canAlign()) {
1679
				this.scribe.alignFragment(messageAlignment, 0);
1680
			}
1646
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1681
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1647
			messageAlignment.startingColumn = -1;
1648
		}
1682
		}
1649
		TypeReference[] typeArguments = messageSend.typeArguments;
1683
		TypeReference[] typeArguments = messageSend.typeArguments;
1650
		if (typeArguments != null) {
1684
		if (typeArguments != null) {
Lines 1678-1691 Link Here
1678
			}
1712
			}
1679
			int argumentsLength = arguments.length;
1713
			int argumentsLength = arguments.length;
1680
			if (argumentsLength > 1) {
1714
			if (argumentsLength > 1) {
1715
				int alignmentMode = this.preferences.alignment_for_arguments_in_method_invocation;
1681
				Alignment argumentsAlignment = this.scribe.createAlignment(
1716
				Alignment argumentsAlignment = this.scribe.createAlignment(
1682
						"messageArguments", //$NON-NLS-1$
1717
						Alignment.MESSAGE_ARGUMENTS,
1683
						this.preferences.alignment_for_arguments_in_method_invocation,
1718
						alignmentMode,
1684
						argumentsLength,
1719
						argumentsLength,
1685
						this.scribe.scanner.currentPosition);
1720
						this.scribe.scanner.currentPosition);
1686
				this.scribe.enterAlignment(argumentsAlignment);
1721
				this.scribe.enterAlignment(argumentsAlignment);
1687
				boolean ok = false;
1722
				boolean ok = false;
1688
				do {
1723
				do {
1724
					switch (alignmentMode & Alignment.SPLIT_MASK) {
1725
						case Alignment.M_COMPACT_SPLIT:
1726
						case Alignment.M_NEXT_PER_LINE_SPLIT:
1727
							argumentsAlignment.startingColumn = this.scribe.column;
1728
							break;
1729
					}
1689
					try {
1730
					try {
1690
						for (int i = 0; i < argumentsLength; i++) {
1731
						for (int i = 0; i < argumentsLength; i++) {
1691
							if (i > 0) {
1732
							if (i > 0) {
Lines 1696-1702 Link Here
1696
							if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1737
							if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1697
								this.scribe.space();
1738
								this.scribe.space();
1698
							}
1739
							}
1740
							int fragmentIndentation = 0;
1741
							if (i == 0) {
1742
								int wrappedIndex = argumentsAlignment.wrappedIndex();
1743
								if (wrappedIndex >= 0) {
1744
									fragmentIndentation = argumentsAlignment.fragmentIndentations[wrappedIndex];
1745
									if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
1746
										this.scribe.indentationLevel = fragmentIndentation;
1747
									}
1748
								}
1749
							}
1699
							arguments[i].traverse(this, scope);
1750
							arguments[i].traverse(this, scope);
1751
							argumentsAlignment.startingColumn = -1;
1700
						}
1752
						}
1701
						ok = true;
1753
						ok = true;
1702
					} catch (AlignmentException e) {
1754
					} catch (AlignmentException e) {
Lines 1705-1720 Link Here
1705
				} while (!ok);
1757
				} while (!ok);
1706
				this.scribe.exitAlignment(argumentsAlignment, true);
1758
				this.scribe.exitAlignment(argumentsAlignment, true);
1707
			} else {
1759
			} else {
1708
				for (int i = 0; i < argumentsLength; i++) {
1760
				arguments[0].traverse(this, scope);
1709
					if (i > 0) {
1710
						this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
1711
						this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1712
					}
1713
					if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
1714
						this.scribe.space();
1715
					}
1716
					arguments[i].traverse(this, scope);
1717
				}
1718
			}
1761
			}
1719
			this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_method_invocation);
1762
			this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_method_invocation);
1720
		} else {
1763
		} else {
Lines 1741-1753 Link Here
1741
			}
1784
			}
1742
			int argumentLength = arguments.length;
1785
			int argumentLength = arguments.length;
1743
			Alignment argumentsAlignment = this.scribe.createAlignment(
1786
			Alignment argumentsAlignment = this.scribe.createAlignment(
1744
					"methodArguments",//$NON-NLS-1$
1787
					Alignment.METHOD_ARGUMENTS,
1745
					methodDeclarationParametersAlignment,
1788
					methodDeclarationParametersAlignment,
1746
					argumentLength,
1789
					argumentLength,
1747
					this.scribe.scanner.currentPosition);
1790
					this.scribe.scanner.currentPosition);
1748
			this.scribe.enterAlignment(argumentsAlignment);
1791
			this.scribe.enterAlignment(argumentsAlignment);
1749
			boolean ok = false;
1792
			boolean ok = false;
1750
			do {
1793
			do {
1794
				switch (methodDeclarationParametersAlignment & Alignment.SPLIT_MASK) {
1795
					case Alignment.M_COMPACT_SPLIT:
1796
					case Alignment.M_NEXT_PER_LINE_SPLIT:
1797
						argumentsAlignment.startingColumn = this.scribe.column;
1798
						break;
1799
				}
1751
				try {
1800
				try {
1752
					for (int i = 0; i < argumentLength; i++) {
1801
					for (int i = 0; i < argumentLength; i++) {
1753
						if (i > 0) {
1802
						if (i > 0) {
Lines 1755-1764 Link Here
1755
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1804
							this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
1756
						}
1805
						}
1757
						this.scribe.alignFragment(argumentsAlignment, i);
1806
						this.scribe.alignFragment(argumentsAlignment, i);
1758
						if (i > 0 && spaceAfterComma) {
1807
						if (i == 0) {
1808
							int fragmentIndentation = argumentsAlignment.fragmentIndentations[0];
1809
							if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
1810
								this.scribe.indentationLevel = fragmentIndentation;
1811
							}
1812
						} else if (spaceAfterComma) {
1759
							this.scribe.space();
1813
							this.scribe.space();
1760
						}
1814
						}
1761
						arguments[i].traverse(this, methodDeclaration.scope);
1815
						arguments[i].traverse(this, methodDeclaration.scope);
1816
						argumentsAlignment.startingColumn = -1;
1762
					}
1817
					}
1763
					ok = true;
1818
					ok = true;
1764
				} catch (AlignmentException e) {
1819
				} catch (AlignmentException e) {
Lines 1792-1798 Link Here
1792
		if (arguments != null) {
1847
		if (arguments != null) {
1793
			int argumentLength = arguments.length;
1848
			int argumentLength = arguments.length;
1794
			Alignment argumentsAlignment = this.scribe.createAlignment(
1849
			Alignment argumentsAlignment = this.scribe.createAlignment(
1795
					"enumConstantArguments",//$NON-NLS-1$
1850
					Alignment.ENUM_CONSTANTS_ARGUMENTS,
1796
					methodDeclarationParametersAlignment,
1851
					methodDeclarationParametersAlignment,
1797
					argumentLength,
1852
					argumentLength,
1798
					this.scribe.scanner.currentPosition);
1853
					this.scribe.scanner.currentPosition);
Lines 1930-1936 Link Here
1930
		if (thrownExceptions != null) {
1985
		if (thrownExceptions != null) {
1931
			int thrownExceptionsLength = thrownExceptions.length;
1986
			int thrownExceptionsLength = thrownExceptions.length;
1932
			Alignment throwsAlignment = this.scribe.createAlignment(
1987
			Alignment throwsAlignment = this.scribe.createAlignment(
1933
					"throws",//$NON-NLS-1$
1988
					Alignment.THROWS,
1934
					alignmentForThrowsClause,
1989
					alignmentForThrowsClause,
1935
					thrownExceptionsLength, // throws is the first token
1990
					thrownExceptionsLength, // throws is the first token
1936
					this.scribe.scanner.currentPosition);
1991
					this.scribe.scanner.currentPosition);
Lines 1968-1974 Link Here
1968
	 * Merged traversal of member (types, fields, methods)
2023
	 * Merged traversal of member (types, fields, methods)
1969
	 */
2024
	 */
1970
	private void formatTypeMembers(TypeDeclaration typeDeclaration) {
2025
	private void formatTypeMembers(TypeDeclaration typeDeclaration) {
1971
		Alignment memberAlignment = this.scribe.createMemberAlignment("typeMembers", this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT, 3, this.scribe.scanner.currentPosition); //$NON-NLS-1$
2026
		Alignment memberAlignment = this.scribe.createMemberAlignment(
2027
				Alignment.TYPE_MEMBERS,
2028
				this.preferences.align_type_members_on_columns ? Alignment.M_MULTICOLUMN : Alignment.M_NO_ALIGNMENT,
2029
				3,
2030
				this.scribe.scanner.currentPosition);
1972
		this.scribe.enterMemberAlignment(memberAlignment);
2031
		this.scribe.enterMemberAlignment(memberAlignment);
1973
		ASTNode[] members = computeMergedMemberDeclarations(typeDeclaration);
2032
		ASTNode[] members = computeMergedMemberDeclarations(typeDeclaration);
1974
		boolean isChunkStart = false;
2033
		boolean isChunkStart = false;
Lines 2329-2335 Link Here
2329
			}
2388
			}
2330
			int argumentLength = arguments.length;
2389
			int argumentLength = arguments.length;
2331
			Alignment argumentsAlignment =this.scribe.createAlignment(
2390
			Alignment argumentsAlignment =this.scribe.createAlignment(
2332
					"allocation",//$NON-NLS-1$
2391
					Alignment.ALLOCATION,
2333
					this.preferences.alignment_for_arguments_in_allocation_expression,
2392
					this.preferences.alignment_for_arguments_in_allocation_expression,
2334
					argumentLength,
2393
					argumentLength,
2335
					this.scribe.scanner.currentPosition);
2394
					this.scribe.scanner.currentPosition);
Lines 2530-2536 Link Here
2530
					this.scribe.printNewLine();
2589
					this.scribe.printNewLine();
2531
				}
2590
				}
2532
				Alignment arrayInitializerAlignment =this.scribe.createAlignment(
2591
				Alignment arrayInitializerAlignment =this.scribe.createAlignment(
2533
						"array_initializer",//$NON-NLS-1$
2592
						Alignment.ARRAY_INITIALIZER,
2534
						this.preferences.alignment_for_expressions_in_array_initializer,
2593
						this.preferences.alignment_for_expressions_in_array_initializer,
2535
						Alignment.R_OUTERMOST,
2594
						Alignment.R_OUTERMOST,
2536
						expressionsLength,
2595
						expressionsLength,
Lines 2803-2809 Link Here
2803
			this.scribe.space();
2862
			this.scribe.space();
2804
		}
2863
		}
2805
2864
2806
		Alignment assignmentAlignment = this.scribe.createAlignment("assignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
2865
		Alignment assignmentAlignment = this.scribe.createAlignment(
2866
				Alignment.ASSIGNMENT,
2867
				this.preferences.alignment_for_assignment,
2868
				Alignment.R_OUTERMOST,
2869
				1,
2870
				this.scribe.scanner.currentPosition);
2807
		this.scribe.enterAlignment(assignmentAlignment);
2871
		this.scribe.enterAlignment(assignmentAlignment);
2808
		boolean ok = false;
2872
		boolean ok = false;
2809
		do {
2873
		do {
Lines 3128-3134 Link Here
3128
		if (this.preferences.insert_space_after_assignment_operator) {
3192
		if (this.preferences.insert_space_after_assignment_operator) {
3129
			this.scribe.space();
3193
			this.scribe.space();
3130
		}
3194
		}
3131
		Alignment assignmentAlignment = this.scribe.createAlignment("compoundAssignmentAlignment", this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); //$NON-NLS-1$
3195
		Alignment assignmentAlignment = this.scribe.createAlignment(
3196
				Alignment.COMPOUND_ASSIGNMENT,
3197
				this.preferences.alignment_for_assignment,
3198
				Alignment.R_OUTERMOST,
3199
				1,
3200
				this.scribe.scanner.currentPosition);
3132
		this.scribe.enterAlignment(assignmentAlignment);
3201
		this.scribe.enterAlignment(assignmentAlignment);
3133
		boolean ok = false;
3202
		boolean ok = false;
3134
		do {
3203
		do {
Lines 3162-3168 Link Here
3162
    	conditionalExpression.condition.traverse(this, scope);
3231
    	conditionalExpression.condition.traverse(this, scope);
3163
3232
3164
    	Alignment conditionalExpressionAlignment =this.scribe.createAlignment(
3233
    	Alignment conditionalExpressionAlignment =this.scribe.createAlignment(
3165
    			"conditionalExpression", //$NON-NLS-1$
3234
    			Alignment.CONDITIONAL_EXPRESSION,
3166
    			this.preferences.alignment_for_conditional_expression,
3235
    			this.preferences.alignment_for_conditional_expression,
3167
    			2,
3236
    			2,
3168
    			this.scribe.scanner.currentPosition);
3237
    			this.scribe.scanner.currentPosition);
Lines 3567-3573 Link Here
3567
			}
3636
			}
3568
			int argumentLength = arguments.length;
3637
			int argumentLength = arguments.length;
3569
			Alignment argumentsAlignment =this.scribe.createAlignment(
3638
			Alignment argumentsAlignment =this.scribe.createAlignment(
3570
					"explicit_constructor_call",//$NON-NLS-1$
3639
					Alignment.EXPLICIT_CONSTRUCTOR_CALL,
3571
					this.preferences.alignment_for_arguments_in_explicit_constructor_call,
3640
					this.preferences.alignment_for_arguments_in_explicit_constructor_call,
3572
					argumentLength,
3641
					argumentLength,
3573
					this.scribe.scanner.currentPosition);
3642
					this.scribe.scanner.currentPosition);
Lines 3826-3832 Link Here
3826
				}
3895
				}
3827
			} else if (elseStatement == null && this.preferences.keep_simple_if_on_one_line) {
3896
			} else if (elseStatement == null && this.preferences.keep_simple_if_on_one_line) {
3828
				Alignment compactIfAlignment = this.scribe.createAlignment(
3897
				Alignment compactIfAlignment = this.scribe.createAlignment(
3829
						"compactIf", //$NON-NLS-1$
3898
						Alignment.COMPACT_IF,
3830
						this.preferences.alignment_for_compact_if,
3899
						this.preferences.alignment_for_compact_if,
3831
						Alignment.R_OUTERMOST,
3900
						Alignment.R_OUTERMOST,
3832
						1,
3901
						1,
Lines 4064-4077 Link Here
4064
				messageSend.receiver.traverse(this, scope);
4133
				messageSend.receiver.traverse(this, scope);
4065
				int alignmentMode = this.preferences.alignment_for_selector_in_method_invocation;
4134
				int alignmentMode = this.preferences.alignment_for_selector_in_method_invocation;
4066
				messageAlignment = this.scribe.createAlignment(
4135
				messageAlignment = this.scribe.createAlignment(
4067
						"messageAlignment", //$NON-NLS-1$
4136
						Alignment.MESSAGE_SEND,
4068
						alignmentMode,
4137
						alignmentMode,
4069
						1,
4138
						1,
4070
						this.scribe.scanner.currentPosition);
4139
						this.scribe.scanner.currentPosition);
4071
				this.scribe.enterAlignment(messageAlignment);
4140
				this.scribe.enterAlignment(messageAlignment);
4072
				boolean ok = false;
4141
				boolean ok = false;
4073
				do {
4142
				do {
4074
					switch (alignmentMode) {
4143
					switch (alignmentMode & Alignment.SPLIT_MASK) {
4075
						case Alignment.M_COMPACT_SPLIT:
4144
						case Alignment.M_COMPACT_SPLIT:
4076
						case Alignment.M_NEXT_PER_LINE_SPLIT:
4145
						case Alignment.M_NEXT_PER_LINE_SPLIT:
4077
							messageAlignment.startingColumn = this.scribe.column;
4146
							messageAlignment.startingColumn = this.scribe.column;
Lines 4134-4140 Link Here
4134
4203
4135
		// Create alignment
4204
		// Create alignment
4136
		Alignment methodDeclAlignment = this.scribe.createAlignment(
4205
		Alignment methodDeclAlignment = this.scribe.createAlignment(
4137
				"methodDeclaration",//$NON-NLS-1$
4206
				Alignment.METHOD_DECLARATION,
4138
				this.preferences.alignment_for_method_declaration,
4207
				this.preferences.alignment_for_method_declaration,
4139
				Alignment.R_INNERMOST,
4208
				Alignment.R_INNERMOST,
4140
				3,
4209
				3,
Lines 4289-4295 Link Here
4289
		if (memberValuePairs != null) {
4358
		if (memberValuePairs != null) {
4290
			int length = memberValuePairs.length;
4359
			int length = memberValuePairs.length;
4291
			Alignment annotationAlignment = this.scribe.createAlignment(
4360
			Alignment annotationAlignment = this.scribe.createAlignment(
4292
					"annotationMemberValuePairs",//$NON-NLS-1$
4361
					Alignment.ANNOTATION_MEMBERS_VALUE_PAIRS,
4293
					this.preferences.alignment_for_arguments_in_annotation,
4362
					this.preferences.alignment_for_arguments_in_annotation,
4294
					length,
4363
					length,
4295
					this.scribe.scanner.currentPosition);
4364
					this.scribe.scanner.currentPosition);
Lines 4637-4643 Link Here
4637
			}
4706
			}
4638
			int argumentLength = arguments.length;
4707
			int argumentLength = arguments.length;
4639
			Alignment argumentsAlignment =this.scribe.createAlignment(
4708
			Alignment argumentsAlignment =this.scribe.createAlignment(
4640
					"allocation",//$NON-NLS-1$
4709
					Alignment.ALLOCATION,
4641
					this.preferences.alignment_for_arguments_in_qualified_allocation_expression,
4710
					this.preferences.alignment_for_arguments_in_qualified_allocation_expression,
4642
					argumentLength,
4711
					argumentLength,
4643
					this.scribe.scanner.currentPosition);
4712
					this.scribe.scanner.currentPosition);
Lines 4896-4902 Link Here
4896
		this.scribe.printComment();
4965
		this.scribe.printComment();
4897
		ASTNode[] fragments = stringLiteral.literals;
4966
		ASTNode[] fragments = stringLiteral.literals;
4898
		int fragmentsSize = stringLiteral.counter;
4967
		int fragmentsSize = stringLiteral.counter;
4899
		Alignment binaryExpressionAlignment = this.scribe.createAlignment("binaryExpressionAlignment", this.preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, fragmentsSize, this.scribe.scanner.currentPosition); //$NON-NLS-1$
4968
		Alignment binaryExpressionAlignment = this.scribe.createAlignment(
4969
				Alignment.BINARY_EXPRESSION,
4970
				this.preferences.alignment_for_binary_expression,
4971
				Alignment.R_OUTERMOST,
4972
				fragmentsSize,
4973
				this.scribe.scanner.currentPosition);
4900
		this.scribe.enterAlignment(binaryExpressionAlignment);
4974
		this.scribe.enterAlignment(binaryExpressionAlignment);
4901
		boolean ok = false;
4975
		boolean ok = false;
4902
		do {
4976
		do {
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-27 / +62 lines)
Lines 595-618 Link Here
595
	    return INVALID_TOKEN;
595
	    return INVALID_TOKEN;
596
    }
596
    }
597
597
598
	public Alignment createAlignment(String name, int mode, int count, int sourceRestart){
598
	public Alignment createAlignment(int kind, int mode, int count, int sourceRestart){
599
		return createAlignment(name, mode, Alignment.R_INNERMOST, count, sourceRestart);
599
		return createAlignment(kind, mode, Alignment.R_INNERMOST, count, sourceRestart);
600
	}
600
	}
601
601
602
	public Alignment createAlignment(String name, int mode, int count, int sourceRestart, boolean adjust){
602
	public Alignment createAlignment(int kind, int mode, int count, int sourceRestart, boolean adjust){
603
		return createAlignment(name, mode, Alignment.R_INNERMOST, count, sourceRestart, adjust);
603
		return createAlignment(kind, mode, Alignment.R_INNERMOST, count, sourceRestart, adjust);
604
	}
604
	}
605
605
606
	public Alignment createAlignment(String name, int mode, int tieBreakRule, int count, int sourceRestart){
606
	public Alignment createAlignment(int kind, int mode, int tieBreakRule, int count, int sourceRestart){
607
		return createAlignment(name, mode, tieBreakRule, count, sourceRestart, this.formatter.preferences.continuation_indentation, false);
607
		return createAlignment(kind, mode, tieBreakRule, count, sourceRestart, this.formatter.preferences.continuation_indentation, false);
608
	}
608
	}
609
609
610
	public Alignment createAlignment(String name, int mode, int count, int sourceRestart, int continuationIndent, boolean adjust){
610
	public Alignment createAlignment(int kind, int mode, int count, int sourceRestart, int continuationIndent, boolean adjust){
611
		return createAlignment(name, mode, Alignment.R_INNERMOST, count, sourceRestart, continuationIndent, adjust);
611
		return createAlignment(kind, mode, Alignment.R_INNERMOST, count, sourceRestart, continuationIndent, adjust);
612
	}
612
	}
613
613
614
	public Alignment createAlignment(String name, int mode, int tieBreakRule, int count, int sourceRestart, int continuationIndent, boolean adjust){
614
	public Alignment createAlignment(int kind, int mode, int tieBreakRule, int count, int sourceRestart, int continuationIndent, boolean adjust){
615
		Alignment alignment = new Alignment(name, mode, tieBreakRule, this, count, sourceRestart, continuationIndent);
615
		Alignment alignment = new Alignment(kind, mode, tieBreakRule, this, count, sourceRestart, continuationIndent);
616
		// adjust break indentation
616
		// adjust break indentation
617
		if (adjust && this.memberAlignment != null) {
617
		if (adjust && this.memberAlignment != null) {
618
			Alignment current = this.memberAlignment;
618
			Alignment current = this.memberAlignment;
Lines 674-681 Link Here
674
		return alignment;
674
		return alignment;
675
	}
675
	}
676
676
677
	public Alignment createMemberAlignment(String name, int mode, int count, int sourceRestart) {
677
	public Alignment createMemberAlignment(int kind, int mode, int count, int sourceRestart) {
678
		Alignment mAlignment = createAlignment(name, mode, Alignment.R_INNERMOST, count, sourceRestart);
678
		Alignment mAlignment = createAlignment(kind, mode, Alignment.R_INNERMOST, count, sourceRestart);
679
		mAlignment.breakIndentationLevel = this.indentationLevel;
679
		mAlignment.breakIndentationLevel = this.indentationLevel;
680
		return mAlignment;
680
		return mAlignment;
681
	}
681
	}
Lines 724-736 Link Here
724
		this.memberAlignment = current.enclosing;
724
		this.memberAlignment = current.enclosing;
725
	}
725
	}
726
726
727
	public Alignment getAlignment(String name){
728
		if (this.currentAlignment != null) {
729
			return this.currentAlignment.getAlignment(name);
730
		}
731
		return null;
732
	}
733
734
	/**
727
	/**
735
	 * Answer actual indentation level based on true column position
728
	 * Answer actual indentation level based on true column position
736
	 * @return int
729
	 * @return int
Lines 1105-1115 Link Here
1105
						// skip
1098
						// skip
1106
					}
1099
					}
1107
					this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
1100
					this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
1108
					boolean canUseAlignmentIndentation = (nextToken != TerminalTokens.TokenNameLBRACE || !this.currentAlignment.name.equals("localDeclarationAssignmentAlignment")); //$NON-NLS-1$
1101
					boolean canUseAlignmentIndentation = (nextToken != TerminalTokens.TokenNameLBRACE || this.currentAlignment.kind != Alignment.LOCAL_DECLARATION_ASSIGNMENT);
1109
					if (canUseAlignmentIndentation &&
1102
					if (canUseAlignmentIndentation &&
1110
							(!this.formatBrace ||
1103
							(!this.formatBrace ||
1111
									this.currentAlignment.name.equals("array_initializer") || //$NON-NLS-1$
1104
									this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER ||
1112
									this.currentAlignment.name.equals("binaryExpressionAlignment")) && //$NON-NLS-1$
1105
									this.currentAlignment.kind == Alignment.BINARY_EXPRESSION) &&
1113
							this.indentationLevel < this.currentAlignment.breakIndentationLevel) {
1106
							this.indentationLevel < this.currentAlignment.breakIndentationLevel) {
1114
						this.indentationLevel = this.currentAlignment.breakIndentationLevel;
1107
						this.indentationLevel = this.currentAlignment.breakIndentationLevel;
1115
					}
1108
					}
Lines 1219-1228 Link Here
1219
		// look for outermost breakable one
1212
		// look for outermost breakable one
1220
		int relativeDepth = 0, outerMostDepth = -1;
1213
		int relativeDepth = 0, outerMostDepth = -1;
1221
		Alignment targetAlignment = this.currentAlignment;
1214
		Alignment targetAlignment = this.currentAlignment;
1215
		int previousKind = -1;
1216
		boolean insideMessageArguments = false;
1217
		boolean insideMessageSend = false;
1222
		while (targetAlignment != null){
1218
		while (targetAlignment != null){
1223
			if (targetAlignment.tieBreakRule == Alignment.R_OUTERMOST && targetAlignment.couldBreak()){
1219
			boolean couldBreak = targetAlignment.tieBreakRule == Alignment.R_OUTERMOST ||
1220
				((insideMessageArguments || insideMessageSend) && targetAlignment.kind == Alignment.MESSAGE_ARGUMENTS
1221
						&& (!targetAlignment.wasReset() || previousKind != Alignment.MESSAGE_SEND));
1222
			if (couldBreak && targetAlignment.couldBreak()){
1224
				outerMostDepth = relativeDepth;
1223
				outerMostDepth = relativeDepth;
1225
			}
1224
			}
1225
			switch (targetAlignment.kind) {
1226
				case Alignment.MESSAGE_ARGUMENTS:
1227
					insideMessageArguments = true;
1228
					break;
1229
				case Alignment.MESSAGE_SEND:
1230
					insideMessageSend = true;
1231
					break;
1232
			}
1233
			previousKind = targetAlignment.kind;
1226
			targetAlignment = targetAlignment.enclosing;
1234
			targetAlignment = targetAlignment.enclosing;
1227
			relativeDepth++;
1235
			relativeDepth++;
1228
		}
1236
		}
Lines 1232-1245 Link Here
1232
		// look for innermost breakable one
1240
		// look for innermost breakable one
1233
		relativeDepth = 0;
1241
		relativeDepth = 0;
1234
		targetAlignment = this.currentAlignment;
1242
		targetAlignment = this.currentAlignment;
1235
		while (targetAlignment != null){
1243
		AlignmentException alignmentException = null;
1236
			if (targetAlignment.couldBreak()){
1244
		int msgArgsDepth = -1;
1237
				throw new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
1245
		while (targetAlignment != null) {
1246
			if (targetAlignment.kind == Alignment.MESSAGE_ARGUMENTS) {
1247
				msgArgsDepth = relativeDepth;
1248
			}
1249
			if (alignmentException == null) {
1250
				if (targetAlignment.couldBreak()) {
1251
					// do not throw the exception immediately to have a chance to reset
1252
					// previously broken alignments (see bug 203588)
1253
					alignmentException = new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
1254
				}
1255
			} else if (targetAlignment.wasSplit) {
1256
				// reset the nearest already broken outermost alignment.
1257
				// Note that it's not done twice to avoid infinite loop while raising
1258
				// the exception on an innermost alignment...
1259
				if (!targetAlignment.wasReset()) {
1260
					targetAlignment.reset();
1261
					if (msgArgsDepth > alignmentException.relativeDepth) {
1262
						alignmentException.relativeDepth = msgArgsDepth;
1263
					}
1264
					throw alignmentException;
1265
				}
1238
			}
1266
			}
1239
			targetAlignment = targetAlignment.enclosing;
1267
			targetAlignment = targetAlignment.enclosing;
1240
			relativeDepth++;
1268
			relativeDepth++;
1241
		}
1269
		}
1270
		if (alignmentException != null) {
1271
			throw alignmentException;
1272
		}
1242
		// did not find any breakable location - proceed
1273
		// did not find any breakable location - proceed
1274
		if (this.currentAlignment != null) {
1275
			this.currentAlignment.blockAlign = false;
1276
			this.currentAlignment.tooLong = true;
1277
		}
1243
	}
1278
	}
1244
1279
1245
	/*
1280
	/*
Lines 2560-2566 Link Here
2560
			   			commentIndentationLevel = this.column - 1;
2595
			   			commentIndentationLevel = this.column - 1;
2561
					}
2596
					}
2562
				} else {
2597
				} else {
2563
					if (this.currentAlignment != null && this.currentAlignment.name.equals("array_initializer") && //$NON-NLS-1$
2598
					if (this.currentAlignment != null && this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER &&
2564
						this.indentationLevel < this.currentAlignment.breakIndentationLevel &&
2599
						this.indentationLevel < this.currentAlignment.breakIndentationLevel &&
2565
						this.lastLineComment.lines > 0)
2600
						this.lastLineComment.lines > 0)
2566
					{
2601
					{
(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (-17 / +138 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter.align;
11
package org.eclipse.jdt.internal.formatter.align;
12
12
13
import org.eclipse.core.runtime.Assert;
13
import org.eclipse.jdt.internal.formatter.Location;
14
import org.eclipse.jdt.internal.formatter.Location;
14
import org.eclipse.jdt.internal.formatter.Scribe;
15
import org.eclipse.jdt.internal.formatter.Scribe;
15
16
Lines 20-27 Link Here
20
 */
21
 */
21
public class Alignment {
22
public class Alignment {
22
23
24
	// Kind of alignment
25
	public int kind;
26
	public static final int ALLOCATION = 1;
27
	public static final int ANNOTATION_MEMBERS_VALUE_PAIRS = 2;
28
	public static final int ARRAY_INITIALIZER = 3;
29
	public static final int ASSIGNMENT = 4;
30
	public static final int BINARY_EXPRESSION = 5;
31
	public static final int CASCADING_MESSAGE_SEND = 6;
32
	public static final int COMPACT_IF = 7;
33
	public static final int COMPOUND_ASSIGNMENT = 8;
34
	public static final int CONDITIONAL_EXPRESSION = 9;
35
	public static final int ENUM_CONSTANTS = 10;
36
	public static final int ENUM_CONSTANTS_ARGUMENTS = 11;
37
	public static final int EXPLICIT_CONSTRUCTOR_CALL = 12;
38
	public static final int FIELD_DECLARATION_ASSIGNMENT = 13;
39
	public static final int LOCAL_DECLARATION_ASSIGNMENT = 14;
40
	public static final int MESSAGE_ARGUMENTS = 15;
41
	public static final int MESSAGE_SEND = 16;
42
	public static final int METHOD_ARGUMENTS = 17;
43
	public static final int METHOD_DECLARATION = 18;
44
	public static final int MULTIPLE_FIELD = 19;
45
	public static final int SUPER_CLASS = 20;
46
	public static final int SUPER_INTERFACES = 21;
47
	public static final int THROWS = 22;
48
	public static final int TYPE_MEMBERS = 23;
49
23
	// name of alignment
50
	// name of alignment
24
	public String name;
51
	public String name;
52
	public static final String[] NAMES = {
53
		"", //$NON-NLS-1$
54
		"allocation", //$NON-NLS-1$
55
		"annotationMemberValuePairs", //$NON-NLS-1$
56
		"array_initializer", //$NON-NLS-1$
57
		"assignmentAlignment", //$NON-NLS-1$
58
		"binaryExpressionAlignment", //$NON-NLS-1$
59
		"cascadingMessageSendAlignment", //$NON-NLS-1$
60
		"compactIf", //$NON-NLS-1$
61
		"compoundAssignmentAlignment", //$NON-NLS-1$
62
		"conditionalExpression", //$NON-NLS-1$
63
		"enumConstants", //$NON-NLS-1$
64
		"enumConstantArguments", //$NON-NLS-1$
65
		"explicit_constructor_call", //$NON-NLS-1$
66
		"fieldDeclarationAssignmentAlignment", //$NON-NLS-1$
67
		"localDeclarationAssignmentAlignment", //$NON-NLS-1$
68
		"messageArguments", //$NON-NLS-1$
69
		"messageAlignment", //$NON-NLS-1$
70
		"methodArguments", //$NON-NLS-1$
71
		"methodDeclaration", //$NON-NLS-1$
72
		"multiple_field", //$NON-NLS-1$
73
		"superclass", //$NON-NLS-1$
74
		"superInterfaces", //$NON-NLS-1$
75
		"throws", //$NON-NLS-1$
76
		"typeMembers", //$NON-NLS-1$
77
	};
25
78
26
	// link to enclosing alignment
79
	// link to enclosing alignment
27
	public Alignment enclosing;
80
	public Alignment enclosing;
Lines 45-53 Link Here
45
	public int shiftBreakIndentationLevel;
98
	public int shiftBreakIndentationLevel;
46
	public int[] fragmentBreaks;
99
	public int[] fragmentBreaks;
47
	public boolean wasSplit;
100
	public boolean wasSplit;
101
	public boolean blockAlign = false;
102
	public boolean tooLong = false;
48
103
49
	public Scribe scribe;
104
	public Scribe scribe;
50
105
106
	// reset
107
	private boolean reset = false;
108
51
	/*
109
	/*
52
	 * Alignment modes
110
	 * Alignment modes
53
	 */
111
	 */
Lines 133-141 Link Here
133
	public static final int CHUNK_ENUM = 4;
191
	public static final int CHUNK_ENUM = 4;
134
192
135
	// location to align and break on.
193
	// location to align and break on.
136
	public Alignment(String name, int mode, int tieBreakRule, Scribe scribe, int fragmentCount, int sourceRestart, int continuationIndent){
194
	public Alignment(int kind, int mode, int tieBreakRule, Scribe scribe, int fragmentCount, int sourceRestart, int continuationIndent){
137
195
138
		this.name = name;
196
		Assert.isTrue(kind >=ALLOCATION && kind <=TYPE_MEMBERS);
197
		this.kind = kind;
198
		this.name = NAMES[kind];
139
		this.location = new Location(scribe, sourceRestart);
199
		this.location = new Location(scribe, sourceRestart);
140
		this.mode = mode;
200
		this.mode = mode;
141
		this.tieBreakRule = tieBreakRule;
201
		this.tieBreakRule = tieBreakRule;
Lines 174-182 Link Here
174
		}
234
		}
175
	}
235
	}
176
236
177
	public boolean checkChunkStart(int kind, int startIndex, int sourceRestart) {
237
	public boolean checkChunkStart(int chunk, int startIndex, int sourceRestart) {
178
		if (this.chunkKind != kind) {
238
		if (this.chunkKind != chunk) {
179
			this.chunkKind = kind;
239
			this.chunkKind = chunk;
180
240
181
			// when redoing same chunk alignment, must not reset
241
			// when redoing same chunk alignment, must not reset
182
			if (startIndex != this.chunkStartIndex) {
242
			if (startIndex != this.chunkStartIndex) {
Lines 232-237 Link Here
232
		}
292
		}
233
		return depth;
293
		return depth;
234
	}
294
	}
295
	
296
	/**
297
	 * Returns whether the alignment can be aligned or not.
298
	 * Only used for message send alignment, it currently blocks its alignment
299
	 * when it's at the first nesting level of a message send. It allow to save
300
	 * space on the argument broken line by reducing the number of indentations.
301
	 */
302
	public boolean canAlign() {
303
		if (this.tooLong) {
304
			return true;
305
		}
306
		boolean canAlign = true;
307
		Alignment enclosingAlignment = this.enclosing;
308
		while (enclosingAlignment != null) {
309
			switch (enclosingAlignment.kind) {
310
				case Alignment.ALLOCATION:
311
				case Alignment.MESSAGE_ARGUMENTS:
312
					// message send inside arguments, avoid to align
313
					if (enclosingAlignment.isWrapped() && 
314
							(enclosingAlignment.fragmentIndex > 0 || enclosingAlignment.fragmentCount < 2)) {
315
						return !this.blockAlign;
316
					}
317
					if (enclosingAlignment.tooLong) {
318
						return true;
319
					}
320
					canAlign = false;
321
					break;
322
				case Alignment.MESSAGE_SEND:
323
					// multiple depth of message send, hence allow current to align
324
					switch (this.kind) {
325
						case Alignment.ALLOCATION:
326
						case Alignment.MESSAGE_ARGUMENTS:
327
						case Alignment.MESSAGE_SEND:
328
							Alignment superEnclosingAlignment = enclosingAlignment.enclosing;
329
							while (superEnclosingAlignment != null) {
330
								switch (superEnclosingAlignment.kind) {
331
									case Alignment.ALLOCATION:
332
									case Alignment.MESSAGE_ARGUMENTS:
333
									case Alignment.MESSAGE_SEND:
334
										// block the alignment of the intermediate message send
335
										if (this.scribe.nlsTagCounter == 0) {
336
											enclosingAlignment.blockAlign = true;
337
										}
338
										return !this.blockAlign;
339
								}
340
								superEnclosingAlignment = superEnclosingAlignment.enclosing;
341
							}
342
							break;
343
					}
344
					return !this.blockAlign;
345
			}
346
			enclosingAlignment = enclosingAlignment.enclosing;
347
		}
348
		return canAlign && !this.blockAlign;
349
	}
235
350
236
	public boolean couldBreak(){
351
	public boolean couldBreak(){
237
		int i;
352
		int i;
Lines 329-340 Link Here
329
		return false; // cannot split better
444
		return false; // cannot split better
330
	}
445
	}
331
446
332
	public Alignment getAlignment(String targetName) {
447
	public boolean isWrapped() {
333
448
		return this.fragmentBreaks[this.fragmentIndex] == BREAK;
334
		if (targetName.equals(this.name)) return this;
449
	}
335
		if (this.enclosing == null) return null;
336
450
337
		return this.enclosing.getAlignment(targetName);
451
	public int wrappedIndex() {
452
		for (int i = 0, max = this.fragmentCount; i < max; i++) {
453
			if (this.fragmentBreaks[i] == BREAK) {
454
				return i;
455
			}
456
		}
457
		return -1;
338
	}
458
	}
339
459
340
	// perform alignment effect for current fragment
460
	// perform alignment effect for current fragment
Lines 366-371 Link Here
366
	// reset fragment indentation/break status
486
	// reset fragment indentation/break status
367
	public void reset() {
487
	public void reset() {
368
488
489
		this.wasSplit = false;
369
		if (this.fragmentCount > 0){
490
		if (this.fragmentCount > 0){
370
			this.fragmentIndentations = new int[this.fragmentCount];
491
			this.fragmentIndentations = new int[this.fragmentCount];
371
			this.fragmentBreaks = new int[this.fragmentCount];
492
			this.fragmentBreaks = new int[this.fragmentCount];
Lines 375-380 Link Here
375
		if ((this.mode & M_FORCE) != 0) {
496
		if ((this.mode & M_FORCE) != 0) {
376
			couldBreak();
497
			couldBreak();
377
		}
498
		}
499
		this.reset = true;
378
	}
500
	}
379
501
380
	public void toFragmentsString(StringBuffer buffer){
502
	public void toFragmentsString(StringBuffer buffer){
Lines 397-402 Link Here
397
		// First line is for class and name
519
		// First line is for class and name
398
		buffer.append(indentation);
520
		buffer.append(indentation);
399
		buffer
521
		buffer
522
			.append("<kind: ")	//$NON-NLS-1$
523
			.append(this.kind)
524
			.append("> ");	//$NON-NLS-1$
525
		buffer
400
			.append("<name: ")	//$NON-NLS-1$
526
			.append("<name: ")	//$NON-NLS-1$
401
			.append(this.name)
527
			.append(this.name)
402
			.append(">\n");	//$NON-NLS-1$
528
			.append(">\n");	//$NON-NLS-1$
Lines 463-474 Link Here
463
		}
589
		}
464
	}
590
	}
465
591
466
	public boolean isWrapped() {
592
	public boolean wasReset() {
467
		for (int i = 0, max = this.fragmentCount; i < max; i++) {
593
		return this.reset;
468
			if (this.fragmentBreaks[i] == BREAK) {
469
				return true;
470
			}
471
		}
472
		return false;
473
	}
594
	}
474
}
595
}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (-34 / +593 lines)
Lines 14-19 Link Here
14
14
15
import junit.framework.Test;
15
import junit.framework.Test;
16
16
17
import org.eclipse.jdt.core.JavaCore;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.formatter.CodeFormatter;
19
import org.eclipse.jdt.core.formatter.CodeFormatter;
19
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
20
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
Lines 634-639 Link Here
634
}
635
}
635
636
636
/**
637
/**
638
 * @bug 59891: [formatter] the code formatter doesn't respect my new lines
639
 * @test Ensure that the formatter keep line breaks wrapping set by users in the code
640
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=59891"
641
 */
642
//static { TESTS_PREFIX = "testBug059891"; }
643
public void testBug059891_01() throws JavaModelException {
644
	this.formatterPrefs.page_width = 40;
645
	String source =
646
		"public class X01 {\n" +
647
		"	void test() {\n" + 
648
		"		foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8));\n" + 
649
		"	}\n" + 
650
		"}\n";
651
	formatSource(source,
652
		"public class X01 {\n" + 
653
		"	void test() {\n" + 
654
		"		foo(bar(1, 2, 3, 4),\n" + 
655
		"				bar(5, 6, 7, 8));\n" + 
656
		"	}\n" + 
657
		"}\n"
658
	);
659
}
660
public void testBug059891_01b() throws JavaModelException {
661
	this.formatterPrefs = null;
662
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
663
	this.formatterOptions.put(
664
			DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
665
			DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
666
	String source =
667
		"public class X01 {\n" +
668
		"	void test() {\n" + 
669
		"		foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8));\n" + 
670
		"	}\n" + 
671
		"}\n";
672
	formatSource(source,
673
		"public class X01 {\n" +
674
		"	void test() {\n" + 
675
		"		foo(bar(1, 2, 3, 4),\n" + 
676
		"			bar(5, 6, 7, 8));\n" + 
677
		"	}\n" + 
678
		"}\n"
679
	);
680
}
681
public void testBug059891_02() throws JavaModelException {
682
	this.formatterPrefs.page_width = 40;
683
	String source =
684
		"public class X02 {\n" +
685
		"	void test() {\n" + 
686
		"		foo(bar(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), bar(11, 12, 13, 14, 15, 16, 17, 18, 19, 20));\n" + 
687
		"	}\n" + 
688
		"}\n";
689
	formatSource(source,
690
		"public class X02 {\n" + 
691
		"	void test() {\n" + 
692
		"		foo(bar(1, 2, 3, 4, 5, 6, 7, 8,\n" + 
693
		"				9, 10),\n" + 
694
		"				bar(11, 12, 13, 14, 15,\n" + 
695
		"						16, 17, 18, 19,\n" + 
696
		"						20));\n" + 
697
		"	}\n" + 
698
		"}\n"
699
	);
700
}
701
public void testBug059891_02b() throws JavaModelException {
702
	this.formatterPrefs = null;
703
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
704
	this.formatterOptions.put(
705
			DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
706
			DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
707
	String source =
708
		"public class X02 {\n" +
709
		"	void test() {\n" + 
710
		"		foo(bar(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), bar(11, 12, 13, 14, 15, 16, 17, 18, 19, 20));\n" + 
711
		"	}\n" + 
712
		"}\n";
713
	formatSource(source,
714
		"public class X02 {\n" +
715
		"	void test() {\n" + 
716
		"		foo(bar(1, 2, 3, 4, 5, 6, 7, 8,\n" + 
717
		"				9, 10),\n" + 
718
		"			bar(11, 12, 13, 14, 15, 16,\n" + 
719
		"				17, 18, 19, 20));\n" + 
720
		"	}\n" + 
721
		"}\n"
722
	);
723
}
724
public void testBug059891_03() throws JavaModelException {
725
	this.formatterPrefs.page_width = 40;
726
	String source =
727
		"public class X03 {\n" +
728
		"	void test() {\n" + 
729
		"		foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8), bar(9, 10, 11, 12));\n" + 
730
		"	}\n" + 
731
		"}\n";
732
	formatSource(source,
733
		"public class X03 {\n" + 
734
		"	void test() {\n" + 
735
		"		foo(bar(1, 2, 3, 4),\n" + 
736
		"				bar(5, 6, 7, 8),\n" + 
737
		"				bar(9, 10, 11, 12));\n" + 
738
		"	}\n" + 
739
		"}\n"
740
	);
741
}
742
public void testBug059891_03b() throws JavaModelException {
743
	this.formatterPrefs = null;
744
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "40");
745
	this.formatterOptions.put(
746
			DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
747
			DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
748
	String source =
749
		"public class X03 {\n" +
750
		"	void test() {\n" + 
751
		"		foo(bar(1, 2, 3, 4), bar(5, 6, 7, 8), bar(9, 10, 11, 12));\n" + 
752
		"	}\n" + 
753
		"}\n";
754
	formatSource(source,
755
		"public class X03 {\n" +
756
		"	void test() {\n" + 
757
		"		foo(bar(1, 2, 3, 4),\n" + 
758
		"			bar(5, 6, 7, 8),\n" + 
759
		"			bar(9, 10, 11, 12));\n" + 
760
		"	}\n" + 
761
		"}\n"
762
	);
763
}
764
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=146175
765
public void testBug059891_146175() throws JavaModelException {
766
	String source =
767
		"public class FormatterDemo {\n" + 
768
		"\n" + 
769
		"    public void fooBar() {\n" + 
770
		"        SomeOtherClass instanceOfOtherClass = new SomeOtherClass();\n" + 
771
		"\n" + 
772
		"        /* The following statement demonstrates the formatter issue */\n" + 
773
		"        SomeOtherClass.someMethodInInnerClass(\n" + 
774
		"            instanceOfOtherClass.anotherMethod(\"Value of paramter 1\"),\n" + 
775
		"            instanceOfOtherClass.anotherMethod(\"Value of paramter 2\"));\n" + 
776
		"\n" + 
777
		"    }\n" + 
778
		"\n" + 
779
		"    private static class SomeOtherClass {\n" + 
780
		"        public static void someMethodInInnerClass(\n" + 
781
		"            String param1,\n" + 
782
		"            String param2) {\n" + 
783
		"        }\n" + 
784
		"        public String anotherMethod(String par) {\n" + 
785
		"            return par;\n" + 
786
		"        }\n" + 
787
		"    }\n" + 
788
		"}\n";
789
	formatSource(source,
790
		"public class FormatterDemo {\n" + 
791
		"\n" + 
792
		"	public void fooBar() {\n" + 
793
		"		SomeOtherClass instanceOfOtherClass = new SomeOtherClass();\n" + 
794
		"\n" + 
795
		"		/* The following statement demonstrates the formatter issue */\n" + 
796
		"		SomeOtherClass.someMethodInInnerClass(\n" + 
797
		"				instanceOfOtherClass.anotherMethod(\"Value of paramter 1\"),\n" + 
798
		"				instanceOfOtherClass.anotherMethod(\"Value of paramter 2\"));\n" + 
799
		"\n" + 
800
		"	}\n" + 
801
		"\n" + 
802
		"	private static class SomeOtherClass {\n" + 
803
		"		public static void someMethodInInnerClass(String param1, String param2) {\n" + 
804
		"		}\n" + 
805
		"\n" + 
806
		"		public String anotherMethod(String par) {\n" + 
807
		"			return par;\n" + 
808
		"		}\n" + 
809
		"	}\n" + 
810
		"}\n"
811
	);
812
}
813
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=164093
814
public void testBug059891_164093_01() throws JavaModelException {
815
	this.formatterPrefs = null;
816
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "30");
817
	this.formatterOptions.put(
818
			DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION,
819
			DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
820
	String source =
821
		"public class Test {\n" + 
822
		"    int someLongMethodName(int foo,  boolean bar, String yetAnotherArg) {\n" + 
823
		"        return 0;\n" + 
824
		"    }\n" + 
825
		"}\n";
826
	formatSource(source,
827
		"public class Test {\n" + 
828
		"	int someLongMethodName(	int foo,\n" + 
829
		"							boolean bar,\n" + 
830
		"							String yetAnotherArg) {\n" + 
831
		"		return 0;\n" + 
832
		"	}\n" + 
833
		"}\n"
834
	);
835
}
836
public void testBug059891_164093_02() throws JavaModelException {
837
	this.formatterPrefs = null;
838
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "55");
839
	this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
840
	this.formatterOptions.put(
841
			DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SELECTOR_IN_METHOD_INVOCATION,
842
			DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
843
	String source =
844
		"public class X01 {\n" + 
845
		"    void foo() {\n" + 
846
		"           someIdentifier(someArg).someMethodName().someMethodName(foo, bar).otherMethod(arg0, arg1);\n" + 
847
		"    }\n" + 
848
		"}\n";
849
	formatSource(source,
850
		"public class X01 {\n" + 
851
		"    void foo() {\n" + 
852
		"        someIdentifier(someArg).someMethodName()\n" + 
853
		"                               .someMethodName(foo,\n" + 
854
		"                                       bar)\n" + 
855
		"                               .otherMethod(arg0, arg1);\n" + 
856
		"    }\n" + 
857
		"}\n"
858
	);
859
}
860
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203588
861
public void testBug059891_203588() throws JavaModelException {
862
	String source =
863
		"public class Test {\n" + 
864
		"public void a()\n" + 
865
		"{\n" + 
866
		"  if(true)\n" + 
867
		"  {\n" + 
868
		"    allocation.add(idx_ta + 1, Double.valueOf(allocation.get(idx_ta).doubleValue() + q));\n" + 
869
		"  }\n" + 
870
		"}\n" + 
871
		"}\n";
872
	formatSource(source,
873
		"public class Test {\n" + 
874
		"	public void a() {\n" + 
875
		"		if (true) {\n" + 
876
		"			allocation.add(idx_ta + 1,\n" + 
877
		"					Double.valueOf(allocation.get(idx_ta).doubleValue() + q));\n" + 
878
		"		}\n" + 
879
		"	}\n" + 
880
		"}\n"
881
	);
882
}
883
// wksp1
884
public void testBug059891_wksp1_01() throws JavaModelException {
885
	String source =
886
		"public class X01 {\n" + 
887
		"	private void reportError(String name) throws ParseError {\n" + 
888
		"		throw new ParseError(MessageFormat.format(AntDTDSchemaMessages.getString(\"NfmParser.Ambiguous\"), new String[]{name})); //$NON-NLS-1$\n" + 
889
		"	}\n" + 
890
		"}\n";
891
	formatSource(source,
892
		"public class X01 {\n" + 
893
		"	private void reportError(String name) throws ParseError {\n" + 
894
		"		throw new ParseError(\n" + 
895
		"				MessageFormat.format(\n" + 
896
		"						AntDTDSchemaMessages.getString(\"NfmParser.Ambiguous\"), new String[] { name })); //$NON-NLS-1$\n" + 
897
		"	}\n" + 
898
		"}\n"
899
	);
900
}
901
public void testBug059891_wksp1_02() throws JavaModelException {
902
	String source =
903
		"public class X02 {\n" + 
904
		"	private void parseBuildFile(Project project) {\n" + 
905
		"		if (!buildFile.exists()) {\n" + 
906
		"			throw new BuildException(MessageFormat.format(InternalAntMessages.getString(\"InternalAntRunner.Buildfile__{0}_does_not_exist_!_1\"), //$NON-NLS-1$\n" + 
907
		"						 new String[]{buildFile.getAbsolutePath()}));\n" + 
908
		"		}\n" + 
909
		"		if (!buildFile.isFile()) {\n" + 
910
		"			throw new BuildException(MessageFormat.format(InternalAntMessages.getString(\"InternalAntRunner.Buildfile__{0}_is_not_a_file_1\"), //$NON-NLS-1$\n" + 
911
		"							new String[]{buildFile.getAbsolutePath()}));\n" + 
912
		"		}\n" + 
913
		"	}\n" + 
914
		"}\n";
915
	formatSource(source,
916
		"public class X02 {\n" + 
917
		"	private void parseBuildFile(Project project) {\n" + 
918
		"		if (!buildFile.exists()) {\n" + 
919
		"			throw new BuildException(\n" + 
920
		"					MessageFormat.format(\n" + 
921
		"							InternalAntMessages\n" + 
922
		"									.getString(\"InternalAntRunner.Buildfile__{0}_does_not_exist_!_1\"), //$NON-NLS-1$\n" + 
923
		"							new String[] { buildFile.getAbsolutePath() }));\n" + 
924
		"		}\n" + 
925
		"		if (!buildFile.isFile()) {\n" + 
926
		"			throw new BuildException(\n" + 
927
		"					MessageFormat.format(\n" + 
928
		"							InternalAntMessages\n" + 
929
		"									.getString(\"InternalAntRunner.Buildfile__{0}_is_not_a_file_1\"), //$NON-NLS-1$\n" + 
930
		"							new String[] { buildFile.getAbsolutePath() }));\n" + 
931
		"		}\n" + 
932
		"	}\n" + 
933
		"}\n"
934
	);
935
}
936
public void testBug059891_wksp1_03() throws JavaModelException {
937
	String source =
938
		"public class X03 {\n" + 
939
		"\n" + 
940
		"	protected void foo() {\n" + 
941
		"		printTargets(project, subNames, null, InternalAntMessages.getString(\"InternalAntRunner.Subtargets__5\"), 0); //$NON-NLS-1$\n" + 
942
		"	}\n" + 
943
		"}\n";
944
	formatSource(source,
945
		"public class X03 {\n" + 
946
		"\n" + 
947
		"	protected void foo() {\n" + 
948
		"		printTargets(project, subNames, null,\n" + 
949
		"				InternalAntMessages\n" + 
950
		"						.getString(\"InternalAntRunner.Subtargets__5\"), 0); //$NON-NLS-1$\n" + 
951
		"	}\n" + 
952
		"}\n"
953
	);
954
}
955
public void testBug059891_wksp1_04() throws JavaModelException {
956
	String source =
957
		"public class X04 {\n" + 
958
		"	void foo() {\n" + 
959
		"		if (AntUIPlugin.getDefault().getPreferenceStore().getBoolean(IAntUIPreferenceConstants.OUTLINE_LINK_WITH_EDITOR)) {\n" + 
960
		"			synchronizeOutlinePage(node, true);\n" + 
961
		"		}\n" + 
962
		"	}\n" + 
963
		"}\n";
964
	formatSource(source,
965
		"public class X04 {\n" + 
966
		"	void foo() {\n" + 
967
		"		if (AntUIPlugin.getDefault().getPreferenceStore()\n" + 
968
		"				.getBoolean(IAntUIPreferenceConstants.OUTLINE_LINK_WITH_EDITOR)) {\n" + 
969
		"			synchronizeOutlinePage(node, true);\n" + 
970
		"		}\n" + 
971
		"	}\n" + 
972
		"}\n"
973
	);
974
}
975
public void testBug059891_wksp1_05() throws JavaModelException {
976
	String source =
977
		"public class X05 {\n" + 
978
		"void foo() {\n" + 
979
		"		if (false && AntUIPlugin.getDefault().getPreferenceStore().getBoolean(AntEditorPreferenceConstants.TEMPLATES_USE_CODEFORMATTER)) {\n" + 
980
		"		}\n" + 
981
		"}\n" + 
982
		"}\n";
983
	formatSource(source,
984
		"public class X05 {\n" + 
985
		"	void foo() {\n" + 
986
		"		if (false && AntUIPlugin\n" + 
987
		"				.getDefault()\n" + 
988
		"				.getPreferenceStore()\n" + 
989
		"				.getBoolean(\n" + 
990
		"						AntEditorPreferenceConstants.TEMPLATES_USE_CODEFORMATTER)) {\n" + 
991
		"		}\n" + 
992
		"	}\n" + 
993
		"}\n"
994
	);
995
}
996
// TODO Improve this formatting as it let the message send argument in one line over the max width
997
public void testBug059891_wksp1_06() throws JavaModelException {
998
	String source =
999
		"public class X06 {\n" + 
1000
		"	public void launch() {\n" + 
1001
		"		try {\n" + 
1002
		"			if ((javaProject == null) || !javaProject.exists()) {\n" + 
1003
		"				abort(PDEPlugin________.getResourceString(\"JUnitLaunchConfig_____\"), null, IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT);\n" + 
1004
		"			}\n" + 
1005
		"		} catch (CoreException e) {\n" + 
1006
		"		}\n" + 
1007
		"	}\n" + 
1008
		"}\n";
1009
	formatSource(source,
1010
		"public class X06 {\n" + 
1011
		"	public void launch() {\n" + 
1012
		"		try {\n" + 
1013
		"			if ((javaProject == null) || !javaProject.exists()) {\n" + 
1014
		"				abort(PDEPlugin________\n" + 
1015
		"						.getResourceString(\"JUnitLaunchConfig_____\"),\n" + 
1016
		"						null,\n" + 
1017
		"						IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT);\n" + 
1018
		"			}\n" + 
1019
		"		} catch (CoreException e) {\n" + 
1020
		"		}\n" + 
1021
		"	}\n" + 
1022
		"}\n"
1023
	);
1024
}
1025
public void testBug059891_wksp1_07() throws JavaModelException {
1026
	String source =
1027
		"public class X07 {\n" + 
1028
		"	void foo() {\n" + 
1029
		"		if (true) {\n" + 
1030
		"			configureAntObject(result, element, task, task.getTaskName(), InternalCoreAntMessages.getString(\"AntCorePreferences.No_library_for_task\")); //$NON-NLS-1$\n" + 
1031
		"		}\n" + 
1032
		"	}\n" + 
1033
		"}\n";
1034
	formatSource(source,
1035
		"public class X07 {\n" + 
1036
		"	void foo() {\n" + 
1037
		"		if (true) {\n" + 
1038
		"			configureAntObject(\n" + 
1039
		"					result,\n" + 
1040
		"					element,\n" + 
1041
		"					task,\n" + 
1042
		"					task.getTaskName(),\n" + 
1043
		"					InternalCoreAntMessages\n" + 
1044
		"							.getString(\"AntCorePreferences.No_library_for_task\")); //$NON-NLS-1$\n" + 
1045
		"		}\n" + 
1046
		"	}\n" + 
1047
		"}\n"
1048
	);
1049
}
1050
public void testBug059891_wksp1_08() throws JavaModelException {
1051
	String source =
1052
		"public class X08 {\n" + 
1053
		"	public void foo() {\n" + 
1054
		"		if (true) {\n" + 
1055
		"			IStatus status= new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalCoreAntMessages.getString(\"AntRunner.Already_in_progess\"), new String[]{buildFileLocation}), null); //$NON-NLS-1$\n" + 
1056
		"		}\n" + 
1057
		"	}\n" + 
1058
		"}\n";
1059
	formatSource(source,
1060
		"public class X08 {\n" + 
1061
		"	public void foo() {\n" + 
1062
		"		if (true) {\n" + 
1063
		"			IStatus status = new Status(\n" + 
1064
		"					IStatus.ERROR,\n" + 
1065
		"					AntCorePlugin.PI_ANTCORE,\n" + 
1066
		"					AntCorePlugin.ERROR_RUNNING_BUILD,\n" + 
1067
		"					MessageFormat.format(\n" + 
1068
		"							InternalCoreAntMessages\n" + 
1069
		"									.getString(\"AntRunner.Already_in_progess\"), new String[] { buildFileLocation }), null); //$NON-NLS-1$\n" + 
1070
		"		}\n" + 
1071
		"	}\n" + 
1072
		"}\n"
1073
	);
1074
}
1075
public void testBug059891_wksp1_09() throws JavaModelException {
1076
	String source =
1077
		"public class X09 {\n" + 
1078
		"	void foo() {\n" + 
1079
		"		if (true) {\n" + 
1080
		"			String secondFileName = secondDirectoryAbsolutePath + File.separator + currentFile.substring(firstDirectoryAbsolutePath.length() + 1);\n" + 
1081
		"		}\n" + 
1082
		"	}\n" + 
1083
		"}\n";
1084
	formatSource(source,
1085
		"public class X09 {\n" + 
1086
		"	void foo() {\n" + 
1087
		"		if (true) {\n" + 
1088
		"			String secondFileName = secondDirectoryAbsolutePath\n" + 
1089
		"					+ File.separator\n" + 
1090
		"					+ currentFile\n" + 
1091
		"							.substring(firstDirectoryAbsolutePath.length() + 1);\n" + 
1092
		"		}\n" + 
1093
		"	}\n" + 
1094
		"}\n"
1095
	);
1096
}
1097
public void testBug059891_wksp1_10() throws JavaModelException {
1098
	String source =
1099
		"public class X10 {\n" + 
1100
		"	void foo() {\n" + 
1101
		"		if (true) {\n" + 
1102
		"			if (true) {\n" + 
1103
		"				throw new BuildException(InternalAntMessages.getString(\"InternalAntRunner.Could_not_load_the_version_information._10\")); //$NON-NLS-1$\n" + 
1104
		"			}\n" + 
1105
		"		}\n" + 
1106
		"	}\n" + 
1107
		"}\n";
1108
	formatSource(source,
1109
		"public class X10 {\n" + 
1110
		"	void foo() {\n" + 
1111
		"		if (true) {\n" + 
1112
		"			if (true) {\n" + 
1113
		"				throw new BuildException(\n" + 
1114
		"						InternalAntMessages\n" + 
1115
		"								.getString(\"InternalAntRunner.Could_not_load_the_version_information._10\")); //$NON-NLS-1$\n" + 
1116
		"			}\n" + 
1117
		"		}\n" + 
1118
		"	}\n" + 
1119
		"}\n"
1120
	);
1121
}
1122
public void testBug059891_wksp1_11() throws JavaModelException {
1123
	String source =
1124
		"public class X11 {\n" + 
1125
		"	private void antFileNotFound() {\n" + 
1126
		"		reportError(AntLaunchConfigurationMessages.getString(\"AntLaunchShortcut.Unable\"), null); //$NON-NLS-1$	\n" + 
1127
		"	}\n" + 
1128
		"}\n";
1129
	formatSource(source,
1130
		"public class X11 {\n" + 
1131
		"	private void antFileNotFound() {\n" + 
1132
		"		reportError(\n" + 
1133
		"				AntLaunchConfigurationMessages\n" + 
1134
		"						.getString(\"AntLaunchShortcut.Unable\"), null); //$NON-NLS-1$	\n" + 
1135
		"	}\n" + 
1136
		"}\n"
1137
	);
1138
}
1139
public void testBug059891_wksp1_12() throws JavaModelException {
1140
	String source =
1141
		"public class X12 {\n" + 
1142
		"	void foo() {\n" + 
1143
		"        if (this.fTests.size() == 0) {\n" + 
1144
		"            this.addTest(TestSuite\n" + 
1145
		"                    .warning(\"No tests found in \" + theClass.getName())); //$NON-NLS-1$\n" + 
1146
		"        }\n" + 
1147
		"	}\n" + 
1148
		"}\n";
1149
	formatSource(source,
1150
		"public class X12 {\n" + 
1151
		"	void foo() {\n" + 
1152
		"		if (this.fTests.size() == 0) {\n" + 
1153
		"			this.addTest(TestSuite\n" +
1154
		"					.warning(\"No tests found in \" + theClass.getName())); //$NON-NLS-1$\n" + 
1155
		"		}\n" + 
1156
		"	}\n" + 
1157
		"}\n"
1158
	);
1159
}
1160
1161
/**
637
 * @bug 198074: [formatter] the code formatter doesn't respect my new lines
1162
 * @bug 198074: [formatter] the code formatter doesn't respect my new lines
638
 * @test Ensure that the formatter keep line breaks wrapping set by users in the code
1163
 * @test Ensure that the formatter keep line breaks wrapping set by users in the code
639
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
1164
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
Lines 1114-1119 Link Here
1114
}
1639
}
1115
1640
1116
/**
1641
/**
1642
 * @bug 203588: [formatter] Qualified invocation + binary expressions excessive wrap
1643
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=203588"
1644
 */
1645
public void testBug203588() throws JavaModelException {
1646
	String source =
1647
		"public class Test {\n" +
1648
		"void foo() {\n" +
1649
		"	while (true) {\n" +
1650
		"		if (patternChar\n" +
1651
		"			!= (isCaseSensitive\n" +
1652
		"				? name[iName]\n" +
1653
		"				: Character.toLowerCase(name[iName]))\n" +
1654
		"			&& patternChar != \'?\') {\n" +
1655
		"			return;\n" +
1656
		"		}\n" +
1657
		"	}\n" +
1658
		"}\n" +
1659
		"}\n";
1660
	formatSource(source,
1661
		"public class Test {\n" +
1662
		"	void foo() {\n" +
1663
		"		while (true) {\n" +
1664
		"			if (patternChar != (isCaseSensitive ? name[iName] : Character\n" +
1665
		"					.toLowerCase(name[iName])) && patternChar != \'?\') {\n" +
1666
		"				return;\n" +
1667
		"			}\n" +
1668
		"		}\n" +
1669
		"	}\n" +
1670
		"}\n"
1671
	);
1672
}
1673
1674
/**
1117
 * @bug 252556: [formatter] Spaces removed before formatted region of a compilation unit.
1675
 * @bug 252556: [formatter] Spaces removed before formatted region of a compilation unit.
1118
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252556"
1676
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252556"
1119
 */
1677
 */
Lines 2412-2420 Link Here
2412
		"\n" +
2970
		"\n" +
2413
		"	void foo() {\n" +
2971
		"	void foo() {\n" +
2414
		"		StringBuilder builder = new StringBuilder();\n" +
2972
		"		StringBuilder builder = new StringBuilder();\n" +
2415
		"		builder.append(\"abc\").append(\"def\").append(\"ghi\").append(\"jkl\").append(\n" +
2973
		"		builder.append(\"abc\").append(\"def\").append(\"ghi\").append(\"jkl\")\n" + 
2416
		"				\"mno\")\n" +
2974
		"				.append(\"mno\")\n" + 
2417
		"				.append(\"pqr\").append(\"stu\").append(\"vwx\").append(\"yz\");\n" +
2975
		"				.append(\"pqr\").append(\"stu\").append(\"vwx\").append(\"yz\");\n" + 
2418
		"	}\n" +
2976
		"	}\n" +
2419
		"}\n"
2977
		"}\n"
2420
	);
2978
	);
Lines 2486-2499 Link Here
2486
		"\n" +
3044
		"\n" +
2487
		"	void foo() {\n" +
3045
		"	void foo() {\n" +
2488
		"		StringBuilder builder = new StringBuilder();\n" +
3046
		"		StringBuilder builder = new StringBuilder();\n" +
2489
		"		builder.append(\"abc\").append(\n" +
3047
		"		builder.append(\"abc\")\n" + 
2490
		"				\"def\").append(\"ghi\")\n" +
3048
		"				.append(\"def\")\n" + 
2491
		"				.append(\"jkl\").append(\n" +
3049
		"				.append(\"ghi\")\n" + 
2492
		"						\"mno\")\n" +
3050
		"				.append(\"jkl\")\n" + 
2493
		"				.append(\"pqr\").append(\n" +
3051
		"				.append(\"mno\")\n" + 
2494
		"						\"stu\").append(\n" +
3052
		"				.append(\"pqr\")\n" + 
2495
		"						\"vwx\").append(\n" +
3053
		"				.append(\"stu\")\n" + 
2496
		"						\"yz\");\n" +
3054
		"				.append(\"vwx\")\n" + 
3055
		"				.append(\"yz\");\n" + 
2497
		"	}\n" +
3056
		"	}\n" +
2498
		"}\n"
3057
		"}\n"
2499
	);
3058
	);
Lines 2516-2530 Link Here
2516
		"\n" +
3075
		"\n" +
2517
		"	void foo() {\n" +
3076
		"	void foo() {\n" +
2518
		"		StringBuilder builder = new StringBuilder();\n" +
3077
		"		StringBuilder builder = new StringBuilder();\n" +
2519
		"		builder.append(\"abc\").append(\n" +
3078
		"		builder.append(\"abc\")\n" + 
2520
		"				\"def\")\n" +
3079
		"				.append(\"def\")\n" + 
2521
		"				.append(\"ghi\").append(\n" +
3080
		"				.append(\"ghi\")\n" + 
2522
		"						\"jkl\").append(\n" +
3081
		"				.append(\"jkl\")\n" + 
2523
		"						\"mno\")\n" +
3082
		"				.append(\"mno\")\n" + 
2524
		"				.append(\"pqr\").append(\n" +
3083
		"				.append(\"pqr\")\n" + 
2525
		"						\"stu\").append(\n" +
3084
		"				.append(\"stu\")\n" + 
2526
		"						\"vwx\").append(\n" +
3085
		"				.append(\"vwx\")\n" + 
2527
		"						\"yz\");\n" +
3086
		"				.append(\"yz\");\n" + 
2528
		"	}\n" +
3087
		"	}\n" +
2529
		"}\n"
3088
		"}\n"
2530
	);
3089
	);
Lines 2548-2562 Link Here
2548
		"\n" +
3107
		"\n" +
2549
		"	void foo() {\n" +
3108
		"	void foo() {\n" +
2550
		"		StringBuilder builder = new StringBuilder();\n" +
3109
		"		StringBuilder builder = new StringBuilder();\n" +
2551
		"		builder.append(\"abc\").append(\n" +
3110
		"		builder.append(\"abc\")\n" + 
2552
		"				\"def\")\n" +
3111
		"				.append(\"def\")\n" + 
2553
		"				.append(\"ghi\").append(\n" +
3112
		"				.append(\"ghi\")\n" + 
2554
		"						\"jkl\").append(\n" +
3113
		"				.append(\"jkl\")\n" + 
2555
		"						\"mno\")\n" +
3114
		"				.append(\"mno\")\n" + 
2556
		"				.append(\"pqr\").append(\n" +
3115
		"				.append(\"pqr\")\n" + 
2557
		"						\"stu\").append(\n" +
3116
		"				.append(\"stu\")\n" + 
2558
		"						\"vwx\")\n" +
3117
		"				.append(\"vwx\")\n" + 
2559
		"				.append(\"yz\");\n" +
3118
		"				.append(\"yz\");\n" + 
2560
		"	}\n" +
3119
		"	}\n" +
2561
		"}\n"
3120
		"}\n"
2562
	);
3121
	);
Lines 4932-4942 Link Here
4932
		"			if (point != null) {\n" + 
5491
		"			if (point != null) {\n" + 
4933
		"				// Following message send was unnecessarily split\n" + 
5492
		"				// Following message send was unnecessarily split\n" + 
4934
		"				sb.append(PATH_SMOOTH_QUAD_TO)\n" + 
5493
		"				sb.append(PATH_SMOOTH_QUAD_TO)\n" + 
4935
		"						.append(\n" + 
5494
		"						.append(String\n" + 
4936
		"								String.valueOf(midValue(point.x, point_plus1.x)))\n" + 
5495
		"								.valueOf(midValue(point.x, point_plus1.x)))\n" + 
4937
		"						.append(XML_SPACE)\n" + 
5496
		"						.append(XML_SPACE)\n" + 
4938
		"						.append(\n" + 
5497
		"						.append(String\n" + 
4939
		"								String.valueOf(midValue(point.y, point_plus1.y)));\n" + 
5498
		"								.valueOf(midValue(point.y, point_plus1.y)));\n" + 
4940
		"			} else {\n" + 
5499
		"			} else {\n" + 
4941
		"				break;\n" + 
5500
		"				break;\n" + 
4942
		"			}\n" + 
5501
		"			}\n" + 
Lines 4992-4998 Link Here
4992
		"					null, // qualifier\n" + 
5551
		"					null, // qualifier\n" + 
4993
		"					null, // stopKeyValue\n" + 
5552
		"					null, // stopKeyValue\n" + 
4994
		"					ScanController.GT // stopSearchOp\n" + 
5553
		"					ScanController.GT // stopSearchOp\n" + 
4995
		"					);\n" + 
5554
		"			);\n" + 
4996
		"		}\n" + 
5555
		"		}\n" + 
4997
		"\n" + 
5556
		"\n" + 
4998
		"	}\n" + 
5557
		"	}\n" + 
(-)workspace/Formatter/test026/A_out.java (-1 / +2 lines)
Lines 7-13 Link Here
7
				.someQuiteLongMessageSend("aaaaaaaaaaa", "bbbbbbbbbbbbb",
7
				.someQuiteLongMessageSend("aaaaaaaaaaa", "bbbbbbbbbbbbb",
8
						"cccccccc");
8
						"cccccccc");
9
		Alignment expressionsAlignment = this.scribe.createAlignment(
9
		Alignment expressionsAlignment = this.scribe.createAlignment(
10
				"expressions", Alignment.M_COMPACT_SPLIT
10
				"expressions",
11
				Alignment.M_COMPACT_SPLIT
11
						+ someMessageSend(Alignment.M_COMPACT_SPLIT,
12
						+ someMessageSend(Alignment.M_COMPACT_SPLIT,
12
								Alignment.M_COMPACT_SPLIT,
13
								Alignment.M_COMPACT_SPLIT,
13
								Alignment.M_COMPACT_SPLIT,
14
								Alignment.M_COMPACT_SPLIT,
(-)workspace/Formatter/test167/A_out.java (-2 / +2 lines)
Lines 2-9 Link Here
2
	X(String s) {
2
	X(String s) {
3
	}
3
	}
4
	protected void foo() {
4
	protected void foo() {
5
		X a = new X(new StringBuffer("this").append("is").append("a").append(
5
		X a = new X(new StringBuffer("this").append("is").append("a")
6
				"long").append("argument").toString()) {
6
				.append("long").append("argument").toString()) {
7
			public void run() {
7
			public void run() {
8
			}
8
			}
9
		};
9
		};
(-)workspace/Formatter/test169/A_out.java (-2 / +2 lines)
Lines 2-8 Link Here
2
	X(String s) {
2
	X(String s) {
3
	}
3
	}
4
	protected void foo() {
4
	protected void foo() {
5
		cmd.createArgument().foo().test().error().setFile(
5
		cmd.createArgument().foo().test().error()
6
				destDir.getAbsoluteFile());
6
				.setFile(destDir.getAbsoluteFile());
7
	}
7
	}
8
}
8
}
(-)workspace/Formatter/test170/A_out.java (-2 / +2 lines)
Lines 2-8 Link Here
2
	X(String s) {
2
	X(String s) {
3
	}
3
	}
4
	protected void foo() {
4
	protected void foo() {
5
		cmd.createArgument().foo().test().error().setFile(
5
		cmd.createArgument().foo().test().error()
6
				(Name) (destDir()).getAbsoluteFile());
6
				.setFile((Name) (destDir()).getAbsoluteFile());
7
	}
7
	}
8
}
8
}
(-)workspace/Formatter/test337/A_out.java (-2 / +2 lines)
Lines 110-117 Link Here
110
	}
110
	}
111
	private IPlatform acquirePlatform() {
111
	private IPlatform acquirePlatform() {
112
		if (platformTracker == null) {
112
		if (platformTracker == null) {
113
			platformTracker = new ServiceTracker(context, IPlatform.class
113
			platformTracker = new ServiceTracker(context,
114
					.getName(), null);
114
					IPlatform.class.getName(), null);
115
			platformTracker.open();
115
			platformTracker.open();
116
		}
116
		}
117
		IPlatform result = (IPlatform) platformTracker.getService();
117
		IPlatform result = (IPlatform) platformTracker.getService();
(-)workspace/Formatter/test455/A_out.java (-8 / +6 lines)
Lines 4-19 Link Here
4
		try {
4
		try {
5
			IJavaProject javaProject = getJavaProject(configuration);
5
			IJavaProject javaProject = getJavaProject(configuration);
6
			if ((javaProject == null) || !javaProject.exists()) {
6
			if ((javaProject == null) || !javaProject.exists()) {
7
				abort(
7
				abort(PDEPlugin
8
						PDEPlugin
8
						.getResourceString("JUnitLaunchConfiguration.error.invalidproject"), null, IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
9
								.getResourceString("JUnitLaunchConfiguration.error.invalidproject"), null, IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
10
			}
9
			}
11
			IType[] testTypes = getTestTypes(configuration, javaProject,
10
			IType[] testTypes = getTestTypes(configuration, javaProject,
12
					new SubProgressMonitor(monitor, 1));
11
					new SubProgressMonitor(monitor, 1));
13
			if (testTypes.length == 0) {
12
			if (testTypes.length == 0) {
14
				abort(
13
				abort(PDEPlugin
15
						PDEPlugin
14
						.getResourceString("JUnitLaunchConfiguration.error.notests"), null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_MAIN_TYPE); //$NON-NLS-1$
16
								.getResourceString("JUnitLaunchConfiguration.error.notests"), null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_MAIN_TYPE); //$NON-NLS-1$
17
			}
15
			}
18
			monitor.worked(1);
16
			monitor.worked(1);
19
17
Lines 38-45 Link Here
38
36
39
			setDefaultSourceLocator(launch, configuration);
37
			setDefaultSourceLocator(launch, configuration);
40
			launch.setAttribute(PORT_ATTR, Integer.toString(port));
38
			launch.setAttribute(PORT_ATTR, Integer.toString(port));
41
			launch.setAttribute(TESTTYPE_ATTR, testTypes[0]
39
			launch.setAttribute(TESTTYPE_ATTR,
42
					.getHandleIdentifier());
40
					testTypes[0].getHandleIdentifier());
43
			PDEPlugin.getDefault().getLaunchesListener().manage(launch);
41
			PDEPlugin.getDefault().getLaunchesListener().manage(launch);
44
			launcher.getVMRunner(mode).run(runnerConfig, launch, monitor);
42
			launcher.getVMRunner(mode).run(runnerConfig, launch, monitor);
45
			monitor.worked(1);
43
			monitor.worked(1);
(-)workspace/Formatter/test484/A_out.java (-3 / +2 lines)
Lines 2-10 Link Here
2
	public void launch() {
2
	public void launch() {
3
		try {
3
		try {
4
			if ((javaProject == null) || !javaProject.exists()) {
4
			if ((javaProject == null) || !javaProject.exists()) {
5
				abort(
5
				abort(PDEPlugin
6
						PDEPlugin
6
						.getResourceString("JUnitLaunchConfiguration.error.invalidproject"), null, IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
7
								.getResourceString("JUnitLaunchConfiguration.error.invalidproject"), null, IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
8
			}
7
			}
9
		} catch (CoreException e) {
8
		} catch (CoreException e) {
10
		}
9
		}
(-)workspace/Formatter/test485/A_out.java (-3 / +2 lines)
Lines 2-10 Link Here
2
	public void launch() {
2
	public void launch() {
3
		try {
3
		try {
4
			if ((javaProject == null) || !javaProject.exists()) {
4
			if ((javaProject == null) || !javaProject.exists()) {
5
				abort(
5
				abort(PDEPlugin
6
						PDEPlugin
6
						.getResourceString("JUnitLaunchConfiguration.error.invalidproject"),
7
								.getResourceString("JUnitLaunchConfiguration.error.invalidproject"),
8
						null,
7
						null,
9
						IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT);
8
						IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT);
10
			}
9
			}

Return to bug 59891