#34 Java Mode indentation bug

closed-fixed
nobody
None
5
2002-12-08
2002-12-03
Michael Rutter
No

J is not indenting properly in cases such as this:
public class Blarg {
protected void method(Object source, Object[] path,
int[] childIndices) {
// Guaranteed to return a non-null array
int i = 0;
}
}

It instead indents as such:

public class Blarg {
protected void method(Object source, Object[] path,
int[] childIndices) {
// Guaranteed to return a
non-null array
int i = 0;
}
}

Anything after the opening brace of the method gets
shifted heavily to the right.

Discussion

  • Michael Rutter
    Michael Rutter
    2002-12-03

    File with the above code

     
    Attachments
  • Michael Rutter
    Michael Rutter
    2002-12-03

    Logged In: YES
    user_id=563255

    Whoops. The real cause is having the opening brace of the
    method on the same line as the closing paren of the method
    when the method declaration takes up multiple lines.

     
  • Michael Rutter
    Michael Rutter
    2002-12-04

    Logged In: YES
    user_id=563255

    There is another case where indentation is not correct in
    Java Mode. This is when the opening brace for an anonymous
    inner class is on it's own line, such as:
    var.addSomething(new Something()
    {

     
  • Peter Graves
    Peter Graves
    2002-12-08

    Logged In: YES
    user_id=558172

    The first bug is fixed in tonight's development snapshot.

    The second bug (when the opening brace for an anonymous
    inner class is on its own line) is unrelated to the first.
    For now (at least) this one is a "won't fix".

    It's not just that the opening brace is on its own line; the
    real problem is that you're actually -defining- an anonymous
    inner class in the argument list of a method call.

    There are undoubtedly a number of bugs like this that show
    up when you do pathological things with anonymous inner
    classes, and for most if not all of them there are easy
    workarounds, e.g.:

    Something foo = new Something()
    {
    // ...
    };
    var.addSomething(foo);

    Which not only indents correctly, it's more readable to
    begin with.

    The idea of indentation is to make code -more- readable.

    There's no sense wasting time on support for the automatic
    indentation of inherently unreadable constructs.

     
  • Peter Graves
    Peter Graves
    2002-12-08

    • status: open --> closed-fixed