Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse caret jumps to constructor while typing

Tags:

eclipse

While typing in Eclipse (Java) I often have the problem that when I begin to type accessors, the caret jumps down to the beginning of the constructor definition. So in a document like this:

private int mSomeInt;

public 

in|public MyClass(){
}

I would like to manually type out the accessor (getter/setter) for mSomeInt, but when I press space after 'public' above, the caret jumps to the beginning of 'public MyClass'.

I often type complete lines to look up and find my methods jumbled with the constructor (like above).

Any help would be appreciated.

Note - this isn't only with accessors but rather any access modifiers that I define before the constructor or another method.

Edit

After unsuccessfully trying Deco's solution below, I've managed to narrow it down a little further.

The problem only happens if I have all the blocks in the file in a collapsed state (ctrl+shift+numPadDivide). I can see the problem is now that the new access modifier I type is then (quickly) collapsed into the below method. i.e. Eclipse is actually taking the first accessor modifier and collapsing everything from there, even though my intention is actually to write a new method.

The only solution I've been able to find is to only edit the source with all the 'fold' elements unfolded.

like image 633
LintfordPickle Avatar asked Jan 02 '12 13:01

LintfordPickle


1 Answers

Under Window -> Preferences -> <Language> (e.g. Java) -> Editor there is a Content Assist menu item where you can configure auto completion and caret placement as well as auto-activation of it and the delay it uses.

Edit:

After your update to the original question I was able to successfully replicate this in Eclipse Indigo. When you have all of the code blocks collapsed it looks like Eclipse assumes that the code you are writing needs to be in that block (rather than as a variable declaration). I'm not sure if this is expected behaviour or not - but the only way around it I've found is to edit the code with the main block open, and then close it after the fact - or turn folding off altogether.

From what I can tell there are various folding plugins/addons that you can get for Eclipse which override the default behaviour and might function better? A quick Google search will be able to get you a list of them quickly.

I'd probably also suggest posting this as an issue on the Eclipse support site for their official answer.

like image 199
Deco Avatar answered Sep 30 '22 19:09

Deco