Bug 479898 - [formatter] removes whitespace between final and first exception in multi-line multi-catch
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
index ced990a..5e31729 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -12304,4 +12304,20 @@
"}"
);
}
-}
\ No newline at end of file
+/**
+ * https://bugs.eclipse.org/479898 - [formatter] removes whitespace between final and first exception in multi-line multi-catch
+ */
+public void testBug479898() {
+ this.formatterPrefs.alignment_for_union_type_in_multicatch = Alignment.M_COMPACT_SPLIT + Alignment.M_INDENT_ON_COLUMN;
+ String source =
+ "public class FormattingTest {\r\n" +
+ " public void formatterTest() {\r\n" +
+ " try {\r\n" +
+ " } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException\r\n" +
+ " | NoSuchMethodException e) {\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ "}";
+ formatSource(source);
+}
+}
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
index 1d24564..e128b03 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 Mateusz Matela and others.
+ * Copyright (c) 2014, 2016 Mateusz Matela and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -656,7 +656,9 @@
this.secondaryWrapIndexes.add(this.tm.firstIndexIn(type, -1));
}
}
- this.wrapParentIndex = this.tm.firstIndexBefore(node, TokenNameLPAREN);
+ this.wrapParentIndex = this.tm.firstIndexBefore(node, -1);
+ while (this.tm.get(this.wrapParentIndex).isComment())
+ this.wrapParentIndex--;
this.wrapGroupEnd = this.tm.lastIndexIn(types.get(types.size() - 1), -1);
handleWrap(this.options.alignment_for_union_type_in_multicatch);
} else {