Java: Add test for multiply-bounded wildcards

This exercises several cases of variables bounded both by a wildcard and by a bound on the type parameter, checking that the extractor strips the wildcards and captures to decide on a concrete type for the parameters and return values.
This commit is contained in:
Chris Smowton
2022-11-02 11:57:42 +00:00
parent 1cd30847f6
commit d999c1d3dd
3 changed files with 28 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()