solve deep rewrites in function rules in java backend

@yilongli please review