aboutsummaryrefslogtreecommitdiffstats
path: root/tests/reproducers/simple/JSToJFuncResol/srcs/JSToJFuncResol.java
blob: 4f7b7f767366d25f90c34c59c8be8a0b9c1e6636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import java.applet.Applet;
import netscape.javascript.JSObject;

public class JSToJFuncResol extends Applet {

    /****** Primitive (numeric) value resolutions ******/

    /* Javascript primitive numeric (int) value resolutions:
     * - to an analogous primitive Java type (best - lowest cost)
     * - to another primitive numeric Java type (long) (second lowest)
     * - to Java String type (third lowest)
     */

    public void numeric( int p){
        System.out.println("numeric(int) with "+p);
    }

    public void numeric(long p) {
        System.out.println("numeric(long) with "+p);
    }

    public void numeric(String p) {
        System.out.println("numeric(String) with "+p);
    }

    /* Javascript primitive numeric (int) value resolutions:
     * - to a different primitive Java numeric type (double) (best - second lowest cost)
     * - to Java string (third lowest cost)
     */

    public void numericToDifferentNumeric(double p) {
        System.out.println("numericToDifferentNumeric(double) with "+p);
    }

    public void numericToDifferentNumeric(String p) {
        System.out.println("numericToDifferentNumeric(String) with "+p);
    }

    /* Javascript primitive numeric (floating point) value resolutions:
     * - to a primitive Java numeric type (double) (best - lowest cost)
     * - to Java char
     */

    public void numericToDouble(double p) {
        System.out.println("numericToDouble(double) with "+p);
    }

    public void numericToDouble(char p) {
        System.out.println("numericToDouble(char) with "+p);
    }



    /****** Null resolutions ******/

    /* Javascript null value resolutions:
     * - to any nonprimitive Java type (e.g. Integer) (best)
     * - to a primitive Java type (int) (not allowed)
     */

    public void nullToInteger(Integer p) {

        System.out.println("nullToInteger(Integer) with "+p);
    }

    public void nullToInteger(int p) {
        System.out.println("nullToInteger(int) with "+p);
    }

    /****** Java inherited class resolutions ******/

    /* Java inherited class (OverloadTestHelper2) value resolutions:
     * - to the same class type (OverloadTestHelper2) (best)
     * - to a superclass (OverloadTestHelper1) (second best)
     * - to a subclass (OverloadTestHelper3) (not possible)
     */

    public void inheritedClass(OverloadTestHelper2 p) {
        System.out.println("inheritedClass(OverloadTestHelper2) with "+p);
    }

    public void inheritedClass(OverloadTestHelper1 p) {
        System.out.println("inheritedClass(OverloadTestHelper1) with "+p);
    }

    public void inheritedClass(OverloadTestHelper3 p) {
        System.out.println("inheritedClass(OverloadTestHelper3) with "+p);
    }

    /* Java inherited class (OverloadTestHelper3) value resolutions:
     * - to a superclass (OverloadTestHelper2) (best - second lowest cost)
     * - to a superclass of superclass (OverloadTestHelper1) (higher cost)
     */

    public void inheritedClassToParent1(OverloadTestHelper2 p) {
        System.out.println("inheritedClassToParent1(OverloadTestHelper2) with "+p);
    }

    public void inheritedClassToParent1(OverloadTestHelper1 p) {
        System.out.println("inheritedClassToParent1(OverloadTestHelper1) with "+p);
    }

    /* Java inherited class (OverloadTestHelper2) resolutions:
     * - to the superclass (OverloadTestHelper1) (best - second lowest cost)
     * - to Java String (third lowest cost)
     */

    public void inheritedClassToParent2(OverloadTestHelper1 p) {
        System.out.println("inheritedClassToParent2(OverloadTestHelper1) with "+p);
    }

    public void inheritedClassToParent2(String p) {
        System.out.println("inheritedClassToParent2(String) with "+p);
    }


    /****** Java object resolutions ******/

    /* Java object (OverloadTestHelper1) value resolutions:
     * - to Java String (best - third lowest cost)
     * - to a different nonprimitive Java class (JSObject) (not possible)
     */

    public void javaObjectToString(String p) {
        System.out.println("javaObjectToString(String) with "+p);
    }

    public void javaObjectToString(JSObject p) {
        System.out.println("javaObjectToString(JSObject) with "+p);
    }

    /****** String resolutions ******/

    /* Javascript string value resolutions:
     * - to a primitive numeric Java type (double) (best - second lowest cost)
     * - to a nonprimitive Java class (OverloadTestHelper1 as a dummy)(not possible)
     */

    public void javascriptStringToNumeric(double p) {
        System.out.println("javascriptStringToNumeric(double) with "+p);
    }

    public void javascriptStringToNumeric(OverloadTestHelper1 p) {
        System.out.println("javascriptStringToNumeric(OverloadTestHelper1) with "+p);
    }

    /****** Javascript object resolutions ******/

    /* Javascript object value resolutions:
     * - to JSObject Java type (best - lowest cost)
     * - to Java String type (fourth lowest cost)
     * - to Java array of Strings (fourth lowest cost)
     * - to a Java superclass (Object) (second lowest cost)
     */

    public void javascriptObject(JSObject p) {
        System.out.println("javascriptObject(JSObject) with "+p);
    }

    public void javascriptObject(String p) {
        System.out.println("javascriptObject(String) with "+p);
    }

    public void javascriptObject(String[] p) {
        System.out.println("javascriptObject(String[]) with "+p);
    }

    public void javascriptObject(Object p) {
        System.out.println("javascriptObject(Object) with "+p);
    }

    /* Javascript object (array) value resolutions:
     * - to a Java array of primitive numeric Java type (int[]) (best - fourth lowest cost)
     * - to a nonprimitive Java class Integer (impossible)
     */

    public void javascriptObjectToArray(int[] p) {
        System.out.println("javascriptObjectToArray(int[]) with "+p);
    }

    public void javascriptObjectToArray(Integer p) {
        System.out.println("javascriptObjectToArray(Integer) with "+p);
    }


    /****** Not allowed resolutions *******/

    /* Impossible resolutions all should result in
     * "Error on Java side: No suitable method named ... with matching args found"
     * - null to a primitive numeric Java type (int)
     * - JSObject (window) to a different nonprimitive Java class (OverloadTestHelper1)
     * - non-array value (numeric primitive 25) to array
     */

    public void nullToPrimitive(int p) {
        System.out.println("nullToPrimitive(int) with "+p);
    }

    public void javascriptObjectToUnrelatedType(OverloadTestHelper1 p) {
        System.out.println("javascriptObjectToUnrelatedType(OverloadTesthelper1) with "+p);
    }

    public void unsupported(Object[] p) {
        System.out.println("unsupported(Object[]) with "+p);
    }

    /****** Auxiliary methods and classes ******/

    public void init() {
        String initStr = "JSToJFuncResol applet initialized.";
        System.out.println(initStr);
    }

    public void writeAfterTests(){
        System.out.println("afterTests");
    }

    //dummy classes for passing objects as function parameters
    public class OverloadTestHelper1 {};
    public class OverloadTestHelper2 extends OverloadTestHelper1 {};
    public class OverloadTestHelper3 extends  OverloadTestHelper2 {};

    public OverloadTestHelper1 getNewOverloadTestHelper1(){
        return new OverloadTestHelper1();
    }

    public OverloadTestHelper2 getNewOverloadTestHelper2(){
        return new OverloadTestHelper2();
    }

    public OverloadTestHelper3 getNewOverloadTestHelper3(){
        return new OverloadTestHelper3();
    }

}