Problems using @j2sNative

11 views
Skip to first unread message

udo.bo...@googlemail.com

unread,
May 8, 2012, 3:19:53 AM5/8/12
to java2...@googlegroups.com
I am using j2s for quite some time now and everything worked fine so far. However I am now trying out the "advanced" feature @j2sNative, without success.

I used the example at http://j2s.sourceforge.net/articles/tutorial-advanced-programming-on-j2s.html#j2snative. But instead of the embedded JavaScript the compiler generated

c$ = Clazz.declareType (null, "HelloJ2SNative");
c$.sayHello = Clazz.defineMethod (c$, "sayHello",
function () {
System.out.println ("Hello, Java");
});
c$.sayHei = Clazz.defineMethod (c$, "sayHei",
function (name) {
if (name != null) {
System.out.println ("Hei, " + name + ", how are you?");
} else {
System.out.println ("Hei, how are you?");
}}, "~S");
c$.saySomething = Clazz.defineMethod (c$, "saySomething",
function () {
{
}});
c$.main = Clazz.defineMethod (c$, "main",
function (args) {
HelloJ2SNative.sayHi ();
HelloJ2SNative.sayHello ();
HelloJ2SNative.sayHei ("Josson");
HelloJ2SNative.saySomething ();
}, "~A");


I.e. the original "Java" code ('System.out.println...') is kept and the "sayHi" method is missing.

Any suggestions what is going wrong? Do I have to switch on something to enable the @j2s... features?

Thanks in advance,

Udo

P.S.: I tried it both in Eclipse 3.6 and Eclipse 3.7 (MacOSX).

Zhou Renjian

unread,
May 8, 2012, 11:17:34 AM5/8/12
to java2...@googlegroups.com
J2S in Eclipse 3.7 is not tested. But J2S in Eclipse 3.6 is tested and supported. And I just now tested the @j2s* again in Eclipse 3.6 under Lion and it worked as expected, getting same JavaScript as quoted in the tutorial.

J2S in Eclipse 3.7 may generate JavaScript ignoring @j2s* javadoc tags, because of different JDT APIs in 3.6 and 3.7. If your project or your workspace is shared between 3.6 and 3.7. J2S in Eclipse 3.6 may be affected, not re-generating the correct JavaScript.

J2S in Eclipse 3.7 or later versions may not come soon. If @j2s* javadoc tags are not supported in 3.7, try to use @J2S* annotations instead. For example, the following snippet is coming from net.sf.j2s.ajax.SimplePipeHelper:

@J2SIgnore

private static BlockingQueue<SimplePipeRunnable> toBeDestroyedPipes = new LinkedBlockingQueue<SimplePipeRunnable>();

@J2SIgnore

private SimplePipeHelper() {

//

}


/*

* Browser mode

*/

@J2SNative({

"if (key == null || pipe == null) return;",

"if (net.sf.j2s.ajax.SimplePipeHelper.pipes == null) {",

" net.sf.j2s.ajax.SimplePipeHelper.pipes = new Object ();",

"}",

"net.sf.j2s.ajax.SimplePipeHelper.pipes[key] = pipe;"

})

public static void registerPipe(String key, SimplePipeRunnable pipe) {

if (key == null || pipe == null) return;

if (pipes == null) {

pipes = Collections.synchronizedMap(new HashMap<String, SimplePipeRunnable>(50));

}

pipes.put(key, pipe);

}

/*

* Server side

*/

@J2SIgnore

synchronized static String registerPipe(SimplePipeRunnable pipe) {

if (pipe.pipeKey != null) {

System.out.println("ERROR!!! pipeKey should be null here! " + pipe.pipeKey);

}

// if (pipe == null) return null; // should never register null pipe!

if (pipes == null) {

pipes = Collections.synchronizedMap(new HashMap<String, SimplePipeRunnable>(50));

}

String key = nextPipeKey();

while (pipes.get(key) != null) {

key = nextPipeKey();;

}

pipes.put(key, pipe);

if (pipeMap == null) {

pipeMap = Collections.synchronizedMap(new HashMap<String, List<SimpleSerializable>>());

}

List<SimpleSerializable> list = pipeMap.get(key);

if (list == null) {

list = new Vector<SimpleSerializable>();

pipeMap.put(key, list);

}

return key;

}



Regards,
Zhou Renjian



--
You received this message because you are subscribed to the Google Groups "Java2Script" group.
To view this discussion on the web visit https://groups.google.com/d/msg/java2script/-/n_4p8N8pR70J.
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.

Udo

unread,
May 10, 2012, 2:29:49 PM5/10/12
to Java2Script
Thanks for your reply.

I solved the issue.

In my Eclipse project Javadoc processing was disabled.

After I enabled Javadoc processing (Project > Properties > Java
Compiler > JavaDoc > Process Javadoc comments) @j2sNative is working
as expected.

Thanks,

Udo






On May 8, 5:17 pm, Zhou Renjian <zhourenj...@gmail.com> wrote:
> J2S in Eclipse 3.7 is not tested. But J2S in Eclipse 3.6 is tested and
> supported. And I just now tested the @j2s* again in Eclipse 3.6 under Lion
> and it worked as expected, getting same JavaScript as quoted in the
> tutorial.
>
> J2S in Eclipse 3.7 may generate JavaScript ignoring @j2s* javadoc tags,
> because of different JDT APIs in 3.6 and 3.7. If your project or your
> workspace is shared between 3.6 and 3.7. J2S in Eclipse 3.6 may be
> affected, not re-generating the correct JavaScript.
>
> J2S in Eclipse 3.7 or later versions may not come soon. If @j2s* javadoc
> tags are not supported in 3.7, try to use @J2S* annotations instead. For
> example, the following snippet is coming from
> net.sf.j2s.ajax.SimplePipeHelper:
>
>  @J2SIgnore
>
> private static BlockingQueue<SimplePipeRunnable> toBeDestroyedPipes =
> newLinkedBlockingQueue<SimplePipeRunnable>();
> >http://j2s.sourceforge.net/articles/tutorial-advanced-programming-on-....
Reply all
Reply to author
Forward
0 new messages