Bug 104796 [formatter] Indentation BREAKS if a inline class is built inside a switch-case statement
If I try to create a new class inline from an interface for examle (actionListener, Runnable, etc...) it normally works right and the indentation (highlighting everything and hitting CTRL-I) works just right like // Runnable with correct indentation new Runnable() { public void run() { // Do nothing } }; If instead I try to do this inside a switch case statement, after the methods, the }; closing the class gets WRONG indentation and all the indentation after this gets bugges like this: // Runnable with bugged indentation due to case new Runnable() { public void run() { // Do nothing } }; // bug here Minimal test case provided: public class IndentationSwitchCaseBug { public static void IBreakIndentation() { // Runnable with correct indentation new Runnable() { public void run() { // Do nothing } }; int i = 5; switch (i) { case 0: // Indentation works right here break; case 1: // Runnable with bugged indentation due to case new Runnable() { public void run() { // Do nothing } }; // You can see the indentation gets bugged when a runnable // is used inside a switch-case statemente break; } } }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java
* the content in <code>fDocument</code> in the range [start, indent),
	 * with every character replaced by a space except for tabs, which are kept
	 * as such.
	 * <p>
	 * If <code>convertSpaceRunsToTabs</code> is <code>true</code>, every
	 * run of the number of spaces that make up a tab are replaced by a tab
	 * character. If it is not set, no conversion takes place, but tabs in the
	 * original range are still copied verbatim.
	 * </p>
	 *
	 * @param start the start of the document region to copy the indent from
	 * @param indent the exclusive end of the document region to copy the indent
	 *        from
	 * @param convertSpaceRunsToTabs whether to convert consecutive runs of
	 *        spaces to tabs
	 * @return the indentation corresponding to the document content specified
	 *         by <code>start</code> and <code>indent</code>
	 */
	private StringBuffer createIndent(int start, final int indent, final boolean convertSpaceRunsToTabs) {
		final boolean convertTabs= prefUseTabs() && convertSpaceRunsToTabs;
		final int tabLen= prefTabSize();
		final StringBuffer ret= new StringBuffer();
		try {
			int spaces= 0;
			while (start < indent) {
				char ch= fDocument.getChar(start);
				if (ch == '\t') {
					ret.append('\t');
					spaces= 0;
				} else if (convertTabs) {