enums

18 views
Skip to first unread message

Pavel

unread,
Feb 12, 2011, 1:52:58 PM2/12/11
to Java2Script
Is there really support for enums as announced?

Enum.js from last "stable" version (j2s-2.0.0-20100601) has bad
dependences on classes java.security.AccessController and
PrivilegedExceptionAction.

[code]
public class Main {

public enum Numbers { ONE, TWO}

public static void main(String[] args) {
System.out.println(Numbers.ONE);
}
}
[/code]

Zhou Renjian

unread,
Feb 12, 2011, 11:13:51 PM2/12/11
to java2...@googlegroups.com
Hi,

Thanks for reporting this bug.

It seems that we pack the wrong *.js. We should pack this following
handwritten Enum.js instead the compiled one:
http://java2script.googlecode.com/svn/trunk/sources/net.sf.j2s.java.core/src/java/lang/Enum.js

Regards,
Zhou Renjian

--
http://webuzz.im/ web instant messengers
(Gtalk/MSN/Yahoo!/Facebook/AIM/ICQ/Jabber)
http://j2s.sourceforge.net/ Java2Script

> --
> You received this message because you are subscribed to the Google Groups "Java2Script" group.
> To post to this group, send email to java2...@googlegroups.com.
> To unsubscribe from this group, send email to java2script...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/java2script?hl=en.
>
>

Pavel

unread,
Feb 13, 2011, 5:53:01 PM2/13/11
to Java2Script
Thanks for your answer.

I tried use svn version before, but there is other problem:
"Uncaught TypeError: Cannot read property 'ONE' of undefined"

source:
[code]
package testenum;
public class Main {
public enum Numbers { ONE, TWO}
public static void main(String[] args) {
System.out.println(Numbers.ONE);
}
}
[/code]

output:
[code]
Clazz.declarePackage ("testenum");
Clazz.load (["java.lang.Enum"], "testenum.Main", null, function () {
c$ = Clazz.declareType (testenum, "Main");
if (!Clazz.isClassDefined ("testenum.Main")) {
testenum.Main.$Main$ ();
}
c$.main = Clazz.defineMethod (c$, "main",
function (args) {
System.out.println (testenum.Main.Numbers.ONE);
}, "~A");
c$.$Main$ = function () {
Clazz.pu$h ();
c$ = Clazz.declareType (testenum, "Main", Enum);
Clazz.defineEnumConstant (c$, "ONE", 0, []);
Clazz.defineEnumConstant (c$, "TWO", 1, []);
c$ = Clazz.p0p ();
};
});
[/code]

Zhou Renjian

unread,
Feb 14, 2011, 10:13:14 AM2/14/11
to java2...@googlegroups.com
Hi Pavel,

Thanks for your feedback.

It seems that nested enum does not get correctly compiled. Before we
can fix this compiler bug, we suggest you move enum into a standalone
*.java file to avoid this compiler bug.

Regards,
Zhou Renjian

--
http://webuzz.im/ web instant messengers
(Gtalk/MSN/Yahoo!/Facebook/AIM/ICQ/Jabber)
http://j2s.sourceforge.net/ Java2Script

Zhou Renjian

unread,
Feb 14, 2011, 11:19:33 AM2/14/11
to java2...@googlegroups.com
Check SVN revision 1170 for this bug fix:
https://java2script.googlecode.com/svn/trunk/sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Regards,
Zhou Renjian

--
http://webuzz.im/ web instant messengers
(Gtalk/MSN/Yahoo!/Facebook/AIM/ICQ/Jabber)
http://j2s.sourceforge.net/ Java2Script

Pavel

unread,
Mar 29, 2011, 7:45:46 PM3/29/11
to Java2Script
It works well, thanks.

On Feb 14, 6:19 pm, Zhou Renjian <zhourenj...@gmail.com> wrote:
> Check SVN revision 1170 for this bug fix:https://java2script.googlecode.com/svn/trunk/sources/net.sf.j2s.core/...
>
> Regards,
> Zhou Renjian
Reply all
Reply to author
Forward
0 new messages