void () { String s1 = "new SimpleDateFormat(\"yyyyMMddHHmmss\")"; String s2 = "'expr"; String s3 = "new AtomicReference<DateFormat>($expr$)"; String expectedResult = "new AtomicReference<DateFormat>(new SimpleDateFormat(\"yyyyMMddHHmmss\"))"; assertEquals("Replacement of top-level expression only", expectedResult, replace(s1, s2, s3)); String s4 = "get(\"smth\")"; String s5 = "'expr"; String s6 = "new Integer($expr$)"; String expectedResult1 = "new Integer(get(\"smth\"))"; assertEquals("Replacement of top-level expression only", expectedResult1, replace(s4, s5, s6)); String in = """ class X { boolean x(int foo, int bar) { return foo - 1 < bar - 1; } }"""; String what = "'_intA:[exprtype( *int|Integer )] - '_const < '_intB:[exprtype( *int|Integer )] - '_const"; String by = "$intA$ < $intB$"; String expected = """ class X { boolean x(int foo, int bar) { return foo < bar; } }"""; assertEquals("No errors in pattern", expected, replace(in, what, by)); }