Skip to content

Commit 5475978

Browse files
committed
Test_Init, Test_Generic_Java8, others.
1 parent 5077b2e commit 5475978

File tree

8 files changed

+145
-41
lines changed

8 files changed

+145
-41
lines changed

sources/net.sf.j2s.core/test/src/test/Test_.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Test_ {
1111

1212
private static int i_ = 0;
1313
private int t = 0;
14-
14+
1515
public void showt() {
1616
System.out.println(t);
1717
}
@@ -32,7 +32,6 @@ public void showt() {
3232

3333

3434
public static void main(String[] args) {
35-
Test_Abstract.main(args);
3635
Test_Anon.main(args);
3736
Test_Appendable.main(args);
3837
Test_Array.main(args);
@@ -64,6 +63,8 @@ public static void main(String[] args) {
6463
Test_GenericAnon.main(args);
6564
Test_GenericEABIXY2.main(args);
6665
Test_GenericExt2.main(args);
66+
Test_Init.main(args);
67+
Test_Inner.main(args);
6768
Test_Instance.main(args);
6869
Test_Interface.main(args);
6970
Test_Interface2.main(args);

sources/net.sf.j2s.core/test/src/test/Test_Abstract.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

sources/net.sf.j2s.core/test/src/test/Test_Call.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ public class Test_Call extends Test_call0 implements Comparable<Test_Call>{
44

55
int y = 0;
66

7-
private transient Integer icall = null;
7+
int testing1;
8+
int testing2 = 3;
89

10+
@Override
11+
void checkTesting(int pass) {
12+
System.out.println("testing:" + testing1 + " " + testing2);
13+
assert(testing2 == (pass == 1 ? 0 : 3));
14+
if (pass == 1)
15+
testing2 = 2;
16+
}
917

18+
19+
private transient Integer icall = null;
20+
1021
void init() {
1122
assert(this instanceof Test_call0);
1223
assert(this instanceof Comparable);
@@ -27,6 +38,8 @@ private void setTY(int y) {
2738
}
2839

2940
Test_Call() {
41+
super();
42+
checkTesting(2);
3043
setX(-1);
3144
new Inner1();
3245
assert(x == -1 && y == 100);
@@ -66,5 +79,4 @@ public int compareTo(Test_Call o) {
6679
return 0;
6780
}
6881

69-
7082
}

sources/net.sf.j2s.core/test/src/test/Test_Generic_Java8.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import javax.swing.ListCellRenderer;
88

99
public class Test_Generic_Java8 extends Test_ implements ListCellRenderer {
10-
11-
10+
1211
/**
1312
* Demonstrates the issue with Java8 classes being generic while Java6
1413
* version is not. As long as the transpiler is working in a Java8
@@ -20,7 +19,7 @@ public class Test_Generic_Java8 extends Test_ implements ListCellRenderer {
2019
* @param args
2120
*/
2221
public static void main(String[] args) {
23-
22+
2423
Test_Generic_Java8 test = new Test_Generic_Java8();
2524
// calls getListCellRendererComponent$javax_swing_JList$O$I$Z$Z
2625
test.getListCellRendererComponent(null, null, 0, false, false);
@@ -32,7 +31,7 @@ public void test(Object o) {
3231
// This next call will be to this.addItem$O in Java6
3332
// but to this.addItem$TE in Java8. Since the SwingJS version
3433
// is addItem$O, we need to alias this call to that as
35-
// ((O$ = this).addItem$TE || O$.addItem$O).apply(O$,[o]);
34+
// (($o$ = this).addItem$TE || $o$.addItem$O).apply($o$,[o]);
3635
//
3736
addItem(o);
3837
System.out.println("added " + o);

sources/net.sf.j2s.core/test/src/test/Test_Init.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,74 @@
88
*/
99
public class Test_Init extends Test_init0 {
1010

11-
int testing1;
11+
// statics -- defined once
12+
13+
static {
14+
System.out.println("point 2");
15+
System.out.println("static string sts/sts0:" + Test_Init.sts + " " + sts0);
16+
assert(++loadpt == 2);
17+
18+
int is = 0;
19+
int bs = is + 3;
20+
}
21+
22+
// static fields -- will be defined twice -- first for initial defaults (in class), then final values (in $clinit$)
23+
24+
static int iAs = 'A';
25+
static char cs = 'C';
26+
static char cis = 65;
27+
static byte bAAs = 'A';
28+
static int iABs = 'A' + cs;
29+
static String sts = "test";
30+
static int testing1s;
31+
static int testing2s = 3;
32+
static String s;
33+
static String s0 = "0";
34+
35+
36+
37+
// nonstatic fields -- will be defined twice -- first for initial default ($init0$), then final values ($init$)
38+
39+
int iA = 'A';
40+
char c = 'C';
41+
char ci = 65;
42+
byte bAA = 'A';
43+
int iAB = 'A' + c;
44+
String st = "test";
45+
46+
47+
int testing1;
1248
int testing2 = 3;
49+
1350

1451
String s1;
1552
String s2 = "testing";
53+
54+
// initializer - defined once, in $init$ only
55+
56+
{
57+
System.out.println("point 5");
58+
System.out.println("static string sts/sts0:" + Test_Init.sts + " " + sts0);
59+
assert(++loadpt == 5);
60+
int i = 0;
61+
int b = i + 3;
62+
}
1663

17-
static String s;
1864

65+
1966
Test_Init() {
2067
super();
68+
System.out.println("point 6");
69+
assert(++loadpt == 6);
70+
2171
checkTesting(2);
2272
}
2373

2474
@Override
2575
void checkTesting(int pass) {
26-
System.out.println("testing:" + testing1 + " " + testing2);
27-
System.out.println("s:" + s1 + " " + s2);
76+
System.out.println("pass " + pass + " static string sts/sts0:" + sts + " " + sts0);
77+
System.out.println("pass " + pass + " testing:" + testing1 + " " + testing2);
78+
System.out.println("pass " + pass + " s:" + s1 + " " + s2);
2879
assert(testing2 == (pass == 1 ? 0 : 3));
2980
assert(s2 == (pass == 1 ? null : "testing"));
3081
// note: this next setting will be ignored!
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package test;
2+
3+
4+
public abstract class Test_Inner extends Test_ {
5+
6+
final static String a = "a string";
7+
static String b = "bstring";
8+
9+
static class Test_Abstract_a {
10+
11+
void testing() {
12+
System.out.println("this is " + a);
13+
assert (a == "a string");
14+
}
15+
}
16+
17+
18+
Test_Inner c = new Test_Inner() {
19+
void test() {
20+
}
21+
22+
};
23+
24+
public static void main(String[] args) {
25+
Test_Abstract_a x = new Test_Abstract_a();
26+
x.testing();
27+
System.out.println("Test_Inner OK");
28+
}
29+
30+
}

sources/net.sf.j2s.core/test/src/test/Test_call0.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
public class Test_call0 extends Test_ {
44

5+
6+
void checkTesting(int pass) {
7+
System.out.println("--");
8+
}
9+
10+
511
int x, y;
612

713
void init(){
@@ -21,6 +27,7 @@ public String toString() {
2127
}
2228

2329
public Test_call0() {
30+
checkTesting(1);
2431
init();
2532
};
2633

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
package test;
22

33
public class Test_init0 extends Test_ {
4+
5+
double test01;
6+
double test02 = 0;
7+
8+
static int loadpt = 0;
9+
10+
static String sts0 = "sts0";
11+
12+
{
13+
System.out.println("point 3");
14+
System.out.println("static string sts/sts0:" + Test_Init.sts + " " + sts0);
15+
assert(++loadpt == 3);
16+
}
417

18+
static {
19+
System.out.println("point 1");
20+
System.out.println("static string sts/sts0:" + Test_Init.sts + " " + sts0);
21+
assert(++loadpt == 1);
22+
changeSts();
23+
}
24+
525
void checkTesting(int pass) {
626
System.out.println("--");
7-
}
27+
}
28+
829

30+
private static String changeSts() {
31+
String s = Test_Init.sts;
32+
Test_Init.sts = "temp_only";
33+
return s;
34+
}
35+
36+
937
public Test_init0() {
38+
System.out.println("point 4");
39+
assert(++loadpt == 4);
40+
sts0 = "new";
1041
checkTesting(1);
42+
assert(test01 == 0 && test02 == 0);
1143
};
1244

1345
}

0 commit comments

Comments
 (0)