Java: Add test regarding the type of an implicit this expression

This commit is contained in:
Chris Smowton
2022-08-26 15:51:44 +01:00
parent 8e0a006665
commit 25b4d485b4
3 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
class Gen<T> {
void m(T t) { }
}
class SubSpec extends Gen<String> {
void foo() {
m("direct implicit this");
this.m("direct explicit this");
}
class Inner {
void bar() {
m("direct implicit this from inner");
SubSpec.this.m("direct explicit this from inner");
}
}
void hasLocal() {
class Local {
void baz() {
m("direct implicit this from local");
SubSpec.this.m("direct explicit this from local");
}
}
}
}
class SubGen<S> extends Gen<S> {
void foo() {
m((S)"direct implicit this (generic sub)");
this.m((S)"direct explicit this (generic sub)");
}
class Inner {
void bar() {
m((S)"direct implicit this from inner (generic sub)");
SubGen.this.m((S)"direct explicit this from inner (generic sub)");
}
}
}
class Intermediate<S> extends Gen<S> { }
class GrandchildSpec extends Intermediate<String> {
void foo() {
m("indirect implicit this");
this.m("indirect explicit this");
}
class Inner {
void bar() {
m("indirect implicit this from inner");
GrandchildSpec.this.m("indirect explicit this from inner");
}
}
}
class GrandchildGen<R> extends Intermediate<R> {
void foo() {
m((R)"indirect implicit this (generic sub)");
this.m((R)"indirect explicit this (generic sub)");
}
class Inner {
void bar() {
m((R)"indirect implicit this from inner (generic sub)");
GrandchildGen.this.m((R)"indirect explicit this from inner (generic sub)");
}
}
}
class UninvolvedOuter {
class InnerGen<T> {
void m(T t) { }
}
class InnerSpec extends InnerGen<String> {
void foo() {
m("direct implicit this, from inner to inner");
this.m("direct explicit this, from inner to inner");
}
}
}

View File

@@ -0,0 +1,20 @@
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |
| 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> |

View File

@@ -0,0 +1,5 @@
import java
from MethodAccess ma
select ma, ma.getAnArgument().getAChildExpr*().(StringLiteral), ma.getCallee(),
ma.getCallee().getDeclaringType()