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
private void nextToken() {
		nextToken(fPosition);
	}
	/**
	 * Reads the next token in backward direction of <code>start</code> from
	 * the heuristic scanner and sets the fields <code>fToken, fPreviousPosition</code>
	 * and <code>fPosition</code> accordingly.
	 *
	 * @param start the start offset from which to scan backwards
	 */
	private void nextToken(int start) {
		fToken= fScanner.previousToken(start - 1, JavaHeuristicScanner.UNBOUND);
		fPreviousPos= start;
		fPosition= fScanner.getPosition() + 1;
		try {
			fLine= fDocument.getLineOfOffset(fPosition);
		} catch (BadLocationException e) {
			fLine= -1;
		}
	}
	/**
	 * Returns <code>true</code> if the current tokens look like a method
	 * declaration header (i.e. only the return type and method name). The
	 * heuristic calls <code>nextToken</code> and expects an identifier
	 * (method name) and a type declaration (an identifier with optional
	 * brackets) which also covers the visibility modifier of constructors; it
	 * does not recognize package visible constructors.
	 *
	 * @return <code>true</code> if the current position looks like a method
	 *         declaration header.