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

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-3 / +17 lines)
Lines 1394-1401 Link Here
1394
				this.scribe.scanner.currentPosition);
1394
				this.scribe.scanner.currentPosition);
1395
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1395
		this.scribe.enterAlignment(cascadingMessageSendAlignment);
1396
		boolean ok = false;
1396
		boolean ok = false;
1397
		boolean setStartingColumn = startingPositionInCascade == 1;
1398
		switch (this.preferences.alignment_for_arguments_in_method_invocation) {
1399
			case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
1400
			case Alignment.M_NEXT_SHIFTED_SPLIT:
1401
			case Alignment.M_ONE_PER_LINE_SPLIT:
1402
				setStartingColumn = false;
1403
				break;
1404
		}
1397
		do {
1405
		do {
1398
			if (startingPositionInCascade == 1) {
1406
			if (setStartingColumn) {
1399
				cascadingMessageSendAlignment.startingColumn = this.scribe.column;
1407
				cascadingMessageSendAlignment.startingColumn = this.scribe.column;
1400
			}
1408
			}
1401
			try {
1409
			try {
Lines 4083-4097 Link Here
4083
			Alignment messageAlignment = null;
4091
			Alignment messageAlignment = null;
4084
			if (!messageSend.receiver.isImplicitThis()) {
4092
			if (!messageSend.receiver.isImplicitThis()) {
4085
				messageSend.receiver.traverse(this, scope);
4093
				messageSend.receiver.traverse(this, scope);
4094
				int alignmentMode = this.preferences.alignment_for_selector_in_method_invocation;
4086
				messageAlignment = this.scribe.createAlignment(
4095
				messageAlignment = this.scribe.createAlignment(
4087
						"messageAlignment", //$NON-NLS-1$
4096
						"messageAlignment", //$NON-NLS-1$
4088
						this.preferences.alignment_for_selector_in_method_invocation,
4097
						alignmentMode,
4089
						1,
4098
						1,
4090
						this.scribe.scanner.currentPosition);
4099
						this.scribe.scanner.currentPosition);
4091
				this.scribe.enterAlignment(messageAlignment);
4100
				this.scribe.enterAlignment(messageAlignment);
4092
				boolean ok = false;
4101
				boolean ok = false;
4093
				do {
4102
				do {
4094
					messageAlignment.startingColumn = this.scribe.column;
4103
					switch (alignmentMode) {
4104
						case Alignment.M_COMPACT_SPLIT:
4105
						case Alignment.M_NEXT_PER_LINE_SPLIT:
4106
							messageAlignment.startingColumn = this.scribe.column;
4107
							break;
4108
					}
4095
					try {
4109
					try {
4096
						formatMessageSend(messageSend, scope, messageAlignment);
4110
						formatMessageSend(messageSend, scope, messageAlignment);
4097
						ok = true;
4111
						ok = true;
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (+89 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.formatter.IndentManipulation;
19
import org.eclipse.jdt.core.formatter.IndentManipulation;
20
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
20
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
21
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
21
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
22
import org.eclipse.jdt.internal.formatter.align.Alignment;
22
23
23
public class FormatterBugsTests extends FormatterRegressionTests {
24
public class FormatterBugsTests extends FormatterRegressionTests {
24
25
Lines 4018-4021 Link Here
4018
		"}\n"
4019
		"}\n"
4019
	);
4020
	);
4020
}
4021
}
4022
4023
/**
4024
 * @bug 302552: [Formatter] Wrap when necessary too aggressive on short qualifiers
4025
 * @test 
4026
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302552"
4027
 */
4028
public void testBug302552_LW0() {
4029
	this.formatterPrefs.page_width = 20;
4030
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NO_ALIGNMENT;
4031
	String source = 
4032
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4033
	formatSource(source,
4034
		"class Sample2 {\n" + 
4035
		"	int foo(Some a) {\n" + 
4036
		"		return a.getFirst();\n" + 
4037
		"	}\n" + 
4038
		"}\n"
4039
	);
4040
}
4041
public void testBug302552_LW1() {
4042
	this.formatterPrefs.page_width = 20;
4043
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_COMPACT_SPLIT;
4044
	String source = 
4045
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4046
	formatSource(source,
4047
		"class Sample2 {\n" + 
4048
		"	int foo(Some a) {\n" + 
4049
		"		return a.getFirst();\n" + 
4050
		"	}\n" + 
4051
		"}\n"
4052
	);
4053
}
4054
public void testBug302552_LW2() {
4055
	this.formatterPrefs.page_width = 20;
4056
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
4057
	String source = 
4058
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4059
	formatSource(source,
4060
		"class Sample2 {\n" + 
4061
		"	int foo(Some a) {\n" + 
4062
		"		return a\n" + 
4063
		"				.getFirst();\n" + 
4064
		"	}\n" + 
4065
		"}\n"
4066
	);
4067
}
4068
public void testBug302552_LW3() {
4069
	this.formatterPrefs.page_width = 20;
4070
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_ONE_PER_LINE_SPLIT;
4071
	String source = 
4072
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4073
	formatSource(source,
4074
		"class Sample2 {\n" + 
4075
		"	int foo(Some a) {\n" + 
4076
		"		return a\n" + 
4077
		"				.getFirst();\n" + 
4078
		"	}\n" + 
4079
		"}\n"
4080
	);
4081
}
4082
public void testBug302552_LW4() {
4083
	this.formatterPrefs.page_width = 20;
4084
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NEXT_SHIFTED_SPLIT;
4085
	String source = 
4086
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4087
	formatSource(source,
4088
		"class Sample2 {\n" + 
4089
		"	int foo(Some a) {\n" + 
4090
		"		return a\n" + 
4091
		"				.getFirst();\n" + 
4092
		"	}\n" + 
4093
		"}\n"
4094
	);
4095
}
4096
public void testBug302552_LW5() {
4097
	this.formatterPrefs.page_width = 20;
4098
	this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NEXT_PER_LINE_SPLIT;
4099
	String source = 
4100
		"class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
4101
	formatSource(source,
4102
		"class Sample2 {\n" + 
4103
		"	int foo(Some a) {\n" + 
4104
		"		return a.getFirst();\n" + 
4105
		"	}\n" + 
4106
		"}\n"
4107
	);
4108
}
4109
4021
}
4110
}

Return to bug 302552