void () { String s9 = """ class X {{ int a[] = new int[] { 1,2,3,4}; int b[] = { 2,3,4,5 }; Object[] c = new Object[] { "", null}; Object[] d = {null, null}; Object[] e = {}; Object[] f = new Object[]{}; String[] g = new String[]{}; String[] h = new String[]{new String()}; }}"""; assertEquals("Find new array expressions, but no array initializer expressions", 5, findMatchesCount(s9, "new '_ []{ '_* }")); assertEquals("Find new int array expressions, including array initializer expressions", 2, findMatchesCount(s9, "new int []{ '_* }")); assertEquals("Find new int array expressions, including array initializer expressions using variable ", 2, findMatchesCount(s9, "new '_a?:int [] { '_* }")); assertEquals("Find all new array expressions, including array initializers", 8, findMatchesCount(s9, "new '_? []{ '_* }")); assertEquals("Find new Object array expressions, including array initializer expressions", 4, findMatchesCount(s9, "new Object[] { '_* }")); assertEquals("Find only array initializer expressions", 3, findMatchesCount(s9, "new '_{0,0}[] { '_* }")); assertEquals("Find only int array initializer expressions", 1, findMatchesCount(s9, "new '_{0,0}:int [] { '_* }")); assertEquals("Try to find String array initializer expressions", 0, findMatchesCount(s9, "new '_{0,0}:String [] { '_* }")); assertEquals("Find empty array initializers", 2, findMatchesCount(s9, "new Object[] {}")); String arrays = """ class X {{ int[] a = new int[20]; byte[] b = new @Q byte[30]; }}"""; assertEquals("Improper array search", 1, findMatchesCount(arrays, "new int['_a]")); assertEquals("Find array of primitives", 2, findMatchesCount(arrays, "new '_X['_a]")); String multiDimensional = """ class X {{ String[] s1 = {}; String[] s2 = new String[]{}; String[][] s3 = new String[][]{}; }}"""; assertEquals("Find 2 dimensional array", 1, findMatchesCount(multiDimensional, "new String[][]{}")); assertEquals("Find 1 dimensional arrays", 2, findMatchesCount(multiDimensional, "new String[]{}")); assertEquals("Find empty 1 dimensional arrays", 2, findMatchesCount(multiDimensional, "new String[0]")); String singleDimensional = """ class X {{ String[] ss1 = new String[0]; String[][] ss2 = new String[0][]; }}"""; assertEquals("Find empty array", 1, findMatchesCount(singleDimensional, "new String[0]")); }