5

EDIT: Turns out this is a long-standing bug with Eclipse and enums / array initializers, which is really unfortunate.


In Eclipse, I'm finding that I don't have access to any kind of code completion inside of enums. Here's a WIP, of course, snippet of code that I'm working with.

enum PlayerState implements State<Player> {

NORMAL(){

    @Override
    public void enter(Player player){

    }

    @Override
    public void update(Player player){

    }

},

JUMP_START(){

    Timer jumpTimer = new Timer();
    public void enter(Player player){
        jumpTimer.set(1);
    }

    public void update(Player player){

    }

},

GLOBAL_STATE(){

    @Override
    public void update(Player player){
    }
};

@Override
public void enter(Player player) {
}

@Override
public void exit(Player player) {
}

@Override
public boolean onMessage(Player player, Telegram telegram) {
    return false;
}

}

So in this code, I have no completion with "player.", or with "jumpTimer.". To note, I'm working with the GDX-AI library to manage a state machine, and it advises putting the states into an enum, like I have above. Note that I was able to have completion in IntelliJ. I've tried enabling "Java Proposals" in the Preferences/Java/Editor/Content Assist/Advanced section, but that didn't work, and restarting the IDE didn't help, either.

Any ideas?

EDIT: To confirm, this is just a snippet, and the code as a whole does compile. There's nothing wrong with the way it works so far, as far as I can tell; Eclipse isn't throwing any errors, so it's fine. The only issue is code completion, at the moment.

Oh, also, the strange thing is that Eclipse can tell me what's wrong with code (i.e. doing "changeState()" on the state machine from the state through the Player class will have a syntax error because I'm not providing an argument). So, there's some level of code checking, but no code hinting? I dunno...

Noumenon
  • 5,099
  • 4
  • 53
  • 73
SolarLune
  • 1,229
  • 3
  • 12
  • 14
  • Does this even compile? Enums are final types; you should not be able to anonymously extend them like that. – Thorn G Mar 31 '15 at 15:20
  • 3
    @TomG: It looks fine to me. See the `Operation` example in http://docs.oracle.com/javase/8/docs/technotes/guides/language/enums.html – Jon Skeet Mar 31 '15 at 15:25
  • Wow, TIL. I didn't realize enums allowed that level of customization; I've been doing it the "switch on this" way. – Thorn G Mar 31 '15 at 15:33
  • 1
    Add your edit 2 as an answer to your own question. – djechlin Mar 31 '15 at 17:09
  • 3
    I have the same problem. I use enums whenever possible (hell, i push enums to the limit...) and it's very annoying that eclipse fails completely in the autocomplete when writing inside enum values. Still looking for a solution... – marcolopes Apr 01 '15 at 03:46

0 Answers0