Java rewrite engine

merge with the java backend