void () { final String s15 = "'T;"; final String s1 = "class X {{ if (true) { aaa(var); }}}"; assertEquals("search for parameterized pattern", 3, findMatchesCount(s1, s15)); final String s2 = "class X {{ if (true) { aaa(var); bbb(var2); }\n if(1==1) { system.out.println('o'); }}}"; assertEquals("search for parameterized pattern 2", 7, findMatchesCount(s2, s15)); options.setRecursiveSearch(false); assertEquals("search for parameterized pattern-non-recursive", 1, findMatchesCount(s1, s15)); assertEquals("search for parameterized pattern 2-non-recursive", 2, findMatchesCount(s2, s15)); final String s23 = "class X {{ a[i] = 1; b[a[i]] = f(); if (a[i]==1) return b[c[i]]; }}"; final String s24_2 = "'T['_T2:.*i.* ]"; // typed vars with arrays assertEquals("typed pattern with array 2-non-recursive", 4, findMatchesCount(s23, s24_2)); options.setRecursiveSearch(true); assertEquals("search for parameterized pattern 3", 1, findMatchesCount(s2, "if('_T) { '_T2; }")); final String s17 = """ class X {{ token.getText().equals(token2.getText()); token.getText().equals(token2.getText2()); token.a.equals(token2.b); token.a.equals(token2.a); }}"""; assertEquals("search for parameterized pattern in field selection", 1, findMatchesCount(s17, "'_T1.'_T2.equals('_T3.'_T2);")); assertEquals("search for parameterized pattern with method call", 1, findMatchesCount(s17, "'_T1.'_T2().equals('_T3.'_T2());")); assertEquals("search for parameterized pattern with method call ep.2", 4, findMatchesCount(s17, "'_T1.'_T2")); final String s19 = "class X {{ Aaa a = (Aaa)b; Aaa c = (Bbb)d; }}"; assertEquals("search for same var constraint", 1, findMatchesCount(s19, "'_T1 'T2 = ('_T1)'_T3;")); assertEquals("search for same var constraint for semi anonymous typed vars", 1, findMatchesCount(s19, "'_T1 '_T2 = ('_T1)'_T3;")); final String s22 = "class X {{ Aaa a = (Aaa)b; Bbb c = (Bbb)d; }}"; assertEquals("search for typed var constraint", 1, findMatchesCount(s22, "'_T1:Aa* 'T2 = ('_T1)'_T3;")); try { findMatchesCount(s22, "'_T1:A* 'T2 = ( '_T1:A+ )'_T3;"); fail("search for noncompatible typed var constraint"); } catch(MalformedPatternException ignored) {} assertEquals("search for same typed var constraint", 1, findMatchesCount(s22, "'_T1:Aa* 'T2 = ( '_T1 )'_T3;")); final String s65 = "class X {{ if (A instanceof B) {} else if (B instanceof C) {}}}"; assertEquals("typed instanceof", 1, findMatchesCount(s65, " '_T instanceof '_T2:B")); try { findMatchesCount(s65, "'_T instanceof"); fail("warn on incomplete instanceof"); } catch (MalformedPatternException e) { assertEquals("Type expected", e.getMessage()); } assertEquals("typed pattern with array", 2, findMatchesCount(s23, "'T['_T2:.*i.* ] = '_T3;")); assertEquals("typed pattern with array 2", 6, findMatchesCount(s23, s24_2)); final String s25 = """ class MatcherImpl { void doMatch(int a) {} } class Matcher { abstract void doMatch(int a);} class Matcher2Impl { void doMatch(int a, int b) {} }"""; assertEquals("typed pattern in class name, method name, return type, parameter type and name", 1, findMatchesCount(s25, "class 'T:.*Impl { '_T2 '_T3('_T4 '_T5) {\n\n} } ")); final String s27 = "class A {} interface B {}"; assertEquals("finding interface", 1, findMatchesCount(s27, "interface 'T {}")); final String s29 = "class A { void B(int C) {} } class D { void E(double e) {} }"; assertEquals("anonymous typed vars", 1, findMatchesCount(s29, "class '_ { void '_('_:int '_); } ")); final String s31 = "class A extends B { } class D extends B { } class C extends C {}"; assertEquals("finding class descendants", 2, findMatchesCount(s31, "class '_ extends B { } ")); final String s33 = "class A implements B,C { } class D implements B,D { } class C2 implements C,B {}"; assertEquals("interface implementation", 2, findMatchesCount(s33, "class '_ implements B,C { } ")); final String s35 = "class A { int b; double c; void d() {} int e() {} } \n" + "class A2 { int b; void d() {} }"; assertEquals("different order of fields and methods", 1, findMatchesCount(s35, "class '_ { double '_; int '_; int '_() {} void '_() {} } ")); final String s37 = "class A { void d() throws B,C,D {} } class A2 { void d() throws B,C {} }"; assertEquals("different order in throws", 1, findMatchesCount(s37, "class 'T { '_ '_() throws D,C {} } ")); final String s39 = "class A extends B { } class A2 { }"; assertEquals("match of class without extends to class with it", 2, findMatchesCount(s39, "class 'T { } ")); final String s41 = "class A extends B { int a = 1; } class B { int[] c= new int[2]; } \n" + "class D { double e; } class E { int d; } "; assertEquals("match of class without extends to class with it, ep. 2", 2, findMatchesCount(s41, "class '_ { '_T '_T2 = '_T3; } ")); assertEquals("match of class without extends to class with it, ep 3", 4, findMatchesCount(s41, "class '_ { '_T '_T2; } ")); assertEquals("match class with fields without initializers", 2, findMatchesCount(s41, "class '_ { '_T '_T2 = '_T3{0,0}; } ")); final String s51 = "class C extends B { } class B extends A { } class E {}"; assertEquals("typed reference element", 2, findMatchesCount(s51, "class '_ extends '_ { }")); final String s59 = "interface A { void B(); }"; assertEquals("empty name for typed var", 1, findMatchesCount(s59, "interface '_ { void '_(); }")); final String s63 = " class A { A() {} } class B { public void run() {} }"; final String s64 = " class 'T { public void '_T2:run () {} }"; assertEquals("comparing method with constructor", 1, findMatchesCount(s63, s64)); final String s63_2 = """ class A { A() {} class B { public void run() {} } class D { public void run() {} } } class C {}"""; assertEquals("finding nested class", 2, findMatchesCount(s63_2, s64)); assertEquals("find nested class by special pattern", 2, findMatchesCount(s63_2, "class '_ { class 'T { public void '_T2:run () {} } }")); final String s61 = "class X {{ a=b; c=d; return; } { e=f; } {}}"; assertEquals("+ regexp for typed var", 4, findMatchesCount(s61, "{ 'T; }")); assertEquals("? regexp for typed var", 2, findMatchesCount(s61, "{ '_T?; }")); assertEquals("* regexp for anonymous typed var", 3, findMatchesCount(s61, "{ '_*; }")); assertEquals("+ regexp for anonymous typed var", 2, findMatchesCount(s61, "{ '_+; }")); assertEquals("? regexp for anonymous typed var", 2, findMatchesCount(s61, "{ '_?; }")); final String s67 = "class X {{ buf.append((VirtualFile)a); }}"; assertEquals("cast in method arguments", 1, findMatchesCount(s67, " (VirtualFile)'T")); final String s69 = """ class X {{ System.getProperties(); System.out.println(); java.lang.System.out.println(); some.other.System.out.println(); }}"""; assertEquals("searching for static field in static call", 2, findMatchesCount(s69, " System.out ")); assertEquals("searching for static field in static call, 2", 2, findMatchesCount(s69, " java.lang.System.out ")); final String s71 = """ class A { class D { D() { c(); } } void a() { c(); new MouseListener() { void b() { c(); } }; } }"""; assertEquals("statement inside anonymous class", 3, findMatchesCount(s71, " c(); ")); final String s91 = """ class a { void b() { int c; c = 1; b(); a a1; } }"""; assertEquals("clever regexp match", 2, findMatchesCount(s91, "'T:a")); assertEquals("clever regexp match 2", 2, findMatchesCount(s91, "'T:b")); assertEquals("clever regexp match 3", 2, findMatchesCount(s91, "'T:c")); }