This product is in beta state.
It is available to registered beta testers only.

The SplitBrains plugin for IntelliJ provides advanced refactoring and analysis tools for projects.

Splitbrains is a refactoring tool for IntelliJ. It allows the developer to declare splitpoints in a project, and then take actions on code that defines, contains, uses, references, or depends on those splitpoints.

Splitbrains also provides tools to assist in the in decoupling of dependencies, such as:

  • Separating a codebase into model, view, and controller
  • Removing UI dependencies
  • Removing database dependencies
  • I8N (Internationalization)
  • Providing warnings and restrictions to prevent code from appearing in the wrong place

    Nomenclature

Splitpoint
A piece of code that identifies code that should be split from the source. A splitpoint identifies the separation of .
Trigger
Defines what is considered to be a splitpoint
Source
The unit that will be moved, such as file, class, method, or member.
Target
The location where to move the source when it contains a splitpoint.
Action
Operations to perform when triggers are met. # Splitbrains Script The Splitbrains Script is a simple JSON file that defines splitpoint triggers, sources, targets, and actions. It lives in the root of a project. See the appendix for examples.

IntelliJ Actions

The follow actions are added to IntelliJ menus, and can be assigned to keyboard shortcuts.

  • Analyze
  • Run Script
  • Show Dependencies
  • Create Script

    Triggers

Comment
A regular expression that occurs in a comment
Text
A regular expression that occurs in a file
Package
A regular expression that matches a package declaration.
Import
A class that imports a package
Class
A code that is or depends on a class
Method
A code that declares or calls a method
Field
A code declares or access a field
Annotation
An item annotated with the specified annotation # Source Determines what is moved when a splitpoint is triggered. The only supported value is File. Future plans include support for Package, Class, Method, Field, and Property. # Actions Actions define what to do with the sources when splitpoints are triggered. ## Analyze ## Report ## Move Move the source to the target and change all references. The original code is removed. ## Copy Copy the source to the target. Does not change references. The original code is left intact. ## Copy And Reference Copy the source to the target and change all references. The original code is left intact.

Use this if you are OK with duplicate code in different packages. If there are non-refactored libraries that reference the code, this will prevent them from reporting a Class Not Found Exception.

Repackage

Move the source to a new package in the same or different module.

{
    "type" : "repackage",
    "newPackage : "com.some.package"
    "rebase" : ["com.some"],
    "referenceAction": "update|ignore"
    "module" : "new module"
}

rebase

Sources will be placed within the target package. The rebase parameter specifies prefixes of the source package that will be stripped, and then append to the new package. Unmatched packages will be moved into the new package using their entire package name.

If rebase is not defined, all sources will be moved into the new package.

newPackage a.b.c
sourcePackage x.y.z.Class
result a.b.c.Class

rebase  = "x.y.z"
newPackage a.b.c
sourcePackage x.y.z.Class
result a.b.c.Class

rebase  = "x.y"
newPackage a.b.c
sourcePackage x.y.z.Class
result a.b.c.z.Class

rebase = ""
newPackage a.b.c
sourcePackage x.y.z.Class
result a.b.c.x.y.z.Class

referenceAction

The action to perform on references to any modified packages. This will affect any files that import the package.

update
The imports will be changed to the new package.
ignore
The imports will remain unchanged.

module

The target module. If unset, the same module as the source will be used.

Annotate

Backup

Modify

Notify

Sample Script

{
  "name": "Untitled Splitbrains Script",
  "trigger": {
    "packages": [
      "tv.twelvetone.splitpoint_samples.old_package"
    ]
  },
  "source": "file",
  "action": [
    {
      "type": "report"
    },
    {
      "type": "repackage",
      "newPackage": "tv.twelvetone.splitpoint_samples.new_package"
    },
    {
      "type": "x-backup",
      "toFolder": "splitbrains_copy"
    }
  ],
  "target": {
  }
}

Sample Usage

Trigger on import of com.vaadin.*
Source is file.
Target is new module - Vaadin Client
This will move all files that depend on Vaadin to a new module.

Next, we can move any com.mysql code to a sql module.