Alex Rivera | Logout

Syntax error , insert "EnumBody" to complete EnumDeclaration

Asked 2012-11-01T07:55:41.037
9

I was in middle of coding and accidentally put the following line of code at the part of class where we declare instance variables. but i checked and it gives the same error anywhere by anywhere i mean : inside a static block, inside constructor, inside any class method. except when private; is put as the first line of the class it gives Syntax error, insert "EnumBody" to complete ClassBodyDeclarations (as written by @chaitanya10 in comments below and also verified by me on my workspace) error in eclipse tooltip when we hover cursor over it.

I understand there is error.
but I dont understand the error message when i hover cursor over the error. what is the meaning of this message?

why does it expecting EnumBody ?

Below is the screenshot.

enter image description here

Edit
Report

1 Answer

5

For what it's worth, the following:

public class Foo;

Error: Syntax error, insert "ClassBody" to complete ClassBodyDeclarations

public enum Foo;

Error: Syntax error, insert "EnumBody" to complete ClassBodyDeclarations

public interface Foo;

Error Syntax error, insert "InterfaceBody" to complete ClassBodyDeclarations

Anyway, I think what happens is, in this org.eclipse.jdt.internal.compiler.parser.Parser.consumeEnumConstantHeader(), it tries to recover when it gets the parsing error with this code:

if(this.currentToken == TokenNameSEMICOLON) {
    RecoveredType currentType = currentRecoveryType();
    if(currentType != null) {
        currentType.insideEnumConstantPart = false;
    }
}

So it correctly figures out that we're not inside an enumeration, so we get an error like above, but it doesn't realize that we don't even know if it is an enumeration. You can look at the source here:

In other words, it's probably a bug that the Eclipse team introduced when they added Enumerations, it's handled slightly differently than some of the other tokens, which causes it to be Recovered in a different way and therefore shows up in the compiler errors.

answered 2012-11-09T05:27:42.300

Your Answer