开发者

Eclipse 'Anonymous Inner Type' - autocomplete

开发者 https://www.devze.com 2023-01-13 12:27 出处:网络
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:

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 codi开发者_JAVA技巧ngtemplates 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


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号