Skip to content

A tool for manipulating symbols present in Java source files.

License

Notifications You must be signed in to change notification settings

fedora-java/jurand

Repository files navigation

Jurand — Java removal of annotations

A tool for manipulating symbols present in .java source files.

The tool can be used for patching .java sources in cases where using sed is insufficient due to Java language syntax. The tool follows Java language rules rather than applying simple regular expressions on the source code.

Currently the tool is able to remove import statements and annotations.

Usage

jurand [optional flags] <matcher>... [file path]...
Matcher
-n <name>

Simple (not fully-qualified) class name.

-p <pattern>

Regex pattern to match names used in code.

Optional flags
-a

Also remove annotations used in code.

-i, --in-place

Replace the contents of files.

-s, --strict

Fail if any of the specified options was redundant and no changes associated
with the option were made. This option is only applicable together with -i.

Specification

The tool removes import statements of specified matching class names and if -a is specified then also removes annotations. Arguments can be specified in arbitrary order.

File path arguments are handled the following way:

  • Symlinks are ignored

  • Regular files are handled regardless of the file name

  • Directories are traversed recursively and all .java files are handled

If no file path is provided then the tool reads from the standard input.

Class name matching can be done in two ways: -n to match simple class names or -p to match the provided regex pattern against fully qualified names as present in the sources. These options can be specified multiple times.

The specific implementation of the regex search engine is subject to change. Therefore only simple patterns should be used to guarantee that they will work with future versions.

The tool writes the results to standard output unless -i option is specified in which case it will replace the original files' content.

Strict mode

Additionally, when doing in-place modifications, it is possible to also specify -s or --strict which will cause the tool invocation to fail in the following cases:

  • No changes were made to any of the user-provided file or directory subtree

  • One of the matchers did not match anything

  • -a was specified but no annotation was removed

Note

Unicode literals (\uXXXX) are currently not recognized.