CodeQL library for Java
Search

Predicate indirectlyInstantiates

Generalisation of instantiates that takes subtyping into account:

  • HashSet<Integer> indirectly instantiates Collection (but also HashSet and Set), with the 0-th type parameter being Integer;
  • a class MyList extends ArrayList<Runnable> also instantiates Collection (as well as AbstractList, AbstractCollection and List), with the 0-th type parameter being Runnable;
  • the same is true of class MyOtherList<T> extends ArrayList<Runnable> (note that it does not instantiate the type parameter to T);
  • a class MyIntMap<V> extends HashMap<Integer, V> instantiates Map (among others) with the 0-th type parameter being Integer and the 1-th type parameter being V.

Import path

import semmle.code.java.Collections
predicate indirectlyInstantiates(RefType t, GenericType g, int i, RefType arg)