views:

60

answers:

3

Hello everyone,

Sometimes I tend using autocomplete from eclipse (3.5) for anonymous inner types. For some reason eclipse always puts ending-parenthesis and semicolon in wrong order. A small example:

button.addActionListener( new Act... ) // <-- Pressing Autocomplete (strg+space)

results in:

button.addActionListener( new ActionListener()
{

  @Override
  public void actionPerformed( ActionEvent e )
  {
    // TODO Auto-generated method stub

  }
};) // <-- why?

Didnt found that anywhere in codingtemplates of eclipse. I also cant yet switch to 3.6, eventhough I dont know, if that is "fixed" there already (if that is even supposed to be an error), since eclipse probably just dont know, that it has to use the parenthesis behind autocomplete. Guess handling that is kinda complicated, since he wont check what chars are behind autocomplete, and so he cant use the ending-parenthesis? Correct me, if I should be wrong.

Guess I just have a bad day (common mondays!), which is why it annyoys me right now, but maybe someone has an idea how to influence this behaviour?

Greets, ymene

+2  A: 

Guess I just have a bad day (common mondays!), which is why it annyoys me right now, but maybe someone has an idea how to influence this behaviour?

File a bug with Eclipse.

This behavior does bother me somewhat, but not to the extent of filing a bug about it.

Alexander Pogrebnyak
same for me, but since it seems to be fixed in helios, not worth a try anymore anyway! ;)
ymene
+1  A: 

try this instead then (it's probably better style anyway!):

ActionListener actionListener = new Act...
button.addActionListener(actionListener);

This is what I think they probably had in mind (as in this case the semi-colon is useful). However, If Helios fixes this by omitting the semi-colon as Skip Head suggests, then it would seem that they have trouble determining whether you are writing inside brackets or not - given that your code doesn't compile yet at this stage.

Robert
I thought about that solution, too, but I normally try to avoid local variables, if they were not really necessary, except for reading proposes. But in this case I think it still reads well, with adding it directly.
ymene
Without getting into too much of a debate about style, I'll just back up my assertion by saying that using local variables in this way allows you to maintain your code more easily, in a similar way to always using braces in if or looping constructs: they are ready to just use if you need them; they are easy to read, as each statement does only one thing at a time; and the compiler will (likely) optimise the same way anyway.
Robert
+4  A: 

It seems to (sort of) work in Helios (3.6). It doesn't put the semi-colon at all.

Skip Head
+1. Concur, does not happen in Helios anymore, maybe that's why it doesn't bother me that much anymore. :-)
Alexander Pogrebnyak
one more reason to finally switch, thanks for that info!
ymene