Merge pull request #11079 from smowton/smowton/test/test-java-extractor-vs-captured-type-variables

Java: Add test for multiply-bounded wildcards
This commit is contained in:
Chris Smowton
2022-11-07 12:31:19 +00:00
committed by GitHub
6 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
public class Test {
static class BoundedGeneric<T extends CharSequence> {
public T getter(int unused) { return null; }
public void setter(T t) { }
}
public static BoundedGeneric<?> getUnbounded() { return null; }
public static BoundedGeneric<? super String> getLowerBounded() { return null; }
public static void test() {
CharSequence cs = getUnbounded().getter(0);
Object o = getLowerBounded().getter(0);
getUnbounded().setter(null);
getLowerBounded().setter(null);
}
}

View File

@@ -0,0 +1,4 @@
| Test$BoundedGeneric.class:0:0:0:0 | getter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric<? super String> | CharSequence | int |
| Test$BoundedGeneric.class:0:0:0:0 | getter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric<?> | CharSequence | int |
| Test$BoundedGeneric.class:0:0:0:0 | setter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric<? super String> | void | String |
| Test$BoundedGeneric.class:0:0:0:0 | setter | Test$BoundedGeneric.class:0:0:0:0 | BoundedGeneric<?> | void | <nulltype> |

View File

@@ -0,0 +1,5 @@
import java
from MethodAccess ma
select ma.getCallee(), ma.getCallee().getDeclaringType(), ma.getCallee().getReturnType().toString(),
ma.getCallee().getAParamType().toString()

View File

@@ -0,0 +1,13 @@
import java.util.Collection;
public class Test {
public Collection<? extends CharSequence> getCollection() {
return null;
}
public void test() {
this.getCollection().isEmpty();
}
}

View File

@@ -0,0 +1,5 @@
import java
from Method m, Type t
where m.getAParamType() = t and t.toString().matches("%? super ? extends%")
select m, t