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
}
	/**
	 * Returns the reference position regarding to indentation for <code>position</code>,
	 * or <code>NOT_FOUND</code>.
	 *
	 * <p>If <code>peekNextChar</code> is <code>true</code>, the next token after
	 * <code>offset</code> is read and taken into account when computing the
	 * indentation. Currently, if the next token is the first token on the line
	 * (i.e. only preceded by whitespace), the following tokens are specially
	 * handled:
	 * <ul>
	 * 	<li><code>switch</code> labels are indented relative to the switch block</li>
	 * 	<li>opening curly braces are aligned correctly with the introducing code</li>
	 * 	<li>closing curly braces are aligned properly with the introducing code of
	 * 		the matching opening brace</li>
	 * 	<li>closing parenthesis' are aligned with their opening peer</li>
	 * 	<li>the <code>else</code> keyword is aligned with its <code>if</code>, anything
	 * 		else is aligned normally (i.e. with the base of any introducing statements).</li>
	 *  <li>if there is no token on the same line after <code>offset</code>, the indentation
	 * 		is the same as for an <code>else</code> keyword</li>
	 * </ul>
	 *
	 * @param offset the offset for which the reference is computed
	 * @param nextToken the next token to assume in the document
	 * @return the reference statement relative to which <code>offset</code>
	 *         should be indented, or {@link JavaHeuristicScanner#NOT_FOUND}
	 */
	public int findReferencePosition(int offset, int nextToken) {
		boolean danglingElse= false;
		boolean unindent= false;