Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 458208 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java (+2 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Jesper S Moller - Contribution for bug 402173
10
 *     Jesper S Moller - Contribution for bug 402173
11
 *                       Contribution for bug 402892
11
 *                       Contribution for bug 402892
12
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.core.tests;
14
package org.eclipse.jdt.core.tests;
14
15
Lines 37-42 Link Here
37
		TEST_SUITES.add(FormatterCommentsClearBlankLinesTests.class);
38
		TEST_SUITES.add(FormatterCommentsClearBlankLinesTests.class);
38
		TEST_SUITES.add(FormatterJavadocDontIndentTagsTests.class);
39
		TEST_SUITES.add(FormatterJavadocDontIndentTagsTests.class);
39
		TEST_SUITES.add(FormatterJavadocDontIndentTagsDescriptionTests.class);
40
		TEST_SUITES.add(FormatterJavadocDontIndentTagsDescriptionTests.class);
41
		TEST_SUITES.add(FormatterOldBugsGistTests.class);
40
	}
42
	}
41
43
42
	public static Class[] getTestClasses() {
44
	public static Class[] getTestClasses() {
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugs18Tests.java (-3 / +4 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.formatter;
12
package org.eclipse.jdt.core.tests.formatter;
12
13
Lines 185-191 Link Here
185
			"			// nothing\n" +
186
			"			// nothing\n" +
186
			"			System.out.println(\"\");\n" +
187
			"			System.out.println(\"\");\n" +
187
			"			return \"\";\n" +
188
			"			return \"\";\n" +
188
			"		} );\n" +
189
			"		});\n" +
189
			"	}\n" +
190
			"	}\n" +
190
			"\n" +
191
			"\n" +
191
			"	public Function<String, String> testBad() {\n" +
192
			"	public Function<String, String> testBad() {\n" +
Lines 193-199 Link Here
193
			"			// nothing\n" +
194
			"			// nothing\n" +
194
			"			System.out.println(\"\");\n" +
195
			"			System.out.println(\"\");\n" +
195
			"			return \"\";\n" +
196
			"			return \"\";\n" +
196
			"		} );\n" +
197
			"		});\n" +
197
			"	}\n" +
198
			"	}\n" +
198
			"\n" +
199
			"\n" +
199
			"	public Function<String, String> foo(Function<String, String> f) {\n" +
200
			"	public Function<String, String> foo(Function<String, String> f) {\n" +
Lines 230-236 Link Here
230
			"				}\n"+
231
			"				}\n"+
231
			"			}\n"+
232
			"			}\n"+
232
			"\n"+
233
			"\n"+
233
			"		} ).start();\n"+
234
			"		}).start();\n"+
234
			"	}\n"+
235
			"	}\n"+
235
			"}\n";
236
			"}\n";
236
237
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java (-30 / +198 lines)
Lines 11-16 Link Here
11
 *     Robin Stocker - Bug 49619 - [formatting] comment formatter leaves whitespace in comments
11
 *     Robin Stocker - Bug 49619 - [formatting] comment formatter leaves whitespace in comments
12
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
12
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
13
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
13
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
14
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.jdt.core.tests.formatter;
16
package org.eclipse.jdt.core.tests.formatter;
16
17
Lines 1372-1378 Link Here
1372
// see also bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=287462
1373
// see also bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=287462
1373
public void testBug198074_dup201022() throws JavaModelException {
1374
public void testBug198074_dup201022() throws JavaModelException {
1374
	this.formatterPrefs.join_wrapped_lines = false;
1375
	this.formatterPrefs.join_wrapped_lines = false;
1375
	this.formatterPrefs.wrap_before_binary_operator = false;
1376
	String source =
1376
	String source =
1377
		"public class Test {\n" +
1377
		"public class Test {\n" +
1378
		"\n" +
1378
		"\n" +
Lines 1399-1405 Link Here
1399
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700
1399
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700
1400
public void testBug198074_dup213700() throws JavaModelException {
1400
public void testBug198074_dup213700() throws JavaModelException {
1401
	this.formatterPrefs.join_wrapped_lines = false;
1401
	this.formatterPrefs.join_wrapped_lines = false;
1402
	this.formatterPrefs.wrap_before_binary_operator = false;
1403
	String source =
1402
	String source =
1404
		"public class Test {\n" +
1403
		"public class Test {\n" +
1405
		"\n" +
1404
		"\n" +
Lines 1906-1912 Link Here
1906
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
1905
		"@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + 
1907
		"		activationConfig = {\n" + 
1906
		"		activationConfig = {\n" + 
1908
		"				@ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
1907
		"				@ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + 
1909
		"						propertyValue = \"0/10 * * * * ?\") })\n" + 
1908
		"						propertyValue = \"0/10 * * * * ?\")\n" + 
1909
		"		})\n" + 
1910
		"@RunAs(\"admin\")\n" + 
1910
		"@RunAs(\"admin\")\n" + 
1911
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
1911
		"@ResourceAdapter(\"quartz-ra.rar\")\n" + 
1912
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
1912
		"@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" + 
Lines 8041-8049 Link Here
8041
		"public class X07 {\n" + 
8041
		"public class X07 {\n" + 
8042
		"\n" + 
8042
		"\n" + 
8043
		"	static final long[] jjtoToken = {\n" + 
8043
		"	static final long[] jjtoToken = {\n" + 
8044
		"			0x7fbfecffL, };\n" + 
8044
		"			0x7fbfecffL,\n" + 
8045
		"	};\n" + 
8045
		"	static final long[] jjtoSkip = {\n" + 
8046
		"	static final long[] jjtoSkip = {\n" + 
8046
		"			0x400000L, };\n" + 
8047
		"			0x400000L,\n" + 
8048
		"	};\n" + 
8047
		"\n" + 
8049
		"\n" + 
8048
		"}\n"
8050
		"}\n"
8049
	);
8051
	);
Lines 8072-8081 Link Here
8072
		"\n" + 
8074
		"\n" + 
8073
		"	static final long[] jjtoToken =\n" + 
8075
		"	static final long[] jjtoToken =\n" + 
8074
		"	{\n" + 
8076
		"	{\n" + 
8075
		"			0x7fbfecffL, };\n" + 
8077
		"			0x7fbfecffL,\n" + 
8078
		"	};\n" + 
8076
		"	static final long[] jjtoSkip =\n" + 
8079
		"	static final long[] jjtoSkip =\n" + 
8077
		"	{\n" + 
8080
		"	{\n" + 
8078
		"			0x400000L, };\n" +
8081
		"			0x400000L,\n" +
8082
		"	};\n" + 
8079
		"\n" + 
8083
		"\n" + 
8080
		"}\n"
8084
		"}\n"
8081
	);
8085
	);
Lines 8124-8130 Link Here
8124
		"public class X09 {\n" + 
8128
		"public class X09 {\n" + 
8125
		"	public Class[] getAdapterList() {\n" + 
8129
		"	public Class[] getAdapterList() {\n" + 
8126
		"		return new Class[] {\n" + 
8130
		"		return new Class[] {\n" + 
8127
		"				IWorkbenchAdapter.class };\n" + 
8131
		"				IWorkbenchAdapter.class\n" + 
8132
		"		};\n" + 
8128
		"	}\n" + 
8133
		"	}\n" + 
8129
		"}\n"
8134
		"}\n"
8130
	);
8135
	);
Lines 8796-8802 Link Here
8796
}
8801
}
8797
public void testBug330313_wksp1_25_njl() {
8802
public void testBug330313_wksp1_25_njl() {
8798
	this.formatterPrefs.join_wrapped_lines = false;
8803
	this.formatterPrefs.join_wrapped_lines = false;
8799
	this.formatterPrefs.wrap_before_binary_operator = false;
8800
	String source =
8804
	String source =
8801
		"package wksp1;\n" + 
8805
		"package wksp1;\n" + 
8802
		"\n" + 
8806
		"\n" + 
Lines 8811-8817 Link Here
8811
}
8815
}
8812
public void testBug330313_wksp1_26_njl() {
8816
public void testBug330313_wksp1_26_njl() {
8813
	this.formatterPrefs.join_wrapped_lines = false;
8817
	this.formatterPrefs.join_wrapped_lines = false;
8814
	this.formatterPrefs.wrap_before_binary_operator = false;
8815
	String source =
8818
	String source =
8816
		"package wksp1;\n" + 
8819
		"package wksp1;\n" + 
8817
		"\n" + 
8820
		"\n" + 
Lines 8962-8968 Link Here
8962
}
8965
}
8963
public void testBug330313_wksp1_30_njl() {
8966
public void testBug330313_wksp1_30_njl() {
8964
	this.formatterPrefs.join_wrapped_lines = false;
8967
	this.formatterPrefs.join_wrapped_lines = false;
8965
	this.formatterPrefs.wrap_before_binary_operator = false;
8966
	setPageWidth80();
8968
	setPageWidth80();
8967
	String source =
8969
	String source =
8968
		"package wksp1;\n" + 
8970
		"package wksp1;\n" + 
Lines 9083-9089 Link Here
9083
}
9085
}
9084
public void testBug330313_wksp1_33_njl() {
9086
public void testBug330313_wksp1_33_njl() {
9085
	this.formatterPrefs.join_wrapped_lines = false;
9087
	this.formatterPrefs.join_wrapped_lines = false;
9086
	this.formatterPrefs.wrap_before_binary_operator = false;
9087
	String source =
9088
	String source =
9088
		"package wksp1;\n" + 
9089
		"package wksp1;\n" + 
9089
		"\n" + 
9090
		"\n" + 
Lines 9106-9113 Link Here
9106
		"	void foo() {\n" + 
9107
		"	void foo() {\n" + 
9107
		"		if (inMetaTag &&\n" + 
9108
		"		if (inMetaTag &&\n" + 
9108
		"				(t1.image.equalsIgnoreCase(\"name\") ||\n" + 
9109
		"				(t1.image.equalsIgnoreCase(\"name\") ||\n" + 
9109
		"						t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")) &&\n" + 
9110
		"						t1.image.equalsIgnoreCase(\"HTTP-EQUIV\"))\n" + 
9110
		"				t2 != null) {\n" + 
9111
		"				&& t2 != null) {\n" + 
9111
		"			currentMetaTag = t2.image.toLowerCase();\n" + 
9112
		"			currentMetaTag = t2.image.toLowerCase();\n" + 
9112
		"		}\n" + 
9113
		"		}\n" + 
9113
		"	}\n" + 
9114
		"	}\n" + 
Lines 9305-9311 Link Here
9305
		"	 * 		\"GeneralPage.DoubleClick\", resName, 1,\n" + 
9306
		"	 * 		\"GeneralPage.DoubleClick\", resName, 1,\n" + 
9306
		"	 * 		new String[][] {\n" + 
9307
		"	 * 		new String[][] {\n" + 
9307
		"	 * 				{ \"Open Browser\", \"open\" },\n" + 
9308
		"	 * 				{ \"Open Browser\", \"open\" },\n" + 
9308
		"	 * 				{ \"Expand Tree\", \"expand\" } },\n" + 
9309
		"	 * 				{ \"Expand Tree\", \"expand\" }\n" + 
9310
		"	 * 		},\n" + 
9309
		"	 * 		parent);\n" + 
9311
		"	 * 		parent);\n" + 
9310
		"	 * </pre>\n" + 
9312
		"	 * </pre>\n" + 
9311
		"	 */\n" + 
9313
		"	 */\n" + 
Lines 9337-9343 Link Here
9337
		"			/* INACTIVE */ { \"INACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + 
9339
		"			/* INACTIVE */ { \"INACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + 
9338
		"			/* PARTLY_ACTIVE */ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\",\n" + 
9340
		"			/* PARTLY_ACTIVE */ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\",\n" + 
9339
		"					\"PARTLY_ACTIVE\" },\n" + 
9341
		"					\"PARTLY_ACTIVE\" },\n" + 
9340
		"			/* ACTIVE */ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"ACTIVE\" } };\n" + 
9342
		"			/* ACTIVE */ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"ACTIVE\" }\n" + 
9343
		"	};\n" + 
9341
		"}\n"
9344
		"}\n"
9342
	);
9345
	);
9343
}
9346
}
Lines 9508-9514 Link Here
9508
		"				user,\n" + 
9511
		"				user,\n" + 
9509
		"				revision,\n" + 
9512
		"				revision,\n" + 
9510
		"				String.valueOf(delta),\n" + 
9513
		"				String.valueOf(delta),\n" + 
9511
		"				line });\n" + 
9514
		"				line\n" + 
9515
		"		});\n" + 
9512
		"	}\n" + 
9516
		"	}\n" + 
9513
		"}\n"
9517
		"}\n"
9514
	);
9518
	);
Lines 9611-9617 Link Here
9611
		"							IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR),\n" + 
9615
		"							IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR),\n" + 
9612
		"					new Color[] {\n" + 
9616
		"					new Color[] {\n" + 
9613
		"							colorRegistry.get(\n" + 
9617
		"							colorRegistry.get(\n" + 
9614
		"									IWorkbenchThemeConstants.INACTIVE_TAB_BG_START) },\n" + 
9618
		"									IWorkbenchThemeConstants.INACTIVE_TAB_BG_START)\n" + 
9619
		"					},\n" + 
9615
		"					new int[0],\n" + 
9620
		"					new int[0],\n" + 
9616
		"					true);\n" + 
9621
		"					true);\n" + 
9617
		"		}\n" + 
9622
		"		}\n" + 
Lines 9780-9786 Link Here
9780
		"								public char[][] getCompoundName() {\n" + 
9785
		"								public char[][] getCompoundName() {\n" + 
9781
		"									return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + 
9786
		"									return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + 
9782
		"								}\n" + 
9787
		"								}\n" + 
9783
		"							} },\n" + 
9788
		"							}\n" + 
9789
		"					},\n" + 
9784
		"					null);\n" + 
9790
		"					null);\n" + 
9785
		"		}\n" + 
9791
		"		}\n" + 
9786
		"	}\n" + 
9792
		"	}\n" + 
Lines 9985-9991 Link Here
9985
		"								return info.getLocal()\n" + 
9991
		"								return info.getLocal()\n" + 
9986
		"										.getType() == IResource.FILE;\n" + 
9992
		"										.getType() == IResource.FILE;\n" + 
9987
		"							}\n" + 
9993
		"							}\n" + 
9988
		"						} }),\n" + 
9994
		"						}\n" + 
9995
		"				}),\n" + 
9989
		"				// Conflicting changes of files will fail if the local is not\n" + 
9996
		"				// Conflicting changes of files will fail if the local is not\n" + 
9990
		"				// managed\n" + 
9997
		"				// managed\n" + 
9991
		"				// or is an addition\n" + 
9998
		"				// or is an addition\n" + 
Lines 10012-10018 Link Here
10012
		"								}\n" + 
10019
		"								}\n" + 
10013
		"								return false;\n" + 
10020
		"								return false;\n" + 
10014
		"							}\n" + 
10021
		"							}\n" + 
10015
		"						} }),\n" + 
10022
		"						}\n" + 
10023
		"				}),\n" + 
10016
		"				// Conflicting changes involving a deletion on one side will\n" + 
10024
		"				// Conflicting changes involving a deletion on one side will\n" + 
10017
		"				// aways fail\n" + 
10025
		"				// aways fail\n" + 
10018
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
10026
		"				new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + 
Lines 10031-10037 Link Here
10031
		"											&& !base.equals(remote));\n" + 
10039
		"											&& !base.equals(remote));\n" + 
10032
		"								}\n" + 
10040
		"								}\n" + 
10033
		"							}\n" + 
10041
		"							}\n" + 
10034
		"						} }),\n" + 
10042
		"						}\n" + 
10043
		"				}),\n" + 
10035
		"				// Conflicts where the file type is binary will work but are not\n" + 
10044
		"				// Conflicts where the file type is binary will work but are not\n" + 
10036
		"				// merged\n" + 
10045
		"				// merged\n" + 
10037
		"				// so they should be skipped\n" + 
10046
		"				// so they should be skipped\n" + 
Lines 10060-10068 Link Here
10060
		"								}\n" + 
10069
		"								}\n" + 
10061
		"								return false;\n" + 
10070
		"								return false;\n" + 
10062
		"							}\n" + 
10071
		"							}\n" + 
10063
		"						} }),\n" + 
10072
		"						}\n" + 
10073
		"				}),\n" + 
10064
		"				// Outgoing changes may not fail but they are skipped as well\n" + 
10074
		"				// Outgoing changes may not fail but they are skipped as well\n" + 
10065
		"				new SyncInfoDirectionFilter(SyncInfo.OUTGOING) });\n" + 
10075
		"				new SyncInfoDirectionFilter(SyncInfo.OUTGOING)\n" + 
10076
		"		});\n" + 
10066
		"	}\n" + 
10077
		"	}\n" + 
10067
		"}\n"
10078
		"}\n"
10068
	);
10079
	);
Lines 10113-10119 Link Here
10113
		"					{ 104, 20 },\n" + 
10124
		"					{ 104, 20 },\n" + 
10114
		"					{ 108, 21 },\n" + 
10125
		"					{ 108, 21 },\n" + 
10115
		"					{ 12, 1856 },\n" + 
10126
		"					{ 12, 1856 },\n" + 
10116
		"					{ 13, 1920 } }, };\n" + 
10127
		"					{ 13, 1920 } },\n" + 
10128
		"	};\n" + 
10117
		"}\n"
10129
		"}\n"
10118
	);
10130
	);
10119
}
10131
}
Lines 10254-10260 Link Here
10254
		"					UNKNOWN,\n" + 
10266
		"					UNKNOWN,\n" + 
10255
		"					UNKNOWN,\n" + 
10267
		"					UNKNOWN,\n" + 
10256
		"					UNKNOWN,\n" + 
10268
		"					UNKNOWN,\n" + 
10257
		"					UNKNOWN } };\n" + 
10269
		"					UNKNOWN }\n" + 
10270
		"	};\n" + 
10258
		"\n" + 
10271
		"\n" + 
10259
		"}\n"
10272
		"}\n"
10260
	);
10273
	);
Lines 10300-10306 Link Here
10300
		"					\"READ_POTENTIAL\",\n" + 
10313
		"					\"READ_POTENTIAL\",\n" + 
10301
		"					\"UNKNOWN\",\n" + 
10314
		"					\"UNKNOWN\",\n" + 
10302
		"					\"UNKNOWN\",\n" + 
10315
		"					\"UNKNOWN\",\n" + 
10303
		"					\"UNKNOWN\" }, };\n" + 
10316
		"					\"UNKNOWN\" },\n" + 
10317
		"	};\n" + 
10304
		"\n" + 
10318
		"\n" + 
10305
		"}\n"
10319
		"}\n"
10306
	);
10320
	);
Lines 10348-10354 Link Here
10348
		"					\"READ_POTENTIAL\",\n" + 
10362
		"					\"READ_POTENTIAL\",\n" + 
10349
		"					\"UNKNOWN\",\n" + 
10363
		"					\"UNKNOWN\",\n" + 
10350
		"					\"UNKNOWN\",\n" + 
10364
		"					\"UNKNOWN\",\n" + 
10351
		"					\"UNKNOWN\" }, };\n" + 
10365
		"					\"UNKNOWN\" },\n" + 
10366
		"	};\n" + 
10352
		"\n" + 
10367
		"\n" + 
10353
		"}\n"
10368
		"}\n"
10354
	);
10369
	);
Lines 10389-10395 Link Here
10389
		"                    \"1234567890123456789012345678901234567890\" },\n" + 
10404
		"                    \"1234567890123456789012345678901234567890\" },\n" + 
10390
		"            /* Comment 3 */ {\n" + 
10405
		"            /* Comment 3 */ {\n" + 
10391
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\",\n" + 
10406
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\",\n" + 
10392
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" }, };\n" + 
10407
		"                    \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + 
10408
		"    };\n" + 
10393
		"\n" + 
10409
		"\n" + 
10394
		"}\n"
10410
		"}\n"
10395
	);
10411
	);
Lines 10720-10724 Link Here
10720
	String source = "/**/int f;";
10736
	String source = "/**/int f;";
10721
	formatSource(source, source, CodeFormatter.K_STATEMENTS);
10737
	formatSource(source, source, CodeFormatter.K_STATEMENTS);
10722
}
10738
}
10723
10739
/**
10740
 * @bug 458208: [formatter] follow up bug for comments 
10741
 * @test test a space is not added after a lambda expression in parenthesis
10742
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=458208#c2"
10743
 */
10744
public void testBug458208() throws Exception {
10745
	String source =
10746
		"package p;\n" + 
10747
		"import java.util.function.IntConsumer;\n" + 
10748
		"class TestInlineLambda1 {\n" + 
10749
		"	{\n" + 
10750
		"		IntConsumer op = (x -> {}    );\n" + 
10751
		"	}\n" + 
10752
		"}\n";
10753
	formatSource(source,
10754
		"package p;\n" + 
10755
		"\n" + 
10756
		"import java.util.function.IntConsumer;\n" + 
10757
		"\n" + 
10758
		"class TestInlineLambda1 {\n" + 
10759
		"	{\n" + 
10760
		"		IntConsumer op = (x -> {\n" + 
10761
		"		});\n" + 
10762
		"	}\n" + 
10763
		"}\n"
10764
	);
10765
}
10766
/**
10767
 * @bug 458208: [formatter] follow up bug for comments 
10768
 * @test test that comments in switch statements are properly indented
10769
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=458208#c21"
10770
 */
10771
public void testBug458208b() throws Exception {
10772
	formatSource(
10773
		"package p;\n" + 
10774
		"\n" + 
10775
		"public class C1 {\n" + 
10776
		"	void foo(int x) {\n" + 
10777
		"		switch (x) {\n" + 
10778
		"		// case 1\n" + 
10779
		"		case 1:\n" + 
10780
		"			break;\n" + 
10781
		"		// case 2\n" + 
10782
		"		case 2:\n" + 
10783
		"			break;\n" + 
10784
		"		// no more cases\n" + 
10785
		"		}\n" + 
10786
		"	}\n" + 
10787
		"\n" + 
10788
		"	int bar(int x) {\n" + 
10789
		"		while (true) {\n" + 
10790
		"			int y = 9;\n" + 
10791
		"			switch (x) {\n" + 
10792
		"			// case 1\n" + 
10793
		"			case 1:\n" + 
10794
		"				// should return\n" + 
10795
		"				return y;\n" + 
10796
		"			// case 2\n" + 
10797
		"			case 2:\n" + 
10798
		"				// should break\n" + 
10799
		"				break;\n" + 
10800
		"			case 3:\n" + 
10801
		"				// TODO\n" + 
10802
		"			}\n" + 
10803
		"		}\n" + 
10804
		"	}\n" + 
10805
		"}\n"
10806
	);
10807
}
10808
/**
10809
 * @bug 458208: [formatter] follow up bug for comments 
10810
 * @test test that elements separated with empty lines are properly indented
10811
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=458208#c18"
10812
 */
10813
public void testBug458208c() throws Exception {
10814
	final int wrapAllOnColumn = Alignment.M_NEXT_PER_LINE_SPLIT + Alignment.M_INDENT_ON_COLUMN + Alignment.M_FORCE;
10815
	this.formatterPrefs.alignment_for_enum_constants = wrapAllOnColumn;
10816
	this.formatterPrefs.alignment_for_arguments_in_enum_constant = wrapAllOnColumn;
10817
	this.formatterPrefs.alignment_for_expressions_in_array_initializer = wrapAllOnColumn;
10818
	String source = 
10819
		"package p;\n" + 
10820
		"\n" + 
10821
		"public enum TestEnum {\n" + 
10822
		"	FIRST_ENUM(\"first type\",\n" + 
10823
		"	           new SomeClass(),\n" + 
10824
		"	           new OtherEnumType[] { OtherEnumType.FOO }),\n" + 
10825
		"\n" + 
10826
		"	SECOND_ENUM(\"second type\",\n" + 
10827
		"	            new SomeClassOtherClass(),\n" + 
10828
		"	            new OtherEnumType[] { OtherEnumType.BAR }),\n" + 
10829
		"\n" + 
10830
		"	THIRD_ENUM(\"third type\",\n" + 
10831
		"	            new YetAnotherClass(),\n" + 
10832
		"	            new OtherEnumType[] { OtherEnumType.FOOBAR,\n" + 
10833
		"	                                  OtherEnumType.FOOBARBAZ,\n" + 
10834
		"\n" + 
10835
		"	                                  OtherEnumType.LONGERFOOBARBAZ,\n" + 
10836
		"	                                  OtherEnumType.MORELETTERSINHERE });\n" + 
10837
		"\n" + 
10838
		"	/* data members and methods go here */\n" + 
10839
		"	TestEnum(String s, Cls s1, OtherEnumType[] e) {\n" + 
10840
		"	}\n" + 
10841
		"}";
10842
	formatSource(source,
10843
		"package p;\n" + 
10844
		"\n" + 
10845
		"public enum TestEnum {\n" + 
10846
		"						FIRST_ENUM(	\"first type\",\n" + 
10847
		"									new SomeClass(),\n" + 
10848
		"									new OtherEnumType[] { OtherEnumType.FOO }),\n" + 
10849
		"\n" + 
10850
		"						SECOND_ENUM(\"second type\",\n" + 
10851
		"									new SomeClassOtherClass(),\n" + 
10852
		"									new OtherEnumType[] { OtherEnumType.BAR }),\n" + 
10853
		"\n" + 
10854
		"						THIRD_ENUM(	\"third type\",\n" + 
10855
		"									new YetAnotherClass(),\n" + 
10856
		"									new OtherEnumType[] {	OtherEnumType.FOOBAR,\n" + 
10857
		"															OtherEnumType.FOOBARBAZ,\n" + 
10858
		"\n" + 
10859
		"															OtherEnumType.LONGERFOOBARBAZ,\n" + 
10860
		"															OtherEnumType.MORELETTERSINHERE });\n" + 
10861
		"\n" + 
10862
		"	/* data members and methods go here */\n" + 
10863
		"	TestEnum(String s, Cls s1, OtherEnumType[] e) {\n" + 
10864
		"	}\n" + 
10865
		"}"
10866
	);
10867
}
10868
/**
10869
 * @bug 458208: [formatter] follow up bug for comments 
10870
 * @test test that enum constants are not indented with spaces when "Use spaces to indent wrapped lines" is on
10871
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=458208#c24"
10872
 */
10873
public void testBug458208d() throws Exception {
10874
	this.formatterPrefs.alignment_for_enum_constants = Alignment.M_COMPACT_SPLIT;
10875
	this.formatterPrefs.use_tabs_only_for_leading_indentations = true;
10876
	setPageWidth80();
10877
	String source = 
10878
		"package p;\n" + 
10879
		"\n" + 
10880
		"public enum TestEnum {\n" + 
10881
		"	ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, ELEVEN, TWELWE, THIRTEEN, FOURTEEN, FIFTEEN;\n" + 
10882
		"}";
10883
	formatSource(source,
10884
		"package p;\n" + 
10885
		"\n" + 
10886
		"public enum TestEnum {\n" + 
10887
		"	ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, ELEVEN, TWELWE,\n" + 
10888
		"	THIRTEEN, FOURTEEN, FIFTEEN;\n" + 
10889
		"}"
10890
	);
10891
}
10724
}
10892
}
(-)a/org.eclipse.jdt.core/eclipse.jdt.ui.patch.txt (-4 lines)
Lines 1-114 Link Here
1
### Eclipse Workspace Patch 1.0
2
#P org.eclipse.jdt.ui
3
diff --git ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java
4
index bbcb3bb..949bf62 100644
(-)a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java (-1 / +2 lines)
Lines 11-16 Link Here
11
 *								bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code
11
 *								bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code
12
 *     Harry Terkelsen (het@google.com) - Bug 449262 - Allow the use of third-party Java formatters
12
 *     Harry Terkelsen (het@google.com) - Bug 449262 - Allow the use of third-party Java formatters
13
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
13
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
14
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.jdt.internal.formatter;
16
package org.eclipse.jdt.internal.formatter;
16
17
Lines 369-375 Link Here
369
	private void prepareWraps(int kind) {
370
	private void prepareWraps(int kind) {
370
		WrapPreparator wrapPreparator = new WrapPreparator(this.tokenManager, this.workingOptions, kind);
371
		WrapPreparator wrapPreparator = new WrapPreparator(this.tokenManager, this.workingOptions, kind);
371
		this.astRoot.accept(wrapPreparator);
372
		this.astRoot.accept(wrapPreparator);
372
		wrapPreparator.finishUp();
373
		wrapPreparator.finishUp(this.astRoot);
373
	}
374
	}
374
375
375
	/**
376
	/**
(-)a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java (-32 / +29 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
11
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.formatter;
13
package org.eclipse.jdt.internal.formatter;
13
14
Lines 54-59 Link Here
54
import org.eclipse.jdt.core.dom.Modifier;
55
import org.eclipse.jdt.core.dom.Modifier;
55
import org.eclipse.jdt.core.dom.NormalAnnotation;
56
import org.eclipse.jdt.core.dom.NormalAnnotation;
56
import org.eclipse.jdt.core.dom.PackageDeclaration;
57
import org.eclipse.jdt.core.dom.PackageDeclaration;
58
import org.eclipse.jdt.core.dom.ReturnStatement;
57
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
59
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
58
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
60
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
59
import org.eclipse.jdt.core.dom.Statement;
61
import org.eclipse.jdt.core.dom.Statement;
Lines 291-325 Link Here
291
		handleBracedCode(node, node.getExpression(), this.options.brace_position_for_switch,
293
		handleBracedCode(node, node.getExpression(), this.options.brace_position_for_switch,
292
				this.options.indent_switchstatements_compare_to_switch, true);
294
				this.options.indent_switchstatements_compare_to_switch, true);
293
295
296
		List<Statement> statements = node.statements();
294
		if (this.options.indent_switchstatements_compare_to_cases) {
297
		if (this.options.indent_switchstatements_compare_to_cases) {
295
			int openBraceIndex = this.tm.firstIndexIn(node, TokenNameLBRACE);
298
			int nonBreakStatementEnd = -1;
296
			this.tm.get(openBraceIndex + 1).indent();
299
			for (Statement statement : statements) {
297
			int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
300
				if (statement instanceof SwitchCase) {
298
			this.tm.get(closeBraceIndex).unindent();
301
					if (nonBreakStatementEnd >= 0) {
302
						// indent only comments between previous and current statement
303
						this.tm.get(nonBreakStatementEnd + 1).indent();
304
						this.tm.firstTokenIn(statement, -1).unindent();
305
					}
306
				} else if (!(statement instanceof BreakStatement || statement instanceof Block)) {
307
					indent(statement);
308
				}
309
				nonBreakStatementEnd = (statement instanceof BreakStatement || statement instanceof ReturnStatement)
310
						? -1 : this.tm.lastIndexIn(statement, -1);
311
			}
312
			if (nonBreakStatementEnd >= 0) {
313
				// indent comments between last statement and closing brace 
314
				this.tm.get(nonBreakStatementEnd + 1).indent();
315
				this.tm.lastTokenIn(node, TokenNameRBRACE).unindent();
316
			}
317
		}
318
		if (this.options.indent_breaks_compare_to_cases) {
319
			for (Statement statement : statements) {
320
				if (statement instanceof BreakStatement)
321
					indent(statement);
322
			}
299
		}
323
		}
300
324
301
		boolean isBreakStatement = false;
302
		List<Statement> statements = node.statements();
303
		for (Statement statement : statements) {
325
		for (Statement statement : statements) {
304
			if (isBreakStatement) // actually, was break statement
305
				this.tm.firstTokenIn(statement, -1).indent();
306
			isBreakStatement = statement instanceof BreakStatement;
307
			if (this.options.indent_switchstatements_compare_to_cases
308
					&& (isBreakStatement || statement instanceof SwitchCase || statement instanceof Block)) {
309
				unindent(statement);
310
			}
311
			if (statement instanceof Block)
326
			if (statement instanceof Block)
312
				continue; // will add break in visit(Block) if necessary
327
				continue; // will add break in visit(Block) if necessary
313
			if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
328
			if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
314
				breakLineBefore(statement);
329
				breakLineBefore(statement);
315
			if (isBreakStatement) {
316
				if (this.options.indent_breaks_compare_to_cases)
317
					indent(statement);
318
				this.tm.firstTokenAfter(statement, -1).unindent();
319
			}
320
		}
330
		}
321
		if (isBreakStatement) // actually, was break statement
322
			this.tm.lastTokenIn(node, -1).indent();
323
331
324
		return true;
332
		return true;
325
	}
333
	}
Lines 569-591 Link Here
569
577
570
	private void indent(ASTNode node) {
578
	private void indent(ASTNode node) {
571
		int startIndex = this.tm.firstIndexIn(node, -1);
579
		int startIndex = this.tm.firstIndexIn(node, -1);
572
		while (startIndex > 0 && this.tm.get(startIndex - 1).isComment()
580
		while (startIndex > 0 && this.tm.get(startIndex - 1).isComment())
573
				&& !(node.getParent() instanceof SwitchStatement))
574
			startIndex--;
581
			startIndex--;
575
		this.tm.get(startIndex).indent();
582
		this.tm.get(startIndex).indent();
576
		int lastIndex = this.tm.lastIndexIn(node, -1);
583
		int lastIndex = this.tm.lastIndexIn(node, -1);
577
		if (lastIndex + 1 < this.tm.size())
584
		if (lastIndex + 1 < this.tm.size())
578
			this.tm.get(lastIndex + 1).unindent();
585
			this.tm.get(lastIndex + 1).unindent();
579
	}
580
581
	private void unindent(ASTNode node) {
582
		int startIndex = this.tm.firstIndexIn(node, -1);
583
		// no symmetry with indent(): unindent is only used in switch statement
584
		// and should not include preceding comments
585
		this.tm.get(startIndex).unindent();
586
		int lastIndex = this.tm.lastIndexIn(node, -1);
587
		if (lastIndex + 1 < this.tm.size())
588
			this.tm.get(lastIndex + 1).indent();
589
	}
586
	}
590
587
591
	public void finishUp() {
588
	public void finishUp() {
(-)a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java (-3 / +6 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] IndexOutOfBoundsException in TokenManager - https://bugs.eclipse.org/462945
11
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.formatter;
13
package org.eclipse.jdt.internal.formatter;
13
14
Lines 497-505 Link Here
497
		handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
498
		handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
498
		if (this.options.insert_space_after_closing_brace_in_block) {
499
		if (this.options.insert_space_after_closing_brace_in_block) {
499
			int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
500
			int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
500
			if (closeBraceIndex + 1 < this.tm.size()
501
			if (closeBraceIndex + 1 < this.tm.size()) {
501
					&& this.tm.get(closeBraceIndex + 1).tokenType != TokenNameSEMICOLON)
502
				int nextToken = this.tm.get(closeBraceIndex + 1).tokenType;
502
				this.tm.get(closeBraceIndex).spaceAfter();
503
				if (nextToken != TokenNameSEMICOLON && nextToken != TokenNameRPAREN)
504
					this.tm.get(closeBraceIndex).spaceAfter();
505
			}
503
		}
506
		}
504
		return true;
507
		return true;
505
	}
508
	}
(-)a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapExecutor.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter.linewrap;
12
package org.eclipse.jdt.internal.formatter.linewrap;
12
13
Lines 631-637 Link Here
631
632
632
	int getWrapIndent(Token token) {
633
	int getWrapIndent(Token token) {
633
		WrapPolicy policy = token.getWrapPolicy();
634
		WrapPolicy policy = token.getWrapPolicy();
634
		if (policy == null || (token.getLineBreaksBefore() > 1 && !policy.isForced))
635
		if (policy == null || (token.getLineBreaksBefore() > 1 && !policy.isForced && !policy.isTopPriority()))
635
			return token.getIndent(); // no additional indentation after an empty line
636
			return token.getIndent(); // no additional indentation after an empty line
636
637
637
		if (this.options.never_indent_line_comments_on_first_column && token.tokenType == TokenNameCOMMENT_LINE
638
		if (this.options.never_indent_line_comments_on_first_column && token.tokenType == TokenNameCOMMENT_LINE
(-)a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java (-9 / +46 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
9
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] Formatter does not format Java code correctly, especially when max line width is set - https://bugs.eclipse.org/303519
10
 *     Mateusz Matela <mateusz.matela@gmail.com> - [formatter] follow up bug for comments - https://bugs.eclipse.org/458208
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter.linewrap;
12
package org.eclipse.jdt.internal.formatter.linewrap;
12
13
Lines 20-29 Link Here
20
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameLPAREN;
21
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameLPAREN;
21
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameOR;
22
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameOR;
22
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameQUESTION;
23
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameQUESTION;
24
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameRBRACE;
23
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameRPAREN;
25
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameRPAREN;
24
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameStringLiteral;
26
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameStringLiteral;
25
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameextends;
27
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameextends;
26
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameimplements;
28
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameimplements;
29
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameIdentifier;
27
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamenew;
30
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamenew;
28
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamethrows;
31
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamethrows;
29
32
Lines 358-371 Link Here
358
			if (operand instanceof InfixExpression && samePrecedence(node, (InfixExpression) operand)) {
361
			if (operand instanceof InfixExpression && samePrecedence(node, (InfixExpression) operand)) {
359
				findTokensToWrap((InfixExpression) operand, depth + 1);
362
				findTokensToWrap((InfixExpression) operand, depth + 1);
360
			}
363
			}
361
			if (this.options.wrap_before_binary_operator) {
364
			int indexBefore = this.tm.firstIndexBefore(operand, -1);
362
				int index = this.tm.firstIndexBefore(operand, -1);
365
			while (this.tm.get(indexBefore).isComment())
363
				while (this.tm.get(index).isComment())
366
				indexBefore--;
364
					index--;
367
			assert node.getOperator().toString().equals(this.tm.toString(indexBefore));
365
				assert node.getOperator().toString().equals(this.tm.toString(index));
368
			int indexAfter = this.tm.firstIndexIn(operand, -1);
366
				this.wrapIndexes.add(index);
369
			this.wrapIndexes.add(this.options.wrap_before_binary_operator ? indexBefore : indexAfter);
367
			} else {
370
368
				this.wrapIndexes.add(this.tm.firstIndexIn(operand, -1));
371
			if (!this.options.join_wrapped_lines) {
372
				// TODO there should be an option for never joining wraps on opposite side of the operator
373
				if (this.options.wrap_before_binary_operator) {
374
					if (this.tm.countLineBreaksBetween(this.tm.get(indexAfter - 1), this.tm.get(indexAfter)) > 0)
375
						this.wrapIndexes.add(indexAfter);
376
				} else {
377
					if (this.tm.countLineBreaksBetween(this.tm.get(indexBefore), this.tm.get(indexBefore - 1)) > 0)
378
						this.wrapIndexes.add(indexBefore);
379
				}
369
			}
380
			}
370
		}
381
		}
371
	}
382
	}
Lines 397-402 Link Here
397
			this.wrapParentIndex = this.tm.firstIndexBefore(expressions.get(0), TokenNameLBRACE);
408
			this.wrapParentIndex = this.tm.firstIndexBefore(expressions.get(0), TokenNameLBRACE);
398
			this.wrapGroupEnd = this.tm.lastIndexIn(node, -1);
409
			this.wrapGroupEnd = this.tm.lastIndexIn(node, -1);
399
			handleWrap(this.options.alignment_for_expressions_in_array_initializer, node);
410
			handleWrap(this.options.alignment_for_expressions_in_array_initializer, node);
411
		}
412
		if (!this.options.join_wrapped_lines
413
				&& !this.options.insert_new_line_before_closing_brace_in_array_initializer) {
414
			// if there is a line break before the closing brace, formatter should treat it as a valid wrap to preserve
415
			int closingBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
416
			Token closingBrace = this.tm.get(closingBraceIndex);
417
			if (this.tm.countLineBreaksBetween(this.tm.get(closingBraceIndex - 1), closingBrace) == 1) {
418
				int openingBraceIndex = this.tm.firstIndexIn(node, TokenNameLBRACE);
419
				closingBrace.setWrapPolicy(
420
						new WrapPolicy(0, openingBraceIndex, this.currentDepth, 1, true, false, -1, false));
421
			}
400
		}
422
		}
401
		return true;
423
		return true;
402
	}
424
	}
Lines 679-690 Link Here
679
				indentOnColumn, topPriorityGroupEnd, false);
701
				indentOnColumn, topPriorityGroupEnd, false);
680
	}
702
	}
681
703
682
	public void finishUp() {
704
	public void finishUp(ASTNode astRoot) {
683
		preserveExistingLineBreaks();
705
		preserveExistingLineBreaks();
684
		new WrapExecutor(this.tm, this.options).executeWraps();
706
		new WrapExecutor(this.tm, this.options).executeWraps();
685
		if (this.fieldAligner != null)
707
		if (this.fieldAligner != null)
686
			this.fieldAligner.alignComments();
708
			this.fieldAligner.alignComments();
687
		wrapComments();
709
		wrapComments();
710
		fixEnumConstantIndents(astRoot);
688
	}
711
	}
689
712
690
	private void preserveExistingLineBreaks() {
713
	private void preserveExistingLineBreaks() {
Lines 769-772 Link Here
769
			}
792
			}
770
		}
793
		}
771
	}
794
	}
795
796
	private void fixEnumConstantIndents(ASTNode astRoot) {
797
		if (this.options.use_tabs_only_for_leading_indentations) {
798
			// enum constants should be indented like other declarations, not like wrapped elements
799
			astRoot.accept(new ASTVisitor() {
800
801
				@Override
802
				public boolean visit(EnumConstantDeclaration node) {
803
					WrapPreparator.this.tm.firstTokenIn(node, TokenNameIdentifier).setWrapPolicy(null);
804
					return true;
805
				}
806
			});
807
		}
808
	}
772
}
809
}

Return to bug 458208