JAVA_REMOVE_IMPORTS(7)

πŸ“¦
version 1.3.5 Β· 4 versions
, in fedora 43

πŸ’– JAVA_REMOVE_IMPORTS πŸ’–

okay bestie, welcome to java_remove_imports, part of the Java packaging support squad, section 7 of the manual. she's a macro, she's iconic, and she's about to yeet your import statements into the sun. let's get into it ✨


🌸 NAME 🌸

java_remove_imports β€” remove import statements from Java source files 🧹✨


πŸŽ€ SYNOPSIS πŸŽ€

%java_remove_imports [optional flags] <matcher>... [file path]...

πŸ’… DESCRIPTION πŸ’…

so this macro removes import statements from Java source files. that's the whole vibe. πŸ’–

here's the tea on how she decides what to delete: the script takes all the non-whitespace content that comes after the import [static] statement and matches it against every pattern you handed over with the -p flag. meanwhile, all the simple class names get matched against the names you gave with the -n flag. two lanes, both working at the same time. slay. πŸ‘‘

πŸ¦‹ how file paths get handled πŸ¦‹

file path arguments are handled the following way, no cap:

  • symlinks are ignored. we simply do not see them. πŸ™ˆ
  • regular files are handled regardless of the file name. doesn't matter what you called it, she's gonna look.
  • directories get traversed recursively and all .java files are handled. all of them. every single one. 🌈

and yes, arguments can be specified in arbitrary order. you do you, boo. 🫢

⭐ matcher (one of these) ⭐

  • -n <name> β€” simple class name to be matched against the simple names of imported symbols. names are matched for exact equality. can be specified multiple times. πŸ’«
  • -p <pattern> β€” regex patterns to be matched against imported symbols. each imported symbol found in the code is matched against each pattern. can be specified multiple times. πŸ”₯

✨ optional flags ✨

  • -s, --strict β€” fail if any of the user provided arguments were redundant. she's checking your work, bestie. don't waste her time. πŸ’€

🌈 EXAMPLES 🌈

example of usage in a .spec file:

%java_remove_imports src -n Nullable

examples of patterns:

  • import statements present in Java source file:
1) import java.lang.Runnable;
2) import java.util.List;
3) import static java.util.*;
4) import static java.lang.String.valueOf;
5) import com.google.common.util.concurrent.Service;
  • names used to match:
Name 'Runnable' matches 1)
Name 'String' matches 4)

Name 'util' does not match anything.
Name '*' does not match anything.
Name 'valueOf' does not match anything.
  • patterns used to match:
Pattern 'Runnable' matches 1).
Pattern '[*]' matches 3).
Pattern 'java[.]util' matches 2), 3).
Pattern 'util' matches 2), 3), 5).
Patterns 'java', 'java.*' match 1) - 4).

Pattern 'static' does not match anything.

see how 'Runnable' and 'String' pulled their weight but 'util', '*' and 'valueOf' did absolutely nothing? that's the exact energy --strict is gonna clock. πŸ‘€


😭 REPORTING BUGS 😭

found a bug? bugs should be reported through the issue tracker at GitHub:

https://github.com/fedora-java/jurand/issues

please do it there, not in my DMs. πŸ™


πŸ‘‘ AUTHOR πŸ‘‘

written by MariΓ‘n Konček. king behavior, fr fr. πŸ’œ


🫢 SEE ALSO 🫢

java_remove_annotations(7).


okay that's the whole page bestie, go forth and de-import ✨

this has been JAVA_REMOVE_IMPORTS πŸ’– from 2025-07-24 πŸ’– filed under JAVA_REMOVE_IMPORTS(7) πŸ’– mwah, take care of her πŸŽ€

πŸ“¦ where this page comes from