-
Notifications
You must be signed in to change notification settings - Fork 56
Background
- Download the jar file from the latest [Release].
- Close Eclipse.
- Put the jar file in eclipse/dropin folder.
- Start Eclipse.
By assuming that the current directory 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.