Save Actions Plugin
Supports configurable, Eclipse like, save actions, including "optimize imports", "reformat code", "rearrange code", "compile file" and some quick fixes like "add / remove 'this' qualifier", etc. The plugin executes the configured actions when the file is synchronised (or saved) on disk.
Using the save actions plugin makes your code cleaner and more uniform across your code base by enforcing your code style and code rules every time you save. The settings file (see files location) can be shared in your development team so that every developer has the same configuration.
The code style applied by the save actions plugin is the one configured your settings at "File > Settings > Editor > Code Style". For some languages, custom formatter may also be triggered by the save actions plugin. For example for Dart developers, enable "Use the dartfmt tool when formatting the whole file" option in "File > Settings > Editor > Code Style > Dart > Dartfmt".
Thank you to JetBrains that supports our plugin: they provide an open-source license to us, necessary to build, test and deploy this plugin. Check out their products at https://www.jetbrains.com.
- Eclipse support
- Files location
- JetBrains plugin page
All JetBrains products
- Optimize imports
- Run on file save, shortcut, batch (or a combination)
- Run on multiple files by choosing a scope
- Reformat code (whole file or only changed text)
- Rearrange code (reorder methods, fields, etc.)
- Include / exclude files with regex support
- Works on any file type (Java, Python, XML, etc.)
- Uses a settings file per project you can commit (see Files location)
- Available keymaps and actions for activation (see Keymap and actions)
Java IDE products
Works in JetBrains IDE with Java support, like Intellij IDEA and AndroidStudio.
- Eclipse configuration file
.epfsupport (see Eclipse support)
- Automatically fix Java inspections (see Java quick fixes)
Built with IntelliJ IDEA IC-2016.3, JDK 1.8, those are the currently supported products, and is not expected to work in other products:
- Intellij IDEA (ultimate and community)
- PyCharm (professional and community)
See issue #18 for a beta packaging that you can try in other products.
Install it from your IDE (Intellij IDEA, PyCharm, etc.):
- "File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'"
JetBrains plugin repository
All versions of the plugin are available from the JetBrains plugin repository. You can download the jar and add it to your IDE (you won't get updates thought):
- "File > Settings > Plugins > Install plugin from disk..."
The configurations are located in "File > Settings > Other Settings > Save Actions".
You can quickly toggle the plugin activation by using the "Enable Save Action" action. Use "CTRL + SHIFT + A" then search for it. It will also show if it is currently activated or not.
|Activate save actions on file save||Enable / disable the plugin on file save. Before saving each file, it will perform the configured actions below|
|Activate save actions on shortcut||Enable / disable the plugin on shortcut, by default "CTRL + SHIFT + S" (configured in "File > Keymaps > Main menu > Code > Save Actions")|
|Activate save actions on batch||Enable / disable the plugin on batch, by using "Code > Save Actions > Execute on multiple files"|
|No action if compile errors||Enable / disable no action if there are compile errors. Applied to each file individually|
|Optimize imports||Enable / disable import organization (configured in "File > Settings > Code Style > Java > Imports")|
|Reformat file||Enable / disable formatting (configured in "File > Settings > Code Style"). See "Reformat only changed code" for more options|
|Reformat only changed lines||Enable / disable formatting for only changed lines, which will work only if a VCS is configured|
|Rearrange fields and methods||Enable / disable re-ordering of fields and methods (configured in "File > Settings > Code Style > Java > Arrangement")|
|Compile file||Enable / disable compiling of the modified file. The compiler might compile other files as well. Warning: this option triggers one build action for each file, use sparingly (see #128)|
|File path inclusions||Add / remove file path inclusions (by default, everything included). The Java regular expressions match the whole file name from the project root. Include only Java files:
|File path exclusions||Add / remove file path exclusions to ignore files (overrides inclusions). The Java regular expressions match the whole file name from the project root. Exclude 'Main.java' only in root folder:
|Use external Eclipse configuration||Add external configuration file ".epf" to read settings from. This will update the current settings and use only the ".epf" file content. Use "reset" button to remove|
If a quick fix adds something that is removed by another quick fix, the removal wins.
|Add final modifier to field||The field
|Add final modifier to local variable or parameter||The local variable
|Add static modifier to methods||The method
|Add this to field access||The access to instance field
|Add this to method access||The access to instance method
|Add class qualifier to static member access||The access to class field
|Add class qualifier to static member access outside declaring class only||The access to class field
|Add missing @Override annotations||The method
|Add blocks to if/while/for statements||The statement
|Add missing serialVersionUID field for Serializable classes||The class
|Remove unnecessary this to field and method||The access to instance field
|Remove final from private method||The method
|Remove unnecessary final to local variable or parameter||The local variable
|Remove explicit generic type for diamond||The list creation
|Remove unused suppress warning annotation||The annotation
|Remove unnecessary semicolon||The statement
|Change visibility of field or method to lower access||The field
Save actions are grouped under the menu "Code > Save Actions". Remember that any action is available in the action menu "CTRL + SHIFT + A". You can associate a keymap to any action in "Settings > Keymap > Search 'save actions'".
- Enable Save Actions (default: not binded) will activate or deactivate the plugin by changing the configuration
- Execute Save Actions on shortcut (default: "CTRL + SHIFT + S") will trigger the plugin manually, only if the configuration allows shortcuts (see activation section, the "Activate save actions on shortcut" needs to be enabled)
- Execute Save Actions on multiple files (default: not binded) will show a popup to select the files (or a scope) on which to trigger the plugin
The save-actions plugin supports Eclipse configuration
.epf files (Java IDE only). You can specify a path to an Eclipse configuration file in the "Eclipse support" settings section to import it. The plugin will load the content of the file in the plugin configuration, and disable the plugin configuration options (the checkbox will be grayed out). Use the "reset" button to remove the import.
The plugin will stay in sync with your Eclipse configuration file. Not every features are present on either side, but the ones that are in common are supported.
You can find an example of an Eclipse configuration
.epf file in the test resources.
# @title Save Actions # @description Save Actions # @task_type LASTMOD file_export_version=3.0 /instance/org.eclipse.jdt.ui/editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true /instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code=true /instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code_changes_only=false /instance/org.eclipse.jdt.ui/sp_cleanup.organize_imports=true /instance/org.eclipse.jdt.ui/sp_cleanup.remove_trailing_whitespaces=true ...
- idea.log: The log file the save actions plugin writes in. It contains debug information, prefixed with
com.dubreuia.SaveActionManager. If you are using default locations, it would be in
- saveactions_settings.xml: The settings file is saved by project in the
.ideafolder. That file can be committed in git thus shared in your development team. If you are using the default locations, it would be in
Big thanks to all the contributors submitting issues, testing, and especially submitting pull requests.
See contributors graph