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

Collapse All | Expand All

(-)buildnotes_jdt-core.html (+1 lines)
Lines 48-53 Link Here
48
<br>Project org.eclipse.jdt.core v_A29
48
<br>Project org.eclipse.jdt.core v_A29
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A29">cvs</a>).
49
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_A29">cvs</a>).
50
<h2>What's new in this drop</h2>
50
<h2>What's new in this drop</h2>
51
Patch v06 for bug 264112
51
52
52
<h3>Problem Reports Fixed</h3>
53
<h3>Problem Reports Fixed</h3>
53
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=298243">298243</a>
54
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=298243">298243</a>
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (+6 lines)
Lines 1395-1400 Link Here
1395
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1395
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1396
		boolean ok = false;
1396
		boolean ok = false;
1397
		do {
1397
		do {
1398
			if (startingPositionInCascade == 1) {
1399
				cascadingMessageSendAlignment.startingColumn = this.scribe.column;
1400
			}
1398
			try {
1401
			try {
1399
				this.scribe.alignFragment(cascadingMessageSendAlignment, 0);
1402
				this.scribe.alignFragment(cascadingMessageSendAlignment, 0);
1400
				this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1403
				this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
Lines 1468-1473 Link Here
1468
					if (numberOfParens > 0) {
1471
					if (numberOfParens > 0) {
1469
						manageClosingParenthesizedExpression(currentMessageSend, numberOfParens);
1472
						manageClosingParenthesizedExpression(currentMessageSend, numberOfParens);
1470
					}
1473
					}
1474
					cascadingMessageSendAlignment.startingColumn = -1;
1471
					if (i < size - 1) {
1475
					if (i < size - 1) {
1472
						this.scribe.alignFragment(cascadingMessageSendAlignment, i);
1476
						this.scribe.alignFragment(cascadingMessageSendAlignment, i);
1473
						this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1477
						this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
Lines 1664-1669 Link Here
1664
		if (messageAlignment != null) {
1668
		if (messageAlignment != null) {
1665
			this.scribe.alignFragment(messageAlignment, 0);
1669
			this.scribe.alignFragment(messageAlignment, 0);
1666
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1670
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
1671
			messageAlignment.startingColumn = -1;
1667
		}
1672
		}
1668
		TypeReference[] typeArguments = messageSend.typeArguments;
1673
		TypeReference[] typeArguments = messageSend.typeArguments;
1669
		if (typeArguments != null) {
1674
		if (typeArguments != null) {
Lines 4086-4091 Link Here
4086
				this.scribe.enterAlignment(messageAlignment);
4091
				this.scribe.enterAlignment(messageAlignment);
4087
				boolean ok = false;
4092
				boolean ok = false;
4088
				do {
4093
				do {
4094
					messageAlignment.startingColumn = this.scribe.column;
4089
					try {
4095
					try {
4090
						formatMessageSend(messageSend, scope, messageAlignment);
4096
						formatMessageSend(messageSend, scope, messageAlignment);
4091
						ok = true;
4097
						ok = true;
(-)formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java (-5 / +9 lines)
Lines 120-125 Link Here
120
	public static final int R_OUTERMOST = 1;
120
	public static final int R_OUTERMOST = 1;
121
	public static final int R_INNERMOST = 2;
121
	public static final int R_INNERMOST = 2;
122
	public int tieBreakRule;
122
	public int tieBreakRule;
123
	public int startingColumn = -1;
123
124
124
	// alignment effects on a per fragment basis
125
	// alignment effects on a per fragment basis
125
	public static final int NONE = 0;
126
	public static final int NONE = 0;
Lines 351-361 Link Here
351
			}
352
			}
352
		}
353
		}
353
354
354
		if (this.fragmentBreaks[this.fragmentIndex] == BREAK) {
355
		int fragmentIndentation = this.fragmentIndentations[this.fragmentIndex];
355
			this.scribe.printNewLine();
356
		if (this.startingColumn < 0 || (fragmentIndentation+1) < this.startingColumn) {
356
		}
357
			if (this.fragmentBreaks[this.fragmentIndex] == BREAK) {
357
		if (this.fragmentIndentations[this.fragmentIndex] > 0) {
358
				this.scribe.printNewLine();
358
			this.scribe.indentationLevel = this.fragmentIndentations[this.fragmentIndex];
359
			}
360
			if (fragmentIndentation > 0) {
361
				this.scribe.indentationLevel = fragmentIndentation;
362
			}
359
		}
363
		}
360
	}
364
	}
361
365
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+329 lines)
Lines 3503-3508 Link Here
3503
}
3503
}
3504
3504
3505
/**
3505
/**
3506
 * @bug 264112: [Formatter] Wrap when necessary too aggressive on short qualifiers
3507
 * @test 
3508
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=264112"
3509
 */
3510
// Max line width = 24
3511
public void testBug264112_w24_S1() {
3512
	this.formatterPrefs.page_width = 24;
3513
	String source = 
3514
		"class Sample1 {void foo() {Other.bar( 100,\n" + 
3515
		"200,\n" + 
3516
		"300,\n" + 
3517
		"400,\n" + 
3518
		"500,\n" + 
3519
		"600,\n" + 
3520
		"700,\n" + 
3521
		"800,\n" + 
3522
		"900 );}}\n";
3523
	formatSource(source,
3524
		"class Sample1 {\n" + 
3525
		"	void foo() {\n" + 
3526
		"		Other.bar(100,\n" + 
3527
		"				200,\n" + 
3528
		"				300,\n" + 
3529
		"				400,\n" + 
3530
		"				500,\n" + 
3531
		"				600,\n" + 
3532
		"				700,\n" + 
3533
		"				800,\n" + 
3534
		"				900);\n" + 
3535
		"	}\n" + 
3536
		"}\n"
3537
	);
3538
}
3539
public void testBug264112_w24_S2() {
3540
	this.formatterPrefs.page_width = 24;
3541
	String source = 
3542
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
3543
	formatSource(source,
3544
		"class Sample2 {\n" + 
3545
		"	int foo(Some a) {\n" + 
3546
		"		return a.getFirst();\n" + 
3547
		"	}\n" + 
3548
		"}\n"
3549
	);
3550
}
3551
// Max line width = 25
3552
public void testBug264112_w25_S1() {
3553
	this.formatterPrefs.page_width = 25;
3554
	String source = 
3555
		"class Sample1 {void foo() {Other.bar( 100,\n" + 
3556
		"200,\n" + 
3557
		"300,\n" + 
3558
		"400,\n" + 
3559
		"500,\n" + 
3560
		"600,\n" + 
3561
		"700,\n" + 
3562
		"800,\n" + 
3563
		"900 );}}\n";
3564
	formatSource(source,
3565
		"class Sample1 {\n" + 
3566
		"	void foo() {\n" + 
3567
		"		Other.bar(100,\n" + 
3568
		"				200,\n" + 
3569
		"				300,\n" + 
3570
		"				400,\n" + 
3571
		"				500,\n" + 
3572
		"				600,\n" + 
3573
		"				700,\n" + 
3574
		"				800, 900);\n" + 
3575
		"	}\n" + 
3576
		"}\n"
3577
	);
3578
}
3579
public void testBug264112_w25_S2() {
3580
	this.formatterPrefs.page_width = 25;
3581
	String source = 
3582
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
3583
	formatSource(source,
3584
		"class Sample2 {\n" + 
3585
		"	int foo(Some a) {\n" + 
3586
		"		return a.getFirst();\n" + 
3587
		"	}\n" + 
3588
		"}\n"
3589
	);
3590
}
3591
// Max line width = 26
3592
public void testBug264112_w26_S1() {
3593
	this.formatterPrefs.page_width = 26;
3594
	String source = 
3595
		"class Sample1 {void foo() {Other.bar( 100,\n" + 
3596
		"200,\n" + 
3597
		"300,\n" + 
3598
		"400,\n" + 
3599
		"500,\n" + 
3600
		"600,\n" + 
3601
		"700,\n" + 
3602
		"800,\n" + 
3603
		"900 );}}\n";
3604
	formatSource(source,
3605
		"class Sample1 {\n" + 
3606
		"	void foo() {\n" + 
3607
		"		Other.bar(100,\n" + 
3608
		"				200, 300,\n" + 
3609
		"				400, 500,\n" + 
3610
		"				600, 700,\n" + 
3611
		"				800, 900);\n" + 
3612
		"	}\n" + 
3613
		"}\n"
3614
	);
3615
}
3616
public void testBug264112_w26_S2() {
3617
	this.formatterPrefs.page_width = 26;
3618
	String source = 
3619
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
3620
	formatSource(source,
3621
		"class Sample2 {\n" + 
3622
		"	int foo(Some a) {\n" + 
3623
		"		return a.getFirst();\n" + 
3624
		"	}\n" + 
3625
		"}\n"
3626
	);
3627
}
3628
public void testBug264112_wksp1_01() {
3629
	String source = 
3630
		"package wksp1;\n" + 
3631
		"\n" + 
3632
		"public class X01 {\n" + 
3633
		"\n" + 
3634
		"	public Object foo(Object scope) {\n" + 
3635
		"		if (scope != null) {\n" + 
3636
		"			if (true) {\n" + 
3637
		"				for (int i = 0; i < 10; i++) {\n" + 
3638
		"					if (i == 0) {\n" + 
3639
		"					} else if (i < 5) {\n" + 
3640
		"					} else {\n" + 
3641
		"						scope.problemReporter().typeMismatchErrorActualTypeExpectedType(expression, expressionTb, expectedElementsTb);\n" + 
3642
		"						return null;\n" + 
3643
		"					}\n" + 
3644
		"				}\n" + 
3645
		"			}\n" + 
3646
		"			return null;\n" + 
3647
		"		}\n" + 
3648
		"	}\n" + 
3649
		"\n" + 
3650
		"}\n";
3651
	formatSource(source,
3652
		"package wksp1;\n" + 
3653
		"\n" + 
3654
		"public class X01 {\n" + 
3655
		"\n" + 
3656
		"	public Object foo(Object scope) {\n" + 
3657
		"		if (scope != null) {\n" + 
3658
		"			if (true) {\n" + 
3659
		"				for (int i = 0; i < 10; i++) {\n" + 
3660
		"					if (i == 0) {\n" + 
3661
		"					} else if (i < 5) {\n" + 
3662
		"					} else {\n" + 
3663
		"						scope.problemReporter()\n" + 
3664
		"								.typeMismatchErrorActualTypeExpectedType(\n" + 
3665
		"										expression, expressionTb,\n" + 
3666
		"										expectedElementsTb);\n" + 
3667
		"						return null;\n" + 
3668
		"					}\n" + 
3669
		"				}\n" + 
3670
		"			}\n" + 
3671
		"			return null;\n" + 
3672
		"		}\n" + 
3673
		"	}\n" + 
3674
		"\n" + 
3675
		"}\n"
3676
	);
3677
}
3678
public void testBug264112_wksp1_02() {
3679
	String source = 
3680
		"package wksp1;\n" + 
3681
		"\n" + 
3682
		"public class X02 {\n" + 
3683
		"\n" + 
3684
		"	public String toString() {\n" + 
3685
		"		StringBuffer buffer = new StringBuffer();\n" + 
3686
		"		if (true) {\n" + 
3687
		"			buffer.append(\"- possible values:	[\"); //$NON-NLS-1$ \n" + 
3688
		"			buffer.append(\"]\\n\"); //$NON-NLS-1$ \n" + 
3689
		"			buffer.append(\"- curr. val. index:	\").append(currentValueIndex).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
3690
		"		}\n" + 
3691
		"		buffer.append(\"- description:		\").append(description).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
3692
		"		return buffer.toString();\n" + 
3693
		"	}\n" + 
3694
		"\n" + 
3695
		"}\n";
3696
	formatSource(source,
3697
		"package wksp1;\n" + 
3698
		"\n" + 
3699
		"public class X02 {\n" + 
3700
		"\n" + 
3701
		"	public String toString() {\n" + 
3702
		"		StringBuffer buffer = new StringBuffer();\n" + 
3703
		"		if (true) {\n" + 
3704
		"			buffer.append(\"- possible values:	[\"); //$NON-NLS-1$ \n" + 
3705
		"			buffer.append(\"]\\n\"); //$NON-NLS-1$ \n" + 
3706
		"			buffer.append(\"- curr. val. index:	\").append(currentValueIndex).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
3707
		"		}\n" + 
3708
		"		buffer.append(\"- description:		\").append(description).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + 
3709
		"		return buffer.toString();\n" + 
3710
		"	}\n" + 
3711
		"\n" + 
3712
		"}\n"
3713
	);
3714
}
3715
public void testBug264112_wksp2_01() {
3716
	String source = 
3717
		"package wksp2;\n" + 
3718
		"\n" + 
3719
		"public class X01 {\n" + 
3720
		"\n" + 
3721
		"    private static final String PATH_SMOOTH_QUAD_TO = \"SMOOTH\";\n" + 
3722
		"    private static final String XML_SPACE = \" \";\n" + 
3723
		"    private static final String PATH_CLOSE = \"CLOSE\";\n" + 
3724
		"\n" + 
3725
		"	String foo(Point point, Point point_plus1) {\n" + 
3726
		"        StringBuffer sb = new StringBuffer();\n" + 
3727
		"        while (true) {\n" + 
3728
		"            if (point != null) {\n" + 
3729
		"                // Following message send was unnecessarily split\n" + 
3730
		"                sb.append(PATH_SMOOTH_QUAD_TO)\n" + 
3731
		"                .append(String.valueOf(midValue(point.x, point_plus1.x)))\n" + 
3732
		"                .append(XML_SPACE)\n" + 
3733
		"                .append(String.valueOf(midValue(point.y, point_plus1.y)));\n" + 
3734
		"            } else {\n" + 
3735
		"                break;\n" + 
3736
		"            }\n" + 
3737
		"        }\n" + 
3738
		"        sb.append(PATH_CLOSE);\n" + 
3739
		"\n" + 
3740
		"        return sb.toString();\n" + 
3741
		"    }\n" + 
3742
		"\n" + 
3743
		"    private int midValue(int x1, int x2) {\n" + 
3744
		"        return (x1 + x2) / 2;\n" + 
3745
		"    }\n" + 
3746
		"\n" + 
3747
		"}\n" + 
3748
		"class Point {\n" + 
3749
		"	int x,y;\n" + 
3750
		"}\n";
3751
	formatSource(source,
3752
		"package wksp2;\n" + 
3753
		"\n" + 
3754
		"public class X01 {\n" + 
3755
		"\n" + 
3756
		"	private static final String PATH_SMOOTH_QUAD_TO = \"SMOOTH\";\n" + 
3757
		"	private static final String XML_SPACE = \" \";\n" + 
3758
		"	private static final String PATH_CLOSE = \"CLOSE\";\n" + 
3759
		"\n" + 
3760
		"	String foo(Point point, Point point_plus1) {\n" + 
3761
		"		StringBuffer sb = new StringBuffer();\n" + 
3762
		"		while (true) {\n" + 
3763
		"			if (point != null) {\n" + 
3764
		"				// Following message send was unnecessarily split\n" + 
3765
		"				sb.append(PATH_SMOOTH_QUAD_TO)\n" + 
3766
		"						.append(\n" + 
3767
		"								String.valueOf(midValue(point.x, point_plus1.x)))\n" + 
3768
		"						.append(XML_SPACE)\n" + 
3769
		"						.append(\n" + 
3770
		"								String.valueOf(midValue(point.y, point_plus1.y)));\n" + 
3771
		"			} else {\n" + 
3772
		"				break;\n" + 
3773
		"			}\n" + 
3774
		"		}\n" + 
3775
		"		sb.append(PATH_CLOSE);\n" + 
3776
		"\n" + 
3777
		"		return sb.toString();\n" + 
3778
		"	}\n" + 
3779
		"\n" + 
3780
		"	private int midValue(int x1, int x2) {\n" + 
3781
		"		return (x1 + x2) / 2;\n" + 
3782
		"	}\n" + 
3783
		"\n" + 
3784
		"}\n" + 
3785
		"\n" + 
3786
		"class Point {\n" + 
3787
		"	int x, y;\n" + 
3788
		"}\n"
3789
	);
3790
}
3791
public void testBug264112_wksp2_02() {
3792
	String source = 
3793
		"package wksp2;\n" + 
3794
		"\n" + 
3795
		"public class X02 {\n" + 
3796
		"	\n" + 
3797
		"	void test(X02 indexsc) {\n" + 
3798
		"		if (indexsc == null) {\n" + 
3799
		"		} else {\n" + 
3800
		"\n" + 
3801
		"			indexsc.reopenScan(\n" + 
3802
		"						searchRow,                      	// startKeyValue\n" + 
3803
		"						ScanController.GE,            		// startSearchOp\n" + 
3804
		"						null,                         		// qualifier\n" + 
3805
		"						null, 		                        // stopKeyValue\n" + 
3806
		"						ScanController.GT             		// stopSearchOp \n" + 
3807
		"						);\n" + 
3808
		"		}\n" + 
3809
		"		\n" + 
3810
		"	}\n" + 
3811
		"}\n";
3812
	formatSource(source,
3813
		"package wksp2;\n" + 
3814
		"\n" + 
3815
		"public class X02 {\n" + 
3816
		"\n" + 
3817
		"	void test(X02 indexsc) {\n" + 
3818
		"		if (indexsc == null) {\n" + 
3819
		"		} else {\n" + 
3820
		"\n" + 
3821
		"			indexsc.reopenScan(searchRow, // startKeyValue\n" + 
3822
		"					ScanController.GE, // startSearchOp\n" + 
3823
		"					null, // qualifier\n" + 
3824
		"					null, // stopKeyValue\n" + 
3825
		"					ScanController.GT // stopSearchOp\n" + 
3826
		"					);\n" + 
3827
		"		}\n" + 
3828
		"\n" + 
3829
		"	}\n" + 
3830
		"}\n"
3831
	);
3832
}
3833
3834
/**
3506
 * @bug 297225: [formatter] Indentation may be still wrong in certain circumstances after formatting
3835
 * @bug 297225: [formatter] Indentation may be still wrong in certain circumstances after formatting
3507
 * @test Verify that comment indentation is correct when there's a mix of tab and spaces in
3836
 * @test Verify that comment indentation is correct when there's a mix of tab and spaces in
3508
 * 		existing indentation and all comments formatting is off.
3837
 * 		existing indentation and all comments formatting is off.
(-)workspace/Formatter/test184/A_out.java (-8 / +6 lines)
Lines 2-14 Link Here
2
	X(String s) {
2
	X(String s) {
3
	}
3
	}
4
	protected void foo() {
4
	protected void foo() {
5
		Main
5
		Main.bind(
6
				.bind(
6
				"compile.instantTime", //$NON-NLS-1$
7
						"compile.instantTime", //$NON-NLS-1$
7
				new String[]{
8
						new String[]{
8
						String.valueOf(this.lineCount),
9
								String.valueOf(this.lineCount),
9
						String.valueOf(this.time),
10
								String.valueOf(this.time),
10
						String.valueOf(((int) (this.lineCount * 10000.0 / this.time)) / 10.0)});
11
								String
12
										.valueOf(((int) (this.lineCount * 10000.0 / this.time)) / 10.0)});
13
	}
11
	}
14
}
12
}
(-)workspace/Formatter/test187/A_out.java (-2 / +1 lines)
Lines 240-247 Link Here
240
					.append(_localFilename).append(documentCount)
240
					.append(_localFilename).append(documentCount)
241
					.append(EXTENTION)).toString();
241
					.append(EXTENTION)).toString();
242
			if (log.isDebugEnabled()) {
242
			if (log.isDebugEnabled()) {
243
				log
243
				log.debug("File already exists. Check to see if we need rename existing file");
244
						.debug("File already exists. Check to see if we need rename existing file");
245
			}
244
			}
246
			if (documentCount == 1) {
245
			if (documentCount == 1) {
247
				File backupPdfFile = new File(newFilename);
246
				File backupPdfFile = new File(newFilename);

Return to bug 264112