|
72 | 72 | */ |
73 | 73 | public class RemoveUnusedImports { |
74 | 74 |
|
75 | | - /** |
76 | | - * Configuration for javadoc-only imports. |
77 | | - * |
78 | | - * @deprecated This configuration is no longer supported and will be removed in the future. |
79 | | - */ |
80 | | - @Deprecated |
81 | | - public enum JavadocOnlyImports { |
82 | | - /** Remove imports that are only used in javadoc, and fully qualify any {@code @link} tags. */ |
83 | | - REMOVE, |
84 | | - /** Keep imports that are only used in javadoc. */ |
85 | | - KEEP |
86 | | - } |
87 | | - |
88 | 75 | // Visits an AST, recording all simple names that could refer to imported |
89 | 76 | // types and also any javadoc references that could refer to imported |
90 | 77 | // types (`@link`, `@see`, `@throws`, etc.) |
@@ -197,13 +184,6 @@ public Void visitIdentifier(IdentifierTree node, Void aVoid) { |
197 | 184 | } |
198 | 185 | } |
199 | 186 |
|
200 | | - /** @deprecated use {@link removeUnusedImports(String)} instead. */ |
201 | | - @Deprecated |
202 | | - public static String removeUnusedImports( |
203 | | - final String contents, JavadocOnlyImports javadocOnlyImports) throws FormatterException { |
204 | | - return removeUnusedImports(contents); |
205 | | - } |
206 | | - |
207 | 187 | public static String removeUnusedImports(final String contents) throws FormatterException { |
208 | 188 | Context context = new Context(); |
209 | 189 | // TODO(cushon): this should default to the latest supported source level, same as in Formatter |
@@ -276,17 +256,6 @@ private static RangeMap<Integer, String> buildReplacements( |
276 | 256 | endPosition += sep.length(); |
277 | 257 | } |
278 | 258 | replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), ""); |
279 | | - // fully qualify any javadoc references with the same simple name as a deleted |
280 | | - // non-static import |
281 | | - if (!importTree.isStatic()) { |
282 | | - for (Range<Integer> docRange : usedInJavadoc.get(simpleName)) { |
283 | | - if (docRange == null) { |
284 | | - continue; |
285 | | - } |
286 | | - String replaceWith = importTree.getQualifiedIdentifier().toString(); |
287 | | - replacements.put(docRange, replaceWith); |
288 | | - } |
289 | | - } |
290 | 259 | } |
291 | 260 | return replacements; |
292 | 261 | } |
@@ -349,18 +318,6 @@ private static String applyReplacements(String source, RangeMap<Integer, String> |
349 | 318 | } |
350 | 319 | offset += replaceWith.length() - (range.upperEndpoint() - range.lowerEndpoint()); |
351 | 320 | } |
352 | | - String result = sb.toString(); |
353 | | - |
354 | | - // If there were any non-empty replaced ranges (e.g. javadoc), reformat the fixed regions. |
355 | | - // We could avoid formatting twice in --fix-imports=also mode, but that is not the default |
356 | | - // and removing imports won't usually affect javadoc. |
357 | | - if (!fixedRanges.isEmpty()) { |
358 | | - try { |
359 | | - result = new Formatter().formatSource(result, fixedRanges.asRanges()); |
360 | | - } catch (FormatterException e) { |
361 | | - // javadoc reformatting is best-effort |
362 | | - } |
363 | | - } |
364 | | - return result; |
| 321 | + return sb.toString(); |
365 | 322 | } |
366 | 323 | } |
0 commit comments