Java() doesn't create target for enum-switch anonymous class
This issue was originally created at: 2008-05-06 09:10:11.
This issue was reported by: mbrady.
mbrady said at 2008-05-06 09:10:11
When you 'switch' on an Enum, javac creates an anonymous inner class for the class doing the switch. The Java parser doesn't create the .class file target for this.
For example, when I run 'scons' on the 3 files below, I expect to see
Java parser found classes:
Bar$1.class
Bar.class
Foo$1.class
Foo.class
but I actually see:
Java parser found classes:
Bar.class
Foo.class
Here are the test files. (They are also attached)
Bar.java
public class Bar
{
public void doSomething(Foo x)
{
// This switch statement produce anonymous inner class Bar$1.
switch (x)
{
case A:
case B:
default:
}
}
}
Foo.java
public enum Foo
{
A, B;
public void doSomething()
{
// This switch statement produce anonymous inner class Foo$1.
switch(this)
{
case A:
case B:
default:
}
}
}
SConstruct
env = Environment()
env['JAVAVERSION'] = "1.6"
jclasses = env.Java('.', '.')
print '-' * 60
print 'Java parser found classes:'
print '-' * 60
for jc in jclasses:
print jc
print '-' * 60
mbrady said at 2008-05-06 09:13:10
Created an attachment (id=400) enum Foo that contains a switch statement
mbrady said at 2008-05-06 09:13:33
Created an attachment (id=401) class Bar that contains a switch statement
mbrady said at 2008-05-06 09:14:44
Created an attachment (id=402) SConstruct that lists found .class file targets.
stevenknight said at 2008-05-06 09:34:49
Hi Michael--
Thanks for the report. What version of Java are you using? Different versions have slightly different behavior w.r.t. naming the files for anonymous inner classes, and I want to make sure that whoever fixes this gets the right fix(es) for the right Java versions.
Thanks,
mbrady said at 2008-05-06 09:48:51
Stephen,
I'm using JDK 1.6.0 update 4 (1.6.0_04).
Do you think that this is fixable?
Seems like the parser would have to look at a switch statement and figure out whether it's switching on a primitive or an Enum. Is this do-able with the current parser?
Thanks for your help.
--Michael
gregnoel said at 2008-05-23 13:59:39
Bug party triage.
russel said at 2008-06-05 22:21:08
I wonder if replicating the Java parser in Python is a bad idea, wouldn't it be better to get the Java parser to parse the Java code and report back. By invoking the javadoc command with a suitable Doclet, you can get a parse and report on the parse from the definitive source, the java compiler.
gregnoel said at 2008-12-26 13:30:40
Adjust triage of issues.
managan said at 2009-08-28 12:50:09
add java to keywords
stevenknight said at 2009-11-10 18:00:19
stevenknight => issues@scons
dirkbaechle said at 2014-07-12 06:26:11
added dependency
mwichmann said at 2017-12-12 12:55:14
see also bug #2547
Votes for this issue: 1.
mbrady attached Foo.java at 2008-05-06 09:13:09.
enum Foo that contains a switch statement
mbrady attached Bar.java at 2008-05-06 09:13:32.
class Bar that contains a switch statement
mbrady attached SConstruct at 2008-05-06 09:14:44.
SConstruct that lists found .class file targets.
dirkbaechle said this issue blocks #2733 at 2014-07-12 06:26:11.
Seems to be the same as #2547, can we combine? See also #2742, which has a patch proposal.