Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1933a3652f933d399b3969567cb2fbe43bef1f05 (plain) (blame)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2010 Stephan Herrmann
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * $Id$
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Stephan Herrmann - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.tests.otjld.callinbinding;

import junit.framework.Test;

import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;

public class CallinWithTranslation extends AbstractOTJLDTest {
	
	public CallinWithTranslation(String name) {
		super(name);
	}
	
	// Static initializer to specify tests subset using TESTS_* static variables
	// All specified tests which does not belong to the class are skipped...
	static {
//		TESTS_NAMES = new String[] { "test0c11_implicitlyInheritingStaticRoleMethod1"};
//		TESTS_NUMBERS = new int[] { 1459 };
//		TESTS_RANGE = new int[] { 1097, -1 };
	}
	
	public static Test suite() {
		return buildComparableTestSuite(testClass());
	}

	public static Class testClass() {
		return CallinWithTranslation.class;
	}


    // a callin binding without signatures lifts its parameter
    // 4.4.1-otjld-callin-with-parameter-lifting-1
    public void test441_callinWithParameterLifting1() {
       
       runConformTest(
            new String[] {
		"Team441cwpl1.java",
			    "\n" +
			    "public team class Team441cwpl1 {\n" +
			    "	public class R playedBy T441cwpl1 {\n" +
			    "		void aspect (R other) {\n" +
			    "			System.out.print(other.getValue());\n" +
			    "		}\n" +
			    "		String getValue() {\n" +
			    "			return \"K\";\n" +
			    "		}\n" +
			    "		aspect <- after foo;\n" +
			    "	}\n" +
			    "	public Team441cwpl1(T441cwpl1 o1, T441cwpl1 o2) {\n" +
			    "		activate();\n" +
			    "		o1.foo(o2);\n" +
			    "	}\n" +
			    "	public static void main(String[] args) {\n" +
			    "		new Team441cwpl1(new T441cwpl1(), new T441cwpl1());\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n",
		"T441cwpl1.java",
			    "\n" +
			    "public class T441cwpl1 {\n" +
			    "	void foo(T441cwpl1 other) {\n" +
			    "		System.out.print(\"O\");\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n"
            },
            "OK");
    }

    // a callin binding with array result lifting
    // 4.4.1-otjld-callin-with-result-lifting-2
    public void test441_callinWithResultLifting2() {
       
       runConformTest(
            new String[] {
		"Team441cwrl2.java",
			    "\n" +
			    "public team class Team441cwrl2 {\n" +
			    "    public class R playedBy T441cwrl2 {\n" +
			    "        callin R[] aspect() {\n" +
			    "            R[] ra = base.aspect();\n" +
			    "            System.out.print(ra[0].getValue());\n" +
			    "            return ra;\n" +
			    "        }\n" +
			    "        String getValue() {\n" +
			    "            return \"K\";\n" +
			    "        }\n" +
			    "        aspect <- replace foo;\n" +
			    "    }\n" +
			    "    public Team441cwrl2(T441cwrl2 o1, T441cwrl2 o2) {\n" +
			    "        activate();\n" +
			    "        o1.foo();\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        new Team441cwrl2(new T441cwrl2(), new T441cwrl2());\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T441cwrl2.java",
			    "\n" +
			    "public class T441cwrl2 {\n" +
			    "    T441cwrl2[] foo() {\n" +
			    "        System.out.print(\"O\");\n" +
			    "        T441cwrl2 b = new T441cwrl2();\n" +
			    "        T441cwrl2[] ba = new T441cwrl2[1];\n" +
			    "        ba[0] = b;\n" +
			    "        return ba;\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "OK");
    }

    // a callin binding with array result lifting , base is inner class
    // 4.4.1-otjld-callin-with-result-lifting-2i
    public void test441_callinWithResultLifting2i() {
       
       runConformTest(
            new String[] {
		"Team441cwrl2i.java",
			    "\n" +
			    "public team class Team441cwrl2i {\n" +
			    "    public class R playedBy T441cwrl2i.Inner {\n" +
			    "        callin R[] aspect() {\n" +
			    "            R[] ra = base.aspect();\n" +
			    "            System.out.print(ra[0].getValue());\n" +
			    "            return ra;\n" +
			    "        }\n" +
			    "        String getValue() {\n" +
			    "            return \"K\";\n" +
			    "        }\n" +
			    "        aspect <- replace foo;\n" +
			    "    }\n" +
			    "    public Team441cwrl2i(T441cwrl2i.Inner o1, T441cwrl2i.Inner o2) {\n" +
			    "        activate();\n" +
			    "        o1.foo();\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        T441cwrl2i outer= new T441cwrl2i();\n" +
			    "        new Team441cwrl2i(outer.new Inner(), outer.new Inner());\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T441cwrl2i.java",
			    "\n" +
			    "public class T441cwrl2i {\n" +
			    "    public class Inner {\n" +
			    "        Inner[] foo() {\n" +
			    "            System.out.print(\"O\");\n" +
			    "            Inner b = new Inner();\n" +
			    "            Inner[] ba = new Inner[1];\n" +
			    "            ba[0] = b;\n" +
			    "            return ba;\n" +
			    "        }\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "OK");
    }

    // a callin binds an overloaded base method without specifying signatures
    // 4.4.2-otjld-ambiguous-callin-binding-1
    public void test442_ambiguousCallinBinding1() {
        runNegativeTest(
            new String[] {
		"T442acb1.java",
			    "\n" +
			    "public class T442acb1 {\n" +
			    "		void foo() {}\n" +
			    "		void foo(int i) {}\n" +
			    "}\n" +
			    "	\n",
		"Team442acb1.java",
			    "\n" +
			    "public team class Team442acb1 {\n" +
			    "	protected class R playedBy T442acb1 {\n" +
			    "		void bar () { }\n" +
			    "		bar <- after foo;\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n"
            },
            null);
    }

    // a callin binds a base method that is overloaded along extends without specifying signatures
    // 4.4.2-otjld-ambiguous-callin-binding-2
    public void test442_ambiguousCallinBinding2() {
        runNegativeTest(
            new String[] {
		"T442acb2_1.java",
			    "\n" +
			    "public class T442acb2_1 {\n" +
			    "		void foo(int i) {}\n" +
			    "}\n" +
			    "	\n",
		"T442acb2_2.java",
			    "\n" +
			    "public class T442acb2_2 extends T442acb2_1 {\n" +
			    "		void foo() {}\n" +
			    "}\n" +
			    "	\n",
		"Team442acb2.java",
			    "\n" +
			    "public team class Team442acb2 {\n" +
			    "	protected class R playedBy T442acb2_2 {\n" +
			    "		void bar () { }\n" +
			    "		bar <- after foo;\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n"
            },
            null);
    }

    // a role method return a result which is lowered for passing back to the base
    // 4.4.3-otjld-callin-with-result-lowering-1
    public void test443_callinWithResultLowering1() {
       
       runConformTest(
            new String[] {
		"T443cwrl1Main.java",
			    "\n" +
			    "public class T443cwrl1Main {\n" +
			    "	public static void main (String[] args) {\n" +
			    "		Team443cwrl1 t = new Team443cwrl1();\n" +
			    "		t.test(new T443cwrl1(\"OK\"));\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n",
		"T443cwrl1.java",
			    "\n" +
			    "public class T443cwrl1 {\n" +
			    "	private String value;\n" +
			    "	public T443cwrl1(String value) { this.value = value; }\n" +
			    "	public T443cwrl1 getOther() { return null; }\n" +
			    "	public String getValue() { return this.value; }\n" +
			    "}\n" +
			    "	\n",
		"Team443cwrl1.java",
			    "\n" +
			    "public team class Team443cwrl1 {\n" +
			    "	R masterR;\n" +
			    "	public class R playedBy T443cwrl1 {\n" +
			    "		callin R getMasterR() {\n" +
			    "			return masterR;\n" +
			    "		}\n" +
			    "		getMasterR <- replace getOther;\n" +
			    "	}\n" +
			    "	public void test (T443cwrl1 as R r) {\n" +
			    "		masterR = r;\n" +
			    "		activate();\n" +
			    "		T443cwrl1 obj = new T443cwrl1(\"NOK\");\n" +
			    "		T443cwrl1 other = obj.getOther();\n" +
			    "		System.out.print(other.getValue());\n" +
			    "	}\n" +
			    "}\n" +
			    "	\n"
            },
            "OK");
    }

    // A callin method lifts its arg and passes it (lowered) back to the base call
    // 4.4.4-otjld-callin-replace-lifts-arg-1
    public void test444_callinReplaceLiftsArg1() {
       
       runConformTest(
            new String[] {
		"Team444crla1_2.java",
			    "\n" +
			    "public team class Team444crla1_2 extends Team444crla1_1 {\n" +
			    "    protected class R1 {\n" +
			    "        grumble <- replace test;\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        (new Team444crla1_2()).activate();\n" +
			    "        (new T444crla1_1()).test(new T444crla1_2());        \n" +
			    "    }\n" +
			    "}\n" +
			    "	\n",
		"T444crla1_1.java",
			    "\n" +
			    "public class T444crla1_1 {\n" +
			    "    void test(T444crla1_2 b) {\n" +
			    "        b.test();\n" +
			    "    }\n" +
			    "}\n" +
			    "	\n",
		"T444crla1_2.java",
			    "\n" +
			    "public class T444crla1_2 {\n" +
			    "    public void test() {\n" +
			    "        System.out.print(\"K\");\n" +
			    "    }\n" +
			    "}	\n" +
			    "	\n",
		"Team444crla1_1.java",
			    "\n" +
			    "public team class Team444crla1_1 {\n" +
			    "    protected class R0 playedBy T444crla1_2 {}\n" +
			    "    protected class R2 extends R0 {}\n" +
			    "    protected class R1 playedBy T444crla1_1 {\n" +
			    "        callin void grumble(R2 r) {\n" +
			    "            System.out.print(\"O\");\n" +
			    "            base.grumble(r);\n" +
			    "        }\n" +
			    "\n" +
			    "    }\n" +
			    "}\n" +
			    "	\n"
            },
            "OK");
    }

    // A callin method casts its arg and passes it (downcasted) back to the base call
    // 4.4.5-otjld-callin-replace-casts-arg-1f
    public void test445_callinReplaceCastsArg1f() {
        runNegativeTestMatching(
            new String[] {
		"Team445crca1f.java",
			    "\n" +
			    "public team class Team445crca1f {\n" +
			    "    protected class R playedBy T445crca1f {\n" +
			    "        callin void rm(Object o) {\n" +
			    "            System.out.print(\"O\");\n" +
			    "            base.rm(o);\n" +
			    "        }\n" +
			    "        rm <- replace bm;\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T445crca1f.java",
			    "\n" +
			    "public class T445crca1f {\n" +
			    "    public void bm(String s) {\n" +
			    "        System.out.print(s);\n" +
			    "    }\n" +
			    "}   \n" +
			    "    \n"
            },
            "4.5(d)");
    }

    // A callin method casts its arg and passes it (downcasted) back to the base call
    // 4.4.5-otjld-callin-replace-casts-arg-1
    public void test445_callinReplaceCastsArg1() {
       
       runConformTest(
            new String[] {
		"Team445crca1.java",
			    "\n" +
			    "public team class Team445crca1 {\n" +
			    "    protected class R playedBy T445crca1 {\n" +
			    "        callin <T> void rm(T o) {\n" +
			    "            System.out.print(\"O\");\n" +
			    "            base.rm(o);\n" +
			    "        }\n" +
			    "        rm <- replace bm;\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        T445crca1 b = new T445crca1();\n" +
			    "        Team445crca1 t = new Team445crca1();\n" +
			    "        t.activate();\n" +
			    "        b.bm(\"K\");\n" +
			    "    }\n" +
			    "\n" +
			    "}\n" +
			    "    \n",
		"T445crca1.java",
			    "\n" +
			    "public class T445crca1 {\n" +
			    "    public void bm(String s) {\n" +
			    "        System.out.print(s);\n" +
			    "    }\n" +
			    "}   \n" +
			    "    \n"
            },
            "OK");
    }

    // a callin method lifts an array of bases (inner class)
    // 4.4.6-otjld-callin-array-arg-lifting-1
    public void test446_callinArrayArgLifting1() {
       
       runConformTest(
            new String[] {
		"Team446caal1.java",
			    "\n" +
			    "public team class Team446caal1 {\n" +
			    "    protected class R playedBy T446caal1.Inner {\n" +
			    "        callin void printArray(R[] rs) {\n" +
			    "            System.out.print(\"->\");\n" +
			    "            base.printArray(rs);\n" +
			    "            System.out.print(\"<-\");\n" +
			    "        }\n" +
			    "        void printArray(R[] rs) <- replace void printArray(T446caal1.Inner[] is);\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        new Team446caal1().activate();\n" +
			    "        new T446caal1().test();\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T446caal1.java",
			    "\n" +
			    "public class T446caal1 {\n" +
			    "    public class Inner {\n" +
			    "        void printArray(Inner[] inners) {\n" +
			    "            for (Inner i : inners)\n" +
			    "                i.print();\n" +
			    "        }\n" +
			    "        void print() {\n" +
			    "            System.out.print(\"OK\");\n" +
			    "        }\n" +
			    "    }\n" +
			    "    void test() {\n" +
			    "        Inner i= new Inner();\n" +
			    "        i.printArray(new Inner[]{i});\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "->OK<-");
    }

    public void testBug473392() {
    	runConformTest(
    		new String[] {
    	"t1/MyTeam.java",
    			"package t1;\n" + 
    			"\n" + 
    			"import b1.MyBase;\n" + 
    			"\n" + 
    			"public team class MyTeam {\n" + 
    			"    protected team class Mid { \n" + 
    			"        \n" + 
    			"        protected class R playedBy MyBase {\n" + 
    			"            callin void rm1(R r) {\n" + 
    			"                System.out.println(\"rm1 \" + r.getClass().getName());\n" + 
    			"                base.rm1(r);\n" + 
    			"            }\n" + 
    			"            callin1: rm1 <- replace id, process;\n" + 
    			"            callin R rm2(R r) {\n" + 
    			"                System.out.println(\"rm2\");\n" + 
    			"                return this;\n" + 
    			"            }\n" + 
    			"            callin2: rm2 <- replace id\n" + 
    			"                base when (false);\n" + 
    			"\n" + 
    			"            precedence callin2, callin1;\n" + 
    			"        }\n" + 
    			"    }\n" + 
    			"    \n" + 
    			"    public static void main(String[] args) {\n" + 
    			"        new MyTeam().new Mid().activate();\n" + 
    			"        new MyBase().process(new MyBase());\n" + 
    			"    }\n" + 
    			"}\n",
    	"b1/MyBase.java",
    			"package b1;\n" + 
    			"\n" + 
    			"public class MyBase {\n" + 
    			"    MyBase id(MyBase other) { return this; }\n" + 
    			"    public MyBase process(MyBase other) {\n" + 
    			"        other = id(other);\n" + 
    			"        System.out.println(other.getClass().getName());\n" + 
    			"        return null;\n" + 
    			"    }\n" + 
    			"}\n"
    		},
    		"rm1 t1.MyTeam$__OT__Mid$__OT__R\n" + 
			"rm1 t1.MyTeam$__OT__Mid$__OT__R\n" + 
			"b1.MyBase");
    }

    public void testBug531011_secondary() {
    	runNegativeTest(
    		new String[] {
    			"Main.java",
    			"public class Main {\n" +
    			"	public static void main(String... args) {\n" +
    			"		new t.Team1().activate();\n" +
    			"		System.out.print(b.Base.<String>m());\n" +
    			"	}\n" +
    			"}\n",
    			"b/Base.java",
    			"package b;\n" +
    			"public class Base {\n" +
    			"	public static <T> T m() { return null; }\n" +
    			"}\n",
    			"t/Team1.java",
    			"package t;\n" +
    			"import base b.Base;\n" +
    			"public team class Team1 {\n" +
    			"	protected class R playedBy Base {\n" +
    			"		R() { base(); }\n" +
    			"		<T> T rm() <- replace T m()\n" +
    			"			with { result -> result }\n" +
    			"		static callin <T> T rm() {\n" +
    			"			return base.rm();\n" +
    			"		}\n" +
    			"	}\n" +
    			"}\n"
    		},
			"----------\n" + 
			"1. ERROR in t\\Team1.java (at line 6)\n" + 
			"	<T> T rm() <- replace T m()\n" + 
			"	      ^^\n" + 
			"T cannot be resolved to a type\n" + 
			"----------\n" + 
			"2. ERROR in t\\Team1.java (at line 6)\n" + 
			"	<T> T rm() <- replace T m()\n" + 
			"	      ^^\n" + 
			"T cannot be resolved to a type\n" + 
			"----------\n");
    }
}

Back to the top