RemoveUnusedImports { public static String removeUnusedImports(final String contents) throws FormatterException { Context context = new Context(); JCCompilationUnit unit = parse(context, contents); if (unit == null) { return contents; } UnusedImportScanner scanner = new UnusedImportScanner(JavacTrees.instance(context)); scanner.scan(unit, null); return applyReplacements( contents, buildReplacements(contents, unit, scanner.usedNames, scanner.usedInJavadoc)); }  static String removeUnusedImports(final String contents);  }
@Test public void removeUnused() throws FormatterException { assertThat(removeUnusedImports(input)).isEqualTo(expected); }