Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "VJET/Java2Js Language Translation Reference mapping"
(→Seperators) |
|||
(125 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Lexical Structure == | == Lexical Structure == | ||
Line 265: | Line 12: | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java-keyword | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java-keyword | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js – keyword | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js – keyword | ||
Line 271: | Line 18: | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js-reserved | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js-reserved | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| break | | style="border:1px solid #AAAAAA;padding: 0.2em;"| break | ||
Line 351: | Line 98: | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| boolean | | style="border:1px solid #AAAAAA;padding: 0.2em;"| boolean | ||
Line 474: | Line 221: | ||
package | package | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract | | style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract | ||
Line 528: | Line 275: | ||
export | export | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| delete | | style="border:1px solid #AAAAAA;padding: 0.2em;"| delete | ||
Line 550: | Line 297: | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| JS | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| JS | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| desc | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| desc | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Boolean literals | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Boolean literals | ||
Line 563: | Line 310: | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Literals true/false are directly mapped in java script | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Literals true/false are directly mapped in java script | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| null | | style="border:1px solid #AAAAAA;padding: 0.2em;"| null | ||
Line 580: | Line 327: | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| JS | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| JS | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| ( ) { } <nowiki>[ </nowiki>] <nowiki>; </nowiki>, . | | style="border:1px solid #AAAAAA;padding: 0.2em;"| ( ) { } <nowiki>[ </nowiki>] <nowiki>; </nowiki>, . | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Directly mapped | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Directly mapped | ||
Line 592: | Line 339: | ||
All operators are directly mapped into js. | All operators are directly mapped into js. | ||
− | |||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java operators | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java operators | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
Line 601: | Line 347: | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Description | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Description | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| # <nowiki>= </nowiki> | | style="border:1px solid #AAAAAA;padding: 0.2em;"| # <nowiki>= </nowiki> | ||
# > | # > | ||
Line 736: | Line 482: | ||
a>>>=b; | a>>>=b; | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Direct translation | |
|} | |} | ||
== Types, Values and Variables == | == Types, Values and Variables == | ||
− | + | ||
− | + | === Primitive types and values === | |
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| boolean | + | boolean |
byte | byte | ||
Line 768: | Line 513: | ||
float | float | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | boolean | |
− | + | ||
− | + | ||
int, indirectly supported , declared as int | int, indirectly supported , declared as int | ||
Line 789: | Line 532: | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | + | === Reference Types & Values === | |
− | + | ||
+ | ==== Class type ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package com.ebay.dsf.javatojs.tests; | ||
public class A { | public class A { | ||
− | + | int a=10; | |
− | int a | + | public int p=50; |
− | + | String city; | |
− | public int p | + | String state; |
− | + | public void setCity(String c ){ | |
− | String city | + | this.city=c; |
− | + | } | |
− | String state | + | public String getCity(){ |
− | + | return this.city; | |
− | public void setCity(String c ){ | + | } |
− | + | protected void setState(String s){ | |
− | this.city | + | this.state=s; |
− | + | } | |
− | + | protected String getState(){ | |
− | } | + | return this.state; |
− | + | } | |
− | public String getCity(){ | + | String foo(){ |
− | + | return "foo"; | |
− | return this.city | + | } |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.A") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
− | + | //> int a | |
− | //> int a | + | a:10, |
− | + | //> public int p | |
− | a:10, | + | p:50, |
− | + | //> String city | |
− | //> public int p | + | city:null, |
− | + | //> String state | |
− | p:50, | + | state:null, |
− | + | //> public void setCity(String c) | |
− | //> String city | + | setCity:function(c){ |
− | + | this.city=c; | |
− | city:null, | + | }, |
− | + | //> public String getCity() | |
− | //> String state | + | getCity:function(){ |
− | + | return this.city; | |
− | state:null, | + | }, |
− | + | //> protected void setState(String s) | |
− | //> public void setCity(String c) | + | setState:function(s){ |
− | + | this.state=s; | |
− | setCity:function(c){ | + | }, |
− | + | //> protected String getState() | |
− | this.city=c; | + | getState:function(){ |
− | + | return this.state; | |
− | }, | + | }, |
− | + | //> String foo() | |
− | //> public String getCity() | + | foo:function(){ |
− | + | return "foo"; | |
− | getCity:function(){ | + | } |
− | + | ||
− | return this.city; | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> protected void setState(String s) | + | |
− | + | ||
− | setState:function(s){ | + | |
− | + | ||
− | this.state=s; | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> protected String getState() | + | |
− | + | ||
− | getState:function(){ | + | |
− | + | ||
− | return this.state; | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> String foo() | + | |
− | + | ||
− | foo:function(){ | + | |
− | + | ||
− | return "foo" | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== interface type ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.Inheritance; | + | <source lang="java"> |
− | + | package com.ebay.dsf.javatojs.tests.Inheritance; | |
− | + | ||
public interface Interface3 { | public interface Interface3 { | ||
− | + | String C3="c3"; | |
− | + | String method3(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.itype("com.ebay.dsf.javatojs.tests.Inheritance.Interface3") | ||
.props({ | .props({ | ||
− | + | //> public String C3 | |
− | //> public String C3 | + | C3:"c3" |
− | + | ||
− | C3:"c3" | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public String method3() | |
− | //> public String method3() | + | method3:function(){ |
− | + | } | |
− | method3:function(){ | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== Array type ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
+ | <source lang="java"> | ||
+ | long avg = 10; | ||
+ | long[] la = {1+avg,2,3}; | ||
+ | int[][] twoDimArray = {{1,2,3}, {4,5,6}}; | ||
+ | String[] sa = { "a", "b", "c"}; | ||
+ | String[] sa2 = new String[2]; | ||
+ | Employee[] sa3 = new Employee[2]; | ||
+ | boolean boolArr1[] | ||
+ | = new boolean[]{true}; | ||
+ | boolean boolArr2[][] | ||
+ | = new boolean[][]{{false}}; | ||
+ | boolean boolArr11[] | ||
+ | = new boolean[twoDimArray[0][0]]; | ||
+ | boolean boolArr12[][] | ||
+ | = new boolean[twoDimArray[0][0]] [twoDimArray[0][1]]; | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | + | <source lang="javascript"> |
− | + | var avg=10; | |
− | + | var la=[1+avg,2,3]; | |
− | + | var twoDimArray=[[1,2,3],[4,5,6]]; | |
− | + | var sa=["a","b","c"]; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | var | + | |
− | + | ||
− | var | + | |
− | + | ||
− | var | + | |
− | + | ||
var sa2=new Array(2); | var sa2=new Array(2); | ||
− | |||
var sa3=new Array(2); | var sa3=new Array(2); | ||
− | + | var boolArr1=[true]; | |
− | var | + | var boolArr2=[[false]]; |
− | + | var boolArr11=new Array(twoDimArray[0][0]); | |
− | var | + | |
− | + | ||
− | var boolArr11=new | + | |
− | + | ||
var boolArr12=new Array; | var boolArr12=new Array; | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
− | |||
+ | === Type Variables === | ||
Implemented in comment | Implemented in comment | ||
− | |||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
− | public class | + | public class Pair<T, S>{ |
− | + | private T first; | |
− | { | + | private S second; |
− | + | ||
− | private T first | + | |
− | + | ||
− | private S second | + | |
− | + | ||
− | + | ||
− | + | ||
− | first = f; | + | public Pair(T f, S s){ |
+ | first = f; | ||
+ | second = s; | ||
+ | } | ||
− | + | public T getFirst() { | |
+ | return first; | ||
+ | } | ||
+ | public S getSecond(){ | ||
+ | return second; | ||
+ | } | ||
} | } | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
− | + | //> private T first | |
− | //> private T first | + | first:null, |
− | + | //> private S second | |
− | first:null, | + | second:null, |
− | + | //> public constructs(T f,S s) | |
− | //> private S second | + | constructs:function(f,s){ |
− | + | this.first=f; | |
− | second:null, | + | this.second=s; |
− | + | }, | |
− | //> public constructs(T f,S s) | + | //> public T getFirst() |
− | + | getFirst:function(){ | |
− | constructs:function(f,s){ | + | return this.first; |
− | + | }, | |
− | this.first=f; | + | //> public S getSecond() |
− | + | getSecond:function(){ | |
− | this.second=s; | + | return this.second; |
− | + | } | |
− | }, | + | |
− | + | ||
− | //> public T getFirst() | + | |
− | + | ||
− | getFirst:function(){ | + | |
− | + | ||
− | return this.first; | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public S getSecond() | + | |
− | + | ||
− | getSecond:function(){ | + | |
− | + | ||
− | return this.second; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | + | ||
− | + | ||
|} | |} | ||
− | |||
− | |||
− | |||
+ | === Parameterized type === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| < | + | <source lang="java"> |
− | + | Vector<String> vector = new Vector(); | |
− | + | Collection<Integer> collection = new ArrayList<Integer>(); | |
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | //> Vector<String> vector | ||
vector:null, | vector:null, | ||
− | + | //> Collection<Integer> collection | |
− | + | ||
− | + | ||
collection:null, | collection:null, | ||
− | |||
//> private constructs() | //> private constructs() | ||
− | |||
constructs:function(){ | constructs:function(){ | ||
− | + | this.vector=new this.vjo.Vector(); | |
− | this.vector=new this.vjo.Vector(); | + | this.collection=new this.vjo.ArrayList(); |
− | + | ||
− | this.collection=new this.vjo.ArrayList(); | + | |
− | + | ||
}, | }, | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
− | + | === Sub-Typing === | |
− | + | ||
# Subtyping among primitive types | # Subtyping among primitive types | ||
Line 1,158: | Line 767: | ||
class type is defined using vjo .ctypas as | class type is defined using vjo .ctypas as | ||
− | + | === Variables === | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | ==== Class variable ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | static Float | + | static Integer classVariableInteger = new Integer(10); |
− | + | static Float classVariableFloat; | |
− | static int | + | static int classVariableInt; |
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | //> Integer classVariableInteger | + | <source lang="javascript"> |
− | + | .props({ | |
− | classVariableInteger:null, | + | //> Integer classVariableInteger |
− | + | classVariableInteger:null, | |
− | //> Float classVariableFloat | + | //> Float classVariableFloat |
− | + | classVariableFloat:null, | |
− | classVariableFloat:null, | + | //> int classVariableInt |
− | + | classVariableInt:0 | |
− | //> int classVariableInt | + | |
− | + | ||
− | classVariableInt:0 | + | |
− | + | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10); | |
− | this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10); | + | |
− | + | ||
}) | }) | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== Instance variable ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
− | public class Pair | + | public class Pair{ |
− | + | Integer classVariableInteger = new Integer(10); | |
− | { | + | Float classVariableFloat; |
− | + | int classVariableInt; | |
− | Integer classVariableInteger = new Integer(10); | + | |
− | + | ||
− | Float classVariableFloat | + | |
− | + | ||
− | int classVariableInt | + | |
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer classVariableInteger | |
− | //> Integer classVariableInteger | + | classVariableInteger:null, |
− | + | //> Float classVariableFloat | |
− | classVariableInteger:null, | + | classVariableFloat:null, |
− | + | //> int classVariableInt | |
− | //> Float classVariableFloat | + | classVariableInt:0, |
− | + | //> private constructs() | |
− | classVariableFloat:null, | + | constructs:function(){ |
− | + | this.classVariableInteger=new this.vjo.Integer(10); | |
− | //> int classVariableInt | + | |
− | + | ||
− | classVariableInt:0, | + | |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.classVariableInteger=new this.vjo.Integer(10); | + | |
− | + | ||
} | } | ||
− | |||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== Array components – are unknown variables - partially implemented ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
+ | package com.ebay.dsf.javatojs.tests.operators; | ||
public class Pair{ | public class Pair{ | ||
− | + | String[] stringArray = {new String(), new String()}; | |
− | + | Integer[] intArray; | |
− | + | //Pair[] pairArrayInit = {new Pair(), new Pair()}; | |
− | + | Pair(){ | |
− | + | intArray = new Integer[2]; | |
− | + | intArray[0] = new Integer(20); | |
− | + | intArray[1] = 30; | |
− | Pair(){ | + | } |
− | + | ||
− | intArray = new | + | |
− | + | ||
− | intArray | + | |
− | + | ||
− | intArray | + | |
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.StringFactory") | .needs("vjo.java.lang.StringFactory") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> String[] stringArray | |
− | + | stringArray:null, | |
− | + | //> Integer[] intArray | |
− | stringArray:null, | + | intArray:null, |
− | + | //> constructs() | |
− | + | constructs:function(){ | |
− | + | this.stringArray= | |
− | intArray:null, | + | [vjo.java.lang.StringFactory.build(), |
− | + | vjo.java.lang.StringFactory.build()]; | |
− | //> constructs() | + | this.intArray=new Array(2); |
− | + | this.intArray[0]=new this.vjo.Integer(20); | |
− | constructs:function(){ | + | this.intArray[1]=30; |
− | + | } | |
− | this | + | |
− | + | ||
− | this.intArray=new Array(2); | + | |
− | + | ||
− | this | + | |
− | + | ||
− | this | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== Method parameters ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
+ | package com.ebay.dsf.javatojs.tests.operators; | ||
public class Pair{ | public class Pair{ | ||
− | + | public Pair myMethod(String s, Pair p){ | |
− | public Pair myMethod(String s, Pair p){ | + | String paramString = s; |
− | + | Pair parameterPair = p; | |
− | String paramString = s; | + | return parameterPair; |
− | + | } | |
− | Pair parameterPair = p; | + | |
− | + | ||
− | return parameterPair; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
.protos({ | .protos({ | ||
− | + | //> public Pair myMethod(String s,Pair p) | |
− | //> public Pair myMethod(String s,Pair p) | + | myMethod:function(s,p){ |
− | + | var paramString=s; | |
− | myMethod:function(s,p){ | + | var parameterPair=p; |
− | + | return parameterPair; | |
− | var paramString=s; | + | } |
− | + | ||
− | var parameterPair=p; | + | |
− | + | ||
− | return parameterPair; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| Parameter s, and p exist only within the function | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| Parameter s, and p exist only within the function | ||
− | |||
|} | |} | ||
− | |||
− | |||
+ | ==== Constructor parameters ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
+ | package com.ebay.dsf.javatojs.tests.operators; | ||
public class Pair{ | public class Pair{ | ||
− | + | String s; | |
− | String s | + | Integer i; |
− | + | Pair(String s, Integer i){ | |
− | Integer i | + | this.s =s; |
− | + | this.i=i; | |
− | Pair(String s, Integer i){ | + | } |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> String s | |
− | //> String s | + | s:null, |
− | + | //> Integer i | |
− | s:null, | + | i:null, |
− | + | //> constructs(String s,Integer i) | |
− | //> Integer i | + | constructs:function(s,i){ |
− | + | this.s=s; | |
− | i:null, | + | this.i=i; |
− | + | } | |
− | //> constructs(String s,Integer i) | + | |
− | + | ||
− | constructs:function(s,i){ | + | |
− | + | ||
− | this.s=s; | + | |
− | + | ||
− | this.i=i; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
+ | ==== Exception-handler parameter ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | public class Pair | + | package com.ebay.dsf.javatojs.tests.operators; |
− | + | public class Pair { | |
− | { | + | public Integer getNumber(){ |
− | + | Integer i = 10; | |
− | public Integer getNumber(){ | + | String s = "20.9"; |
− | + | try{ | |
− | Integer i = 10; | + | i = new Integer(s); |
− | + | }catch(NumberFormatException nfe){ | |
− | String s = "20.9" | + | i = 0; |
− | + | } | |
− | try{ | + | return i; |
− | + | } | |
− | i = new Integer(s); | + | |
− | + | ||
− | }catch(NumberFormatException nfe){ | + | |
− | + | ||
− | i = 0; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.NumberFormatException") | .needs("vjo.java.lang.NumberFormatException") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public Integer getNumber() | |
− | //> public Integer getNumber() | + | getNumber:function(){ |
− | + | var i=10; | |
− | getNumber:function(){ | + | var s="20.9"; |
− | + | try { | |
− | var i=10; | + | i=new this.vjo.Integer(s); |
− | + | } | |
− | var s="20.9" | + | catch(nfe){ |
− | + | i=0; | |
− | try { | + | } |
− | + | return i; | |
− | i=new this.vjo.Integer(s); | + | } |
− | + | ||
− | } | + | |
− | + | ||
− | catch(nfe){ | + | |
− | + | ||
− | i=0; | + | |
− | + | ||
− | } | + | |
− | + | ||
− | return i; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | colspan="2" style="border: | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: variable nfe only exists inside catch block. |
− | + | ||
|} | |} | ||
− | |||
− | |||
+ | ==== Local variables ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | public class Pair | + | package com.ebay.dsf.javatojs.tests.operators; |
− | + | public class Pair { | |
− | { | + | public void getNumber(){ |
− | + | String s = new String(); | |
− | public void getNumber(){ | + | Integer i = 20; |
− | + | { | |
− | String s = new String(); | + | String second = "2"; |
− | + | } | |
− | Integer i = 20; | + | } |
− | + | ||
− | { | + | |
− | + | ||
− | String second = "2" | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.StringFactory") | .needs("vjo.java.lang.StringFactory") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void getNumber() | |
− | //> public void getNumber() | + | getNumber:function(){ |
− | + | var s=vjo.java.lang.StringFactory.build(); | |
− | getNumber:function(){ | + | var i=20; |
− | + | { | |
− | var s=vjo.java.lang.StringFactory.build(); | + | var second="2"; |
− | + | } | |
− | var i=20; | + | } |
− | + | ||
− | { | + | |
− | + | ||
− | var second="2" | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
+ | </source> | ||
+ | |} | ||
− | |||
== Conversions and Promotions == | == Conversions and Promotions == | ||
Note1: widening conversions do not require casts | Note1: widening conversions do not require casts | ||
Line 1,536: | Line 1,017: | ||
Note2: narrowing conversions require explicit casts. | Note2: narrowing conversions require explicit casts. | ||
− | + | ==== Identity conversions – conversion to a same type, straight forward ==== | |
− | + | ==== Widening primitive conversions ==== | |
− | + | ||
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| byte b = 10; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
+ | byte b = 10; | ||
short s = b; | short s = b; | ||
Line 1,558: | Line 1,038: | ||
double d = b; | double d = b; | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | var b=10; | ||
var s=b; | var s=b; | ||
Line 1,570: | Line 1,051: | ||
var d=b; | var d=b; | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| # byte to short, int, long, float, or double | | style="border:1px solid #AAAAAA;padding: 0.2em;"| # byte to short, int, long, float, or double | ||
# short to int, long, float, or double | # short to int, long, float, or double | ||
Line 1,578: | Line 1,059: | ||
# float to double | # float to double | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| All conversions are straight forward in js | |
− | + | ||
|} | |} | ||
− | + | ==== Narrowing primitive conversions ==== | |
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| long l = 100l; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
+ | long l = 100l; | ||
byte b = (byte)l; | byte b = (byte)l; | ||
Line 1,600: | Line 1,080: | ||
int i = (int)l; | int i = (int)l; | ||
− | | | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
+ | var l=100; | ||
var b=vjo.java.lang.Util.cast(l,'byte'); | var b=vjo.java.lang.Util.cast(l,'byte'); | ||
Line 1,610: | Line 1,091: | ||
var i=vjo.java.lang.Util.cast(l,'int'); | var i=vjo.java.lang.Util.cast(l,'int'); | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | # short to byte or char | ||
+ | # char to byte or short | ||
+ | # int to byte, short, or char | ||
+ | # long to byte, short, char, or int | ||
+ | # float to byte, short, char, int, or long | ||
+ | # double to byte, short, char, int, long, or float | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: Uses vjo util class to cast | |
+ | |} | ||
− | + | ==== Widening reference conversions ==== | |
− | + | ||
− | + | ||
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| String stringObj = new String(); | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | String stringObj = new String(); | ||
Object object = new Object(); | Object object = new Object(); | ||
− | |||
object = stringObj; | object = stringObj; | ||
− | + | </source> | |
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
+ | <source lang="javascript"> | ||
+ | var stringObj=vjo.java.lang.StringFactory.build(); | ||
var object=new vjo.Object(); | var object=new vjo.Object(); | ||
− | |||
object=stringObj; | object=stringObj; | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | colspan="2" style="border: | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: Uses vjo reference implementation for all reference types |
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
− | |||
− | |||
+ | ==== Narrowing reference conversions ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | + | <source lang="java"> |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
import java.util.List; | import java.util.List; | ||
− | |||
public class Pair{ | public class Pair{ | ||
− | + | public List getNumber(Object object){ | |
− | public List getNumber(Object object){ | + | List list = (List) object; |
− | + | String str = (String) object; | |
− | List list = (List) object; | + | Object myObj = str; |
− | + | return list; | |
− | String str = (String) object; | + | } |
− | + | ||
− | Object myObj = str; | + | |
− | + | ||
− | return list; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public List getNumber(vjo.Object object) | |
− | //> public List getNumber(vjo.Object object) | + | getNumber:function(object){ |
− | + | var list=object; | |
− | getNumber:function(object){ | + | var str=object; |
− | + | var myObj=str; | |
− | var list=object; | + | return list; |
− | + | } | |
− | var str=object; | + | |
− | + | ||
− | var myObj=str; | + | |
− | + | ||
− | return list; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | colspan="2" style="border: | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
− | |||
+ | ==== Boxing conversions ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | + | <source lang="java"> |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
import java.util.List; | import java.util.List; | ||
− | |||
public class Pair{ | public class Pair{ | ||
− | + | Byte ob = 0; | |
− | Byte ob = 0; | + | Short os = 1; |
− | + | Integer oi = 10; | |
− | Short os = 1; | + | Long ol = 20l; |
− | + | Character oc = 'C'; | |
− | Integer oi = 10; | + | Float of = 10.2f; |
− | + | Double od = 12.3; | |
− | Long ol = 20l; | + | public void test(){ |
− | + | Byte ob = 0; | |
− | Character oc = 'C' | + | Short os = 1; |
− | + | Integer oi = 10; | |
− | Float of = 10.2f; | + | Long ol = 20l; |
− | + | Character oc = 'C'<nowiki>;</nowiki> | |
− | Double od = 12.3; | + | Float of = 10.2f; |
− | + | Double od = 12.3; | |
− | public void test(){ | + | } |
− | + | ||
− | Byte ob = 0; | + | |
− | + | ||
− | Short os = 1; | + | |
− | + | ||
− | Integer oi = 10; | + | |
− | + | ||
− | Long ol = 20l; | + | |
− | + | ||
− | Character oc = 'C'<nowiki>;</nowiki> | + | |
− | + | ||
− | Float of = 10.2f; | + | |
− | + | ||
− | Double od = 12.3; | + | |
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
.needs("vjo.java.lang.Byte") | .needs("vjo.java.lang.Byte") | ||
− | |||
.needs("vjo.java.lang.Short") | .needs("vjo.java.lang.Short") | ||
− | |||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Long") | .needs("vjo.java.lang.Long") | ||
− | |||
.needs("vjo.java.lang.Character") | .needs("vjo.java.lang.Character") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.needs("vjo.java.lang.Double") | .needs("vjo.java.lang.Double") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Byte ob | |
− | //> Byte ob | + | ob:0, |
− | + | //> Short os | |
− | ob:0, | + | os:1, |
− | + | //> Integer oi | |
− | //> Short os | + | oi:10, |
− | + | //> Long ol | |
− | os:1, | + | ol:20, |
− | + | //> Character oc | |
− | //> Integer oi | + | oc:'C', |
− | + | //> Float of | |
− | oi:10, | + | of:10.2, |
− | + | //> Double od | |
− | //> Long ol | + | od:12.3, |
− | + | //> public void test() | |
− | ol:20, | + | test:function(){ |
− | + | var ob=0; | |
− | //> Character oc | + | var os=1; |
− | + | var oi=10; | |
− | oc:'C', | + | var ol=20; |
− | + | var oc='C'; | |
− | //> Float of | + | var of=10.2; |
− | + | var od=12.3; | |
− | of:10.2, | + | } |
− | + | ||
− | //> Double od | + | |
− | + | ||
− | od:12.3, | + | |
− | + | ||
− | //> public void test() | + | |
− | + | ||
− | test:function(){ | + | |
− | + | ||
− | var ob=0; | + | |
− | + | ||
− | var os=1; | + | |
− | + | ||
− | var oi=10; | + | |
− | + | ||
− | var ol=20; | + | |
− | + | ||
− | var oc='C' | + | |
− | + | ||
− | var of=10.2; | + | |
− | + | ||
− | var od=12.3; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | colspan="2" style="border: | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| Type is declared in comment for jst translation |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
− | + | ||
− | + | # From type boolean to type Boolean | |
− | + | # From type byte to type Byte | |
− | + | # From type char to type Character | |
− | + | # From type short to type Short | |
− | + | # From type int to type Integer | |
− | + | # From type long to type Long | |
− | + | # From type float to type Float | |
− | + | # From type double to type Double | |
− | + | ||
− | + | ||
+ | ==== Unboxing conversions ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | + | <source lang="java"> |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
public class Pair{ | public class Pair{ | ||
+ | Byte ob = 0; | ||
+ | Short os = 1; | ||
+ | Integer oi = 10; | ||
+ | Long ol = 20l; | ||
+ | Character oc = 'C'; | ||
+ | Float of = 10.2f; | ||
+ | Double od = 12.3; | ||
− | + | byte b = ob; | |
− | + | short s = os; | |
− | + | int i = oi; | |
− | + | long l = ol; | |
− | + | char c = oc; | |
− | + | float f = of; | |
− | + | double d = od; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | byte b = ob | + | |
− | + | ||
− | short s = os | + | |
− | + | ||
− | int i = oi | + | |
− | + | ||
− | long l = ol | + | |
− | + | ||
− | char c = oc | + | |
− | + | ||
− | float f = of | + | |
− | + | ||
− | double d = od | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | ||
.needs("vjo.java.lang.Byte") | .needs("vjo.java.lang.Byte") | ||
− | |||
.needs("vjo.java.lang.Short") | .needs("vjo.java.lang.Short") | ||
− | |||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Long") | .needs("vjo.java.lang.Long") | ||
− | |||
.needs("vjo.java.lang.Character") | .needs("vjo.java.lang.Character") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.needs("vjo.java.lang.Double") | .needs("vjo.java.lang.Double") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Byte ob | |
− | //> Byte ob | + | ob:null, |
− | + | //> Short os | |
− | ob:null, | + | os:null, |
− | + | //> Integer oi | |
− | //> Short os | + | oi:null, |
− | + | //> Long ol | |
− | os:null, | + | ol:null, |
− | + | //> Character oc | |
− | //> Integer oi | + | oc:null, |
− | + | //> Float of | |
− | oi:null, | + | of:null, |
− | + | //> Double od | |
− | //> Long ol | + | od:null, |
− | + | //> byte b | |
− | ol:null, | + | b:0, |
− | + | //> short s | |
− | //> Character oc | + | s:0, |
− | + | //> int i | |
− | oc:null, | + | i:0, |
− | + | //> long l | |
− | //> Float of | + | l:0, |
− | + | //> char c | |
− | of:null, | + | c:null, |
− | + | //> float f | |
− | //> Double od | + | f:0, |
− | + | //> double d | |
− | od:null, | + | d:0, |
− | + | //> private constructs() | |
− | //> byte b | + | constructs:function(){ |
− | + | this.ob=new this.vjo.Byte(0); | |
− | b:0, | + | this.os=new this.vjo.Short(1); |
− | + | this.oi=new this.vjo.Integer(10); | |
− | //> short s | + | this.ol=new this.vjo.Long(20); |
− | + | this.oc=new this.vjo.Character('C'); | |
− | s:0, | + | this.of=new this.vjo.Float(10.2); |
− | + | this.od=new this.vjo.Double(12.3); | |
− | //> int i | + | this.b=this.ob.byteValue(); |
− | + | this.s=this.os.shortValue(); | |
− | i:0, | + | this.i=this.oi.intValue(); |
− | + | this.l=this.ol.longValue(); | |
− | //> long l | + | this.c=this.oc.charValue(); |
− | + | this.f=this.of.floatValue(); | |
− | l:0, | + | this.d=this.od.doubleValue(); |
− | + | } | |
− | //> char c | + | |
− | + | ||
− | c:null, | + | |
− | + | ||
− | //> float f | + | |
− | + | ||
− | f:0, | + | |
− | + | ||
− | //> double d | + | |
− | + | ||
− | d:0, | + | |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.ob=new this.vjo.Byte(0); | + | |
− | + | ||
− | this.os=new this.vjo.Short(1); | + | |
− | + | ||
− | this.oi=new this.vjo.Integer(10); | + | |
− | + | ||
− | this.ol=new this.vjo.Long(20); | + | |
− | + | ||
− | this.oc=new this.vjo.Character('C'); | + | |
− | + | ||
− | this.of=new this.vjo.Float(10.2); | + | |
− | + | ||
− | this.od=new this.vjo.Double(12.3); | + | |
− | + | ||
− | this.b=this.ob.byteValue(); | + | |
− | + | ||
− | this.s=this.os.shortValue(); | + | |
− | + | ||
− | this.i=this.oi.intValue(); | + | |
− | + | ||
− | this.l=this.ol.longValue(); | + | |
− | + | ||
− | this.c=this.oc.charValue(); | + | |
− | + | ||
− | this.f=this.of.floatValue(); | + | |
− | + | ||
− | this.d=this.od.doubleValue(); | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
− | + | # From type Boolean to type boolean | |
− | + | # From type Byte to type byte | |
− | + | # From type Character to type char | |
− | + | # From type Short to type short | |
− | + | # From type Integer to type int | |
− | + | # From type Long to type long | |
− | + | # From type Float to type float | |
− | + | # From type Double to type double | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | ==== Unchecked conversions – not supported ==== | ||
+ | ==== Capture conversions – not supported ==== | ||
+ | ==== String conversions - convert from any other type to String ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| String conversion applies only to the operands of the binary + operator when one | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| String conversion applies only to the operands of the binary + operator when one | ||
− | |||
of the arguments is a String. | of the arguments is a String. | ||
− | + | When adding string to any object, java calls toString() and append to the string. | |
− | + | This behavior is partially supported, ie., only with the user defined type with toString() | |
− | When adding string to any object, java calls toString() and append to the string. This behavior is partially supported, ie., only with the user defined type with toString() implemented in it, other java objects are not supported. | + | implemented in it, other java objects are not supported. |
− | + | |- style="vertical-align:top" | |
− | + | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | |
− | + | ||
− | + | ||
− | |- | + | |
− | + | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.conversion; | + | <source lang="java"> |
− | + | package j2jtest.conversion; | |
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Conversion { | public class Conversion { | ||
− | + | public void method1(){ | |
− | public void method1(){ | + | AnotherClass obj = new AnotherClass(); |
− | + | String simpleStr = " Simple String" + obj; | |
− | AnotherClass obj = new AnotherClass(); | + | Out.log("simpleStr = "+ simpleStr); |
− | + | } | |
− | String simpleStr = " Simple String" + obj | + | |
− | + | ||
− | Out. | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.conversion.Conversion") | |
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void method1() | |
− | //> public void method1() | + | method1:function(){ |
− | + | var obj=new this.vjo.AnotherClass(); | |
− | method1:function(){ | + | var simpleStr=" Simple String"+obj; |
− | + | this.vjo.Out.log("simpleStr = "+simpleStr); | |
− | var obj=new this.vjo.AnotherClass(); | + | } |
− | + | ||
− | var simpleStr=" Simple String"+obj; | + | |
− | + | ||
− | this.vjo.Out.log("simpleStr = "+simpleStr); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | + | <source lang="java"> |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
import java.util.ArrayList; | import java.util.ArrayList; | ||
− | |||
import java.util.List; | import java.util.List; | ||
− | |||
public class Pair{ | public class Pair{ | ||
− | + | List list = new ArrayList(); | |
− | List list = new ArrayList(); | + | String s<nowiki>= "a"+ list; |
− | + | public String getStringFromObject(List myList){ | |
− | String s<nowiki>= | + | String s = "Items in List "+ myList; |
− | + | return myList.toString(); | |
− | public String getStringFromObject(List myList){ | + | } |
− | + | ||
− | String s = "Items in List "+ myList; | + | |
− | + | ||
− | return myList.toString(); | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> List list | |
− | //> List list | + | list:null, |
− | + | //> String s | |
− | list:null, | + | s:null, |
− | + | //> private constructs() | |
− | //> String s | + | constructs:function(){ |
− | + | this.list=new this.vjo.ArrayList(); | |
− | s:null, | + | this.s="a"+this.list; |
− | + | }, | |
− | //> private constructs() | + | //> public String getStringFromObject(List myList) |
− | + | getStringFromObject:function(myList){ | |
− | constructs:function(){ | + | var s="Items in List "+myList; |
− | + | return myList.toString(); | |
− | this.list=new this.vjo.ArrayList(); | + | } |
− | + | ||
− | this.s="a"+this.list; | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public String getStringFromObject(List myList) | + | |
− | + | ||
− | getStringFromObject:function(myList){ | + | |
− | + | ||
− | var s="Items in List "+myList; | + | |
− | + | ||
− | return myList.toString(); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | colspan="2" style="border: | + | | colspan="2" | style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: use toString() method on reference object |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
+ | ==== Value set conversions - not supported'' , Value set conversion ''is the process of mapping a floating-point value from one value set to another without changing its type. ==== | ||
+ | ==== Assignment conversion ==== | ||
+ | ==== Method invocation conversion ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | + | <source lang="javascript"> |
− | + | package com.ebay.dsf.javatojs.tests.operators; | |
import java.util.ArrayList; | import java.util.ArrayList; | ||
− | |||
import java.util.List; | import java.util.List; | ||
− | |||
public class Pair{ | public class Pair{ | ||
− | + | public void testMethod(){ | |
− | public void testMethod(){ | + | Integer integer = new Integer(10); |
− | + | int intValue = 20; | |
− | Integer integer = new Integer(10); | + | ArrayList list = null; |
− | + | identityConversion(integer); | |
− | int intValue = 20; | + | wideningPrimitiveConversion(intValue); |
− | + | wideningReferenceConversion(list); | |
− | ArrayList list = null | + | boxingConversion(intValue); |
− | + | unboxingConversion(intValue); | |
− | + | } | |
− | identityConversion(integer); | + | public void identityConversion(Integer i){ |
− | + | } | |
− | wideningPrimitiveConversion(intValue); | + | public void wideningPrimitiveConversion(long l){ |
− | + | } | |
− | wideningReferenceConversion(list); | + | public void wideningReferenceConversion( List list){ |
− | + | } | |
− | boxingConversion(intValue); | + | public void boxingConversion(Integer i){ |
− | + | } | |
− | unboxingConversion(intValue); | + | public void unboxingConversion(int i){ |
− | + | } | |
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void testMethod() | |
− | //> public void testMethod() | + | testMethod:function(){ |
− | + | var integer=new this.vjo.Integer(10); | |
− | testMethod:function(){ | + | var intValue=20; |
− | + | var list=null; | |
− | var integer=new this.vjo.Integer(10); | + | this.identityConversion(integer); |
− | + | this.wideningPrimitiveConversion(intValue); | |
− | var intValue=20; | + | this.wideningReferenceConversion(list); |
− | + | this.boxingConversion(new this.vjo.Integer(intValue)); | |
− | var list=null | + | this.unboxingConversion(intValue); |
− | + | }, | |
− | this.identityConversion(integer); | + | //> public void identityConversion(Integer i) |
− | + | identityConversion:function(i){ | |
− | this.wideningPrimitiveConversion(intValue); | + | }, |
− | + | //> public void wideningPrimitiveConversion(long l) | |
− | this.wideningReferenceConversion(list); | + | wideningPrimitiveConversion:function(l){ |
− | + | }, | |
− | this.boxingConversion(new this.vjo.Integer(intValue)); | + | //> public void wideningReferenceConversion(List list) |
− | + | wideningReferenceConversion:function(list){ | |
− | this.unboxingConversion(intValue); | + | }, |
− | + | //> public void boxingConversion(Integer i) | |
− | }, | + | boxingConversion:function(i){ |
− | + | }, | |
− | //> public void identityConversion(Integer i) | + | //> public void unboxingConversion(int i) |
− | + | unboxingConversion:function(i){ | |
− | identityConversion:function(i){ | + | } |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void wideningPrimitiveConversion(long l) | + | |
− | + | ||
− | wideningPrimitiveConversion:function(l){ | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void wideningReferenceConversion(List list) | + | |
− | + | ||
− | wideningReferenceConversion:function(list){ | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void boxingConversion(Integer i) | + | |
− | + | ||
− | boxingConversion:function(i){ | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void unboxingConversion(int i) | + | |
− | + | ||
− | unboxingConversion:function(i){ | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
− | + | ==== String conversion ==== | |
− | + | ==== Casting conversion ==== | |
+ | ==== Numeric promotion ==== | ||
== Names == | == Names == | ||
− | |||
− | |||
+ | === Declarations === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| declarations | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| declarations | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| package | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.javatojs.tests.operators; | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | vjo.ctype | |
− | + | ||
− | + | ||
− | + | ||
(“com.ebay.dsf.javatojs.tests.operators.Pair”) | (“com.ebay.dsf.javatojs.tests.operators.Pair”) | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | rowspan="3" style="border:1px solid #AAAAAA;padding: 0.2em;"| import |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| import | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | colspan="2" | + | Only single type import is supported. |
− | + | ||
Import on demand would be converted into necessary single type import. | Import on demand would be converted into necessary single type import. | ||
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | + | import java.util.ArrayList; | |
− | |- | + | |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| import java.util.ArrayList; | + | |
− | + | ||
import java.util.List; | import java.util.List; | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | .needs("vjo.java.lang.Integer") | ||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| import java.util.*; | | style="border:1px solid #AAAAAA;padding: 0.2em;"| import java.util.*; | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | .needs("vjo.java.lang.Integer") | |
− | + | ||
− | + | ||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| class | | style="border:1px solid #AAAAAA;padding: 0.2em;"| class | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| public class Pair | | style="border:1px solid #AAAAAA;padding: 0.2em;"| public class Pair | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") | |
− | + | |- style="vertical-align:top" | |
− | |- | + | |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| interface | | style="border:1px solid #AAAAAA;padding: 0.2em;"| interface | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package com.ebay.dsf.operators; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package com.ebay.dsf.operators; | ||
public interface PairInterface{ | public interface PairInterface{ | ||
− | |||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.itype("com.ebay.dsf.operators.PairInterface") | ||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| member class | | style="border:1px solid #AAAAAA;padding: 0.2em;"| member class | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
+ | private int p = 0; | ||
+ | class PairInner{ | ||
+ | int iCanAccessParentPrivateToo(){ | ||
+ | return p; | ||
+ | } | ||
+ | } | ||
+ | public void testMethod(){ | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
− | + | //> private int p | |
− | //> private int p | + | p:0, |
− | + | PairInner:vjo.ctype() | |
− | p:0, | + | .protos({ |
− | + | //> int iCanAccessParentPrivateToo() | |
− | PairInner:vjo.ctype() | + | iCanAccessParentPrivateToo:function(){ |
− | + | return this.vjo.outer.p; | |
− | .protos({ | + | } |
− | + | }) | |
− | //> int iCanAccessParentPrivateToo() | + | .endType(), |
− | + | //> public void testMethod() | |
− | iCanAccessParentPrivateToo:function(){ | + | testMethod:function(){ |
− | + | } | |
− | return this.vjo.outer.p; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| member interface | | style="border:1px solid #AAAAAA;padding: 0.2em;"| member interface | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
− | + | interface Colors { | |
− | interface Colors { | + | int ''WHITE'' = 0, ''BLACK'' = 1; |
− | + | int getColor(); | |
− | int ''WHITE'' = 0, ''BLACK'' = 1; | + | } |
− | + | ||
− | int getColor(); | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
.protos({ | .protos({ | ||
− | + | Colors:vjo.itype() | |
− | Colors:vjo.itype() | + | .props({ |
− | + | //> public int WHITE | |
− | .props({ | + | WHITE:0, |
− | + | //> public int BLACK | |
− | //> public int WHITE | + | BLACK:1 |
− | + | }) | |
− | WHITE:0, | + | .protos({ |
− | + | //> public int getColor() | |
− | //> public int BLACK | + | getColor:function(){ |
− | + | } | |
− | BLACK:1 | + | }) |
− | + | .endType() | |
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| enum constant | + | | rowspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| enum constant |
− | | colspan="2" style="border: | + | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| TODO: ERROR: Enum, not completely implemented. See the missing function for enum SUNDAY |
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | + | package j2jtest; | |
− | |- | + | |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | |
− | + | ||
public enum EnumTest { | public enum EnumTest { | ||
− | + | SUNDAY{ | |
− | + | int getIndex(){ | |
− | + | return 0; | |
− | int getIndex(){ | + | } |
− | + | }, | |
− | return 0; | + | MONDAY, |
− | + | TUESDAY, | |
+ | WEDNESDAY, | ||
+ | THURSDAY, | ||
+ | FRIDAY, | ||
+ | SATURDAY | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.etype("j2jtest.EnumTest") | |
− | + | .values("SUNDAY, MONDAY, TUESDAY, | |
− | + | WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | .values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") | + | |
− | + | ||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| field in class and interface | | style="border:1px solid #AAAAAA;padding: 0.2em;"| field in class and interface | ||
− | |||
method in class and interface | method in class and interface | ||
− | |||
local variable in block | local variable in block | ||
− | |||
local variable in for statement | local variable in for statement | ||
− | |||
parameter of a method in class and interface | parameter of a method in class and interface | ||
− | |||
parameter of an exception handler | parameter of an exception handler | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | package j2jtest; |
− | + | ||
public class Pair{ | public class Pair{ | ||
− | |||
Integer fieldInClass = new Integer(10); | Integer fieldInClass = new Integer(10); | ||
− | + | public void methodInClass | |
− | public void methodInClass(String parameterOfaMethodInClass){ | + | (String parameterOfaMethodInClass){ |
− | + | String sh = "shhhhhh!";{ | |
− | String sh = "shhhhhh!" | + | |
− | + | ||
Integer localVarInblock = 90; | Integer localVarInblock = 90; | ||
− | |||
} | } | ||
− | + | for( int i=0; i<20; i++){ | |
− | for( int | + | |
− | + | ||
String localVarInForStatement = ""+i; | String localVarInForStatement = ""+i; | ||
− | |||
try{ | try{ | ||
− | |||
Integer k = new Integer(localVarInForStatement); | Integer k = new Integer(localVarInForStatement); | ||
− | |||
}catch (Exception parameterOfAnExceptionHandler){ | }catch (Exception parameterOfAnExceptionHandler){ | ||
− | |||
} | } | ||
− | |||
} | } | ||
− | |||
} | } | ||
− | |||
interface Colors { | interface Colors { | ||
− | |||
Integer ''fieldInInterface'' = 20; | Integer ''fieldInInterface'' = 20; | ||
− | + | int methodInInterface | |
− | int methodInInterface(String parameterOfaMethodInInterface); | + | (String parameterOfaMethodInInterface); |
− | + | ||
} | } | ||
− | |||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Exception") | .needs("vjo.java.lang.Exception") | ||
− | |||
.protos({ | .protos({ | ||
− | |||
//> Integer fieldInClass | //> Integer fieldInClass | ||
− | |||
fieldInClass:null, | fieldInClass:null, | ||
− | |||
Colors:vjo.itype() | Colors:vjo.itype() | ||
− | |||
.props({ | .props({ | ||
− | |||
//> public Integer fieldInInterface | //> public Integer fieldInInterface | ||
− | |||
fieldInInterface:null | fieldInInterface:null | ||
− | |||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public int methodInInterface | |
− | //> public int methodInInterface(String parameterOfaMethodInInterface) | + | (String parameterOfaMethodInInterface) |
− | + | methodInInterface:function | |
− | methodInInterface:function(parameterOfaMethodInInterface){ | + | (parameterOfaMethodInInterface){ |
− | + | ||
} | } | ||
− | |||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.Colors.fieldInInterface= | |
− | this.vjo.Colors.fieldInInterface=new this.vjo.Integer(20); | + | new this.vjo.Integer(20); |
− | + | ||
}) | }) | ||
− | |||
.endType(), | .endType(), | ||
− | |||
//> private constructs() | //> private constructs() | ||
− | |||
constructs:function(){ | constructs:function(){ | ||
− | |||
this.fieldInClass=new this.vjo.Integer(10); | this.fieldInClass=new this.vjo.Integer(10); | ||
− | |||
}, | }, | ||
− | + | //> public void methodInClass | |
− | //> public void methodInClass(String parameterOfaMethodInClass) | + | (String parameterOfaMethodInClass) |
− | + | ||
methodInClass:function(parameterOfaMethodInClass){ | methodInClass:function(parameterOfaMethodInClass){ | ||
− | |||
var sh="shhhhhh!"<nowiki>;</nowiki> | var sh="shhhhhh!"<nowiki>;</nowiki> | ||
− | |||
{ | { | ||
− | |||
var localVarInblock=new this.vjo.Integer(90); | var localVarInblock=new this.vjo.Integer(90); | ||
− | |||
} | } | ||
− | |||
for (var <nowiki>i=0;i<20;i++)</nowiki>{ | for (var <nowiki>i=0;i<20;i++)</nowiki>{ | ||
− | |||
var localVarInForStatement=""+i; | var localVarInForStatement=""+i; | ||
− | |||
try { | try { | ||
− | + | var k=new this.vjo.Integer | |
− | var k=new this.vjo.Integer(localVarInForStatement); | + | (localVarInForStatement); |
− | + | ||
} | } | ||
− | |||
catch(parameterOfAnExceptionHandler){ | catch(parameterOfAnExceptionHandler){ | ||
− | |||
} | } | ||
− | |||
} | } | ||
− | |||
} | } | ||
− | |||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
− | |||
+ | === Names and Identifiers === | ||
+ | === Scope of a Declaration === | ||
+ | ==== Shadowing Declaration ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | <source lang="java"> |
− | + | package j2jtest; | |
public class Pair{ | public class Pair{ | ||
+ | int x = 20; | ||
+ | void myMethod(){ | ||
+ | int x = 10; | ||
+ | System.err.println("x ="+ x); | ||
+ | System.err.println("thix.x="+ this.x); | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
.needs("vjo.java.lang.System") | .needs("vjo.java.lang.System") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> int x | |
− | //> int x | + | x:20, |
− | + | //> void myMethod() | |
− | x:20, | + | myMethod:function(){ |
− | + | var x=10; | |
− | //> void myMethod() | + | this.vjo.System.err.println("x = "+x); |
− | + | this.vjo.System.err.println("thix.x = "+this.x); | |
− | myMethod:function(){ | + | } |
− | + | ||
− | var x=10; | + | |
− | + | ||
− | this.vjo.System.err.println("x = "+x); | + | |
− | + | ||
− | this.vjo.System.err.println("thix.x = "+this.x); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
+ | </source> | ||
+ | |- style="vertical-align:top" | ||
+ | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| Above shows shadowing of a field x by a local variable x . | ||
+ | |} | ||
− | + | ==== Obscured Declarations ==== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | === Members and Inheritance === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.member; | + | <source lang="java"> |
− | + | package j2jtest.member; | |
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Derived extends Base{ | public class Derived extends Base{ | ||
− | + | String instanceMember; | |
− | String instanceMember | + | static String staticMember; |
− | + | public void method1(){ | |
− | static String | + | String local = inheritedMemberVar; |
− | + | local = inheritedStaticMemberVar; | |
− | public void method1(){ | + | local = instanceMember; |
− | + | local = staticMember; | |
− | String local = inheritedMemberVar | + | local = ""; |
− | + | inheritedMemberMethod(); | |
− | local = | + | inheritedStaticMemberMethod(); |
− | + | override(); | |
− | local = instanceMember | + | super.override(); |
− | + | overload(); | |
− | local = | + | overload(local); |
− | + | } | |
− | local = "" | + | public void memberMethod(){ |
− | + | Out.log("Derived.memberMethod"); | |
− | inheritedMemberMethod(); | + | } |
− | + | public static void memberStaticMethod(){ | |
− | inheritedStaticMemberMethod(); | + | Out.log("Derived.memberStaticMethod"); |
− | + | } | |
− | override(); | + | public void override(){ |
− | + | Out.log("Derived.override"); | |
− | super.override(); | + | } |
− | + | public void overload(String s){ | |
− | overload(); | + | Out.log("Derived.overload(String)"); |
− | + | } | |
− | overload( | + | public void abstractMethod(){ |
− | + | Out.log("Derived.abstractMethod"); | |
+ | } | ||
+ | public void abstractMethod(String value){ | ||
+ | Out.log("Derived.abstractMethod(String)"); | ||
+ | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
package j2jtest.member; | package j2jtest.member; | ||
− | |||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public abstract class Base { | public abstract class Base { | ||
+ | String inheritedMemberVar; | ||
+ | static String inheritedStaticMemberVar; | ||
− | + | public void inheritedMemberMethod(){ | |
− | + | Out.log("Base.inheritedMemberMethod"); | |
− | + | } | |
− | + | public void inheritedStaticMemberMethod(){ | |
− | + | Out.log("Base.inheritedStaticMemberMethod"); | |
− | public void inheritedMemberMethod(){ | + | } |
− | + | public void override(){ | |
− | Out. | + | Out.log("Base.override"); |
− | + | } | |
− | } | + | public void overload(){ |
− | + | Out.log("Base.overload"); | |
− | public void inheritedStaticMemberMethod(){ | + | } |
− | + | }</source> | |
− | Out. | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="javascript"> | |
− | } | + | vjo.ctype("j2jtest.member.Derived") |
− | + | ||
− | public void override(){ | + | |
− | + | ||
− | Out. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | public void overload(){ | + | |
− | + | ||
− | Out. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.needs("j2jtest.member.Base") | .needs("j2jtest.member.Base") | ||
− | |||
.inherits("j2jtest.member.Base") | .inherits("j2jtest.member.Base") | ||
− | |||
.props({ | .props({ | ||
− | + | //> String staticMember | |
− | //> String staticMember | + | staticMember:null, |
− | + | //> public void memberStaticMethod() | |
− | staticMember:null, | + | memberStaticMethod:function(){ |
− | + | this.vjo.Out.log("Derived.memberStaticMethod"); | |
− | //> public void memberStaticMethod() | + | } |
− | + | ||
− | memberStaticMethod:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("Derived.memberStaticMethod"); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> String instanceMember | |
− | //> String instanceMember | + | instanceMember:null, |
− | + | //> public void method1() | |
− | instanceMember:null, | + | method1:function(){ |
− | + | var local=this.inheritedMemberVar; | |
− | //> public void method1() | + | local=this.vjo.Base.inheritedStaticMemberVar; |
− | + | local=this.instanceMember; | |
− | method1:function(){ | + | local=this.vjo.Derived.staticMember; |
− | + | local=""; | |
− | var local=this.inheritedMemberVar; | + | this.inheritedMemberMethod(); |
− | + | this.inheritedStaticMemberMethod(); | |
− | local=this.vjo.Base.inheritedStaticMemberVar; | + | this.override(); |
− | + | this.base.override(); | |
− | local=this.instanceMember; | + | overload(); |
− | + | this.overload(local); | |
− | local=this.vjo.Derived.staticMember; | + | }, |
− | + | //> public void memberMethod() | |
− | local="" | + | memberMethod:function(){ |
− | + | this.vjo.Out.log("Derived.memberMethod"); | |
− | this.inheritedMemberMethod(); | + | }, |
− | + | //> public void override() | |
− | this.inheritedStaticMemberMethod(); | + | override:function(){ |
− | + | this.vjo.Out.log("Derived.override"); | |
− | this.override(); | + | }, |
− | + | //> public void abstractMethod() | |
− | this.base.override(); | + | //> public void abstractMethod(String value) |
− | + | abstractMethod:function(){ | |
− | overload(); | + | if(arguments.length===0){ |
− | + | this.abstractMethod_0_0_Derived_ovld(); | |
− | this.overload(local); | + | }else if(this.base && this.base.abstractMethod){ |
− | + | this.base.abstractMethod.apply(this,arguments); | |
− | }, | + | }else if(arguments.length===1){ |
− | + | if(arguments[0] instanceof String || | |
− | //> public void memberMethod() | + | typeof arguments[0]=="string"){ |
− | + | this.abstractMethod_1_0_Derived_ovld(arguments[0]); | |
− | memberMethod:function(){ | + | }else if(this.base && this.base.abstractMethod){ |
− | + | this.base.abstractMethod.apply(this,arguments); | |
− | this.vjo.Out.log("Derived.memberMethod"); | + | } |
− | + | }else if(this.base && this.base.abstractMethod){ | |
− | }, | + | this.base.abstractMethod.apply(this,arguments); |
− | + | } | |
− | //> public void override() | + | }, |
− | + | //> private void abstractMethod_0_0_Derived_ovld() | |
− | override:function(){ | + | abstractMethod_0_0_Derived_ovld:function(){ |
− | + | this.vjo.Out.log("Derived.abstractMethod"); | |
− | this.vjo.Out.log("Derived.override"); | + | }, |
− | + | //> private void | |
− | }, | + | //abstractMethod_1_0_Derived_ovld(String value) |
− | + | abstractMethod_1_0_Derived_ovld:function(value){ | |
− | //> public void abstractMethod() | + | this.vjo.Out.log("Derived.abstractMethod(String)"); |
− | + | }, | |
− | //> public void abstractMethod(String value) | + | //> public void overload(String s) |
− | + | overload:function(s){ | |
− | abstractMethod:function(){ | + | if(arguments.length===1){ |
− | + | if(arguments[0] instanceof String || | |
− | if(arguments.length===0){ | + | typeof arguments[0]=="string"){ |
− | + | this.overload_1_0_Derived_ovld(arguments[0]); | |
− | this.abstractMethod_0_0_Derived_ovld(); | + | }else if(this.base && this.base.overload){ |
− | + | this.base.overload.apply(this,arguments); | |
− | }else if(this.base && this.base.abstractMethod){ | + | } |
− | + | }else if(this.base && this.base.overload){ | |
− | this.base.abstractMethod.apply(this,arguments); | + | this.base.overload.apply(this,arguments); |
− | + | } | |
− | }else if(arguments.length===1){ | + | }, |
− | + | //> private void overload_1_0_Derived_ovld(String s) | |
− | if | + | overload_1_0_Derived_ovld:function(s){ |
− | + | this.vjo.Out.log("Derived.overload(String)"); | |
− | this | + | } |
− | + | ||
− | }else if(this.base && this.base.abstractMethod){ | + | |
− | + | ||
− | this.base.abstractMethod.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }else if(this.base && this.base.abstractMethod){ | + | |
− | + | ||
− | this.base.abstractMethod.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> private void abstractMethod_0_0_Derived_ovld() | + | |
− | + | ||
− | abstractMethod_0_0_Derived_ovld:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("Derived.abstractMethod"); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> private void abstractMethod_1_0_Derived_ovld(String value) | + | |
− | + | ||
− | abstractMethod_1_0_Derived_ovld:function(value){ | + | |
− | + | ||
− | this.vjo.Out.log("Derived.abstractMethod(String)"); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void overload(String s) | + | |
− | + | ||
− | overload:function(s){ | + | |
− | + | ||
− | if(arguments.length===1){ | + | |
− | + | ||
− | if | + | |
− | + | ||
− | this | + | |
− | + | ||
− | }else if(this.base && this.base.overload){ | + | |
− | + | ||
− | this.base.overload.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }else if(this.base && this.base.overload){ | + | |
− | + | ||
− | this.base.overload.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> private void overload_1_0_Derived_ovld(String s) | + | |
− | + | ||
− | overload_1_0_Derived_ovld:function(s){ | + | |
− | + | ||
− | this.vjo.Out.log("Derived.overload(String)"); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | === Access Control === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
+ | int packageAccess; | ||
+ | public int publicAccess; | ||
+ | private int privateAccess; | ||
+ | protected int protectedAccess; | ||
+ | void packageMethod(){ | ||
− | + | } | |
+ | public void publicMethod(){ | ||
− | + | } | |
+ | private void privateMethod(){ | ||
− | + | } | |
− | + | protected void protectedMethod(){ | |
− | protected | + | |
− | + | ||
− | + | ||
− | void | + | |
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
+ | //> int packageAccess | ||
+ | packageAccess:0, | ||
+ | //> public int publicAccess | ||
+ | publicAccess:0, | ||
+ | //> private int privateAccess | ||
+ | privateAccess:0, | ||
+ | //> protected int protectedAccess | ||
+ | protectedAccess:0, | ||
+ | //> void packageMethod() | ||
+ | packageMethod:function(){ | ||
− | //> | + | }, |
+ | //> public void publicMethod() | ||
+ | publicMethod:function(){ | ||
− | + | }, | |
+ | //> private void privateMethod() | ||
+ | privateMethod:function(){ | ||
− | + | }, | |
− | + | //> protected void protectedMethod() | |
− | + | protectedMethod:function(){ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //> protected void protectedMethod() | + | |
− | + | ||
− | protectedMethod:function(){ | + | |
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | === Fully Qualified Names and Canonical Names === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
+ | <source lang="java"> | ||
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
− | + | java.lang.Integer packageAccess; | |
− | java.lang.Integer packageAccess | + | java.util.List l = new java.util.ArrayList(); |
− | + | java.util.Date utilDate = new java.util.Date(); | |
− | java.util.List l = new java.util.ArrayList(); | + | java.sql.Date sqlDate = |
− | + | new java.sql.Date(utilDate.getTime()); | |
− | java.util.Date utilDate = new java.util.Date(); | + | |
− | + | ||
− | java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.needs("java.util.Date") | .needs("java.util.Date") | ||
− | |||
.needs("java.sql.Date") | .needs("java.sql.Date") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer packageAccess | |
− | //> Integer packageAccess | + | packageAccess:null, |
− | + | //> List l | |
− | packageAccess:null, | + | l:null, |
− | + | //> Date utilDate | |
− | //> List l | + | utilDate:null, |
− | + | //> Date sqlDate | |
− | l:null, | + | sqlDate:null, |
− | + | //> private constructs() | |
− | //> Date utilDate | + | constructs:function(){ |
− | + | this.l=new this.vjo.ArrayList(); | |
− | utilDate:null, | + | this.utilDate=new java.util.Date(); |
− | + | this.sqlDate=new java.sql.Date(this.utilDate.getTime()); | |
− | //> Date sqlDate | + | } |
− | + | ||
− | sqlDate:null, | + | |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.l=new this.vjo.ArrayList(); | + | |
− | + | ||
− | this.utilDate=new java.util.Date(); | + | |
− | + | ||
− | this.sqlDate=new java.sql.Date(this.utilDate.getTime()); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | == Packages == | ||
− | |||
− | + | === Package Members === | |
+ | === Compilation Units === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| No implicit imports (ex., java.lang package), imported only if it’s used. | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| No implicit imports (ex., java.lang package), imported only if it’s used. | ||
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | |- | + | package j2jtest; |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | |
− | + | ||
public class Pair{ | public class Pair{ | ||
− | + | Integer i = 10; | |
− | Integer i = 10; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer i | |
− | //> Integer i | + | i:null, |
− | + | //> private constructs() | |
− | i:null, | + | constructs:function(){ |
− | + | this.i=new this.vjo.Integer(10); | |
− | //> private constructs() | + | } |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.i=new this.vjo.Integer(10); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | === Package Declarations === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| There is no explicit package declaration, package name is added to type declaration (name space of type) | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| There is no explicit package declaration, package name is added to type declaration (name space of type) | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
− | + | </source> | |
|} | |} | ||
− | |||
+ | === Import === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| Does not support import on-demand, for ex., package.*; | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| Does not support import on-demand, for ex., package.*; | ||
− | |||
All the compilation units needs to be imported separately . | All the compilation units needs to be imported separately . | ||
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="java"> | |
− | |- | + | package j2jtest; |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | import java.util.*; // |
− | + | ||
− | + | ||
− | import java.util.* | + | |
− | + | ||
public class Pair{ | public class Pair{ | ||
− | + | List list; | |
− | List list | + | HashMap map; |
− | + | ||
− | HashMap map | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.HashMap") | .needs("vjo.java.util.HashMap") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> List list | |
− | //> List list | + | list:null, |
− | + | //> HashMap map | |
− | list:null, | + | map:null |
− | + | ||
− | //> HashMap map | + | |
− | + | ||
− | map:null | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | === Top Level Type Declarations === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| All types should be imported explicitly even if the type belongs to the same package. For ex., from the below code, though Pair2 is defined in the same package of Pair, it requires import, | | colspan="2" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| All types should be imported explicitly even if the type belongs to the same package. For ex., from the below code, though Pair2 is defined in the same package of Pair, it requires import, | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | + | package j2jtest; | |
import java.util.*; | import java.util.*; | ||
− | |||
public class Pair{ | public class Pair{ | ||
− | + | List list; | |
− | List list | + | HashMap map; |
− | + | Pair2 pair2OnSamePackage; | |
− | HashMap map | + | |
− | + | ||
− | Pair2 pair2OnSamePackage | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.HashMap") | .needs("vjo.java.util.HashMap") | ||
− | |||
.needs("j2jtest.Pair2") | .needs("j2jtest.Pair2") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> List list | |
− | //> List list | + | list:null, |
− | + | //> HashMap map | |
− | list:null, | + | map:null, |
− | + | //> Pair2 pair2OnSamePackage | |
− | //> HashMap map | + | pair2OnSamePackage:null |
− | + | ||
− | map:null, | + | |
− | + | ||
− | //> Pair2 pair2OnSamePackage | + | |
− | + | ||
− | pair2OnSamePackage:null | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | + | == Classes == | |
− | + | ||
+ | === Class Declaration === | ||
+ | ==== Class Modifiers ==== | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| class |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair{ | public class Pair{ | ||
− | + | Integer i = 10; | |
− | Integer i = 10; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer i | |
− | //> Integer i | + | i:null, |
− | + | //> private constructs() | |
− | i:null, | + | constructs:function(){ |
− | + | this.i=new this.vjo.Integer(10); | |
− | //> private constructs() | + | } |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.i=new this.vjo.Integer(10); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract class | | style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract class | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public abstract class AbstractClassTest{ | public abstract class AbstractClassTest{ | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.AbstractClassTest") | ||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| final class | | style="border:1px solid #AAAAAA;padding: 0.2em;"| final class | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public final class AbstractClassTest{ | public final class AbstractClassTest{ | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.AbstractClassTest") | ||
.makeFinal() | .makeFinal() | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Sstrictfp class | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Sstrictfp class | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Not supported | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
− | + | ||
− | + | ==== Generic Classes and Type Parameters ==== | |
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
− | + | <source lang="java"> | |
− | + | package j2jtest; | |
− | + | public class Pair<T>{ | |
− | + | T value; | |
− | + | void set(T t){ | |
− | + | this.value = t; | |
− | public class | + | } |
− | + | T get(){ | |
− | T value | + | return value; |
− | + | } | |
− | void set(T t){ | + | Pair<String> testMethod(){ |
− | + | Pair<String> pair = new Pair<String>(); | |
− | this.value = t; | + | return pair; |
− | + | } | |
} | } | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
− | + | //> T value | |
− | //> T value | + | value:null, |
− | + | //> void set(T t) | |
− | value:null, | + | set:function(t){ |
− | + | this.value=t; | |
− | //> void set(T t) | + | }, |
− | + | //> T get() | |
− | set:function(t){ | + | get:function(){ |
− | + | return this.value; | |
− | this.value=t; | + | } |
− | + | ||
− | }, | + | |
− | + | ||
− | //> T get() | + | |
− | + | ||
− | get:function(){ | + | |
− | + | ||
− | return this.value; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | //> Pair<String> testMethod() | |
− | + | ||
− | + | ||
testMethod:function(){ | testMethod:function(){ | ||
− | + | var pair=new this.vjo.Pair(); | |
− | var pair=new this.vjo.Pair(); | + | return pair; |
− | + | ||
− | return pair; | + | |
− | + | ||
} | } | ||
− | + | </source> | |
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | ==== Inner Classes and Enclosing Instances ==== | ||
+ | # Nested | ||
+ | ## static | ||
+ | ## inner | ||
+ | ### anonymous | ||
+ | ### local | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
| colspan="3" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| <center>Nested</center> | | colspan="3" style="border:0.018cm solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"| <center>Nested</center> | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Static | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Static | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest; | ||
public class Pair2 { | public class Pair2 { | ||
+ | void anOuterMethod() { | ||
− | void | + | } |
+ | public static class NestedStatic { | ||
+ | void aNestedStaticMethod() { | ||
+ | } | ||
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.props({ | .props({ | ||
+ | NestedStatic://> public NestedStatic | ||
+ | vjo.ctype() | ||
+ | .protos({ | ||
+ | //> void aNestedStaticMethod() | ||
+ | aNestedStaticMethod:function(){ | ||
− | + | } | |
− | + | }) | |
− | + | .endType() | |
− | + | ||
− | . | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
.protos({ | .protos({ | ||
+ | //> void anOuterMethod() | ||
+ | anOuterMethod:function(){ | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| inner –one level | | style="border:1px solid #AAAAAA;padding: 0.2em;"| inner –one level | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | + | package j2jtest; | |
public class OuterClass { | public class OuterClass { | ||
− | + | int outerVar = 10; | |
− | int outerVar = 10; | + | class InnerClass{ |
− | + | void innerMethod(){ | |
− | class InnerClass{ | + | Out.log("inner" +outerVar); |
− | + | } | |
− | void innerMethod(){ | + | } |
− | + | static void testMethod(){ | |
− | Out. | + | OuterClass outerClass = |
− | + | new OuterClass(); | |
+ | OuterClass.InnerClass innerClass = | ||
+ | new OuterClass().new InnerClass(); | ||
+ | innerClass.innerMethod(); | ||
+ | innerClass = outerClass.new InnerClass(); | ||
+ | innerClass.innerMethod(); | ||
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.OuterClass") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.props({ | .props({ | ||
− | + | //> void testMethod() | |
− | //> void testMethod() | + | testMethod:function(){ |
− | + | var outerClass=new this(); | |
− | testMethod:function(){ | + | var innerClass= |
− | + | new (new this()).InnerClass(); | |
− | var outerClass=new this(); | + | innerClass.innerMethod(); |
− | + | innerClass= | |
− | var innerClass=new (new this()).InnerClass(); | + | new outerClass.InnerClass(); |
− | + | innerClass.innerMethod(); | |
− | innerClass.innerMethod(); | + | } |
− | + | ||
− | innerClass=new outerClass.InnerClass(); | + | |
− | + | ||
− | innerClass.innerMethod(); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> int outerVar | |
− | + | outerVar:10, | |
− | //> int outerVar | + | InnerClass://> InnerClass |
− | + | vjo.ctype() | |
− | outerVar:10, | + | .protos({ |
− | + | //> void innerMethod() | |
− | InnerClass://> InnerClass | + | innerMethod:function(){ |
− | + | this.vjo.Out.log( | |
− | vjo.ctype() | + | "Inside inner class"+ |
− | + | this.vjo.outer.outerVar); | |
− | .protos({ | + | } |
− | + | }) | |
− | //> void innerMethod() | + | .endType() |
− | + | ||
− | innerMethod:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("Inside inner class"+this.vjo.outer.outerVar); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| inner –two level | | style="border:1px solid #AAAAAA;padding: 0.2em;"| inner –two level | ||
− | |||
− | |||
ERROR | ERROR | ||
− | |||
− | |||
inInClass, not getting created | inInClass, not getting created | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | + | package j2jtest; | |
public class OuterClass { | public class OuterClass { | ||
− | + | int outerVar = 10; | |
− | int outerVar = 10; | + | class InnerClass{ |
− | + | class InnerInnerClass{ | |
− | class InnerClass{ | + | void innerInnerMethod(String mssg){ |
− | + | Out.log("InnerInner " +mssg); | |
− | class InnerInnerClass{ | + | } |
− | + | } | |
− | void innerInnerMethod(String mssg){ | + | void innerMethod(String mssg){ |
− | + | Out.log("Inner " +mssg); | |
− | Out. | + | } |
− | + | } | |
+ | static void testMethod(){ | ||
+ | OuterClass.InnerClass innerClass = | ||
+ | new OuterClass().new InnerClass(); | ||
+ | |||
+ | OuterClass.InnerClass.InnerInnerClass | ||
+ | inInClass = | ||
+ | innerClass.new InnerInnerClass(); | ||
+ | |||
+ | innerClass.innerMethod("mssg1"); | ||
+ | inInClass.innerInnerMethod("mssg2"); | ||
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.OuterClass") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.props({ | .props({ | ||
− | + | //> void testMethod() | |
− | //> void testMethod() | + | testMethod:function(){ |
− | + | var innerClass=new (new this()) | |
− | testMethod:function(){ | + | .InnerClass(); |
− | + | var inInClass; | |
− | var innerClass=new (new this()).InnerClass(); | + | innerClass.innerMethod("mssg1"); |
− | + | inInClass.innerInnerMethod("mssg2"); | |
− | var inInClass; | + | } |
− | + | ||
− | innerClass.innerMethod("mssg1"); | + | |
− | + | ||
− | inInClass.innerInnerMethod("mssg2"); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> int outerVar | |
− | //> int outerVar | + | outerVar:10, |
− | + | InnerClass://> InnerClass | |
− | outerVar:10, | + | vjo.ctype() |
− | + | .protos({ | |
− | InnerClass://> InnerClass | + | InnerInnerClass://> InnerInnerClass |
− | + | vjo.ctype() | |
− | vjo.ctype() | + | .protos({ |
− | + | //> void innerInnerMethod(String mssg) | |
− | .protos({ | + | innerInnerMethod:function(mssg){ |
− | + | this.vjo.Out.log("InnerInner "+mssg); | |
− | InnerInnerClass://> InnerInnerClass | + | } |
− | + | }) | |
− | vjo.ctype() | + | .endType(), |
− | + | //> void innerMethod(String mssg) | |
− | .protos({ | + | innerMethod:function(mssg){ |
− | + | this.vjo.Out.log("Inner "+mssg); | |
− | //> void innerInnerMethod(String mssg) | + | } |
− | + | }) | |
− | innerInnerMethod:function(mssg){ | + | .endType() |
− | + | ||
− | this.vjo.Out.log("InnerInner "+mssg); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| anonymous | | style="border:1px solid #AAAAAA;padding: 0.2em;"| anonymous | ||
− | |||
− | |||
ERROR | ERROR | ||
− | |||
− | |||
Not getting created/initialized | Not getting created/initialized | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
+ | <source lang="javascript"> | ||
+ | package j2jtest.innerclass; | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
import java.util.ArrayList; | import java.util.ArrayList; | ||
− | |||
import java.util.List; | import java.util.List; | ||
− | |||
public class AnonymousInnerclass { | public class AnonymousInnerclass { | ||
− | + | List list = new ArrayList(3) { | |
− | List list = new ArrayList(3) { | + | { |
− | + | add("One"); add("Two"); add("Three"); | |
− | + | } | |
− | + | }; | |
− | + | public void testMethod(){ | |
− | + | for(Object value: list){ | |
− | + | Out.log("value="+value); | |
− | + | } | |
− | }; | + | } |
− | + | ||
− | public void testMethod(){ | + | |
− | + | ||
− | for(Object value: list){ | + | |
− | + | ||
− | Out. | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.ctype | |
− | + | ("j2jtest.innerclass.AnonymousInnerclass") | |
− | + | ||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> List list | |
− | //> List list | + | list:null, |
− | + | //> private constructs() | |
− | list:null, | + | constructs:function(){ |
− | + | this.list= | |
− | //> private constructs() | + | vjo.make(this,vjo.java.util.ArrayList,3); |
− | + | }, | |
− | constructs:function(){ | + | //> public void testMethod() |
− | + | testMethod:function(){ | |
− | this.list= | + | this.vjo.Out.log("value="); |
− | + | for (var value,_$itr=this.list.iterator(); | |
− | vjo.make(this,vjo.java.util.ArrayList,3); | + | _$itr.hasNext();){ |
− | + | value=_$itr.next(); | |
− | }, | + | this.vjo.Out.log("value="+value); |
− | + | } | |
− | //> public void testMethod() | + | } |
− | + | ||
− | testMethod:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("value="); | + | |
− | + | ||
− | for (var value,_$itr=this.list.iterator();_$itr.hasNext();){ | + | |
− | + | ||
− | value=_$itr.next(); | + | |
− | + | ||
− | this.vjo.Out.log("value="+value); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
− | + | ==== Superclasses and Subclasses ==== | |
Please refer Names. Members and Inheritance | Please refer Names. Members and Inheritance | ||
− | + | ==== Superinterfaces ==== | |
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Js | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.superinterface; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest.superinterface; | ||
public interface BaseInterface{ | public interface BaseInterface{ | ||
+ | public void method1(); | ||
+ | public void method(int i); | ||
− | + | } | |
− | + | </source> | |
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
+ | <source lang="javascript"> | ||
+ | vjo.itype("j2jtest.superinterface.BaseInterface") | ||
.protos({ | .protos({ | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
− | + | }, | |
− | + | //> public void method(int i) | |
− | + | method:function(i){ | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void method(int i) | + | |
− | + | ||
− | method:function(i){ | + | |
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.superinterface; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest.superinterface; | |
public class ImplClass implements BaseInterface{ | public class ImplClass implements BaseInterface{ | ||
+ | public void method1(){ | ||
− | public void | + | } |
+ | public void method(int i){ | ||
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.superinterface.ImplClass") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("j2jtest.superinterface.BaseInterface") | .needs("j2jtest.superinterface.BaseInterface") | ||
− | |||
.satisfies("j2jtest.superinterface.BaseInterface") | .satisfies("j2jtest.superinterface.BaseInterface") | ||
− | |||
.protos({ | .protos({ | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
− | + | }, | |
− | + | //> public void method(int i) | |
− | + | method:function(i){ | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void method(int i) | + | |
− | + | ||
− | method:function(i){ | + | |
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | |- | + | package j2jtest.superinterface; |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.superinterface; | + | |
− | + | ||
public interface SubInterface extends SuperInterface { | public interface SubInterface extends SuperInterface { | ||
− | } | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.itype("j2jtest.superinterface.SubInterface") | |
.needs("j2jtest.superinterface.SuperInterface") | .needs("j2jtest.superinterface.SuperInterface") | ||
− | |||
.inherits("j2jtest.superinterface.SuperInterface") | .inherits("j2jtest.superinterface.SuperInterface") | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | + | ==== Class Body and Member Declarations ==== | |
− | + | ||
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.classbodyandmember; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest.classbodyandmember; | |
public class ClassBody { | public class ClassBody { | ||
− | + | String field1; | |
− | String field1 | + | static int staticField; |
− | + | static{staticField=12;} | |
− | static int | + | {field1="field1Str";} |
− | + | ||
− | static{ | + | interface classinterface{ |
− | + | void m1(); | |
− | {field1 | + | } |
− | + | class classclass{ | |
− | interface classinterface{ | + | void m1(){} |
− | + | } | |
− | void m1(); | + | void m1(){} |
− | + | ClassBody(){} | |
− | } | + | ClassBody(Integer a){} |
− | + | }</source> | |
− | class classclass{ | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.classbodyandmember.ClassBody") | |
− | void m1(){} | + | |
− | + | ||
− | } | + | |
− | + | ||
− | void m1(){} | + | |
− | + | ||
− | ClassBody(){} | + | |
− | + | ||
− | ClassBody(Integer a){} | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.props({ | .props({ | ||
− | + | //> int staticField | |
− | //> int staticField | + | staticField:0 |
− | + | ||
− | staticField:0 | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
+ | //> String field1 | ||
+ | field1:null, | ||
+ | classinterface://> public classinterface | ||
+ | vjo.itype() | ||
+ | .protos({ | ||
+ | //> public void m1() | ||
+ | m1:function(){ | ||
+ | } | ||
+ | }) | ||
+ | .endType(), | ||
− | //> | + | classclass://> classclass |
+ | vjo.ctype() | ||
+ | .protos({ | ||
+ | //> void m1() | ||
+ | m1:function(){ | ||
− | + | } | |
+ | }) | ||
+ | .endType(), | ||
− | + | //> constructs() | |
+ | //> constructs(Integer a) | ||
+ | constructs:function(){ | ||
+ | { | ||
+ | this.field1="field1Str"; | ||
+ | } | ||
+ | if(arguments.length===0){ | ||
+ | this.constructs_0_0_ClassBody_ovld(); | ||
+ | }else if(arguments.length===1){ | ||
+ | this.constructs_1_0_ClassBody_ovld(arguments[0]); | ||
+ | } | ||
+ | }, | ||
+ | //> void m1() | ||
+ | m1:function(){ | ||
− | + | }, | |
+ | //> private constructs_0_0_ClassBody_ovld() | ||
+ | constructs_0_0_ClassBody_ovld:function(){ | ||
− | + | }, | |
− | + | //> private constructs_1_0_ClassBody_ovld(Integer a) | |
− | //> | + | constructs_1_0_ClassBody_ovld:function(a){ |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | { | |
− | { | + | this.vjo.ClassBody.staticField=12; |
− | + | } | |
− | this.vjo.ClassBody.staticField=12; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | + | .endType(); </source> | |
− | .endType(); | + | |
|} | |} | ||
− | |||
− | |||
+ | === Class Members - see Class Body and Member Declarations === | ||
+ | |||
+ | === Field Declarations === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| access modifier | | style="border:1px solid #AAAAAA;padding: 0.2em;"| access modifier | ||
− | |||
public, private, protected | public, private, protected | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| public Integer I | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | public Integer I =10; | |
private Integer j =20; | private Integer j =20; | ||
− | + | protected Integer k=0; | |
− | protected Integer k | + | </source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | .protos({ | |
− | //> public Integer i | + | //> public Integer i |
− | + | i:null, | |
− | i:null, | + | //> private Integer j |
− | + | j:null, | |
− | //> private Integer j | + | //> protected Integer k |
− | + | k:null, | |
− | j:null, | + | //> EnumTest etest |
− | + | etest:null, | |
− | //> protected Integer k | + | //> private constructs() |
− | + | constructs:function(){ | |
− | k:null, | + | this.i=new this.vjo.Integer(10); |
− | + | this.j=new this.vjo.Integer(20); | |
− | //> EnumTest etest | + | this.k=new this.vjo.Integer(0); |
− | + | }, | |
− | etest:null, | + | </source> |
− | + | |- style="vertical-align:top" | |
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.i=new this.vjo.Integer(10); | + | |
− | + | ||
− | this.j=new this.vjo.Integer(20); | + | |
− | + | ||
− | this.k=new this.vjo.Integer(0); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | |- | + | |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| static fields | | style="border:1px solid #AAAAAA;padding: 0.2em;"| static fields | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| class TestClass { | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | public final Integer | + | class TestClass { |
− | + | public final Integer i = 10; | |
− | private final Integer | + | private final Integer j = 20; |
− | + | protected static final Integer k = 0; | |
− | protected static final Integer | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
+ | vjo.ctype("j2jtest.TestClass") | ||
.props({ | .props({ | ||
− | + | //> public Integer i | |
− | //> public Integer i | + | i:null, |
− | + | //> private Integer j | |
− | i:null, | + | j:null, |
− | + | //> protected Integer k | |
− | //> private Integer j | + | k:null |
− | + | ||
− | j:null, | + | |
− | + | ||
− | //> protected Integer k | + | |
− | + | ||
− | k:null | + | |
− | + | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.TestClass.i=new this.vjo.Integer(10); | |
− | this.vjo.TestClass.i=new this.vjo.Integer(10); | + | this.vjo.TestClass.j=new this.vjo.Integer(20); |
− | + | this.vjo.TestClass.k=new this.vjo.Integer(0); | |
− | this.vjo.TestClass.j=new this.vjo.Integer(20); | + | |
− | + | ||
− | this.vjo.TestClass.k=new this.vjo.Integer(0); | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |- style="vertical-align:top" | |
− | + | ||
− | |- | + | |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| final fields | | style="border:1px solid #AAAAAA;padding: 0.2em;"| final fields | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| class TestClass { | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | class TestClass { | |
− | public static final Integer | + | public static final Integer i = 10; |
− | + | private static final Integer j = 20; | |
− | private static final Integer | + | protected static final Integer k = 0; |
− | + | ||
− | protected static final Integer | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
+ | vjo.ctype("j2jtest.TestClass") | ||
.props({ | .props({ | ||
− | + | //> final public Integer i | |
− | //> final public Integer i | + | i:null, |
− | + | //> final private Integer j | |
− | i:null, | + | j:null, |
− | + | //> final protected Integer k | |
− | //> final private Integer j | + | k:null |
− | + | ||
− | j:null, | + | |
− | + | ||
− | //> final protected Integer k | + | |
− | + | ||
− | k:null | + | |
− | + | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.TestClass.i=new this.vjo.Integer(10); | |
− | this.vjo.TestClass.i=new this.vjo.Integer(10); | + | this.vjo.TestClass.j=new this.vjo.Integer(20); |
− | + | this.vjo.TestClass.k=new this.vjo.Integer(0); | |
− | this.vjo.TestClass.j=new this.vjo.Integer(20); | + | |
− | + | ||
− | this.vjo.TestClass.k=new this.vjo.Integer(0); | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |- style="vertical-align:top" | |
− | + | ||
− | |- | + | |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Transient – | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Transient – | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| class TestClass { | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
+ | class TestClass { | ||
+ | transient Integer i = 10; | ||
+ | }</source> | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Not Supported | ||
− | + | |} | |
− | + | === Method Declarations === | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| method modifiers | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| method modifiers | ||
− | |||
− | |||
− | |||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| | ||
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract, | | style="border:1px solid #AAAAAA;padding: 0.2em;"| abstract, | ||
− | |||
static, final methods | static, final methods | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
+ | package j2jtest; | ||
+ | public abstract class Pair2{ | ||
+ | abstract void abstractMethod(); | ||
+ | static void staticMethod(); | ||
+ | public final void finalMethod(){ | ||
− | + | } | |
− | + | public native void nativeMethod(); | |
− | + | public synchronized void synchronizedMethod() { | |
− | + | ||
− | + | } | |
− | + | strictfp void strictfpMethod(){ | |
− | } | + | |
− | + | ||
− | public native void nativeMethod(); | + | |
− | + | ||
− | public synchronized void synchronizedMethod() { | + | |
− | + | ||
− | } | + | |
− | + | ||
− | strictfp void strictfpMethod(){ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | } | ||
+ | }</source> | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair2") //< abstract | ||
.props({ | .props({ | ||
+ | //> void staticMethod() | ||
+ | staticMethod:function(){ | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
+ | //> abstract void abstractMethod() | ||
+ | abstractMethod:function(){ | ||
− | //> | + | }, |
+ | //> final public void finalMethod() | ||
+ | finalMethod:function(){ | ||
− | + | }, | |
+ | //> public void nativeMethod() | ||
+ | nativeMethod:function(){ | ||
− | }, | + | }, |
+ | //> public void synchronizedMethod() | ||
+ | synchronizedMethod:function(){ | ||
− | + | }, | |
− | + | //> void strictfpMethod() | |
− | + | strictfpMethod:function(){ | |
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //> void strictfpMethod() | + | |
− | + | ||
− | strictfpMethod:function(){ | + | |
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | |||
− | |- | + | |- style="vertical-align:top" |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| synchronized native strictfp | | style="border:1px solid #AAAAAA;padding: 0.2em;"| synchronized native strictfp | ||
− | |||
are not supported | are not supported | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Method throws not supported | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Method throws not supported | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | public void method1() throws Exception { | |
− | + | ||
− | + | ||
+ | }</source> | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | ||
+ | //> public void method1() | ||
method1:function(){ | method1:function(){ | ||
} | } | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Overloading | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Overloading | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest; | |
public class Pair2{ | public class Pair2{ | ||
+ | public void method1() { | ||
− | + | } | |
− | + | public void method1(int i){ | |
− | } | + | |
− | + | ||
− | public void method1(int i){ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | } | ||
+ | public void callMethod(){ | ||
+ | method1(); | ||
+ | method1(); | ||
+ | } | ||
+ | }</source> | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair2") | ||
.protos({ | .protos({ | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
+ | if(arguments.length===0){ | ||
+ | this.method1_0_0(); | ||
+ | }else if(arguments.length===1){ | ||
+ | this.method1_1_0(arguments[0]); | ||
+ | } | ||
+ | }, | ||
+ | //> public void method1_0_0() | ||
+ | method1_0_0:function(){ | ||
− | + | }, | |
− | + | //> public void method1_1_0(int i) | |
− | + | method1_1_0:function(i){ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //> public void method1_1_0(int i) | + | |
− | + | ||
− | method1_1_0:function(i){ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | }, | ||
+ | //> public void callMethod() | ||
+ | callMethod:function(){ | ||
+ | this.method1(); | ||
+ | this.method1(); | ||
+ | } | ||
}) | }) | ||
− | .endType(); | + | .endType(); </source> |
|} | |} | ||
If a static field/method is accessed through instance object, it would be converted to use fully qualified class name to access. | If a static field/method is accessed through instance object, it would be converted to use fully qualified class name to access. | ||
− | + | === Member Type Declarations === | |
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest; | |
− | + | ||
public class Pair2{ | public class Pair2{ | ||
+ | abstract class Abstractclass{ | ||
+ | |||
+ | } | ||
+ | interface MyInterface{ | ||
− | + | } | |
+ | protected class ProtectedClass extends Abstractclass{ | ||
− | } | + | } |
+ | private class PrivateClass implements MyInterface{ | ||
− | + | } | |
− | + | static class StaticClass { | |
− | + | ||
− | + | } | |
+ | final class FinalClass{ | ||
+ | } | ||
+ | PrivateClass pclass = new PrivateClass(); | ||
+ | ProtectedClass prClass = new ProtectedClass(); | ||
+ | StaticClass sClass = new StaticClass(); | ||
+ | Abstractclass aClass = new ProtectedClass(); | ||
+ | MyInterface mInterface = new PrivateClass(); | ||
+ | FinalClass fClass = new FinalClass(); | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.props({ | .props({ | ||
− | + | StaticClass:vjo.ctype() | |
− | StaticClass:vjo.ctype() | + | .endType() |
− | + | ||
− | .endType() | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> PrivateClass pclass | |
− | //> PrivateClass pclass | + | pclass:null, |
− | + | //> ProtectedClass prClass | |
− | pclass:null, | + | prClass:null, |
− | + | //> StaticClass sClass | |
− | //> ProtectedClass prClass | + | sClass:null, |
− | + | //> Abstractclass aClass | |
− | prClass:null, | + | aClass:null, |
− | + | //> MyInterface mInterface | |
− | //> StaticClass sClass | + | mInterface:null, |
− | + | //> FinalClass fClass | |
− | sClass:null, | + | fClass:null, |
− | + | Abstractclass:vjo.ctype() //< abstract | |
− | //> Abstractclass aClass | + | .endType(), |
− | + | MyInterface:vjo.itype() | |
− | aClass:null, | + | .endType(), |
− | + | ProtectedClass:vjo.ctype() | |
− | //> MyInterface mInterface | + | .inherits("j2jtest.Pair2.Abstractclass") |
− | + | .endType(), | |
− | mInterface:null, | + | PrivateClass:vjo.ctype() |
− | + | .satisfies("j2jtest.Pair2.MyInterface") | |
− | //> FinalClass fClass | + | .endType(), |
− | + | FinalClass:vjo.ctype() | |
− | fClass:null, | + | .makeFinal() |
− | + | .endType(), | |
− | Abstractclass:vjo. | + | //> private constructs() |
− | + | constructs:function(){ | |
− | .endType(), | + | this.pclass=new PrivateClass(); |
− | + | this.prClass=new ProtectedClass(); | |
− | MyInterface:vjo.itype() | + | this.sClass=new this.StaticClass(); |
− | + | this.aClass=new ProtectedClass(); | |
− | .endType(), | + | this.mInterface=new PrivateClass(); |
− | + | this.fClass=new FinalClass(); | |
− | ProtectedClass:vjo.ctype() | + | } |
− | + | ||
− | .inherits("j2jtest.Pair2.Abstractclass") | + | |
− | + | ||
− | .endType(), | + | |
− | + | ||
− | PrivateClass:vjo.ctype() | + | |
− | + | ||
− | .satisfies("j2jtest.Pair2.MyInterface") | + | |
− | + | ||
− | .endType(), | + | |
− | + | ||
− | FinalClass:vjo.ctype() | + | |
− | + | ||
− | .makeFinal() | + | |
− | + | ||
− | .endType(), | + | |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.pclass=new PrivateClass(); | + | |
− | + | ||
− | this.prClass=new ProtectedClass(); | + | |
− | + | ||
− | this.sClass=new this.StaticClass(); | + | |
− | + | ||
− | this.aClass=new ProtectedClass(); | + | |
− | + | ||
− | this.mInterface=new PrivateClass(); | + | |
− | + | ||
− | this.fClass=new FinalClass(); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | + | .endType(); </source> | |
− | .endType(); | + | |
|} | |} | ||
− | + | ||
+ | === Instance Initializers === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="vertical-align:top;border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest; | |
public class Pair2{ | public class Pair2{ | ||
− | + | Integer wrapperInteger = 10; | |
− | Integer wrapperInteger = 10; | + | Float wrapperFloat = 12.2f; |
− | + | }</source> | |
− | Float wrapperFloat = 12.2f; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | } | + | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer wrapperInteger | |
− | //> Integer wrapperInteger | + | wrapperInteger:null, |
− | + | //> Float wrapperFloat | |
− | wrapperInteger:null, | + | wrapperFloat:12.2, |
− | + | //> private constructs() | |
− | //> Float wrapperFloat | + | constructs:function(){ |
− | + | this.wrapperInteger=new this.vjo.Integer(10); | |
− | wrapperFloat:12.2, | + | } |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.wrapperInteger=new this.vjo.Integer(10); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | + | .endType(); </source> | |
− | .endType(); | + | |
|} | |} | ||
− | |||
+ | === Static Initializers === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest; | + | | style="vertical-align:top;border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest; | |
public class Pair2 { | public class Pair2 { | ||
− | + | public static Integer i = new Integer(20); | |
− | public static Integer | + | private static Float f = new Float(23); |
− | + | static Pair2 pair; | |
− | private static Float | + | static{ |
− | + | pair = new Pair2(); | |
− | static Pair2 | + | } |
− | + | }</source> | |
− | static{ | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.props({ | .props({ | ||
− | |||
//> public Integer i | //> public Integer i | ||
− | |||
i:null, | i:null, | ||
− | |||
//> private Float f | //> private Float f | ||
− | |||
f:null, | f:null, | ||
− | |||
//> Pair2 pair | //> Pair2 pair | ||
− | |||
pair:null | pair:null | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.Pair2.i=new this.vjo.Integer(20); | |
− | this.vjo.Pair2.i=new this.vjo.Integer(20); | + | this.vjo.Pair2.f=new this.vjo.Float(23); |
− | + | { | |
− | this.vjo.Pair2.f=new this.vjo.Float(23); | + | this.pair=new this(); |
− | + | } | |
− | { | + | |
− | + | ||
− | this.pair=new this(); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | + | .endType(); </source> | |
− | .endType(); | + | |
|} | |} | ||
− | |||
− | |||
+ | === Constructor Declarations - see Class Body and Member Declarations === | ||
+ | === Enums === | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.enum1; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest.enum1; | |
− | + | ||
public enum EnumTest { | public enum EnumTest { | ||
− | + | SUNDAY{ | |
− | + | int getIndex(){ | |
− | + | return 0; | |
− | int getIndex(){ | + | } |
− | + | }, | |
− | return 0; | + | MONDAY, |
− | + | TUESDAY, | |
− | } | + | WEDNESDAY, |
− | + | THURSDAY, | |
− | + | FRIDAY, | |
− | + | SATURDAY | |
− | + | }</source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.etype("j2jtest.enum1.EnumTest") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") | .values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.SUNDAY.getIndex=function(){ | |
− | this.SUNDAY.getIndex=function(){ | + | return 0; |
− | + | }; | |
− | return 0; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | |||
Initialization | Initialization | ||
− | |||
− | |||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest; | |
− | + | ||
public class Pair2 { | public class Pair2 { | ||
− | + | public final int N = 10; | |
− | public final int N = 10; | + | private int[] x = new int[N]; |
− | + | { | |
− | + | for (int i = 0; i < N; i++) | |
− | private int | + | x[i] = i; |
− | + | } | |
− | { | + | public static int L = 5; |
− | + | private static int[] y=new int[L];; | |
− | for (int | + | static { |
− | + | for (int i = 0; i < L; i++) | |
− | x | + | y[i] = i; |
− | + | } | |
− | } | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | public static int | + | vjo.ctype("j2jtest.Pair2") |
− | + | ||
− | private static int | + | |
− | + | ||
− | static { | + | |
− | + | ||
− | for (int | + | |
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.props({ | .props({ | ||
− | + | //> final public int L | |
− | //> final public int L | + | L:5, |
− | + | //> private int[] y | |
− | L:5, | + | y:null |
− | + | ||
− | + | ||
− | + | ||
− | y:null | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> final public int N | |
− | //> final public int N | + | N:10, |
− | + | //> private int[] x | |
− | N:10, | + | x:null, |
− | + | //> private constructs() | |
− | + | constructs:function(){ | |
− | + | this.x=new Array(this.N); | |
− | x:null, | + | { |
− | + | for (var i=0;i<this.N;i++){ | |
− | //> private constructs() | + | this.x[i]=i; |
− | + | } | |
− | constructs:function(){ | + | } |
− | + | } | |
− | this.x=new Array(this.N); | + | |
− | + | ||
− | { | + | |
− | + | ||
− | for (var | + | |
− | + | ||
− | this | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.Pair2.y=new Array(this.L); | |
− | this.vjo.Pair2.y=new Array(this.L); | + | { |
− | + | for (var i=0;i<this.L;i++){ | |
− | { | + | this.y[i]=i; |
− | + | } | |
− | for (var | + | } |
− | + | ||
− | this | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | |||
== Interfaces == | == Interfaces == | ||
Interface Declarations | Interface Declarations | ||
Line 4,790: | Line 3,175: | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| js | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.interfaces; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | + | package j2jtest.interfaces; | |
public interface SuperInterface { | public interface SuperInterface { | ||
− | + | String memberStr=""; | |
− | String | + | public int var1=1; |
− | + | public static int var2=2; | |
− | public int | + | public static final int var3 = 3; |
− | + | String var4 = ""+var3; | |
− | public static int | + | void m1(); |
− | + | void m1(int i); | |
− | public static final int | + | public void m2(); |
− | + | abstract void m3(); | |
− | String | + | public abstract void m4(); |
− | + | ||
− | + | ||
− | void m1(); | + | |
− | + | ||
− | void m1(int i); | + | |
− | + | ||
− | public void m2(); | + | |
− | + | ||
− | abstract void m3(); | + | |
− | + | ||
− | public abstract void m4(); | + | |
− | + | ||
} | } | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | + | vjo.itype("j2jtest.interfaces.SuperInterface") | |
− | + | ||
.props({ | .props({ | ||
− | + | //> public String memberStr | |
− | //> public String memberStr | + | memberStr:"", |
− | + | //> public int var1 | |
− | memberStr:"", | + | var1:1, |
− | + | //> public int var2 | |
− | //> public int var1 | + | var2:2, |
− | + | //> final public int var3 | |
− | var1:1, | + | var3:3, |
− | + | //> public String var4 | |
− | //> public int var2 | + | var4:null |
− | + | ||
− | var2:2, | + | |
− | + | ||
− | //> final public int var3 | + | |
− | + | ||
− | var3:3, | + | |
− | + | ||
− | //> public String var4 | + | |
− | + | ||
− | var4:null | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
+ | //> void m1() | ||
+ | //> public void m1(int i) | ||
+ | m1:function(){ | ||
+ | if(arguments.length===0){ | ||
+ | this.m1_0_0_SuperInterface_ovld(); | ||
+ | }else if(arguments.length===1){ | ||
+ | this.m1_1_0_SuperInterface_ovld(arguments[0]); | ||
+ | } | ||
+ | }, | ||
+ | //> private void m1_0_0_SuperInterface_ovld() | ||
+ | m1_0_0_SuperInterface_ovld:function(){ | ||
− | //> void | + | }, |
+ | //> private void m1_1_0_SuperInterface_ovld(int i) | ||
+ | m1_1_0_SuperInterface_ovld:function(i){ | ||
− | //> public void | + | }, |
+ | //> public void m2() | ||
+ | m2:function(){ | ||
− | + | }, | |
+ | //> public abstract void m3() | ||
+ | m3:function(){ | ||
− | + | }, | |
− | + | //> public abstract void m4() | |
− | + | m4:function(){ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //> public abstract void m4() | + | |
− | + | ||
− | m4:function(){ | + | |
− | + | ||
− | + | ||
+ | } | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.SuperInterface.var4=""+this.var3; | |
− | this.vjo.SuperInterface.var4=""+this.var3; | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| package j2jtest.interfaces; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
+ | package j2jtest.interfaces; | ||
public interface SubInterface extends SuperInterface{ | public interface SubInterface extends SuperInterface{ | ||
− | + | public static int memberInt=20; | |
− | public static int | + | public static String var3 = ""+var2; |
− | + | ||
− | public static String | + | |
− | + | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.itype("j2jtest.interfaces.SubInterface") | ||
.needs("j2jtest.interfaces.SuperInterface") | .needs("j2jtest.interfaces.SuperInterface") | ||
− | |||
.inherits("j2jtest.interfaces.SuperInterface") | .inherits("j2jtest.interfaces.SuperInterface") | ||
− | |||
.props({ | .props({ | ||
− | + | //> public int memberInt | |
− | //> public int memberInt | + | memberInt:20, |
− | + | //> public String var3 | |
− | memberInt:20, | + | var3:null |
− | + | ||
− | //> public String var3 | + | |
− | + | ||
− | var3:null | + | |
− | + | ||
}) | }) | ||
− | |||
.inits(function(){ | .inits(function(){ | ||
− | + | this.vjo.SubInterface.var3=""+this.vjo.SuperInterface.var2; | |
− | this.vjo.SubInterface.var3=""+this.vjo.SuperInterface.var2; | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
+ | </source> | ||
− | |||
− | |||
− | |||
|} | |} | ||
+ | |||
== Arrays == | == Arrays == | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java | ||
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo | ||
− | |- | + | |- style="vertical-align:top" |
− | | style="border:1px solid #AAAAAA;padding: 0.2em;"| long avg = 10; | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
+ | <source lang="java"> | ||
+ | long avg = 10; | ||
+ | long[] la = {1+avg,2,3}; | ||
+ | int[][] twoDimArray = {{1,2,3}, {4,5,6}}; | ||
+ | String[] sa = { "a", "b", "c"}; | ||
+ | String[] sa2 = new String[2]; | ||
+ | Employee[] sa3 = new Employee[2]; | ||
+ | boolean boolArr1[] | ||
+ | = new boolean[]{true}; | ||
+ | boolean boolArr2[][] | ||
+ | = new boolean[][]{{false}}; | ||
+ | boolean boolArr11[] | ||
+ | = new boolean[twoDimArray[0][0]]; | ||
+ | boolean boolArr12[][] | ||
+ | = new boolean[twoDimArray[0][0]] [twoDimArray[0][1]]; | ||
+ | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | ||
+ | <source lang="javascript"> | ||
+ | var avg=10; | ||
+ | var la=[1+avg,2,3]; | ||
+ | var twoDimArray=[[1,2,3],[4,5,6]]; | ||
+ | var sa=["a","b","c"]; | ||
var sa2=new Array(2); | var sa2=new Array(2); | ||
− | |||
var sa3=new Array(2); | var sa3=new Array(2); | ||
− | + | var boolArr1=[true]; | |
− | var | + | var boolArr2=[[false]]; |
− | + | var boolArr11=new Array(twoDimArray[0][0]); | |
− | var | + | |
− | + | ||
− | var boolArr11=new | + | |
− | + | ||
var boolArr12=new Array; | var boolArr12=new Array; | ||
− | + | </source> | |
|} | |} | ||
+ | |||
== ERORS/TO-DO List == | == ERORS/TO-DO List == | ||
− | |||
+ | 1. FIXED. Field initialization should maintain the order. From the below example, initialization order is not maintained. myInt should be initialized before i. | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest; | |
public class Pair2{ | public class Pair2{ | ||
− | + | Integer myInt = 10; | |
− | + | int i = myInt; | |
− | Integer myInt = 10; | + | |
− | + | ||
− | int i = myInt | + | |
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
+ | <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.Pair2") | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer myInt | |
− | //> Integer myInt | + | myInt:null, |
− | + | //> int i | |
− | myInt:null, | + | i:0, |
− | + | //> constructs() | |
− | //> int i | + | constructs:function(){ |
− | + | this.i=this.myInt.intValue(); | |
− | i:0, | + | this.myInt=new this.vjo.Integer(10); |
− | + | } | |
− | //> constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.i=this.myInt.intValue(); | + | |
− | + | ||
− | this.myInt=new this.vjo.Integer(10); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
+ | 2. DOCUMENTED. Overload with primitive and wrapper argument is not correctly transferred in js dispatcher function. From the below example, overLoad(Integer i) would be called regardless of parameter. | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest; | |
public class Pair2{ | public class Pair2{ | ||
− | + | void overLoad(int i){ | |
− | void overLoad(int i){System. | + | System.out.println("called with primitive int"); |
− | + | } | |
+ | void overLoad(Integer i){ | ||
+ | System.out.println("called with wrapper int"); | ||
+ | } | ||
+ | void callOverLoad(){ | ||
+ | overLoad(10); | ||
+ | overLoad(new Integer(12)); | ||
+ | } | ||
} | } | ||
− | + | </source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.System") | .needs("vjo.java.lang.System") | ||
− | |||
.protos({ | .protos({ | ||
+ | //> void overLoad() | ||
+ | overLoad:function(){ | ||
+ | if(arguments.length===1){ | ||
+ | if(arguments[0] instanceof vjo.java.lang.Integer){ | ||
+ | this.overLoad_1_0(arguments[0].intValue()); | ||
+ | }else if(arguments[0] instanceof vjo.java.lang.Integer){ | ||
+ | this.overLoad_1_1(arguments[0]); | ||
+ | } | ||
+ | } | ||
+ | }, | ||
+ | //> void overLoad_1_0(int i) | ||
+ | overLoad_1_0:function(i){ | ||
+ | this.vjo.System.out.println("called with primitive int"); | ||
+ | }, | ||
− | + | //> void overLoad_1_1(Integer i) | |
− | + | overLoad_1_1:function(i){ | |
− | + | this.vjo.System.out.println("called with wrapper int"); | |
− | + | }, | |
− | + | //> void callOverLoad() | |
− | + | callOverLoad:function(){ | |
− | + | this.overLoad(new this.vjo.Integer(10)); | |
− | + | this.overLoad(new this.vjo.Integer(12)); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //> void overLoad_1_1(Integer i) | + | |
− | + | ||
− | overLoad_1_1:function(i){ | + | |
− | + | ||
− | this.vjo.System.out.println("called with wrapper int"); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> void callOverLoad() | + | |
− | + | ||
− | callOverLoad:function(){ | + | |
− | + | ||
− | this.overLoad(new this.vjo.Integer(10)); | + | |
− | + | ||
− | this.overLoad(new this.vjo.Integer(12)); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType();</source> | ||
+ | |} | ||
− | . | + | 3. FIXED. Instance initialization is not consistence. From the below example, float1 and double1 are not initialized in the init constructor. |
− | + | ||
− | + | ||
− | + | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest; | |
public class Pair2{ | public class Pair2{ | ||
− | + | Integer integer2 = 20; | |
− | Integer integer2 = 20; | + | Integer integer1 = new Integer(10); |
− | + | Float float1 = 12.2f; | |
− | Integer integer1 = new Integer(10); | + | Float float2 = new Float(12); |
− | + | Double double1 = 30.5; | |
− | Float float1 = 12.2f; | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | Float float2 = new Float(12); | + | vjo.ctype("j2jtest.Pair2") |
− | + | ||
− | Double double1 = 30.5; | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.needs("vjo.java.lang.Double") | .needs("vjo.java.lang.Double") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> Integer integer2 | |
− | //> Integer integer2 | + | integer2:null, |
− | + | //> Integer integer1 | |
− | integer2:null, | + | integer1:null, |
− | + | //> Float float1 | |
− | //> Integer integer1 | + | float1:12.2, |
− | + | //> Float float2 | |
− | integer1:null, | + | float2:null, |
− | + | //> Double double1 | |
− | //> Float float1 | + | double1:30.5, |
− | + | //> private constructs() | |
− | float1:12.2, | + | constructs:function(){ |
− | + | this.integer1=new this.vjo.Integer(10); | |
− | //> Float float2 | + | this.float2=new this.vjo.Float(12); |
− | + | this.integer2=new this.vjo.Integer(20); | |
− | float2:null, | + | } |
− | + | ||
− | //> Double double1 | + | |
− | + | ||
− | double1:30.5, | + | |
− | + | ||
− | //> private constructs() | + | |
− | + | ||
− | constructs:function(){ | + | |
− | + | ||
− | this.integer1=new this.vjo.Integer(10); | + | |
− | + | ||
− | this.float2=new this.vjo.Float(12); | + | |
− | + | ||
− | this.integer2=new this.vjo.Integer(20); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | |||
+ | 4. NOT APPLICABLE: Don’t give function name starts with “constructs” ie., constructs_0_0. if you have then you’ll see unexpected result as shown below | ||
− | |||
− | |||
− | |||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest; | ||
public class Pair2{ | public class Pair2{ | ||
− | + | Integer integer1=12; | |
− | Integer integer1 | + | Float f = 23.4f; |
− | + | Pair2(){ | |
− | Float f = 23.4f; | + | System.out.println("No arg constructor"); |
− | + | constructs_0_0(); | |
− | + | } | |
− | Pair2(){ | + | Pair2(Integer initValue){ |
− | + | System.out.println("One arg constructor"); | |
− | System. | + | } |
− | + | void constructs_0_0(){ | |
− | constructs_0_0(); | + | System.out.println(" this is not a constructor"); |
− | + | } | |
− | } | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | Pair2(Integer initValue){ | + | vjo.ctype("j2jtest.Pair2") |
− | + | ||
− | System. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | void constructs_0_0(){ | + | |
− | + | ||
− | System. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.needs("vjo.java.lang.Float") | .needs("vjo.java.lang.Float") | ||
− | |||
.needs("vjo.java.lang.System") | .needs("vjo.java.lang.System") | ||
− | |||
.protos({ | .protos({ | ||
+ | //> Integer integer1 | ||
+ | integer1:null, | ||
+ | //> Float f | ||
+ | f:23.4, | ||
+ | //> constructs() | ||
+ | constructs:function(){ | ||
+ | this.integer1=new this.vjo.Integer(12); | ||
+ | if(arguments.length===0){ | ||
+ | if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | }else if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | } | ||
+ | }else if(arguments.length===1){ | ||
+ | this.constructs_1_0(arguments[0]); | ||
+ | } | ||
+ | }, | ||
− | //> Integer integer1 | + | //> constructs_1_0(Integer initValue) |
+ | constructs_1_0:function(initValue){ | ||
+ | this.vjo.System.out.println("One arg constructor"); | ||
+ | }, | ||
+ | //> constructs() | ||
+ | constructs:function(){ | ||
+ | this.integer1=new this.vjo.Integer(12); | ||
+ | if(arguments.length===0){ | ||
+ | if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | }else if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | } | ||
+ | }else if(arguments.length===1){ | ||
+ | this.constructs_1_0(arguments[0]); | ||
+ | }else if(arguments.length===0){ | ||
+ | if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | }else if(arguments.length==0){ | ||
+ | this.constructs_0_0_0_0(); | ||
+ | } | ||
+ | }else if(arguments.length===1){ | ||
+ | this.constructs_1_0(arguments[0]); | ||
+ | } | ||
+ | }, | ||
− | + | //> constructs_0_0_0_0() | |
− | + | constructs_0_0_0_0:function(){ | |
− | //> | + | this.vjo.System.out.println("No arg constructor"); |
− | + | constructs_0_0(); | |
− | + | }, | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | this.vjo.System.out.println("No arg constructor"); | + | |
− | + | ||
− | constructs_0_0(); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | //> void constructs_0_0_0_1() | ||
+ | constructs_0_0_0_1:function(){ | ||
+ | this.vjo.System.out.println(" this is not a constructor"); | ||
+ | } | ||
}) | }) | ||
− | |||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
+ | 5. Need to have reserved/keyword that cannot be used while writing java that would be converted into js. For instance, use of base as method name in base class would cause calling wrong method/confusion | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest; | |
public class Pair{ | public class Pair{ | ||
+ | Integer i =10; | ||
+ | Pair(Integer intValue){ | ||
− | + | } | |
− | + | void base(Integer i){ | |
− | + | System.out.println("Base method"); | |
− | + | } | |
− | + | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
package j2jtest; | package j2jtest; | ||
− | |||
public class Pair2 extends Pair{ | public class Pair2 extends Pair{ | ||
− | + | Pair2(){ | |
− | Pair2(){ | + | super(10); |
− | + | } | |
− | super(10); | + | Pair2(Integer intValue){ |
− | + | super(intValue); | |
+ | base(intValue); | ||
+ | } | ||
} | } | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.Pair2") | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
.needs("j2jtest.Pair") | .needs("j2jtest.Pair") | ||
− | |||
.needs("vjo.java.lang.Integer") | .needs("vjo.java.lang.Integer") | ||
− | |||
.inherits("j2jtest.Pair") | .inherits("j2jtest.Pair") | ||
− | |||
.protos({ | .protos({ | ||
+ | //> constructs() | ||
+ | constructs:function(){ | ||
+ | if(arguments.length===0){ | ||
+ | this.constructs_0_0(); | ||
+ | }else if(arguments.length===1){ | ||
+ | this.constructs_1_0(arguments[0]); | ||
+ | } | ||
+ | }, | ||
− | //> | + | //> constructs_0_0() |
− | + | constructs_0_0:function(){ | |
− | + | this.base(10); | |
− | + | }, | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | constructs_0_0:function(){ | + | |
− | + | ||
− | this.base(10); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | //> constructs_1_0(Integer intValue) | ||
+ | constructs_1_0:function(intValue){ | ||
+ | this.base(intValue); | ||
+ | this.base(intValue); | ||
+ | } | ||
}) | }) | ||
.endType(); | .endType(); | ||
− | + | </source> | |
|} | |} | ||
− | + | ||
+ | 6. DOCUMENTED Don’t use class name, function name or package name for variables. It woks in java but not in javascript. For ex., below code display “test” in java but java script it display the whole java script object | ||
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | String MyClass = "test" | + | class MyClass { |
− | + | String MyClass = "test"; | |
− | public void method1(){ | + | public void method1(){ |
− | + | System.out.println(MyClass); | |
− | System. | + | } |
− | + | }</source> | |
− | } | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.abstract1.MyClass") | |
− | } | + | |
− | + | ||
− | + | ||
.protos({ | .protos({ | ||
− | + | //> String MyClass | |
− | //> String MyClass | + | MyClass:"test", |
− | + | //> public void method1() | |
− | MyClass:"test", | + | method1:function(){ |
− | + | this.vjo.System.out.println(this.vjo.MyClass); | |
− | //> public void method1() | + | } |
− | + | ||
− | method1:function(){ | + | |
− | + | ||
− | this.vjo.System.out.println(this.vjo.MyClass); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | + | .endType(); </source> | |
− | .endType(); | + | |
|} | |} | ||
− | |||
− | |||
+ | 7. FIXED , Inner classes/second level inner classes are not getting created correctly | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | ||
+ | <source lang="java"> | ||
+ | package j2jtest; | ||
public class OuterClass { | public class OuterClass { | ||
− | + | int outerVar = 10; | |
− | int outerVar = 10; | + | class InnerClass{ |
− | + | class InnerInnerClass{ | |
− | class InnerClass{ | + | void innerInnerMethod(String mssg){ |
− | + | Out.log("InnerInner " +mssg); | |
− | class InnerInnerClass{ | + | } |
− | + | } | |
− | void innerInnerMethod(String mssg){ | + | void innerMethod(String mssg){ |
− | + | Out.log("Inner " +mssg); | |
− | Out. | + | } |
− | + | } | |
− | } | + | static void testMethod(){ |
− | + | OuterClass.InnerClass innerClass = | |
− | } | + | new OuterClass().new InnerClass(); |
− | + | ||
− | void innerMethod(String mssg){ | + | OuterClass.InnerClass.InnerInnerClass inInClass = |
− | + | innerClass.new InnerInnerClass(); | |
− | Out. | + | |
− | + | innerClass.innerMethod("mssg1"); | |
− | } | + | inInClass.innerInnerMethod("mssg2"); |
− | + | } | |
− | } | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | static void testMethod(){ | + | vjo.ctype("j2jtest.OuterClass") |
− | + | ||
− | OuterClass.InnerClass innerClass = new OuterClass().new InnerClass(); | + | |
− | + | ||
− | + | ||
− | OuterClass.InnerClass.InnerInnerClass inInClass = innerClass.new InnerInnerClass(); | + | |
− | + | ||
− | innerClass.innerMethod("mssg1"); | + | |
− | + | ||
− | + | ||
− | inInClass.innerInnerMethod("mssg2"); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.props({ | .props({ | ||
− | + | //> void testMethod() | |
− | //> void testMethod() | + | testMethod:function(){ |
− | + | var innerClass=new (new this()) | |
− | testMethod:function(){ | + | .InnerClass(); |
− | + | ||
− | var innerClass=new (new this()).InnerClass(); | + | var inInClass; |
− | + | innerClass.innerMethod("mssg1"); | |
− | var inInClass; | + | inInClass.innerInnerMethod("mssg2"); |
− | + | } | |
− | innerClass.innerMethod("mssg1"); | + | |
− | + | ||
− | inInClass.innerInnerMethod("mssg2"); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> int outerVar | |
− | //> int outerVar | + | outerVar:10, |
− | + | InnerClass://> InnerClass | |
− | outerVar:10, | + | vjo.ctype() |
− | + | .protos({ | |
− | InnerClass://> InnerClass | + | InnerInnerClass://> InnerInnerClass |
− | + | vjo.ctype() | |
− | vjo.ctype() | + | .protos({ |
− | + | //> void innerInnerMethod(String mssg) | |
− | .protos({ | + | innerInnerMethod:function(mssg){ |
− | + | this.vjo.Out.log("InnerInner "+mssg); | |
− | InnerInnerClass://> InnerInnerClass | + | } |
− | + | }) | |
− | vjo.ctype() | + | .endType(), |
− | + | //> void innerMethod(String mssg) | |
− | .protos({ | + | innerMethod:function(mssg){ |
− | + | this.vjo.Out.log("Inner "+mssg); | |
− | //> void innerInnerMethod(String mssg) | + | } |
− | + | }) | |
− | innerInnerMethod:function(mssg){ | + | .endType() |
− | + | ||
− | this.vjo.Out.log("InnerInner "+mssg); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | + | 8. DOCUMENTED. Inner class initialization is not translated correctly. | |
− | + | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest.innerclass; | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
import java.util.ArrayList; | import java.util.ArrayList; | ||
− | |||
import java.util.List; | import java.util.List; | ||
− | |||
public class AnonymousInnerclass { | public class AnonymousInnerclass { | ||
+ | List list = new ArrayList(3) { | ||
+ | {add("One"); add("Two"); add("Three");} | ||
+ | }; | ||
− | + | public void testMethod(){ | |
− | + | for(Object value: list){ | |
− | + | Out.log("value="+value); | |
− | + | } | |
− | + | } | |
− | + | }</source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.innerclass.AnonymousInnerclass") | |
− | + | ||
− | + | ||
− | public void testMethod(){ | + | |
− | + | ||
− | for(Object value: list){ | + | |
− | + | ||
− | Out. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("vjo.java.util.List") | .needs("vjo.java.util.List") | ||
− | |||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> List list | |
− | //> List list | + | list:null, |
− | + | //> private constructs() | |
− | list:null, | + | constructs:function(){ |
− | + | this.list= | |
− | //> private constructs() | + | vjo.make(this,vjo.java.util.ArrayList,3); |
− | + | }, | |
− | constructs:function(){ | + | //> public void testMethod() |
− | + | testMethod:function(){ | |
− | this.list= | + | this.vjo.Out.log("value="); |
− | + | for (var value,_$itr= | |
− | vjo.make(this,vjo.java.util.ArrayList,3); | + | this.list.iterator();_$itr.hasNext();){ |
− | + | value=_$itr.next(); | |
− | }, | + | this.vjo.Out.log("value="+value); |
− | + | } | |
− | //> public void testMethod() | + | } |
− | + | ||
− | testMethod:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("value="); | + | |
− | + | ||
− | for (var value,_$itr=this.list.iterator();_$itr.hasNext();){ | + | |
− | + | ||
− | value=_$itr.next(); | + | |
− | + | ||
− | this.vjo.Out.log("value="+value); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | | | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | 9. FIXED Local inner class | ||
Class Out not imported and create | Class Out not imported and create | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | | style=" | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | | | + | package j2jtest.innerclass; |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
− | |||
import java.util.ArrayList; | import java.util.ArrayList; | ||
− | |||
− | |||
public class LocalInnerclass { | public class LocalInnerclass { | ||
− | + | public void testMethod() { | |
− | + | //Out.log("asasas"); | |
− | + | class Happy { | |
− | + | public void hi() { | |
− | + | ArrayList list = new ArrayList(); | |
− | + | Out o = new Out(); | |
− | + | o.log("Hi"); | |
− | public void hi() { | + | double d = Math.PI; |
− | + | } | |
− | + | } | |
− | + | Happy h = new Happy(); | |
− | + | h.hi(); | |
− | + | } | |
− | + | }</source> | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | + | vjo.ctype("j2jtest.innerclass.LocalInnerclass") | |
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("vjo.java.util.ArrayList") | .needs("vjo.java.util.ArrayList") | ||
− | |||
.needs("vjo.java.lang.Math") | .needs("vjo.java.lang.Math") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void testMethod() | |
− | //> public void testMethod() | + | testMethod:function(){ |
− | + | //> Happy | |
− | testMethod:function(){ | + | vjo.ctype("Happy") |
− | + | .protos({ | |
− | //> Happy | + | //> public void hi() |
− | + | hi:function(){ | |
− | vjo.ctype("Happy") | + | var list=new this.vjo.ArrayList(); |
− | + | var o; | |
− | .protos({ | + | o.log("Hi"); |
− | + | var d=this.vjo.Math.PI; | |
− | //> public void hi() | + | } |
− | + | }) | |
− | hi:function(){ | + | .endType(); |
− | + | var h=new Happy(); | |
− | var list=new this.vjo.ArrayList(); | + | h.hi(); |
− | + | } | |
− | var o; | + | |
− | + | ||
− | o.log("Hi"); | + | |
− | + | ||
− | var d=this.vjo.Math.PI; | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | + | 10. FIXED method overload with super and base class as parameter | |
− | + | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest.constructor; | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class MyClass extends MyClassBase{ | public class MyClass extends MyClassBase{ | ||
− | + | public void testMethod(MyClassBase base){ | |
− | public void testMethod(MyClassBase base){ | + | Out.log("MyClass(MyClassBase)"); |
− | + | ||
− | Out. | + | |
− | + | ||
} | } | ||
− | |||
public void testMethod(MyClass myClass){ | public void testMethod(MyClass myClass){ | ||
− | + | Out.log("MyClass(MyClass)"); | |
− | Out. | + | |
− | + | ||
} | } | ||
− | |||
public void testMethod(){ | public void testMethod(){ | ||
− | + | MyClass myClass = new MyClass(); | |
− | MyClass myClass = new MyClass(); | + | testMethod(myClass); |
− | + | ||
− | testMethod(myClass); | + | |
− | + | ||
} | } | ||
− | + | }</source> | |
− | } | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | | | + | vjo.ctype("j2jtest.constructor.MyClass") |
− | + | ||
.needs("j2jtest.constructor.MyClassBase") | .needs("j2jtest.constructor.MyClassBase") | ||
− | |||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.inherits("j2jtest.constructor.MyClassBase") | .inherits("j2jtest.constructor.MyClassBase") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void testMethod() | |
− | //> public void testMethod() | + | testMethod:function(){ |
− | + | if(arguments.length===1){ | |
− | testMethod:function(){ | + | if(arguments[0] instanceof |
− | + | j2jtest.constructor.MyClassBase){ | |
− | if(arguments.length===1){ | + | this.testMethod_1_0(arguments[0]); |
− | + | }else if(arguments[0] instanceof | |
− | + | j2jtest.constructor.MyClass){ | |
− | + | this.testMethod_1_1(arguments[0]); | |
− | + | } | |
− | + | }else if(arguments.length===0){ | |
− | }else if | + | this.testMethod_0_0(); |
− | + | } | |
− | this | + | }, |
− | + | //> public void testMethod_1_0(MyClassBase base) | |
− | } | + | testMethod_1_0:function(base){ |
− | + | this.vjo.Out.log("MyClass(MyClassBase)"); | |
− | }else if(arguments.length===0){ | + | }, |
− | + | //> public void testMethod_1_1(MyClass myClass) | |
− | this.testMethod_0_0(); | + | testMethod_1_1:function(myClass){ |
− | + | this.vjo.Out.log("MyClass(MyClass)"); | |
− | } | + | }, |
− | + | //> public void testMethod_0_0() | |
− | }, | + | testMethod_0_0:function(){ |
− | + | var myClass=new this.vjo.MyClass(); | |
− | //> public void testMethod_1_0(MyClassBase base) | + | this.testMethod(myClass); |
− | + | } | |
− | testMethod_1_0:function(base){ | + | |
− | + | ||
− | this.vjo.Out.log("MyClass(MyClassBase)"); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void testMethod_1_1(MyClass myClass) | + | |
− | + | ||
− | testMethod_1_1:function(myClass){ | + | |
− | + | ||
− | this.vjo.Out.log("MyClass(MyClass)"); | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> public void testMethod_0_0() | + | |
− | + | ||
− | testMethod_0_0:function(){ | + | |
− | + | ||
− | var myClass=new this.vjo.MyClass(); | + | |
− | + | ||
− | this.testMethod(myClass); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
+ | |} | ||
− | . | + | 11. ERROR Default constructor. Default constructor is not getting created |
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |||
− | |||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest.constructor; | ||
+ | public class MyClass | ||
+ | extends Base{ | ||
+ | }</source> | ||
+ | | colspan="2" style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.constructor.MyClass") | ||
+ | .needs("j2jtest. | ||
+ | constructor.Base") | ||
+ | .inherits("j2jtest. | ||
+ | constructor.Base") | ||
+ | .endType(); </source> | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| style="border:1px solid #AAAAAA;padding: 0.2em;"| Generic object is not translated correctly if two typed parameters are same type | | style="border:1px solid #AAAAAA;padding: 0.2em;"| Generic object is not translated correctly if two typed parameters are same type | ||
− | |||
− | |||
FIXED | FIXED | ||
− | | | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| |
− | + | <source lang="java"> | |
− | public static | + | // translate correctly |
− | + | public static GenericClass<String,Integer> | |
− | + | testMethod(){ | |
− | + | GenericClass<String,Integer> | |
− | Out. | + | object2 = |
− | + | new GenericClass<String, Integer> | |
+ | ("String one",20); | ||
+ | Out.log(object2.one); | ||
return object2; | return object2; | ||
− | |||
} | } | ||
− | + | GenericClass<String, String> testMethod1(){ | |
− | GenericClass | + | GenericClass<String,String> object2 = |
− | + | new GenericClass<String, String>("ss","ss"); | |
− | GenericClass | + | |
− | + | ||
return object2; | return object2; | ||
− | |||
} | } | ||
+ | </source> | ||
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| | |
− | + | <source lang="javascript"> | |
− | | | + | //> public GenericClass<String,Integer> |
− | + | testMethod() | |
testMethod:function(){ | testMethod:function(){ | ||
− | |||
var object2=new this("String one",20); | var object2=new this("String one",20); | ||
− | |||
this.vjo.Out.log(object2.one); | this.vjo.Out.log(object2.one); | ||
− | |||
return object2; | return object2; | ||
− | |||
} | } | ||
− | + | //> GenericClass<String> testMethod1() | |
− | + | ||
− | + | ||
testMethod1:function(){ | testMethod1:function(){ | ||
− | + | var object2=new | |
− | var object2=new this.vjo.GenericClass("ss","ss"); | + | this.vjo.GenericClass("ss","ss"); |
− | + | ||
return object2; | return object2; | ||
− | |||
}, | }, | ||
+ | </source> | ||
+ | |} | ||
− | + | 12. DOCUMENTED Super keyword not translated correctly | |
− | + | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | + | |- style="vertical-align:top" | |
− | |- | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> |
− | + | package j2jtest.inheritance; | |
− | + | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Derived extends Base { | public class Derived extends Base { | ||
− | + | int i=20; | |
− | int i | + | public void method1(){ |
− | + | Out.log(" i = "+super.i); | |
− | public void method1(){ | + | } |
− | + | }</source> | |
− | Out. | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.inheritance.Derived") | |
− | } | + | |
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.needs("j2jtest.inheritance.Base") | .needs("j2jtest.inheritance.Base") | ||
− | |||
.inherits("j2jtest.inheritance.Base") | .inherits("j2jtest.inheritance.Base") | ||
− | |||
.props({ | .props({ | ||
− | + | //> public void touch() | |
− | //> public void touch() | + | touch:function(){ |
− | + | } | |
− | touch:function(){ | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> int i | |
− | //> int i | + | i:20, |
− | + | //> public void method1() | |
− | i:20, | + | method1:function(){ |
− | + | this.vjo.Out.log(" i = "+this.i); | |
− | //> public void method1() | + | } |
− | + | ||
− | method1:function(){ | + | |
− | + | ||
− | this.vjo.Out.log(" i = "+this.i); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | + | |} | |
− | + | ||
− | | | + | |
− | + | ||
+ | 13. DOCUMENTED Cannt have variable name as class name | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |||
− | |||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest.conversion; | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Conversion { | public class Conversion { | ||
− | + | String Conversion = "Conversion string"; | |
− | String Conversion = "Conversion string"; | + | String str = "str"; |
− | + | public static void touch(){ | |
− | String str = "str" | + | } |
− | + | public void method1(){ | |
− | public static void touch(){ | + | Out.log("Conversion = "+ Conversion); |
− | + | Out.log("str = "+ str); | |
− | } | + | } |
− | + | }</source> | |
− | public void method1(){ | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.conversion.Conversion") | |
− | Out. | + | |
− | + | ||
− | Out. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.props({ | .props({ | ||
− | + | //> public void touch() | |
− | //> public void touch() | + | touch:function(){ |
− | + | } | |
− | touch:function(){ | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> String Conversion | |
− | //> String Conversion | + | Conversion:"Conversion string", |
− | + | //> String str | |
− | Conversion:"Conversion string", | + | str:"str", |
− | + | //> public void method1() | |
− | //> String str | + | method1:function(){ |
− | + | this.vjo.Out.log("Conversion = "+this.vjo.Conversion); | |
− | str:"str", | + | this.vjo.Out.log("str = "+this.str); |
− | + | } | |
− | //> public void method1() | + | |
− | + | ||
− | method1:function(){ | + | |
− | + | ||
− | this.vjo.Out.log("Conversion = "+this.vjo.Conversion); | + | |
− | + | ||
− | this.vjo.Out.log("str = "+this.str); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
+ | |} | ||
− | . | + | 14. FIXED Calling overload function from base class is not getting translated. Keyword this is missing |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
Eg., | Eg., | ||
Line 6,108: | Line 3,999: | ||
this. overload(); | this. overload(); | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | + | |- style="vertical-align:top" | |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | |- | + | package j2jtest.member; |
− | + | ||
− | + | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Derived extends Base{ | public class Derived extends Base{ | ||
− | + | public void method1(){ | |
− | public void method1(){ | + | overload(); |
− | + | overload("asasas"); | |
− | overload(); | + | //overload(local); |
− | + | } | |
− | overload("asasas"); | + | public void override(){ |
− | + | Out.log("Derived.override"); | |
− | //overload(local); | + | } |
− | + | public void overload(String s){ | |
+ | Out.log("Derived.overload(String)"); | ||
+ | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
package j2jtest.member; | package j2jtest.member; | ||
− | |||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Base { | public class Base { | ||
− | + | public void override(){ | |
− | public void override(){ | + | Out.log("Base.override"); |
− | + | } | |
− | Out. | + | public void overload(){ |
− | + | Out.log("Base.overload"); | |
− | } | + | } |
− | + | }</source> | |
− | public void overload(){ | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> |
− | + | vjo.ctype("j2jtest.member.Derived") | |
− | Out. | + | |
− | + | ||
− | } | + | |
− | + | ||
− | } | + | |
− | | | + | |
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | |||
.needs("j2jtest.member.Base") | .needs("j2jtest.member.Base") | ||
− | |||
.inherits("j2jtest.member.Base") | .inherits("j2jtest.member.Base") | ||
− | |||
.protos({ | .protos({ | ||
− | + | //> public void method1() | |
− | //> public void method1() | + | method1:function(){ |
− | + | overload(); | |
− | method1:function(){ | + | this.overload("asasas"); |
− | + | }, | |
− | overload(); | + | //> public void override() |
− | + | override:function(){ | |
− | this.overload("asasas"); | + | this.vjo.Out.log("Derived.override"); |
− | + | }, | |
− | }, | + | //> public void overload(String s) |
− | + | overload:function(s){ | |
− | //> public void override() | + | if(arguments.length===1){ |
− | + | if(arguments[0] instanceof String | |
− | override:function(){ | + | || typeof arguments[0]=="string"){ |
− | + | this.overload_1_0_Derived_ovld(arguments[0]); | |
− | this.vjo.Out.log("Derived.override"); | + | }else if(this.base && this.base.overload){ |
− | + | this.base.overload.apply(this,arguments); | |
− | }, | + | } |
− | + | }else if(this.base && this.base.overload){ | |
− | //> public void overload(String s) | + | this.base.overload.apply(this,arguments); |
− | + | } | |
− | overload:function(s){ | + | }, |
− | + | //> private void overload_1_0_Derived_ovld(String s) | |
− | if(arguments.length===1){ | + | overload_1_0_Derived_ovld:function(s){ |
− | + | this.vjo.Out.log("Derived.overload(String)"); | |
− | if | + | } |
− | + | ||
− | this | + | |
− | + | ||
− | }else if(this.base && this.base.overload){ | + | |
− | + | ||
− | this.base.overload.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }else if(this.base && this.base.overload){ | + | |
− | + | ||
− | this.base.overload.apply(this,arguments); | + | |
− | + | ||
− | } | + | |
− | + | ||
− | }, | + | |
− | + | ||
− | //> private void overload_1_0_Derived_ovld(String s) | + | |
− | + | ||
− | overload_1_0_Derived_ovld:function(s){ | + | |
− | + | ||
− | this.vjo.Out.log("Derived.overload(String)"); | + | |
− | + | ||
− | } | + | |
− | + | ||
}) | }) | ||
+ | .endType(); </source> | ||
− | |||
+ | |} | ||
+ | 15. DOCUMENTED. Calling overloaded method with null is not handled correctly. | ||
+ | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | ||
− | |- | + | |- style="vertical-align:top" |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | |
− | + | package j2jtest.member; | |
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
− | + | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | |||
public class Overload { | public class Overload { | ||
+ | public void method1(){ | ||
+ | String notWorking = null; | ||
+ | //overload(); | ||
+ | overload("working"); | ||
+ | overload(notWorking); | ||
+ | } | ||
+ | public void overload(){ | ||
+ | Out.log("Overload.overload()"); | ||
+ | } | ||
+ | public void overload(String s){ | ||
+ | Out.log("Overload.overload(String)"); | ||
+ | } | ||
+ | public void overload(Object s){ | ||
+ | Out.log("Overload.overload(Object)"); | ||
+ | } | ||
+ | }</source> | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | ||
+ | vjo.ctype("j2jtest.member.Overload") | ||
+ | .needs("j2jtest.Out") | ||
+ | .protos({ | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
+ | var notWorking=null; | ||
+ | this.overload("working"); | ||
+ | this.overload(notWorking); | ||
+ | }, | ||
+ | //> public void overload() | ||
+ | //> public void overload(String s) | ||
+ | //> public void overload(vjo.Object s) | ||
+ | overload:function(){ | ||
+ | if(arguments.length===0){ | ||
+ | this.overload_0_0_Overload_ovld(); | ||
+ | }else if(arguments.length===1){ | ||
+ | if(arguments[0] instanceof String | ||
+ | || typeof arguments[0]=="string"){ | ||
+ | this.overload_1_0_Overload_ovld(arguments[0]); | ||
+ | }else if(arguments[0] instanceof vjo.Object){ | ||
+ | this.overload_1_1_Overload_ovld(arguments[0]); | ||
+ | } | ||
+ | } | ||
+ | }, | ||
+ | //> private void overload_0_0_Overload_ovld() | ||
+ | overload_0_0_Overload_ovld:function(){ | ||
+ | this.vjo.Out.log("Overload.overload()"); | ||
+ | }, | ||
+ | //> private void overload_1_0_Overload_ovld(String s) | ||
+ | overload_1_0_Overload_ovld:function(s){ | ||
+ | this.vjo.Out.log("Overload.overload(String)"); | ||
+ | }, | ||
+ | //> private void overload_1_1_Overload_ovld(vjo.Object s) | ||
+ | overload_1_1_Overload_ovld:function(s){ | ||
+ | this.vjo.Out.log("Overload.overload(Object)"); | ||
+ | } | ||
+ | }) | ||
+ | .endType(); </source> | ||
+ | |} | ||
− | + | 16. Abstract method is not getting called correctly. From the example., callAbstractMethod() should call method in implementing class instead it calls from the abstract class method | |
− | + | {| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;" | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | |- style="vertical-align:top" | ||
+ | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="java"> | ||
+ | package j2jtest.abstract1; | ||
+ | import j2jtest.Out; | ||
+ | public class Derived extends Base{ | ||
+ | public void method1(){ | ||
+ | callAbstractMethod(); | ||
+ | } | ||
+ | public void abstractMethod(){ | ||
+ | Out.log("Derived.abstractMethod"); | ||
+ | } | ||
+ | public void abstractMethod(String value){ | ||
+ | Out.log("Derived.abstractMethod(String)"); | ||
+ | } | ||
} | } | ||
− | public | + | package j2jtest.abstract1; |
− | + | import j2jtest.Out; | |
− | Out. | + | public class Base { |
− | + | public String toString(){ | |
− | } | + | return " Hey i am Basie"; |
− | + | } | |
− | public void | + | public void callAbstractMethod(){ |
− | + | Out.log("Base.callAbstractMethod"); | |
− | Out. | + | abstractMethod("StrValue"); |
− | + | } | |
− | } | + | public void abstractMethod(){ |
− | + | Out.log("Base.abstractMethod"); | |
− | public void | + | } |
− | + | public void abstractMethod(String value){ | |
− | Out. | + | Out.log("Base.abstractMethod(String)"); |
− | + | } | |
− | } | + | }</source> |
− | + | | style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript"> | |
− | } | + | vjo.ctype("j2jtest.abstract1.Derived") |
− | | | + | |
− | + | ||
.needs("j2jtest.Out") | .needs("j2jtest.Out") | ||
− | + | .needs("j2jtest.abstract1.Base") | |
+ | .inherits("j2jtest.abstract1.Base") | ||
.protos({ | .protos({ | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
+ | this.callAbstractMethod(); | ||
+ | }, | ||
+ | //> public void abstractMethod() | ||
+ | //> public void abstractMethod(String value) | ||
+ | abstractMethod:function(){ | ||
+ | if(arguments.length===0){ | ||
+ | this.abstractMethod_0_0_Derived_ovld(); | ||
+ | }else if(this.base && this.base.abstractMethod){ | ||
+ | this.base.abstractMethod.apply(this,arguments); | ||
+ | }else if(arguments.length===1){ | ||
+ | if(arguments[0] instanceof String | ||
+ | || typeof arguments[0]=="string"){ | ||
+ | this.abstractMethod_1_0_Derived_ovld(arguments[0]); | ||
+ | }else if(this.base && this.base.abstractMethod){ | ||
+ | this.base.abstractMethod.apply(this,arguments); | ||
+ | } | ||
+ | }else if(this.base && this.base.abstractMethod){ | ||
+ | this.base.abstractMethod.apply(this,arguments); | ||
+ | } | ||
+ | }, | ||
+ | //> private void abstractMethod_0_0_Derived_ovld() | ||
+ | abstractMethod_0_0_Derived_ovld:function(){ | ||
+ | this.vjo.Out.log("Derived.abstractMethod"); | ||
+ | }, | ||
+ | //> private void abstractMethod_1_0_Derived_ovld(String value) | ||
+ | abstractMethod_1_0_Derived_ovld:function(value){ | ||
+ | this.vjo.Out.log("Derived.abstractMethod(String)"); | ||
+ | } | ||
+ | }) | ||
+ | .endType(); </source> | ||
− | |||
− | |||
− | + | |} | |
+ | Type Variables | ||
− | + | A type variable (§4.4) is an unqualified identifier. Type variables are introduced | |
− | + | by generic class declarations (§8.1.2) generic interface declarations (§9.1.2) | |
− | + | generic method declarations (§8.4.4) and by generic constructor declarations | |
− | / | + | Things to Remember/TODO |
− | + | 1 Overloaded method and null parameter | |
− | + | Will get unexpected behaviour if overloaded method is called with null object. In java script, variable type is determined based on the value it has. If the variable has null value then ther is no way to determine the type value. | |
− | + | When passing result of an expression to overloaded method, make sure it’s not null. | |
− | + | 2 Variable name as Class, Pakcage or function name | |
− | + | Do not overload variable name with Class, Pakcage or function name. In java it works fine, when it comes to java script, it evaluates as class or function. | |
− | + | 3 Array components | |
− | + | Array components with custom object creation is not supported. For ex., | |
+ | <source lang="javascript"> | ||
+ | Pair[] pairArrayWithInit = {new Pair(), new Pair()};</source> | ||
− | + | 4 Inner class/ initialization. | |
− | + | Initializing object like shown below is not supported | |
− | + | <source lang="java"> | |
+ | List list = new ArrayList(3) { | ||
+ | { add("One"); add("Two"); add("Three");} | ||
+ | }; | ||
+ | </source> | ||
− | + | 5 Overload method with primitive and wrapper class | |
− | + | Overloading functions/constructor with primitive and wrapper class are not supported. For ex, below function method1 is overloaded using primitive type int and Integer. This type of overload is not supported. | |
− | + | <source lang="java"> | |
+ | public void method1(int intValue){ | ||
− | + | } | |
− | + | public void method1(Integer intValue){ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
+ | </source> | ||
− | + | 6 Class loading and static initializer | |
− | + | In java a class is loaded only if it’s used or referenced and all staic fields/blocks will get executed only at that time of class loading. | |
− | + | ||
− | + | ||
− | + | ||
+ | In VJO there is no such thing called class loading. So all the reference and embedded class’s static variables/blocks are initialized along with the main class. This may cause unexpected bahaviour for ex., | ||
− | + | <source lang="java"> | |
− | + | package j2jtest.todo; | |
− | + | ||
− | + | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | + | public class StaticInit { | |
− | public class | + | static int intValue = 10; |
− | + | public void display(){ | |
− | + | Out.log("intValue="+intValue); | |
− | public void | + | StaticInner staticInner = new StaticInner(); |
− | + | Out.log("intValue="+intValue); | |
− | + | } | |
− | + | static class StaticInner{ | |
+ | static{ | ||
+ | intValue = 20; | ||
+ | } | ||
+ | } | ||
} | } | ||
+ | </source> | ||
− | + | When running the above java class produces the result | |
− | + | intValue=10 | |
+ | intValue=20 | ||
− | + | but translated js file would result | |
− | + | intValue=20 | |
+ | intValue=20 | ||
− | + | as all static blocks run when the main class loads. | |
− | |||
+ | 7 Overload method with super and derived class | ||
− | + | When methods are overloaded based on super and derived class, java checks the variable type and calls the corresponding method with that type. In VJO, it doesn’t check the variable type, it checks the object type and call the corresponding method. For ex., | |
− | + | ||
− | + | ||
− | + | ||
+ | <source lang="java"> | ||
+ | package j2jtest.methodoverload; | ||
import j2jtest.Out; | import j2jtest.Out; | ||
− | + | public class MyClass extends MyClassBase{ | |
− | public class | + | public void testMethod(MyClassBase base){ |
− | + | Out.log("testMethod(MyClassBase)"); | |
− | public | + | } |
− | + | public void testMethod(MyClass myClass){ | |
− | + | Out.log("testMethod(MyClass)"); | |
− | + | } | |
+ | public void testMethod(){ | ||
+ | MyClass myClass = new MyClass(); | ||
+ | MyClassBase myBaseClass = new MyClass(); | ||
+ | testMethod(myClass); | ||
+ | testMethod(myBaseClass); | ||
+ | } | ||
} | } | ||
+ | </source> | ||
+ | Result from Java | ||
− | + | testMethod(MyClass) | |
− | + | testMethod(MyClassBase) | |
− | + | Result from Vjo | |
− | + | testMethod(MyClass) | |
− | + | testMethod(MyClass) | |
− | |||
− | + | 8 Same variable names in super and derived class | |
− | + | Java maintains separate memory space for super and derived class so when variable is declared with same name in super and derived, both can have dirrerent value. VJO donesnt maintain separate memory space for super and derived, vjo shares one memory area for all variables (super and derived). So if a variable is declared with the same name in super and derived, only derived class variable would be available and would be refered as this.variablename. For ex., | |
− | + | ||
− | + | ||
+ | <source lang="java"> | ||
+ | package j2jtest.inheritance; | ||
+ | import j2jtest.Out; | ||
+ | public class Derived extends Base { | ||
+ | int i = 20; | ||
+ | public void method1(){ | ||
+ | Out.log(" i = "+super.i); | ||
+ | } | ||
} | } | ||
− | + | package j2jtest.inheritance; | |
+ | public class Base { | ||
+ | int i = 10; | ||
} | } | ||
− | + | </source> | |
− | + | Would be represented as | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | <source lang="javascript"> | ||
+ | vjo.ctype('j2jtest.inheritance.Derived') //< public | ||
+ | .needs('j2jtest.Out') | ||
+ | .inherits('j2jtest.inheritance.Base') | ||
.protos({ | .protos({ | ||
+ | i:20, //< int | ||
+ | //> public void method1() | ||
+ | method1:function(){ | ||
+ | this.vjo.Out.log(" i = "+this.i); | ||
+ | } | ||
+ | }) | ||
+ | .endType(); | ||
+ | </source> | ||
+ | Java output | ||
− | + | i = 10 | |
− | + | JS output | |
− | + | i = 20 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | 9 Avoid Circular references. For ex., | ||
+ | <source lang="java"> | ||
+ | public class Conversion { | ||
+ | Conversion str = new Conversion(); | ||
} | } | ||
+ | </source> | ||
− | + | 10 Sub classes are not supported. | |
− | + | <source lang="java"> | |
− | + | package j2jtest.member; | |
− | + | import j2jtest.Out; | |
+ | public class MemberClass { | ||
+ | void m1(){ | ||
+ | Out.log("in MemberClass"); | ||
+ | SubClass obj = new SubClass(); | ||
+ | obj.m1(); | ||
+ | } | ||
} | } | ||
− | + | class SubClass{ | |
− | + | public void m1(){ | |
− | + | Out.log("In MyInnerMemberClass.m1()"); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
+ | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[Category:VJET]] | + | [[Category:VJET|Java2JS]] |
+ | [[Category:JavaToJs]] |
Latest revision as of 21:58, 28 January 2013
Contents
- 1 Lexical Structure
- 2 Types, Values and Variables
- 3 Conversions and Promotions
- 3.1 Identity conversions – conversion to a same type, straight forward
- 3.2 Widening primitive conversions
- 3.3 Narrowing primitive conversions
- 3.4 Widening reference conversions
- 3.5 Narrowing reference conversions
- 3.6 Boxing conversions
- 3.7 Unboxing conversions
- 3.8 Unchecked conversions – not supported
- 3.9 Capture conversions – not supported
- 3.10 String conversions - convert from any other type to String
- 3.11 Value set conversions - not supported , Value set conversion is the process of mapping a floating-point value from one value set to another without changing its type.
- 3.12 Assignment conversion
- 3.13 Method invocation conversion
- 3.14 String conversion
- 3.15 Casting conversion
- 3.16 Numeric promotion
- 4 Names
- 5 Packages
- 6 Classes
- 7 Interfaces
- 8 Arrays
- 9 ERORS/TO-DO List
Lexical Structure
Comment
Not supported in AST parser
Identifier
Keywords
Below map shows java keyword mapping in JS/VJO
Java-keyword | Js – keyword | Vjo | Js-reserved |
---|---|---|---|
break
case catch continue default do else finally for if try throw instanceof new return void switch this while |
break
case catch continue default do else finally for if try throw instanceof new return void switch this while |
||
boolean
char short int double float long short public protected private final
extends class interface import static enum package |
boolean
Int short int double float long short public protected private final
< .inherits > < .ctype > <.itype> < vjo.needs > < .props({ }) > < vjo.etype("pkg.Enum") > < vjo.ctype("vjo.pkgname")> |
boolean
char short int double float long short public protected private final
extends class interface import static enum package | |
abstract
byte const- reserved goto -reserved super native synchronized transient
throws assert strictfp |
abstract
byte const goto
native synchronize transient
throws
export | ||
delete
function in var with typeof |
Literals
java | JS | desc |
---|---|---|
Boolean literals
|
true. false | Literals true/false are directly mapped in java script |
null
|
null / false
|
Seperators
Java | JS |
---|---|
( ) { } [ ] ; , . | Directly mapped |
Operators
All operators are directly mapped into js.
Java operators | Java | Js | Description |
---|---|---|---|
# =
|
a= b;
a = a+b; a = a-b; a = a * b; a = a/b; a = a&b; if(a>b){} if(a<b){} if( !(a==b) && (x!=y) || (a<x) || (b>x) || (b<=a) || (x>=y) ){} a= a++; a= a--; a = b^a; a = a%b; a +=b; a -=b; a *=b; a /=b; a &=x; a ^= b; a %= b; a<<=b; a>>=b; a>>>=b; |
a=b;
a=a+b; a=a-b; a=a*b; a=parseInt(a/b); a=a&b; if(a>b){ } if(a<b){ } if( !(a==b)&&(x!=y)||(a<x)||(b>x)||(b<=a) || (x>=y)){ } a=a++; a=a--; a=b^a; a=a%b; a+=b; a-=b; a*=b; a=parseInt(a/b); a&=x; a^=b; a%=b; a<<=b; a>>=b; a>>>=b; |
Direct translation |
Types, Values and Variables
Primitive types and values
Java | js |
---|---|
boolean byte char short
long double float |
boolean int, indirectly supported , declared as int int, indirectly supported, declared as int short
long double float |
Reference Types & Values
Class type
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests; public class A { int a=10; public int p=50; String city; String state; public void setCity(String c ){ this.city=c; } public String getCity(){ return this.city; } protected void setState(String s){ this.state=s; } protected String getState(){ return this.state; } String foo(){ return "foo"; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.A") .protos({ //> int a a:10, //> public int p p:50, //> String city city:null, //> String state state:null, //> public void setCity(String c) setCity:function(c){ this.city=c; }, //> public String getCity() getCity:function(){ return this.city; }, //> protected void setState(String s) setState:function(s){ this.state=s; }, //> protected String getState() getState:function(){ return this.state; }, //> String foo() foo:function(){ return "foo"; } }) .endType(); |
interface type
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests.Inheritance; public interface Interface3 { String C3="c3"; String method3(); } |
vjo.itype("com.ebay.dsf.javatojs.tests.Inheritance.Interface3") .props({ //> public String C3 C3:"c3" }) .protos({ //> public String method3() method3:function(){ } }) .endType(); |
Array type
Java | Vjo |
---|---|
long avg = 10; long[] la = {1+avg,2,3}; int[][] twoDimArray = {{1,2,3}, {4,5,6}}; String[] sa = { "a", "b", "c"}; String[] sa2 = new String[2]; Employee[] sa3 = new Employee[2]; boolean boolArr1[] = new boolean[]{true}; boolean boolArr2[][] = new boolean[][]{{false}}; boolean boolArr11[] = new boolean[twoDimArray[0][0]]; boolean boolArr12[][] = new boolean[twoDimArray[0][0]] [twoDimArray[0][1]]; |
var avg=10; var la=[1+avg,2,3]; var twoDimArray=[[1,2,3],[4,5,6]]; var sa=["a","b","c"]; var sa2=new Array(2); var sa3=new Array(2); var boolArr1=[true]; var boolArr2=[[false]]; var boolArr11=new Array(twoDimArray[0][0]); var boolArr12=new Array; |
Type Variables
Implemented in comment
package com.ebay.dsf.javatojs.tests.operators; public class Pair<T, S>{ private T first; private S second; public Pair(T f, S s){ first = f; second = s; } public T getFirst() { return first; } public S getSecond(){ return second; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .protos({ //> private T first first:null, //> private S second second:null, //> public constructs(T f,S s) constructs:function(f,s){ this.first=f; this.second=s; }, //> public T getFirst() getFirst:function(){ return this.first; }, //> public S getSecond() getSecond:function(){ return this.second; } }) .endType(); |
Parameterized type
Java | Vjo |
---|---|
Vector<String> vector = new Vector(); Collection<Integer> collection = new ArrayList<Integer>(); |
//> Vector<String> vector vector:null, //> Collection<Integer> collection collection:null, //> private constructs() constructs:function(){ this.vector=new this.vjo.Vector(); this.collection=new this.vjo.ArrayList(); }, |
Sub-Typing
- Subtyping among primitive types
- Subtyping among class and interface
- Subtyping among array types
class type is defined using vjo .ctypas as
Variables
Class variable
static Integer classVariableInteger = new Integer(10); static Float classVariableFloat; static int classVariableInt; |
.props({ //> Integer classVariableInteger classVariableInteger:null, //> Float classVariableFloat classVariableFloat:null, //> int classVariableInt classVariableInt:0 }) .inits(function(){ this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10); }) |
Instance variable
package com.ebay.dsf.javatojs.tests.operators; public class Pair{ Integer classVariableInteger = new Integer(10); Float classVariableFloat; int classVariableInt; } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Float") .protos({ //> Integer classVariableInteger classVariableInteger:null, //> Float classVariableFloat classVariableFloat:null, //> int classVariableInt classVariableInt:0, //> private constructs() constructs:function(){ this.classVariableInteger=new this.vjo.Integer(10); } }) .endType(); |
Array components – are unknown variables - partially implemented
package com.ebay.dsf.javatojs.tests.operators; public class Pair{ String[] stringArray = {new String(), new String()}; Integer[] intArray; //Pair[] pairArrayInit = {new Pair(), new Pair()}; Pair(){ intArray = new Integer[2]; intArray[0] = new Integer(20); intArray[1] = 30; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.StringFactory") .protos({ //> String[] stringArray stringArray:null, //> Integer[] intArray intArray:null, //> constructs() constructs:function(){ this.stringArray= [vjo.java.lang.StringFactory.build(), vjo.java.lang.StringFactory.build()]; this.intArray=new Array(2); this.intArray[0]=new this.vjo.Integer(20); this.intArray[1]=30; } }) .endType(); |
Method parameters
package com.ebay.dsf.javatojs.tests.operators; public class Pair{ public Pair myMethod(String s, Pair p){ String paramString = s; Pair parameterPair = p; return parameterPair; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .protos({ //> public Pair myMethod(String s,Pair p) myMethod:function(s,p){ var paramString=s; var parameterPair=p; return parameterPair; } }) .endType(); |
Parameter s, and p exist only within the function |
Constructor parameters
package com.ebay.dsf.javatojs.tests.operators; public class Pair{ String s; Integer i; Pair(String s, Integer i){ this.s =s; this.i=i; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .protos({ //> String s s:null, //> Integer i i:null, //> constructs(String s,Integer i) constructs:function(s,i){ this.s=s; this.i=i; } }) .endType(); |
Exception-handler parameter
package com.ebay.dsf.javatojs.tests.operators; public class Pair { public Integer getNumber(){ Integer i = 10; String s = "20.9"; try{ i = new Integer(s); }catch(NumberFormatException nfe){ i = 0; } return i; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.NumberFormatException") .protos({ //> public Integer getNumber() getNumber:function(){ var i=10; var s="20.9"; try { i=new this.vjo.Integer(s); } catch(nfe){ i=0; } return i; } }) .endType(); |
Note: variable nfe only exists inside catch block. |
Local variables
package com.ebay.dsf.javatojs.tests.operators; public class Pair { public void getNumber(){ String s = new String(); Integer i = 20; { String second = "2"; } } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.StringFactory") .protos({ //> public void getNumber() getNumber:function(){ var s=vjo.java.lang.StringFactory.build(); var i=20; { var second="2"; } } }) .endType(); |
Conversions and Promotions
Note1: widening conversions do not require casts
Note2: narrowing conversions require explicit casts.
Identity conversions – conversion to a same type, straight forward
Widening primitive conversions
java | js |
---|---|
byte b = 10; short s = b; int i = b; long l = b; float f = b; double d = b; |
var b=10; var s=b; var i=b; var l=b; var f=b; var d=b; |
# byte to short, int, long, float, or double
|
All conversions are straight forward in js |
Narrowing primitive conversions
java | vjo |
---|---|
long l = 100l; byte b = (byte)l; short s = (short)l; char c = (char)l; int i = (int)l; |
var l=100; var b=vjo.java.lang.Util.cast(l,'byte'); var s=vjo.java.lang.Util.cast(l,'short'); var c=l; // there is no casting to char var i=vjo.java.lang.Util.cast(l,'int'); |
|
Note: Uses vjo util class to cast |
Widening reference conversions
java | vjo |
---|---|
String stringObj = new String(); Object object = new Object(); object = stringObj; |
var stringObj=vjo.java.lang.StringFactory.build(); var object=new vjo.Object(); object=stringObj; |
Note: Uses vjo reference implementation for all reference types |
Narrowing reference conversions
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests.operators; import java.util.List; public class Pair{ public List getNumber(Object object){ List list = (List) object; String str = (String) object; Object myObj = str; return list; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.util.List") .protos({ //> public List getNumber(vjo.Object object) getNumber:function(object){ var list=object; var str=object; var myObj=str; return list; } }) .endType(); |
Note: |
Boxing conversions
Java | vjo |
---|---|
package com.ebay.dsf.javatojs.tests.operators; import java.util.List; public class Pair{ Byte ob = 0; Short os = 1; Integer oi = 10; Long ol = 20l; Character oc = 'C'; Float of = 10.2f; Double od = 12.3; public void test(){ Byte ob = 0; Short os = 1; Integer oi = 10; Long ol = 20l; Character oc = 'C'<nowiki>;</nowiki> Float of = 10.2f; Double od = 12.3; } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Byte") .needs("vjo.java.lang.Short") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Long") .needs("vjo.java.lang.Character") .needs("vjo.java.lang.Float") .needs("vjo.java.lang.Double") .protos({ //> Byte ob ob:0, //> Short os os:1, //> Integer oi oi:10, //> Long ol ol:20, //> Character oc oc:'C', //> Float of of:10.2, //> Double od od:12.3, //> public void test() test:function(){ var ob=0; var os=1; var oi=10; var ol=20; var oc='C'; var of=10.2; var od=12.3; } }) .endType(); |
Type is declared in comment for jst translation |
- From type boolean to type Boolean
- From type byte to type Byte
- From type char to type Character
- From type short to type Short
- From type int to type Integer
- From type long to type Long
- From type float to type Float
- From type double to type Double
Unboxing conversions
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests.operators; public class Pair{ Byte ob = 0; Short os = 1; Integer oi = 10; Long ol = 20l; Character oc = 'C'; Float of = 10.2f; Double od = 12.3; byte b = ob; short s = os; int i = oi; long l = ol; char c = oc; float f = of; double d = od; } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Byte") .needs("vjo.java.lang.Short") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Long") .needs("vjo.java.lang.Character") .needs("vjo.java.lang.Float") .needs("vjo.java.lang.Double") .protos({ //> Byte ob ob:null, //> Short os os:null, //> Integer oi oi:null, //> Long ol ol:null, //> Character oc oc:null, //> Float of of:null, //> Double od od:null, //> byte b b:0, //> short s s:0, //> int i i:0, //> long l l:0, //> char c c:null, //> float f f:0, //> double d d:0, //> private constructs() constructs:function(){ this.ob=new this.vjo.Byte(0); this.os=new this.vjo.Short(1); this.oi=new this.vjo.Integer(10); this.ol=new this.vjo.Long(20); this.oc=new this.vjo.Character('C'); this.of=new this.vjo.Float(10.2); this.od=new this.vjo.Double(12.3); this.b=this.ob.byteValue(); this.s=this.os.shortValue(); this.i=this.oi.intValue(); this.l=this.ol.longValue(); this.c=this.oc.charValue(); this.f=this.of.floatValue(); this.d=this.od.doubleValue(); } }) .endType(); |
- From type Boolean to type boolean
- From type Byte to type byte
- From type Character to type char
- From type Short to type short
- From type Integer to type int
- From type Long to type long
- From type Float to type float
- From type Double to type double
Unchecked conversions – not supported
Capture conversions – not supported
String conversions - convert from any other type to String
String conversion applies only to the operands of the binary + operator when one
of the arguments is a String. When adding string to any object, java calls toString() and append to the string. This behavior is partially supported, ie., only with the user defined type with toString() implemented in it, other java objects are not supported. | |
Java | js |
---|---|
package j2jtest.conversion; import j2jtest.Out; public class Conversion { public void method1(){ AnotherClass obj = new AnotherClass(); String simpleStr = " Simple String" + obj; Out.log("simpleStr = "+ simpleStr); } } |
vjo.ctype("j2jtest.conversion.Conversion") .needs("j2jtest.Out") .protos({ //> public void method1() method1:function(){ var obj=new this.vjo.AnotherClass(); var simpleStr=" Simple String"+obj; this.vjo.Out.log("simpleStr = "+simpleStr); } }) .endType(); |
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests.operators; import java.util.ArrayList; import java.util.List; public class Pair{ List list = new ArrayList(); String s<nowiki>= "a"+ list; public String getStringFromObject(List myList){ String s = "Items in List "+ myList; return myList.toString(); } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.util.List") .needs("vjo.java.util.ArrayList") .protos({ //> List list list:null, //> String s s:null, //> private constructs() constructs:function(){ this.list=new this.vjo.ArrayList(); this.s="a"+this.list; }, //> public String getStringFromObject(List myList) getStringFromObject:function(myList){ var s="Items in List "+myList; return myList.toString(); } }) .endType(); |
style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: use toString() method on reference object |
Value set conversions - not supported , Value set conversion is the process of mapping a floating-point value from one value set to another without changing its type.
Assignment conversion
Method invocation conversion
Java | Vjo |
---|---|
package com.ebay.dsf.javatojs.tests.operators; import java.util.ArrayList; import java.util.List; public class Pair{ public void testMethod(){ Integer integer = new Integer(10); int intValue = 20; ArrayList list = null; identityConversion(integer); wideningPrimitiveConversion(intValue); wideningReferenceConversion(list); boxingConversion(intValue); unboxingConversion(intValue); } public void identityConversion(Integer i){ } public void wideningPrimitiveConversion(long l){ } public void wideningReferenceConversion( List list){ } public void boxingConversion(Integer i){ } public void unboxingConversion(int i){ } } |
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.util.ArrayList") .needs("vjo.java.util.List") .protos({ //> public void testMethod() testMethod:function(){ var integer=new this.vjo.Integer(10); var intValue=20; var list=null; this.identityConversion(integer); this.wideningPrimitiveConversion(intValue); this.wideningReferenceConversion(list); this.boxingConversion(new this.vjo.Integer(intValue)); this.unboxingConversion(intValue); }, //> public void identityConversion(Integer i) identityConversion:function(i){ }, //> public void wideningPrimitiveConversion(long l) wideningPrimitiveConversion:function(l){ }, //> public void wideningReferenceConversion(List list) wideningReferenceConversion:function(list){ }, //> public void boxingConversion(Integer i) boxingConversion:function(i){ }, //> public void unboxingConversion(int i) unboxingConversion:function(i){ } }) .endType(); |
String conversion
Casting conversion
Numeric promotion
Names
Declarations
declarations | Java | Vjo |
---|---|---|
package | package com.ebay.dsf.javatojs.tests.operators; |
vjo.ctype (“com.ebay.dsf.javatojs.tests.operators.Pair”) |
import |
Only single type import is supported. Import on demand would be converted into necessary single type import. | |
import java.util.ArrayList; import java.util.List; |
.needs("vjo.java.lang.Integer") .needs("vjo.java.util.ArrayList") | |
import java.util.*; |
.needs("vjo.java.lang.Integer") .needs("vjo.java.util.ArrayList") | |
class | public class Pair | vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair") |
interface |
package com.ebay.dsf.operators; public interface PairInterface{ } |
vjo.itype("com.ebay.dsf.operators.PairInterface") .endType(); |
member class |
package j2jtest; public class Pair{ private int p = 0; class PairInner{ int iCanAccessParentPrivateToo(){ return p; } } public void testMethod(){ } } |
vjo.ctype("j2jtest.Pair") .protos({ //> private int p p:0, PairInner:vjo.ctype() .protos({ //> int iCanAccessParentPrivateToo() iCanAccessParentPrivateToo:function(){ return this.vjo.outer.p; } }) .endType(), //> public void testMethod() testMethod:function(){ } }) .endType(); |
member interface |
package j2jtest; public class Pair{ interface Colors { int ''WHITE'' = 0, ''BLACK'' = 1; int getColor(); } } |
vjo.ctype("j2jtest.Pair") .protos({ Colors:vjo.itype() .props({ //> public int WHITE WHITE:0, //> public int BLACK BLACK:1 }) .protos({ //> public int getColor() getColor:function(){ } }) .endType() }) .endType(); |
enum constant | TODO: ERROR: Enum, not completely implemented. See the missing function for enum SUNDAY | |
package j2jtest; public enum EnumTest { SUNDAY{ int getIndex(){ return 0; } }, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } |
vjo.etype("j2jtest.EnumTest") .values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") .endType(); | |
field in class and interface
method in class and interface local variable in block local variable in for statement parameter of a method in class and interface parameter of an exception handler |
package j2jtest; public class Pair{ Integer fieldInClass = new Integer(10); public void methodInClass (String parameterOfaMethodInClass){ String sh = "shhhhhh!";{ Integer localVarInblock = 90; } for( int i=0; i<20; i++){ String localVarInForStatement = ""+i; try{ Integer k = new Integer(localVarInForStatement); }catch (Exception parameterOfAnExceptionHandler){ } } } interface Colors { Integer ''fieldInInterface'' = 20; int methodInInterface (String parameterOfaMethodInInterface); } } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Exception") .protos({ //> Integer fieldInClass fieldInClass:null, Colors:vjo.itype() .props({ //> public Integer fieldInInterface fieldInInterface:null }) .protos({ //> public int methodInInterface (String parameterOfaMethodInInterface) methodInInterface:function (parameterOfaMethodInInterface){ } }) .inits(function(){ this.vjo.Colors.fieldInInterface= new this.vjo.Integer(20); }) .endType(), //> private constructs() constructs:function(){ this.fieldInClass=new this.vjo.Integer(10); }, //> public void methodInClass (String parameterOfaMethodInClass) methodInClass:function(parameterOfaMethodInClass){ var sh="shhhhhh!"<nowiki>;</nowiki> { var localVarInblock=new this.vjo.Integer(90); } for (var <nowiki>i=0;i<20;i++)</nowiki>{ var localVarInForStatement=""+i; try { var k=new this.vjo.Integer (localVarInForStatement); } catch(parameterOfAnExceptionHandler){ } } } }) .endType(); |
Names and Identifiers
Scope of a Declaration
Shadowing Declaration
Java | Vjo |
---|---|
package j2jtest; public class Pair{ int x = 20; void myMethod(){ int x = 10; System.err.println("x ="+ x); System.err.println("thix.x="+ this.x); } } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.lang.System") .protos({ //> int x x:20, //> void myMethod() myMethod:function(){ var x=10; this.vjo.System.err.println("x = "+x); this.vjo.System.err.println("thix.x = "+this.x); } }) .endType(); |
Above shows shadowing of a field x by a local variable x . |
Obscured Declarations
Members and Inheritance
Java | js |
---|---|
package j2jtest.member; import j2jtest.Out; public class Derived extends Base{ String instanceMember; static String staticMember; public void method1(){ String local = inheritedMemberVar; local = inheritedStaticMemberVar; local = instanceMember; local = staticMember; local = ""; inheritedMemberMethod(); inheritedStaticMemberMethod(); override(); super.override(); overload(); overload(local); } public void memberMethod(){ Out.log("Derived.memberMethod"); } public static void memberStaticMethod(){ Out.log("Derived.memberStaticMethod"); } public void override(){ Out.log("Derived.override"); } public void overload(String s){ Out.log("Derived.overload(String)"); } public void abstractMethod(){ Out.log("Derived.abstractMethod"); } public void abstractMethod(String value){ Out.log("Derived.abstractMethod(String)"); } } package j2jtest.member; import j2jtest.Out; public abstract class Base { String inheritedMemberVar; static String inheritedStaticMemberVar; public void inheritedMemberMethod(){ Out.log("Base.inheritedMemberMethod"); } public void inheritedStaticMemberMethod(){ Out.log("Base.inheritedStaticMemberMethod"); } public void override(){ Out.log("Base.override"); } public void overload(){ Out.log("Base.overload"); } } |
vjo.ctype("j2jtest.member.Derived") .needs("j2jtest.Out") .needs("j2jtest.member.Base") .inherits("j2jtest.member.Base") .props({ //> String staticMember staticMember:null, //> public void memberStaticMethod() memberStaticMethod:function(){ this.vjo.Out.log("Derived.memberStaticMethod"); } }) .protos({ //> String instanceMember instanceMember:null, //> public void method1() method1:function(){ var local=this.inheritedMemberVar; local=this.vjo.Base.inheritedStaticMemberVar; local=this.instanceMember; local=this.vjo.Derived.staticMember; local=""; this.inheritedMemberMethod(); this.inheritedStaticMemberMethod(); this.override(); this.base.override(); overload(); this.overload(local); }, //> public void memberMethod() memberMethod:function(){ this.vjo.Out.log("Derived.memberMethod"); }, //> public void override() override:function(){ this.vjo.Out.log("Derived.override"); }, //> public void abstractMethod() //> public void abstractMethod(String value) abstractMethod:function(){ if(arguments.length===0){ this.abstractMethod_0_0_Derived_ovld(); }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); }else if(arguments.length===1){ if(arguments[0] instanceof String || typeof arguments[0]=="string"){ this.abstractMethod_1_0_Derived_ovld(arguments[0]); }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); } }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); } }, //> private void abstractMethod_0_0_Derived_ovld() abstractMethod_0_0_Derived_ovld:function(){ this.vjo.Out.log("Derived.abstractMethod"); }, //> private void //abstractMethod_1_0_Derived_ovld(String value) abstractMethod_1_0_Derived_ovld:function(value){ this.vjo.Out.log("Derived.abstractMethod(String)"); }, //> public void overload(String s) overload:function(s){ if(arguments.length===1){ if(arguments[0] instanceof String || typeof arguments[0]=="string"){ this.overload_1_0_Derived_ovld(arguments[0]); }else if(this.base && this.base.overload){ this.base.overload.apply(this,arguments); } }else if(this.base && this.base.overload){ this.base.overload.apply(this,arguments); } }, //> private void overload_1_0_Derived_ovld(String s) overload_1_0_Derived_ovld:function(s){ this.vjo.Out.log("Derived.overload(String)"); } }) .endType(); |
Access Control
Java | vjo |
---|---|
package j2jtest; public class Pair{ int packageAccess; public int publicAccess; private int privateAccess; protected int protectedAccess; void packageMethod(){ } public void publicMethod(){ } private void privateMethod(){ } protected void protectedMethod(){ } } |
vjo.ctype("j2jtest.Pair") .protos({ //> int packageAccess packageAccess:0, //> public int publicAccess publicAccess:0, //> private int privateAccess privateAccess:0, //> protected int protectedAccess protectedAccess:0, //> void packageMethod() packageMethod:function(){ }, //> public void publicMethod() publicMethod:function(){ }, //> private void privateMethod() privateMethod:function(){ }, //> protected void protectedMethod() protectedMethod:function(){ } }) .endType(); |
Fully Qualified Names and Canonical Names
package j2jtest; public class Pair{ java.lang.Integer packageAccess; java.util.List l = new java.util.ArrayList(); java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.lang.Integer") .needs("vjo.java.util.List") .needs("vjo.java.util.ArrayList") .needs("java.util.Date") .needs("java.sql.Date") .protos({ //> Integer packageAccess packageAccess:null, //> List l l:null, //> Date utilDate utilDate:null, //> Date sqlDate sqlDate:null, //> private constructs() constructs:function(){ this.l=new this.vjo.ArrayList(); this.utilDate=new java.util.Date(); this.sqlDate=new java.sql.Date(this.utilDate.getTime()); } }) .endType(); |
Packages
Package Members
Compilation Units
No implicit imports (ex., java.lang package), imported only if it’s used. | |
package j2jtest; public class Pair{ Integer i = 10; } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.lang.Integer") .protos({ //> Integer i i:null, //> private constructs() constructs:function(){ this.i=new this.vjo.Integer(10); } }) .endType(); |
Package Declarations
There is no explicit package declaration, package name is added to type declaration (name space of type) | |
package j2jtest; public class Pair{ } |
vjo.ctype("j2jtest.Pair") |
Import
Does not support import on-demand, for ex., package.*;
All the compilation units needs to be imported separately . | |
package j2jtest; import java.util.*; // public class Pair{ List list; HashMap map; } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.util.List") .needs("vjo.java.util.HashMap") .protos({ //> List list list:null, //> HashMap map map:null }) .endType(); |
Top Level Type Declarations
All types should be imported explicitly even if the type belongs to the same package. For ex., from the below code, though Pair2 is defined in the same package of Pair, it requires import, | |
package j2jtest; import java.util.*; public class Pair{ List list; HashMap map; Pair2 pair2OnSamePackage; } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.util.List") .needs("vjo.java.util.HashMap") .needs("j2jtest.Pair2") .protos({ //> List list list:null, //> HashMap map map:null, //> Pair2 pair2OnSamePackage pair2OnSamePackage:null }) .endType(); |
Classes
Class Declaration
Class Modifiers
Java | Vjo | |
---|---|---|
class |
package j2jtest; public class Pair{ Integer i = 10; } |
vjo.ctype("j2jtest.Pair") .needs("vjo.java.lang.Integer") .protos({ //> Integer i i:null, //> private constructs() constructs:function(){ this.i=new this.vjo.Integer(10); } }) .endType(); |
abstract class |
package j2jtest; public abstract class AbstractClassTest{ } |
vjo.ctype("j2jtest.AbstractClassTest") .endType(); |
final class |
package j2jtest; public final class AbstractClassTest{ } |
vjo.ctype("j2jtest.AbstractClassTest") .makeFinal() .endType(); |
Sstrictfp class | Not supported |
Generic Classes and Type Parameters
Java | Vjo |
---|---|
package j2jtest; public class Pair<T>{ T value; void set(T t){ this.value = t; } T get(){ return value; } Pair<String> testMethod(){ Pair<String> pair = new Pair<String>(); return pair; } } |
vjo.ctype("j2jtest.Pair") .protos({ //> T value value:null, //> void set(T t) set:function(t){ this.value=t; }, //> T get() get:function(){ return this.value; } }) .endType(); //> Pair<String> testMethod() testMethod:function(){ var pair=new this.vjo.Pair(); return pair; } |
Inner Classes and Enclosing Instances
- Nested
- static
- inner
- anonymous
- local
| ||
Static |
package j2jtest; public class Pair2 { void anOuterMethod() { } public static class NestedStatic { void aNestedStaticMethod() { } } } |
vjo.ctype("j2jtest.Pair2") .props({ NestedStatic://> public NestedStatic vjo.ctype() .protos({ //> void aNestedStaticMethod() aNestedStaticMethod:function(){ } }) .endType() }) .protos({ //> void anOuterMethod() anOuterMethod:function(){ } }) .endType(); |
inner –one level |
package j2jtest; public class OuterClass { int outerVar = 10; class InnerClass{ void innerMethod(){ Out.log("inner" +outerVar); } } static void testMethod(){ OuterClass outerClass = new OuterClass(); OuterClass.InnerClass innerClass = new OuterClass().new InnerClass(); innerClass.innerMethod(); innerClass = outerClass.new InnerClass(); innerClass.innerMethod(); } } |
vjo.ctype("j2jtest.OuterClass") .needs("j2jtest.Out") .props({ //> void testMethod() testMethod:function(){ var outerClass=new this(); var innerClass= new (new this()).InnerClass(); innerClass.innerMethod(); innerClass= new outerClass.InnerClass(); innerClass.innerMethod(); } }) .protos({ //> int outerVar outerVar:10, InnerClass://> InnerClass vjo.ctype() .protos({ //> void innerMethod() innerMethod:function(){ this.vjo.Out.log( "Inside inner class"+ this.vjo.outer.outerVar); } }) .endType() }) .endType(); |
inner –two level
ERROR inInClass, not getting created |
package j2jtest; public class OuterClass { int outerVar = 10; class InnerClass{ class InnerInnerClass{ void innerInnerMethod(String mssg){ Out.log("InnerInner " +mssg); } } void innerMethod(String mssg){ Out.log("Inner " +mssg); } } static void testMethod(){ OuterClass.InnerClass innerClass = new OuterClass().new InnerClass(); OuterClass.InnerClass.InnerInnerClass inInClass = innerClass.new InnerInnerClass(); innerClass.innerMethod("mssg1"); inInClass.innerInnerMethod("mssg2"); } } |
vjo.ctype("j2jtest.OuterClass") .needs("j2jtest.Out") .props({ //> void testMethod() testMethod:function(){ var innerClass=new (new this()) .InnerClass(); var inInClass; innerClass.innerMethod("mssg1"); inInClass.innerInnerMethod("mssg2"); } }) .protos({ //> int outerVar outerVar:10, InnerClass://> InnerClass vjo.ctype() .protos({ InnerInnerClass://> InnerInnerClass vjo.ctype() .protos({ //> void innerInnerMethod(String mssg) innerInnerMethod:function(mssg){ this.vjo.Out.log("InnerInner "+mssg); } }) .endType(), //> void innerMethod(String mssg) innerMethod:function(mssg){ this.vjo.Out.log("Inner "+mssg); } }) .endType() }) .endType(); |
anonymous
ERROR Not getting created/initialized |
package j2jtest.innerclass; import j2jtest.Out; import java.util.ArrayList; import java.util.List; public class AnonymousInnerclass { List list = new ArrayList(3) { { add("One"); add("Two"); add("Three"); } }; public void testMethod(){ for(Object value: list){ Out.log("value="+value); } } } |
vjo.ctype ("j2jtest.innerclass.AnonymousInnerclass") .needs("vjo.java.util.List") .needs("vjo.java.util.ArrayList") .needs("j2jtest.Out") .protos({ //> List list list:null, //> private constructs() constructs:function(){ this.list= vjo.make(this,vjo.java.util.ArrayList,3); }, //> public void testMethod() testMethod:function(){ this.vjo.Out.log("value="); for (var value,_$itr=this.list.iterator(); _$itr.hasNext();){ value=_$itr.next(); this.vjo.Out.log("value="+value); } } }) .endType(); |
Superclasses and Subclasses
Please refer Names. Members and Inheritance
Superinterfaces
Java | Js |
---|---|
package j2jtest.superinterface; public interface BaseInterface{ public void method1(); public void method(int i); } |
vjo.itype("j2jtest.superinterface.BaseInterface") .protos({ //> public void method1() method1:function(){ }, //> public void method(int i) method:function(i){ } }) .endType(); |
package j2jtest.superinterface; public class ImplClass implements BaseInterface{ public void method1(){ } public void method(int i){ } } |
vjo.ctype("j2jtest.superinterface.ImplClass") .needs("j2jtest.superinterface.BaseInterface") .satisfies("j2jtest.superinterface.BaseInterface") .protos({ //> public void method1() method1:function(){ }, //> public void method(int i) method:function(i){ } }) .endType(); |
package j2jtest.superinterface; public interface SubInterface extends SuperInterface { } |
vjo.itype("j2jtest.superinterface.SubInterface") .needs("j2jtest.superinterface.SuperInterface") .inherits("j2jtest.superinterface.SuperInterface") .endType(); |
Class Body and Member Declarations
Java | js |
---|---|
package j2jtest.classbodyandmember; public class ClassBody { String field1; static int staticField; static{staticField=12;} {field1="field1Str";} interface classinterface{ void m1(); } class classclass{ void m1(){} } void m1(){} ClassBody(){} ClassBody(Integer a){} } |
vjo.ctype("j2jtest.classbodyandmember.ClassBody") .needs("vjo.java.lang.Integer") .props({ //> int staticField staticField:0 }) .protos({ //> String field1 field1:null, classinterface://> public classinterface vjo.itype() .protos({ //> public void m1() m1:function(){ } }) .endType(), classclass://> classclass vjo.ctype() .protos({ //> void m1() m1:function(){ } }) .endType(), //> constructs() //> constructs(Integer a) constructs:function(){ { this.field1="field1Str"; } if(arguments.length===0){ this.constructs_0_0_ClassBody_ovld(); }else if(arguments.length===1){ this.constructs_1_0_ClassBody_ovld(arguments[0]); } }, //> void m1() m1:function(){ }, //> private constructs_0_0_ClassBody_ovld() constructs_0_0_ClassBody_ovld:function(){ }, //> private constructs_1_0_ClassBody_ovld(Integer a) constructs_1_0_ClassBody_ovld:function(a){ } }) .inits(function(){ { this.vjo.ClassBody.staticField=12; } }) .endType(); |
Class Members - see Class Body and Member Declarations
Field Declarations
Java | Vjo | |
---|---|---|
access modifier
public, private, protected |
public Integer I =10; private Integer j =20; protected Integer k=0; |
.protos({ //> public Integer i i:null, //> private Integer j j:null, //> protected Integer k k:null, //> EnumTest etest etest:null, //> private constructs() constructs:function(){ this.i=new this.vjo.Integer(10); this.j=new this.vjo.Integer(20); this.k=new this.vjo.Integer(0); }, |
static fields |
class TestClass { public final Integer i = 10; private final Integer j = 20; protected static final Integer k = 0; } |
vjo.ctype("j2jtest.TestClass") .props({ //> public Integer i i:null, //> private Integer j j:null, //> protected Integer k k:null }) .inits(function(){ this.vjo.TestClass.i=new this.vjo.Integer(10); this.vjo.TestClass.j=new this.vjo.Integer(20); this.vjo.TestClass.k=new this.vjo.Integer(0); }) .endType(); |
final fields | class TestClass { public static final Integer i = 10; private static final Integer j = 20; protected static final Integer k = 0; } |
vjo.ctype("j2jtest.TestClass") .props({ //> final public Integer i i:null, //> final private Integer j j:null, //> final protected Integer k k:null }) .inits(function(){ this.vjo.TestClass.i=new this.vjo.Integer(10); this.vjo.TestClass.j=new this.vjo.Integer(20); this.vjo.TestClass.k=new this.vjo.Integer(0); }) .endType(); |
Transient – | class TestClass { transient Integer i = 10; } |
Not Supported |
Method Declarations
method modifiers | ||
---|---|---|
abstract,
static, final methods |
package j2jtest; public abstract class Pair2{ abstract void abstractMethod(); static void staticMethod(); public final void finalMethod(){ } public native void nativeMethod(); public synchronized void synchronizedMethod() { } strictfp void strictfpMethod(){ } } |
vjo.ctype("j2jtest.Pair2") //< abstract .props({ //> void staticMethod() staticMethod:function(){ } }) .protos({ //> abstract void abstractMethod() abstractMethod:function(){ }, //> final public void finalMethod() finalMethod:function(){ }, //> public void nativeMethod() nativeMethod:function(){ }, //> public void synchronizedMethod() synchronizedMethod:function(){ }, //> void strictfpMethod() strictfpMethod:function(){ } }) .endType();
|
synchronized native strictfp
are not supported |
||
Method throws not supported | public void method1() throws Exception { } |
//> public void method1() method1:function(){ } |
Overloading | package j2jtest; public class Pair2{ public void method1() { } public void method1(int i){ } public void callMethod(){ method1(); method1(); } } |
vjo.ctype("j2jtest.Pair2") .protos({ //> public void method1() method1:function(){ if(arguments.length===0){ this.method1_0_0(); }else if(arguments.length===1){ this.method1_1_0(arguments[0]); } }, //> public void method1_0_0() method1_0_0:function(){ }, //> public void method1_1_0(int i) method1_1_0:function(i){ }, //> public void callMethod() callMethod:function(){ this.method1(); this.method1(); } }) .endType(); |
If a static field/method is accessed through instance object, it would be converted to use fully qualified class name to access.
Member Type Declarations
Java | Vjo |
---|---|
package j2jtest; public class Pair2{ abstract class Abstractclass{ } interface MyInterface{ } protected class ProtectedClass extends Abstractclass{ } private class PrivateClass implements MyInterface{ } static class StaticClass { } final class FinalClass{ } PrivateClass pclass = new PrivateClass(); ProtectedClass prClass = new ProtectedClass(); StaticClass sClass = new StaticClass(); Abstractclass aClass = new ProtectedClass(); MyInterface mInterface = new PrivateClass(); FinalClass fClass = new FinalClass(); } |
vjo.ctype("j2jtest.Pair2") .props({ StaticClass:vjo.ctype() .endType() }) .protos({ //> PrivateClass pclass pclass:null, //> ProtectedClass prClass prClass:null, //> StaticClass sClass sClass:null, //> Abstractclass aClass aClass:null, //> MyInterface mInterface mInterface:null, //> FinalClass fClass fClass:null, Abstractclass:vjo.ctype() //< abstract .endType(), MyInterface:vjo.itype() .endType(), ProtectedClass:vjo.ctype() .inherits("j2jtest.Pair2.Abstractclass") .endType(), PrivateClass:vjo.ctype() .satisfies("j2jtest.Pair2.MyInterface") .endType(), FinalClass:vjo.ctype() .makeFinal() .endType(), //> private constructs() constructs:function(){ this.pclass=new PrivateClass(); this.prClass=new ProtectedClass(); this.sClass=new this.StaticClass(); this.aClass=new ProtectedClass(); this.mInterface=new PrivateClass(); this.fClass=new FinalClass(); } }) .endType(); |
Instance Initializers
package j2jtest; public class Pair2{ Integer wrapperInteger = 10; Float wrapperFloat = 12.2f; } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Float") .protos({ //> Integer wrapperInteger wrapperInteger:null, //> Float wrapperFloat wrapperFloat:12.2, //> private constructs() constructs:function(){ this.wrapperInteger=new this.vjo.Integer(10); } }) .endType(); |
Static Initializers
package j2jtest; public class Pair2 { public static Integer i = new Integer(20); private static Float f = new Float(23); static Pair2 pair; static{ pair = new Pair2(); } } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Float") .props({ //> public Integer i i:null, //> private Float f f:null, //> Pair2 pair pair:null }) .inits(function(){ this.vjo.Pair2.i=new this.vjo.Integer(20); this.vjo.Pair2.f=new this.vjo.Float(23); { this.pair=new this(); } }) .endType(); |
Constructor Declarations - see Class Body and Member Declarations
Enums
Java | js |
---|---|
package j2jtest.enum1; public enum EnumTest { SUNDAY{ int getIndex(){ return 0; } }, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } |
vjo.etype("j2jtest.enum1.EnumTest") .values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY") .inits(function(){ this.SUNDAY.getIndex=function(){ return 0; }; }) .endType(); |
Initialization
package j2jtest; public class Pair2 { public final int N = 10; private int[] x = new int[N]; { for (int i = 0; i < N; i++) x[i] = i; } public static int L = 5; private static int[] y=new int[L];; static { for (int i = 0; i < L; i++) y[i] = i; } } |
vjo.ctype("j2jtest.Pair2") .props({ //> final public int L L:5, //> private int[] y y:null }) .protos({ //> final public int N N:10, //> private int[] x x:null, //> private constructs() constructs:function(){ this.x=new Array(this.N); { for (var i=0;i<this.N;i++){ this.x[i]=i; } } } }) .inits(function(){ this.vjo.Pair2.y=new Array(this.L); { for (var i=0;i<this.L;i++){ this.y[i]=i; } } }) .endType(); |
Interfaces
Interface Declarations
Instance Members
Field (Constant) Declarations
Abstract Method Declarations
Member Type Declarations
Java | js |
---|---|
package j2jtest.interfaces; public interface SuperInterface { String memberStr=""; public int var1=1; public static int var2=2; public static final int var3 = 3; String var4 = ""+var3; void m1(); void m1(int i); public void m2(); abstract void m3(); public abstract void m4(); } |
vjo.itype("j2jtest.interfaces.SuperInterface") .props({ //> public String memberStr memberStr:"", //> public int var1 var1:1, //> public int var2 var2:2, //> final public int var3 var3:3, //> public String var4 var4:null }) .protos({ //> void m1() //> public void m1(int i) m1:function(){ if(arguments.length===0){ this.m1_0_0_SuperInterface_ovld(); }else if(arguments.length===1){ this.m1_1_0_SuperInterface_ovld(arguments[0]); } }, //> private void m1_0_0_SuperInterface_ovld() m1_0_0_SuperInterface_ovld:function(){ }, //> private void m1_1_0_SuperInterface_ovld(int i) m1_1_0_SuperInterface_ovld:function(i){ }, //> public void m2() m2:function(){ }, //> public abstract void m3() m3:function(){ }, //> public abstract void m4() m4:function(){ } }) .inits(function(){ this.vjo.SuperInterface.var4=""+this.var3; }) .endType(); |
package j2jtest.interfaces; public interface SubInterface extends SuperInterface{ public static int memberInt=20; public static String var3 = ""+var2; } |
vjo.itype("j2jtest.interfaces.SubInterface") .needs("j2jtest.interfaces.SuperInterface") .inherits("j2jtest.interfaces.SuperInterface") .props({ //> public int memberInt memberInt:20, //> public String var3 var3:null }) .inits(function(){ this.vjo.SubInterface.var3=""+this.vjo.SuperInterface.var2; }) .endType();
|
Arrays
Java | Vjo |
---|---|
long avg = 10; long[] la = {1+avg,2,3}; int[][] twoDimArray = {{1,2,3}, {4,5,6}}; String[] sa = { "a", "b", "c"}; String[] sa2 = new String[2]; Employee[] sa3 = new Employee[2]; boolean boolArr1[] = new boolean[]{true}; boolean boolArr2[][] = new boolean[][]{{false}}; boolean boolArr11[] = new boolean[twoDimArray[0][0]]; boolean boolArr12[][] = new boolean[twoDimArray[0][0]] [twoDimArray[0][1]];
|
var avg=10; var la=[1+avg,2,3]; var twoDimArray=[[1,2,3],[4,5,6]]; var sa=["a","b","c"]; var sa2=new Array(2); var sa3=new Array(2); var boolArr1=[true]; var boolArr2=[[false]]; var boolArr11=new Array(twoDimArray[0][0]); var boolArr12=new Array; |
ERORS/TO-DO List
1. FIXED. Field initialization should maintain the order. From the below example, initialization order is not maintained. myInt should be initialized before i.
package j2jtest; public class Pair2{ Integer myInt = 10; int i = myInt; } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .protos({ //> Integer myInt myInt:null, //> int i i:0, //> constructs() constructs:function(){ this.i=this.myInt.intValue(); this.myInt=new this.vjo.Integer(10); } }) .endType(); |
2. DOCUMENTED. Overload with primitive and wrapper argument is not correctly transferred in js dispatcher function. From the below example, overLoad(Integer i) would be called regardless of parameter.
package j2jtest; public class Pair2{ void overLoad(int i){ System.out.println("called with primitive int"); } void overLoad(Integer i){ System.out.println("called with wrapper int"); } void callOverLoad(){ overLoad(10); overLoad(new Integer(12)); } } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.System") .protos({ //> void overLoad() overLoad:function(){ if(arguments.length===1){ if(arguments[0] instanceof vjo.java.lang.Integer){ this.overLoad_1_0(arguments[0].intValue()); }else if(arguments[0] instanceof vjo.java.lang.Integer){ this.overLoad_1_1(arguments[0]); } } }, //> void overLoad_1_0(int i) overLoad_1_0:function(i){ this.vjo.System.out.println("called with primitive int"); }, //> void overLoad_1_1(Integer i) overLoad_1_1:function(i){ this.vjo.System.out.println("called with wrapper int"); }, //> void callOverLoad() callOverLoad:function(){ this.overLoad(new this.vjo.Integer(10)); this.overLoad(new this.vjo.Integer(12)); } }) .endType(); |
3. FIXED. Instance initialization is not consistence. From the below example, float1 and double1 are not initialized in the init constructor.
package j2jtest; public class Pair2{ Integer integer2 = 20; Integer integer1 = new Integer(10); Float float1 = 12.2f; Float float2 = new Float(12); Double double1 = 30.5; } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Float") .needs("vjo.java.lang.Double") .protos({ //> Integer integer2 integer2:null, //> Integer integer1 integer1:null, //> Float float1 float1:12.2, //> Float float2 float2:null, //> Double double1 double1:30.5, //> private constructs() constructs:function(){ this.integer1=new this.vjo.Integer(10); this.float2=new this.vjo.Float(12); this.integer2=new this.vjo.Integer(20); } }) .endType(); |
4. NOT APPLICABLE: Don’t give function name starts with “constructs” ie., constructs_0_0. if you have then you’ll see unexpected result as shown below
package j2jtest; public class Pair2{ Integer integer1=12; Float f = 23.4f; Pair2(){ System.out.println("No arg constructor"); constructs_0_0(); } Pair2(Integer initValue){ System.out.println("One arg constructor"); } void constructs_0_0(){ System.out.println(" this is not a constructor"); } } |
vjo.ctype("j2jtest.Pair2") .needs("vjo.java.lang.Integer") .needs("vjo.java.lang.Float") .needs("vjo.java.lang.System") .protos({ //> Integer integer1 integer1:null, //> Float f f:23.4, //> constructs() constructs:function(){ this.integer1=new this.vjo.Integer(12); if(arguments.length===0){ if(arguments.length==0){ this.constructs_0_0_0_0(); }else if(arguments.length==0){ this.constructs_0_0_0_0(); } }else if(arguments.length===1){ this.constructs_1_0(arguments[0]); } }, //> constructs_1_0(Integer initValue) constructs_1_0:function(initValue){ this.vjo.System.out.println("One arg constructor"); }, //> constructs() constructs:function(){ this.integer1=new this.vjo.Integer(12); if(arguments.length===0){ if(arguments.length==0){ this.constructs_0_0_0_0(); }else if(arguments.length==0){ this.constructs_0_0_0_0(); } }else if(arguments.length===1){ this.constructs_1_0(arguments[0]); }else if(arguments.length===0){ if(arguments.length==0){ this.constructs_0_0_0_0(); }else if(arguments.length==0){ this.constructs_0_0_0_0(); } }else if(arguments.length===1){ this.constructs_1_0(arguments[0]); } }, //> constructs_0_0_0_0() constructs_0_0_0_0:function(){ this.vjo.System.out.println("No arg constructor"); constructs_0_0(); }, //> void constructs_0_0_0_1() constructs_0_0_0_1:function(){ this.vjo.System.out.println(" this is not a constructor"); } }) .endType(); |
5. Need to have reserved/keyword that cannot be used while writing java that would be converted into js. For instance, use of base as method name in base class would cause calling wrong method/confusion
package j2jtest; public class Pair{ Integer i =10; Pair(Integer intValue){ } void base(Integer i){ System.out.println("Base method"); } } package j2jtest; public class Pair2 extends Pair{ Pair2(){ super(10); } Pair2(Integer intValue){ super(intValue); base(intValue); } } |
vjo.ctype("j2jtest.Pair2") .needs("j2jtest.Pair") .needs("vjo.java.lang.Integer") .inherits("j2jtest.Pair") .protos({ //> constructs() constructs:function(){ if(arguments.length===0){ this.constructs_0_0(); }else if(arguments.length===1){ this.constructs_1_0(arguments[0]); } }, //> constructs_0_0() constructs_0_0:function(){ this.base(10); }, //> constructs_1_0(Integer intValue) constructs_1_0:function(intValue){ this.base(intValue); this.base(intValue); } }) .endType(); |
6. DOCUMENTED Don’t use class name, function name or package name for variables. It woks in java but not in javascript. For ex., below code display “test” in java but java script it display the whole java script object
class MyClass { String MyClass = "test"; public void method1(){ System.out.println(MyClass); } } |
vjo.ctype("j2jtest.abstract1.MyClass") .protos({ //> String MyClass MyClass:"test", //> public void method1() method1:function(){ this.vjo.System.out.println(this.vjo.MyClass); } }) .endType(); |
7. FIXED , Inner classes/second level inner classes are not getting created correctly
package j2jtest; public class OuterClass { int outerVar = 10; class InnerClass{ class InnerInnerClass{ void innerInnerMethod(String mssg){ Out.log("InnerInner " +mssg); } } void innerMethod(String mssg){ Out.log("Inner " +mssg); } } static void testMethod(){ OuterClass.InnerClass innerClass = new OuterClass().new InnerClass(); OuterClass.InnerClass.InnerInnerClass inInClass = innerClass.new InnerInnerClass(); innerClass.innerMethod("mssg1"); inInClass.innerInnerMethod("mssg2"); } } |
vjo.ctype("j2jtest.OuterClass") .needs("j2jtest.Out") .props({ //> void testMethod() testMethod:function(){ var innerClass=new (new this()) .InnerClass(); var inInClass; innerClass.innerMethod("mssg1"); inInClass.innerInnerMethod("mssg2"); } }) .protos({ //> int outerVar outerVar:10, InnerClass://> InnerClass vjo.ctype() .protos({ InnerInnerClass://> InnerInnerClass vjo.ctype() .protos({ //> void innerInnerMethod(String mssg) innerInnerMethod:function(mssg){ this.vjo.Out.log("InnerInner "+mssg); } }) .endType(), //> void innerMethod(String mssg) innerMethod:function(mssg){ this.vjo.Out.log("Inner "+mssg); } }) .endType() }) .endType(); |
8. DOCUMENTED. Inner class initialization is not translated correctly.
package j2jtest.innerclass; import j2jtest.Out; import java.util.ArrayList; import java.util.List; public class AnonymousInnerclass { List list = new ArrayList(3) { {add("One"); add("Two"); add("Three");} }; public void testMethod(){ for(Object value: list){ Out.log("value="+value); } } } |
vjo.ctype("j2jtest.innerclass.AnonymousInnerclass") .needs("vjo.java.util.List") .needs("vjo.java.util.ArrayList") .needs("j2jtest.Out") .protos({ //> List list list:null, //> private constructs() constructs:function(){ this.list= vjo.make(this,vjo.java.util.ArrayList,3); }, //> public void testMethod() testMethod:function(){ this.vjo.Out.log("value="); for (var value,_$itr= this.list.iterator();_$itr.hasNext();){ value=_$itr.next(); this.vjo.Out.log("value="+value); } } }) .endType(); |
9. FIXED Local inner class Class Out not imported and create
package j2jtest.innerclass; import j2jtest.Out; import java.util.ArrayList; public class LocalInnerclass { public void testMethod() { //Out.log("asasas"); class Happy { public void hi() { ArrayList list = new ArrayList(); Out o = new Out(); o.log("Hi"); double d = Math.PI; } } Happy h = new Happy(); h.hi(); } } |
vjo.ctype("j2jtest.innerclass.LocalInnerclass") .needs("vjo.java.util.ArrayList") .needs("vjo.java.lang.Math") .protos({ //> public void testMethod() testMethod:function(){ //> Happy vjo.ctype("Happy") .protos({ //> public void hi() hi:function(){ var list=new this.vjo.ArrayList(); var o; o.log("Hi"); var d=this.vjo.Math.PI; } }) .endType(); var h=new Happy(); h.hi(); } }) .endType(); |
10. FIXED method overload with super and base class as parameter
package j2jtest.constructor; import j2jtest.Out; public class MyClass extends MyClassBase{ public void testMethod(MyClassBase base){ Out.log("MyClass(MyClassBase)"); } public void testMethod(MyClass myClass){ Out.log("MyClass(MyClass)"); } public void testMethod(){ MyClass myClass = new MyClass(); testMethod(myClass); } } |
vjo.ctype("j2jtest.constructor.MyClass") .needs("j2jtest.constructor.MyClassBase") .needs("j2jtest.Out") .inherits("j2jtest.constructor.MyClassBase") .protos({ //> public void testMethod() testMethod:function(){ if(arguments.length===1){ if(arguments[0] instanceof j2jtest.constructor.MyClassBase){ this.testMethod_1_0(arguments[0]); }else if(arguments[0] instanceof j2jtest.constructor.MyClass){ this.testMethod_1_1(arguments[0]); } }else if(arguments.length===0){ this.testMethod_0_0(); } }, //> public void testMethod_1_0(MyClassBase base) testMethod_1_0:function(base){ this.vjo.Out.log("MyClass(MyClassBase)"); }, //> public void testMethod_1_1(MyClass myClass) testMethod_1_1:function(myClass){ this.vjo.Out.log("MyClass(MyClass)"); }, //> public void testMethod_0_0() testMethod_0_0:function(){ var myClass=new this.vjo.MyClass(); this.testMethod(myClass); } }) .endType(); |
11. ERROR Default constructor. Default constructor is not getting created
package j2jtest.constructor; public class MyClass extends Base{ } |
vjo.ctype("j2jtest.constructor.MyClass") .needs("j2jtest. constructor.Base") .inherits("j2jtest. constructor.Base") .endType(); | |
Generic object is not translated correctly if two typed parameters are same type
FIXED |
// translate correctly public static GenericClass<String,Integer> testMethod(){ GenericClass<String,Integer> object2 = new GenericClass<String, Integer> ("String one",20); Out.log(object2.one); return object2; } GenericClass<String, String> testMethod1(){ GenericClass<String,String> object2 = new GenericClass<String, String>("ss","ss"); return object2; } |
//> public GenericClass<String,Integer> testMethod() testMethod:function(){ var object2=new this("String one",20); this.vjo.Out.log(object2.one); return object2; } //> GenericClass<String> testMethod1() testMethod1:function(){ var object2=new this.vjo.GenericClass("ss","ss"); return object2; }, |
12. DOCUMENTED Super keyword not translated correctly
package j2jtest.inheritance; import j2jtest.Out; public class Derived extends Base { int i=20; public void method1(){ Out.log(" i = "+super.i); } } |
vjo.ctype("j2jtest.inheritance.Derived") .needs("j2jtest.Out") .needs("j2jtest.inheritance.Base") .inherits("j2jtest.inheritance.Base") .props({ //> public void touch() touch:function(){ } }) .protos({ //> int i i:20, //> public void method1() method1:function(){ this.vjo.Out.log(" i = "+this.i); } }) .endType(); |
13. DOCUMENTED Cannt have variable name as class name
package j2jtest.conversion; import j2jtest.Out; public class Conversion { String Conversion = "Conversion string"; String str = "str"; public static void touch(){ } public void method1(){ Out.log("Conversion = "+ Conversion); Out.log("str = "+ str); } } |
vjo.ctype("j2jtest.conversion.Conversion") .needs("j2jtest.Out") .props({ //> public void touch() touch:function(){ } }) .protos({ //> String Conversion Conversion:"Conversion string", //> String str str:"str", //> public void method1() method1:function(){ this.vjo.Out.log("Conversion = "+this.vjo.Conversion); this.vjo.Out.log("str = "+this.str); } }) .endType(); |
14. FIXED Calling overload function from base class is not getting translated. Keyword this is missing
Eg.,
overload();
should be
this. overload();
package j2jtest.member; import j2jtest.Out; public class Derived extends Base{ public void method1(){ overload(); overload("asasas"); //overload(local); } public void override(){ Out.log("Derived.override"); } public void overload(String s){ Out.log("Derived.overload(String)"); } } package j2jtest.member; import j2jtest.Out; public class Base { public void override(){ Out.log("Base.override"); } public void overload(){ Out.log("Base.overload"); } } |
vjo.ctype("j2jtest.member.Derived") .needs("j2jtest.Out") .needs("j2jtest.member.Base") .inherits("j2jtest.member.Base") .protos({ //> public void method1() method1:function(){ overload(); this.overload("asasas"); }, //> public void override() override:function(){ this.vjo.Out.log("Derived.override"); }, //> public void overload(String s) overload:function(s){ if(arguments.length===1){ if(arguments[0] instanceof String || typeof arguments[0]=="string"){ this.overload_1_0_Derived_ovld(arguments[0]); }else if(this.base && this.base.overload){ this.base.overload.apply(this,arguments); } }else if(this.base && this.base.overload){ this.base.overload.apply(this,arguments); } }, //> private void overload_1_0_Derived_ovld(String s) overload_1_0_Derived_ovld:function(s){ this.vjo.Out.log("Derived.overload(String)"); } }) .endType();
|
15. DOCUMENTED. Calling overloaded method with null is not handled correctly.
package j2jtest.member; import j2jtest.Out; public class Overload { public void method1(){ String notWorking = null; //overload(); overload("working"); overload(notWorking); } public void overload(){ Out.log("Overload.overload()"); } public void overload(String s){ Out.log("Overload.overload(String)"); } public void overload(Object s){ Out.log("Overload.overload(Object)"); } } |
vjo.ctype("j2jtest.member.Overload") .needs("j2jtest.Out") .protos({ //> public void method1() method1:function(){ var notWorking=null; this.overload("working"); this.overload(notWorking); }, //> public void overload() //> public void overload(String s) //> public void overload(vjo.Object s) overload:function(){ if(arguments.length===0){ this.overload_0_0_Overload_ovld(); }else if(arguments.length===1){ if(arguments[0] instanceof String || typeof arguments[0]=="string"){ this.overload_1_0_Overload_ovld(arguments[0]); }else if(arguments[0] instanceof vjo.Object){ this.overload_1_1_Overload_ovld(arguments[0]); } } }, //> private void overload_0_0_Overload_ovld() overload_0_0_Overload_ovld:function(){ this.vjo.Out.log("Overload.overload()"); }, //> private void overload_1_0_Overload_ovld(String s) overload_1_0_Overload_ovld:function(s){ this.vjo.Out.log("Overload.overload(String)"); }, //> private void overload_1_1_Overload_ovld(vjo.Object s) overload_1_1_Overload_ovld:function(s){ this.vjo.Out.log("Overload.overload(Object)"); } }) .endType(); |
16. Abstract method is not getting called correctly. From the example., callAbstractMethod() should call method in implementing class instead it calls from the abstract class method
package j2jtest.abstract1; import j2jtest.Out; public class Derived extends Base{ public void method1(){ callAbstractMethod(); } public void abstractMethod(){ Out.log("Derived.abstractMethod"); } public void abstractMethod(String value){ Out.log("Derived.abstractMethod(String)"); } } package j2jtest.abstract1; import j2jtest.Out; public class Base { public String toString(){ return " Hey i am Basie"; } public void callAbstractMethod(){ Out.log("Base.callAbstractMethod"); abstractMethod("StrValue"); } public void abstractMethod(){ Out.log("Base.abstractMethod"); } public void abstractMethod(String value){ Out.log("Base.abstractMethod(String)"); } } |
vjo.ctype("j2jtest.abstract1.Derived") .needs("j2jtest.Out") .needs("j2jtest.abstract1.Base") .inherits("j2jtest.abstract1.Base") .protos({ //> public void method1() method1:function(){ this.callAbstractMethod(); }, //> public void abstractMethod() //> public void abstractMethod(String value) abstractMethod:function(){ if(arguments.length===0){ this.abstractMethod_0_0_Derived_ovld(); }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); }else if(arguments.length===1){ if(arguments[0] instanceof String || typeof arguments[0]=="string"){ this.abstractMethod_1_0_Derived_ovld(arguments[0]); }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); } }else if(this.base && this.base.abstractMethod){ this.base.abstractMethod.apply(this,arguments); } }, //> private void abstractMethod_0_0_Derived_ovld() abstractMethod_0_0_Derived_ovld:function(){ this.vjo.Out.log("Derived.abstractMethod"); }, //> private void abstractMethod_1_0_Derived_ovld(String value) abstractMethod_1_0_Derived_ovld:function(value){ this.vjo.Out.log("Derived.abstractMethod(String)"); } }) .endType();
|
Type Variables
A type variable (§4.4) is an unqualified identifier. Type variables are introduced
by generic class declarations (§8.1.2) generic interface declarations (§9.1.2)
generic method declarations (§8.4.4) and by generic constructor declarations
Things to Remember/TODO
1 Overloaded method and null parameter
Will get unexpected behaviour if overloaded method is called with null object. In java script, variable type is determined based on the value it has. If the variable has null value then ther is no way to determine the type value.
When passing result of an expression to overloaded method, make sure it’s not null.
2 Variable name as Class, Pakcage or function name
Do not overload variable name with Class, Pakcage or function name. In java it works fine, when it comes to java script, it evaluates as class or function.
3 Array components
Array components with custom object creation is not supported. For ex.,
Pair[] pairArrayWithInit = {new Pair(), new Pair()};
4 Inner class/ initialization.
Initializing object like shown below is not supported
List list = new ArrayList(3) { { add("One"); add("Two"); add("Three");} };
5 Overload method with primitive and wrapper class
Overloading functions/constructor with primitive and wrapper class are not supported. For ex, below function method1 is overloaded using primitive type int and Integer. This type of overload is not supported.
public void method1(int intValue){ } public void method1(Integer intValue){ }
6 Class loading and static initializer
In java a class is loaded only if it’s used or referenced and all staic fields/blocks will get executed only at that time of class loading.
In VJO there is no such thing called class loading. So all the reference and embedded class’s static variables/blocks are initialized along with the main class. This may cause unexpected bahaviour for ex.,
package j2jtest.todo; import j2jtest.Out; public class StaticInit { static int intValue = 10; public void display(){ Out.log("intValue="+intValue); StaticInner staticInner = new StaticInner(); Out.log("intValue="+intValue); } static class StaticInner{ static{ intValue = 20; } } }
When running the above java class produces the result
intValue=10 intValue=20
but translated js file would result
intValue=20 intValue=20
as all static blocks run when the main class loads.
7 Overload method with super and derived class
When methods are overloaded based on super and derived class, java checks the variable type and calls the corresponding method with that type. In VJO, it doesn’t check the variable type, it checks the object type and call the corresponding method. For ex.,
package j2jtest.methodoverload; import j2jtest.Out; public class MyClass extends MyClassBase{ public void testMethod(MyClassBase base){ Out.log("testMethod(MyClassBase)"); } public void testMethod(MyClass myClass){ Out.log("testMethod(MyClass)"); } public void testMethod(){ MyClass myClass = new MyClass(); MyClassBase myBaseClass = new MyClass(); testMethod(myClass); testMethod(myBaseClass); } }
Result from Java
testMethod(MyClass)
testMethod(MyClassBase)
Result from Vjo
testMethod(MyClass)
testMethod(MyClass)
8 Same variable names in super and derived class
Java maintains separate memory space for super and derived class so when variable is declared with same name in super and derived, both can have dirrerent value. VJO donesnt maintain separate memory space for super and derived, vjo shares one memory area for all variables (super and derived). So if a variable is declared with the same name in super and derived, only derived class variable would be available and would be refered as this.variablename. For ex.,
package j2jtest.inheritance; import j2jtest.Out; public class Derived extends Base { int i = 20; public void method1(){ Out.log(" i = "+super.i); } } package j2jtest.inheritance; public class Base { int i = 10; }
Would be represented as
vjo.ctype('j2jtest.inheritance.Derived') //< public .needs('j2jtest.Out') .inherits('j2jtest.inheritance.Base') .protos({ i:20, //< int //> public void method1() method1:function(){ this.vjo.Out.log(" i = "+this.i); } }) .endType();
Java output
i = 10
JS output
i = 20
9 Avoid Circular references. For ex.,
public class Conversion { Conversion str = new Conversion(); }
10 Sub classes are not supported.
package j2jtest.member; import j2jtest.Out; public class MemberClass { void m1(){ Out.log("in MemberClass"); SubClass obj = new SubClass(); obj.m1(); } } class SubClass{ public void m1(){ Out.log("In MyInnerMemberClass.m1()"); } }