Skip to content

Commit edfc2ab

Browse files
cushoncpovirk
authored andcommitted
Delete obsolete unused import logic
we no longer support removing imports that are used in javadoc. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=263447679
1 parent 75c4c06 commit edfc2ab

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@
7272
*/
7373
public class RemoveUnusedImports {
7474

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-
8875
// Visits an AST, recording all simple names that could refer to imported
8976
// types and also any javadoc references that could refer to imported
9077
// types (`@link`, `@see`, `@throws`, etc.)
@@ -197,13 +184,6 @@ public Void visitIdentifier(IdentifierTree node, Void aVoid) {
197184
}
198185
}
199186

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-
207187
public static String removeUnusedImports(final String contents) throws FormatterException {
208188
Context context = new Context();
209189
// 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(
276256
endPosition += sep.length();
277257
}
278258
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-
}
290259
}
291260
return replacements;
292261
}
@@ -349,18 +318,6 @@ private static String applyReplacements(String source, RangeMap<Integer, String>
349318
}
350319
offset += replaceWith.length() - (range.upperEndpoint() - range.lowerEndpoint());
351320
}
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();
365322
}
366323
}

0 commit comments

Comments
 (0)