void () { final String s81 = """ class Pair<First,Second> { <C,F> void a(B<C> b, D<F> e) throws C { P<Q> r = (S<T>)null; Q q = null; if (r instanceof S<T>) {} } } class Q { void b() {} }"""; assertEquals("parameterized class match", 2, findMatchesCount(s81, "class '_<'T> {}")); assertEquals("parameterized instanceof match", 1, findMatchesCount(s81, "'_Expr instanceof '_Type<'_Parameter+>")); assertEquals("parameterized cast match", 1, findMatchesCount(s81, "( '_Type<'_Parameter+> ) '_Expr")); assertEquals("parameterized symbol without variables matching", 2, findMatchesCount(s81, "S<T>")); assertEquals("parameterized definition match", 3, findMatchesCount(s81, "'_Type<'_Parameter+> 'a = '_Init?;")); assertEquals("parameterized method match", 1, findMatchesCount(s81, "class '_ { <'_+> '_Type 'Method('_ '_*); }")); final String s81_2 = "class Double<T> {} class T {} class Single<First extends A & B> {}"; assertEquals("parameterized constraint match", 2, findMatchesCount(s81_2, "class '_<'_+ extends 'res> {}")); String s82_7 = "'Type"; assertEquals("symbol matches parameterization", 29, findMatchesCount(s81, s82_7)); assertEquals("symbol matches parameterization 2", 7, findMatchesCount(s81_2, s82_7)); String s81_3 = """ class A { public static <T> Collection<T> unmodifiableCollection(int c) { return new d<T>(c); } static class d<E> implements Collection<E>, Serializable { public <T> T[] toArray(T[] a) {return c.toArray(a);} } }"""; assertEquals("typed symbol symbol", 2, findMatchesCount(s81_3, "class '_ { <'_+> '_Type 'Method('_ '_*); }")); String s81_4= """ class A<B> { static <C> void c(D<E> f) throws R<S> { if ( f instanceof G<H>) { ((I<G<K>>)l).a(); throw new P<Q>(); } } } class C { void d(E f) throws Q { if (g instanceof H) { a.c(); b.d(new A() {}); throw new Exception(((I)k)); } } }"""; assertEquals("typed symbol", 8, findMatchesCount(s81_4, "'T<'_Subst+>")); String s81_5 = "class A { HashMap<String, Integer> variable = new HashMap<String, Integer>(\"aaa\");}"; String s82_9 = "'_Type<'_GType, '_GType2> '_instance = new '_Type<'_GType, '_GType2>('_Param);"; assertEquals("generic vars in new", 1, findMatchesCount(s81_5,s82_9)); assertEquals("no exception on searching for diamond operator", 0, findMatchesCount(s81_5, "new 'Type<>('_Param)")); assertEquals("order of parameters matters", 0, findMatchesCount(s81_5, "HashMap<Integer, String>")); assertEquals("order of parameters matters 2", 2, findMatchesCount(s81_5, "HashMap<String, Integer>")); String source1 = "class Comparator<T> { private Comparator<String> c; private Comparator d; private Comparator e; }"; assertEquals("qualified type should not match 1", 0, findMatchesCount(source1, "java.util.Comparator 'a;")); assertEquals("qualified type should not match 2", 0, findMatchesCount(source1, "java.util.Comparator<String> 'a;")); assertEquals("unparameterized type query should match", 3, findMatchesCount(source1, "Comparator 'a;")); assertEquals("parameterized type query should only match parameterized", 1, findMatchesCount(source1, "Comparator<'_a> 'b;")); assertEquals("should find unparameterized only", 2, findMatchesCount(source1, "Comparator<'_a{0,0}> 'b;")); String source2 = "class A<@Q T> {}\n" + "class B<T> {}"; assertEquals("find annotated type parameter", 1, findMatchesCount(source2, "class '_A<@Q '_T> {}")); // @todo typed vars constrains (super), // @todo generic method invocation //String s83 = "class A {} List<A> a; List b;"; //String s84 = "'a:List 'c;"; //String s84_2 = "'a:List\\<'_\\> 'c;"; //String s84_3 = "'a:List(?>\\<'_\\>) 'c;"; // //assertEquals( // "finding list", // findMatchesCount(s83,s84), // 2 //); // //assertEquals( // "finding list 2", // findMatchesCount(s83,s84_2), // 1 //); // //assertEquals( // "finding list 3", // findMatchesCount(s83,s84_3), // 1 //); }