void () { final String s = """ class X {{ debug("In action performed:"+event); project = (Project)event.getDataContext().getData(DataConstants.PROJECT); CodeEditorManager.getInstance(project).commitAllToPsiFile(); file = (PsiFile) event.getDataContext().getData("psi.File"); ((dialog==null)? (dialog = new SearchDialog()): dialog ).show(); }}"""; assertEquals("statement search", 1, findMatchesCount(s, "((dialog==null)? (dialog = new SearchDialog()): dialog).show();")); final String s5 = """ class X { { System.out.println(); while(false) { do { pattern = pattern.getNextSibling(); } while (pattern!=null && filterLexicalNodes(pattern)); } do { pattern = pattern.getNextSibling(); } while (pattern!=null && filterLexicalNodes(pattern)); { { do { pattern = pattern.getNextSibling(); } while (pattern!=null && filterLexicalNodes(pattern)); } } } }"""; assertEquals("several constructions match", 3, findMatchesCount(s5, """ do { pattern = pattern.getNextSibling(); } while (pattern!=null && filterLexicalNodes(pattern));""")); assertEquals("several constructions 2", 0, findMatchesCount(s5, """ do { pattern.getNextSibling(); } while (pattern!=null && filterLexicalNodes(pattern));""")); final String s7 = """ class X {{ if (true) throw new UnsupportedPatternException(statement.toString()); if (true) { throw new UnsupportedPatternException(statement.toString()); } }}"""; assertEquals("several constructions 3", 2, findMatchesCount(s7, """ if (true) { throw new UnsupportedPatternException(statement.toString()); }""")); assertEquals("several constructions 4", 2, findMatchesCount(s7, "if (true) throw new UnsupportedPatternException(statement.toString());")); final String s1000 = """ class X { { lastTest = "search for parameterized pattern"; matches = testMatcher.findMatches(s14_1,s15, options); if (matches.size()!=2 ) return false; lastTest = "search for parameterized pattern"; matches = testMatcher.findMatches(s14_1,s15, options); if (matches.size()!=2 ) return false; } }"""; final String s1001 = """ lastTest = '_Descr; matches = testMatcher.findMatches('_In,'_Pattern, options); if (matches.size()!='_Number ) return false;"""; assertEquals("several operators 5", 2, findMatchesCount(s1000, s1001)); final String s85 = "class X {{ int a; a=1; a=1; return a; }}"; assertEquals("two the same statements search", 1, findMatchesCount(s85, "'T; 'T;")); assertEquals("simple statement search (ignoring whitespace)", 4, findMatchesCount(s85, "'T ;")); final String s87 = "class X {{ getSomething(\"2\"); getSomething(\"1\"); a.call(); }}"; assertEquals("search for simple call", 1, findMatchesCount(s87, " '_Instance.'Call('_*); ")); assertEquals("search for simple call 2", 3, findMatchesCount(s87, " 'Call('_*); ")); assertEquals("search for simple call 3", 3, findMatchesCount(s87, " '_Instance?.'Call('_*); ")); assertEquals("search for simple call 4", 2, findMatchesCount(s87, " '_Instance{0,0}.'Call('_*); ")); String s10015 = "class X {{ DocumentListener[] listeners = getCachedListeners(); }}"; assertEquals("search for definition with init", 1, findMatchesCount(s10015, "'_Type 'Var = '_Call();")); String s10017 = "class X {{ a = b; b = c; a=a; c=c; }}"; assertEquals("search silly assignments", 2, findMatchesCount(s10017, "'_a = '_a;")); String s10019 = "class X {{ a.b(); a.b(null); a.b(null, 1); }}"; assertEquals("search parameter", 1, findMatchesCount(s10019, "a.b(null);")); String s1008 = "class X {{ int a, b, c, d; int a,b,c; int c,d; int e; }}"; assertEquals("search many declarations", 2, findMatchesCount(s1008, "int '_a{3,4};")); String s1 = "class X {{ super(1,1); call(1,1); call(2,2); }}"; assertEquals("search super", 1, findMatchesCount(s1, "super('_t*);")); String s10021 = """ class X {{ short a = 1; short b = 2; short c = a.b(); }}"""; assertEquals("search def init bug", 1, findMatchesCount(s10021, "short '_a = '_b.b();")); String s10023 = """ class X {{ abstract class A { public abstract short getType(); } A a; switch(a.getType()) { default: return 0; } switch(a.getType()) { case 1: { return 0; } } }}"""; assertEquals("finding switch", 2, findMatchesCount(s10023, "switch('_a:[exprtype( short )]) { '_statement*; }")); String s10025 = """ class X {{ A[] a; A b[]; A c; }}"""; assertEquals("array types in dcl", 2, findMatchesCount(s10025, "A[] 'a;")); assertEquals("array types in dcl 2", 2, findMatchesCount(s10025, "A 'a[];")); String s10027 = """ class X {{ try { a(); } catch(Exception ex) {} try { a(); } finally {} try { a(); } catch(Exception ex) {} finally {} }}"""; assertEquals("finally matching", 2, findMatchesCount(s10027, "try { a(); } finally {}\n")); String s10029 = "class X {{ for(String a:b) { System.out.println(a); }}}"; assertEquals("for each matching", 1, findMatchesCount(s10029, "for(String a:b) { '_a; }")); String s10031 = """ class X {{ try { a(); } catch(Exception ex) {} catch(Error error) { 1=1; } try { a(); } catch(Exception ex) {} }}"""; assertEquals("catch parameter matching", 3, findMatchesCount(s10031, "try { a(); } catch('_Type 'Arg) { '_Statements*; }\n")); String s10033 = """ class X {{ return x; return !x; return (x); return (x); return !(x); }}"""; assertEquals("Find statement with parenthesized expr",2,findMatchesCount(s10033, "return ('a);")); assertEquals("Find statement ignoring parentheses expr 2", 3, findMatchesCount(s10033, "return 'a:[regex( x )];")); String in = """ class X {{ if (true) { System.out.println(); } else { System.out.println(); } if (true) System.out.println(); }}"""; assertEquals("Find if statement with else", 2, findMatchesCount(in, "if ('_exp) { '_statement*; }")); assertEquals("Find if statement without else", 1, findMatchesCount(in, "if ('_exp) { '_statement*; } else { '_statement2{0,0}; }")); String in2 = """ /** * javadoc */ class A { /* comment */ void a() { System.out.println(); // comment } }"""; assertEquals("Should find statements and comments in statement context only", 2, findMatchesCount(in2, "'_statement;")); String in3 = """ class X {{ new Object().hashCode(); new Object().toString(); }}"""; assertEquals("Find typed expression statements", 1, findMatchesCount(in3, "'_expr:[exprtype( int )];")); String in4 = """ class X { void x() { System.out.println(); {} // comment switch (1) { case 1: {} } } }"""; assertEquals("block statement is a statement too", 1, findMatchesCount(in4, """ void '_x() { '_st*; }""")); String in5 = """ class X { void x() { while (true) {} } }"""; assertEquals("match block statement with statement variable", 1, findMatchesCount(in5, "while (true) '_st;")); }