Вопрос

Eclipse (any version AFAIK) has some weird behavior related to folding in Java code. Suppose I’m editing this class:

class A {
  String field;
  @Nonnull 
  Object method(){
    // whatever
  }
}

If folding is enabled and I tell it to collapse everything (it’s Control-NumSlash in mine, but that might be customized), the method is correctly folded, i.e. it shows only Object method()... for the method. All good ’till now.

The part that bothers me is that if I move the cursor right after field;, press Enter, and type something like “public”, and then stop for a second, Eclipse automatically folds that word into the method below.

That might seem reasonable (presumably it assumes I wanted to add that qualifier to the method); but in practice what I’m actually doing is trying to add a new method, and paused for a moment to think about its return type or maybe its name. (If I wanted to modify the method I’d unfold it first, since it might already have that qualifier, folded.)

I hate this “feature” with passion, but I can’t for the life of me find out how to disable it, nor even which of the damned mess of plugins (that Eclipse keeps insisting I should not be allowed to remove) is responsible for it so I can file a bug report.

So, does anyone know (1) where does that behavior come from, and hopefully (2) how can I get rid of it but keep manual folding? Thanks!

(For the record, I’m using Kepler SR1, but this behavior goes back a really long time, at least five years or so.)

Это было полезно?

Решение

I don't believe there's any way to prevent it from doing that unless you just make a habit of putting a semicolon ; or closing curly brace } after public which prevents the Object method(){.. from 'folding' it up. I believe it's written to fold everything up until the closest semicolon which is why @Nonnull is also included.

The only options for folding I can find are located in Window > Preferences > Java > Editor > folding

I would consider this to be a bug, or just a feature that had unintended side effects.

Funny enough, if you put almost any symbol or misspell public it wont fold it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top