Skip to content

Commit 25b4d48

Browse files
committed
Java: Add test regarding the type of an implicit this expression
1 parent 8e0a006 commit 25b4d48

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
class Gen<T> {
2+
void m(T t) { }
3+
}
4+
5+
class SubSpec extends Gen<String> {
6+
void foo() {
7+
m("direct implicit this");
8+
this.m("direct explicit this");
9+
}
10+
11+
class Inner {
12+
void bar() {
13+
m("direct implicit this from inner");
14+
SubSpec.this.m("direct explicit this from inner");
15+
}
16+
}
17+
18+
void hasLocal() {
19+
class Local {
20+
void baz() {
21+
m("direct implicit this from local");
22+
SubSpec.this.m("direct explicit this from local");
23+
}
24+
}
25+
}
26+
}
27+
28+
class SubGen<S> extends Gen<S> {
29+
void foo() {
30+
m((S)"direct implicit this (generic sub)");
31+
this.m((S)"direct explicit this (generic sub)");
32+
}
33+
34+
class Inner {
35+
void bar() {
36+
m((S)"direct implicit this from inner (generic sub)");
37+
SubGen.this.m((S)"direct explicit this from inner (generic sub)");
38+
}
39+
}
40+
}
41+
42+
class Intermediate<S> extends Gen<S> { }
43+
44+
class GrandchildSpec extends Intermediate<String> {
45+
void foo() {
46+
m("indirect implicit this");
47+
this.m("indirect explicit this");
48+
}
49+
50+
class Inner {
51+
void bar() {
52+
m("indirect implicit this from inner");
53+
GrandchildSpec.this.m("indirect explicit this from inner");
54+
}
55+
}
56+
}
57+
58+
class GrandchildGen<R> extends Intermediate<R> {
59+
void foo() {
60+
m((R)"indirect implicit this (generic sub)");
61+
this.m((R)"indirect explicit this (generic sub)");
62+
}
63+
64+
class Inner {
65+
void bar() {
66+
m((R)"indirect implicit this from inner (generic sub)");
67+
GrandchildGen.this.m((R)"indirect explicit this from inner (generic sub)");
68+
}
69+
}
70+
}
71+
72+
class UninvolvedOuter {
73+
class InnerGen<T> {
74+
void m(T t) { }
75+
}
76+
77+
class InnerSpec extends InnerGen<String> {
78+
void foo() {
79+
m("direct implicit this, from inner to inner");
80+
this.m("direct explicit this, from inner to inner");
81+
}
82+
}
83+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| Test.java:7:5:7:29 | m(...) | Test.java:7:7:7:28 | "direct implicit this" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
2+
| Test.java:8:5:8:34 | m(...) | Test.java:8:12:8:33 | "direct explicit this" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
3+
| Test.java:13:7:13:42 | m(...) | Test.java:13:9:13:41 | "direct implicit this from inner" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
4+
| Test.java:14:7:14:55 | m(...) | Test.java:14:22:14:54 | "direct explicit this from inner" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
5+
| Test.java:21:9:21:44 | m(...) | Test.java:21:11:21:43 | "direct implicit this from local" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
6+
| Test.java:22:9:22:57 | m(...) | Test.java:22:24:22:56 | "direct explicit this from local" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
7+
| Test.java:30:5:30:46 | m(...) | Test.java:30:10:30:45 | "direct implicit this (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<S> |
8+
| Test.java:31:5:31:51 | m(...) | Test.java:31:15:31:50 | "direct explicit this (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<S> |
9+
| Test.java:36:7:36:59 | m(...) | Test.java:36:12:36:58 | "direct implicit this from inner (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<S> |
10+
| Test.java:37:7:37:71 | m(...) | Test.java:37:24:37:70 | "direct explicit this from inner (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<S> |
11+
| Test.java:46:5:46:31 | m(...) | Test.java:46:7:46:30 | "indirect implicit this" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
12+
| Test.java:47:5:47:36 | m(...) | Test.java:47:12:47:35 | "indirect explicit this" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
13+
| Test.java:52:7:52:44 | m(...) | Test.java:52:9:52:43 | "indirect implicit this from inner" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
14+
| Test.java:53:7:53:64 | m(...) | Test.java:53:29:53:63 | "indirect explicit this from inner" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<String> |
15+
| Test.java:60:5:60:48 | m(...) | Test.java:60:10:60:47 | "indirect implicit this (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<R> |
16+
| Test.java:61:5:61:53 | m(...) | Test.java:61:15:61:52 | "indirect explicit this (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<R> |
17+
| Test.java:66:7:66:61 | m(...) | Test.java:66:12:66:60 | "indirect implicit this from inner (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<R> |
18+
| Test.java:67:7:67:80 | m(...) | Test.java:67:31:67:79 | "indirect explicit this from inner (generic sub)" | Gen.class:0:0:0:0 | m | Gen.class:0:0:0:0 | Gen<R> |
19+
| Test.java:79:7:79:52 | m(...) | Test.java:79:9:79:51 | "direct implicit this, from inner to inner" | UninvolvedOuter$InnerGen.class:0:0:0:0 | m | UninvolvedOuter$InnerGen.class:0:0:0:0 | InnerGen<String> |
20+
| Test.java:80:7:80:57 | m(...) | Test.java:80:14:80:56 | "direct explicit this, from inner to inner" | UninvolvedOuter$InnerGen.class:0:0:0:0 | m | UninvolvedOuter$InnerGen.class:0:0:0:0 | InnerGen<String> |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from MethodAccess ma
4+
select ma, ma.getAnArgument().getAChildExpr*().(StringLiteral), ma.getCallee(),
5+
ma.getCallee().getDeclaringType()

0 commit comments

Comments
 (0)