- An eclipse plugin
- Offers in the problems view tips for simplifying your code
- Batch laconize a function, file and project
- Installation button (drag to your eclipse workspace)
- This plugin's page on market place
The laconizer or spartnizer is an Eclipse plugin that automatically applies the principles of Spartan Programming to your Java code. It applies many different tippers, which are little rules that provide suggestions on how to shorten and simplify your code, e.g, by using fewer variables, factoring out common structures, more efficient use of control flow, etc.
This project was conceived as an academic project in the Technion - Israel Institute of Technology, and was later developed for several years by different students and members of the Computer Science faculty.
The refactorings made by this plug-in are based on the concept of Spartan Programming, which suggests guidelines for writing short, clean code. There's a lot of reading material on the subject in the project wiki.
- Download the jar file from the latest Release.
- Close Eclipse.
- Put the jar file in eclipse/dropin folder.
- Start Eclipse.
By asuming that the current derectory is at relative path "?", Clone the repository by:
git clone https://github.com/SpartanRefactoring/Spartanizer.git
After cloning the repository, go into the ?/Spartanizer/SpartanRefactoring directory and execute:
mvn package
The packaged plug-in (.jar file) will be created in the
?/Spartanizer/SpartanRefactoring/target
directory.
Copy the .jar file into your eclipse directory, Eclipse/dropins or plugins, and
run Eclipse.
-
Open Eclipse and go to "Install New Software...". From the list of install sites, pick The Eclipse Project Updates and make sure you've installed all the items from the categories Eclipse Platform, Eclipse Platform SDK and Eclipse Plugin Development Tools. Failure to install one of these will result in import errors.
-
Create a run configuration by running the project (Ctrl+F11), then elect to run it as an Eclipse Application.
- If a new instance of Eclipse doesn't launch, open the run configurations for the project and make sure that in the Program to Run box, "Run a product" is selected and the box next to it says "org.eclipse.platform.ide".
-
Go to File -> Export.... Under the Plug-in Development category, choose the Deployable plug-ins and fragments, and continue until the plug-in has been built successfully.
A tipper, in the context of this project, is a small object responsible for converting one form of code into another, under two major assumptions:
-
The latter is shorter and/or more comprehensible than the former.
-
Both forms are semantically equivalent, meaning that both versions do exactly the same thing (yet the latter may perform more efficiently).
Consider this basic programmers' mistake:
if(myString.length() < 5) {
return true;
} else {
return false;
}
Which can be shortened to:
if(myString.length() < 5)
return true;
return false;
Or even:
return myString.length() < 5;
Spartan Refactoring first detects this problem by:
- Finding a matching tipper,
- Notifying the user that a spartanization can be made
- Finally while preserving the programmer's intention, revises the
if
block all the way to the last example.
The plugin works by analyzing the abstract syntax tree (AST) generated by Eclipse for each of the compilation units in the current Java project. After the AST has been generated, and the user had asked to apply a set of tipper to the code, it is traversed using an ASTVisitor, and the tipper are applied one by one to the tree.
After the traversal is complete, the transformations made to the AST are written back to the source code.
The project is available under the MIT License