Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 401883

Summary: Enum in a Scrapbook page fails
Product: [Eclipse Project] JDT Reporter: Robert Mark Bram <robertmarkbram>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, Michael_Rennie, robertmarkbram, srikanth_sankaran
Version: 4.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Robert Mark Bram CLA 2013-02-27 06:41:38 EST
Not sure if this is a bug or if I am going a bit crazy.. Am trying to do some quick testing of enums in an Eclipse jpage Scrapbook (using JDK 1.7.0_02, Win XP 64-bit, Eclipse Juno)

class A {
    enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}
}
A a = new A();

When I execute the code above in a Scrapbook page I get the error below.

The member enum Month can only be defined inside a top-level class or interface

I tried moving the enum out of a class definition with code such as:

enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}
Month.valueOf("JAN");

And these are the errors I got for the above:

The member enum Month can only be defined inside a top-level class or interface
Month cannot be resolved.

Maybe Eclipse just puts all the code into a main method, in which case this is a limitation and not a bug.. but either way it limits the usefulness of a jpage.
Comment 1 Michael Rennie CLA 2013-08-02 00:03:55 EDT
This is a bug in the way we are creating the snippet classfile, we are putting the enum in the wrong spot:

public class CodeSnippet_1 extends GlobalVariables_3 {
@Override public void run() throws Throwable {
class A {
    enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}
}
A a = new A();
}
}

This code will never work since you can't have an enum in a local type.

Jay, is there something debug should be doing to have JDT create the correct snippet? Break apart the snippet and pass in the enum as a var? In the scrapbook we run evals using the EvaluationContext from a call to: getJavaProject().newEvaluationContext() passing the ICodeSnippetRequestor LocalEvaluationEngine (for some context how we run it).
Comment 2 Jay Arthanareeswaran CLA 2013-08-05 05:54:40 EDT
(In reply to comment #1)
> Jay, is there something debug should be doing to have JDT create the correct
> snippet? Break apart the snippet and pass in the enum as a var? In the
> scrapbook we run evals using the EvaluationContext from a call to:
> getJavaProject().newEvaluationContext() passing the ICodeSnippetRequestor
> LocalEvaluationEngine (for some context how we run it).

I didn't quite understand what you meant by 'var'. Did you mean something like this?

class Month {
	Month JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC;
}
Comment 3 Michael Rennie CLA 2013-08-06 11:28:44 EDT
(In reply to comment #2)
> (In reply to comment #1)
> > Jay, is there something debug should be doing to have JDT create the correct
> > snippet? Break apart the snippet and pass in the enum as a var? In the
> > scrapbook we run evals using the EvaluationContext from a call to:
> > getJavaProject().newEvaluationContext() passing the ICodeSnippetRequestor
> > LocalEvaluationEngine (for some context how we run it).
> 
> I didn't quite understand what you meant by 'var'. Did you mean something
> like this?
> 
> class Month {
> 	Month JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC;
> }

No, I was thinking aloud that there was some kind of way we could work around the problem by passing the enum into one of the variable collections when we call IEvaluationContext#evaluateCodeSnippet(..), but it would not work.
Comment 4 Eclipse Genie CLA 2020-04-19 16:30:22 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.