About jSparrow
Java Refactoring for Eclipse IDE
About jSparrow
JSPARROW – YOUR JAVA REFACTORING PARTNER
To help developers refactor in Java, we have developed a tool called jSparrow. jSparrow is an IDE extension that aids Java developers in refactoring system-wide Java code with a rule-based approach.
You can for free install jSparrow to your Eclipse IDE and view all the refactorings on your project directly.

Java Refactorings Available
See the table below to browse all the available refactorings. Note that all jSparrow rules have a Minimum Java Version, which means that a rule with (for example) a Minimum Java version of 1.1 can be used on Java version 1.1 and all Java versions after 1.1.
All jSparrow’s refactoring rules
Included in Trial:
- Collapse If StatementsMinimum Java Version 1.1
- Replace equals() on Enum ConstantsMinimum Java Version 5
- Replace For-Loop with Enhanced-For-LoopMinimum Java Version 5
- Replace Expression Lambda with Method ReferenceMinimum Java Version 8
- Use Optional::filterMinimum Java Version 8
- Split Multiple Variable DeclarationsMinimum Java Version 1.1
- Organize ImportsMinimum Java Version 1.1
- Use @Override AnnotationMinimum Java Version 6
- Remove Boxing for String ConversionsMinimum Java Version 1.1
- Remove Double NegationsMinimum Java Version 1.1
- Remove Unnecessary SemicolonsMinimum Java Version 1.1
- Remove Null-Checks Before InstanceofMinimum Java Version 1.1
- Remove toString() on StringMinimum Java Version 1.1
- Remove Unnecessary Thrown Exceptions on Method SignaturesMinimum Java Version 1.1
- Reorder String Equality CheckMinimum Java Version 1.1
- Use Try-With-ResourceMinimum Java Version 7
- Replace Equality Check with isEmpty()Minimum Java Version 6
- Use Offset Based String MethodsMinimum Java Version 1.1
- Replace Inefficient Constructors with valueOf()Minimum Java Version 5
- Use SecureRandomMinimum Java Version 1.2
Included in every package
- Add Braces to Control StatementsMinimum Java Version 1.1
- Avoid Concatenation in Logging StatementsMinimum Java Version 1.1
- Chain AssertJ AssertThat StatementsMinimum Java Version 7
- Collapse If StatementsMinimum Java Version 1.1
- Create Temp Files Using Java NIOMinimum Java Version 1.7
- Escape User Inputs in SQL QueriesMinimum Java Version 1.1
- Hide Default Constructor In Utility ClassesMinimum Java Version 1.1
- Insert Break Statements in For-loopsMinimum Java Version 5
- Make Fields And Variables FinalMinimum Java Version 1.1
- Make SerialVersionUID Static FinalMinimum Java Version 1.1
- Organize ImportsMinimum Java Version 1.1
- Rearrange Class MembersMinimum Java Version 1.1
- Reformat CodeMinimum Java Version 1.1
- Remove Boxing for String ConversionsMinimum Java Version 1.1
- Remove Collection::addAllMinimum Java Version 1.2
- Remove Deprecated Date ConstructsMinimum Java Version 1.1
- Remove Double NegationsMinimum Java Version 1.1
- Remove Explicit Call To super()Minimum Java Version 1.1
- Remove Explicit Type ArgumentMinimum Java Version 7
- Remove Inherited Interfaces from Class DeclarationMinimum Java Version 1
- Remove Lambda Expression BracesMinimum Java Version 8
- Remove Modifiers in Interface PropertiesMinimum Java Version 1.1
- Remove Null-Checks Before InstanceofMinimum Java Version 1.1
- Remove Redundant CloseMinimum Java Version 7
- Remove Redundant Type CastsMinimum Java Version 1.1
- Remove toString() on StringMinimum Java Version 1.1
- Remove Unnecessary SemicolonsMinimum Java Version 1.1
- Remove Unnecessary Thrown Exceptions on Method SignaturesMinimum Java Version 1.1
- Remove Unused FieldsMinimum Java Version 1.1
- Remove Unused Local VariablesMinimum Java Version 1.1
- Remove Unused MethodsMinimum Java Version 1.1
- Remove Unused Parameters in Private MethodsMinimum Java Version 1.1
- Remove Unused TypesMinimum Java Version 1.1
- Rename FieldsMinimum Java Version 1.1
- Reorder ModifiersMinimum Java Version 1.1
- Reorder String Equality CheckMinimum Java Version 1.1
- Replace Assignment with Compound OperatorMinimum Java Version 1.4
- Replace Collection.sort with List.sortMinimum Java Version 8
- Replace Concatenation with Infix-OperationMinimum Java Version 1.1
- Replace Equality Check with isEmpty()Minimum Java Version 6
- Replace equals() on Enum ConstantsMinimum Java Version 5
- Replace Expression Lambda with Method ReferenceMinimum Java Version 8
- Replace For-Loop with Enhanced-For-LoopMinimum Java Version 5
- Replace For-Loop with Iterable::forEachMinimum Java Version 8
- Replace For-Loop with Stream::collect(Collectors.joining())Minimum Java Version 5
- Replace For-Loop with Stream::findFirstMinimum Java Version 8
- Replace For-Loop with Stream::MatchMinimum Java Version 8
- Replace For-Loop with Stream::sumMinimum Java Version 8
- Replace For-Loop with Stream::takeWhileMinimum Java Version 9
- Replace indexOf() with contains()Minimum Java Version 5
- Replace Inefficient Constructors with valueOf()Minimum Java Version 5
- Replace JUnit 3 TestsMinimum Java Version 8
- Replace JUnit 4 Annotations with JUnit JupiterMinimum Java Version 5
- Replace JUnit 4 Assertions with JUnit JupiterMinimum Java Version 8
- Replace JUnit 4 Assumptions with JUnit JupiterMinimum Java Version 8
- Replace JUnit 4 Category with JUnit Jupiter TagMinimum Java Version 8
- Replace JUnit assertThat with HamcrestMinimum Java Version 5
- Replace JUnit Assumptions with Hamcrest JUnitMinimum Java Version 5
- Replace JUnit Expected Annotation Property with assertThrowsMinimum Java Version 8
- Replace JUnit ExpectedException with assertThrowsMinimum Java Version 8
- Replace JUnit Timeout Annotation Property with assertTimeoutMinimum Java Version 8
- Replace Map::get by Map::getOrDefaultMinimum Java Version 8
- Replace Multi Branch If By SwitchMinimum Java Version 14
- Replace Nested Loops with flatMapMinimum Java Version 8
- Replace put(..) with putIfAbsent(..)Minimum Java Version 8
- Replace removeAll() with clear()Minimum Java Version 1.2
- Replace Request Mapping AnnotationMinimum Java Version 5
- Replace Set.removeAll With ForEachMinimum Java Version 8
- Replace static final Collections with Collections.unmodifiable…()Minimum Java Version 2
- Replace Stream.collect() by Stream.toList()Minimum Java Version 16
- Replace String.format by String.formattedMinimum Java Version 15
- Replace While-Loop with Enhanced For-LoopMinimum Java Version 5
- Replace Wrong Class for LoggerMinimum Java Version 1.1
- Reuse Random ObjectsMinimum Java Version 1.1
- Shift AssertJ Description Before AssertionMinimum Java Version 7
- Split Multiple Variable DeclarationsMinimum Java Version 1.1
- StringBuffer() to StringBuilder()Minimum Java Version 5
- System Out To LoggingMinimum Java Version 1.1
- Use @Override AnnotationMinimum Java Version 6
- Use Arrays StreamMinimum Java Version 8
- Use BufferedReader::linesMinimum Java Version 8
- Use Collections Singleton ListMinimum Java Version 1.3
- Use Comparator MethodsMinimum Java Version 1.8
- Use Dedicated AssertionsMinimum Java Version 5
- Use Dedicated AssertJ AssertionsMinimum Java Version 8
- Use equals() on Primitive ObjectsMinimum Java Version 1.1
- Use Factory Methods for CollectionsMinimum Java Version 9
- Use Files.newBufferedReaderMinimum Java Version 7
- Use Files.newBufferedWriterMinimum Java Version 7
- Use Files.writeStringMinimum Java Version 11
- Use Functional InterfacesMinimum Java Version 8
- Use Guard ConditionMinimum Java Version 1.1
- Use Java RecordsMinimum Java Version 16
- Use Local Variable Type InferenceMinimum Java Version 10
- Use Multi CatchMinimum Java Version 7
- Use Offset Based String MethodsMinimum Java Version 1.1
- Use Optional::ifPresentMinimum Java Version 8
- Use Optional::ifPresentOrElseMinimum Java Version 8
- Use Optional::mapMinimum Java Version 8
- Use Optional::filterMinimum Java Version 8
- Use Parameterized JPA QueryMinimum Java Version 1.1
- Use Parameterized LDAP QueryMinimum Java Version 1.3
- Use Parameterized QueryMinimum Java Version 1.1
- Use Pattern Matching for InstanceofMinimum Java Version 16
- Use Portable NewlineMinimum Java Version 5
- Use Predefined Standard CharsetMinimum Java Version 1.7
- Use SecureRandomMinimum Java Version 1.2
- Use Stream::collectMinimum Java Version 8
- Use Stream::filterMinimum Java Version 8
- Use Stream::mapMinimum Java Version 8
- Use String JoinMinimum Java Version 8
- Use String LiteralsMinimum Java Version 1.1
- Use StringBuilder::appendMinimum Java Version 5
- Use StringUtils MethodsMinimum Java Version 1.1
- Use Switch ExpressionMinimum Java Version 14
- Use Text BlockMinimum Java Version 15
- Use Try-With-ResourceMinimum Java Version 7
jSparrow in-depth
Other development environments are:
Maven, GitHub
jSparrow is a plugin for Eclipse IDE, Maven, and GitHub.
However, jSparrow for Maven
and GitHub is
currently only available through contacting us. You’ll work
tightly with one of
our
inhouse-developers because of potential library
restrictions.
Additionally, we
are currently working
on introducing jSparrow to Visual Studio Code. This page
‘About jSparrow’ will
only include the
technical specification of the jSparrow Eclipse IDE plugin.
jSparrow’s Pipeline consists of:
- Prepare to refactor
- Perform refactoring on working copy
- Commit refactoring on “finish”
For each selected Java source file, a new state is created.
Each state consists of
the original file
and a working copy that is subsequently analyzed with the
refactoring rules.
jSparrow then iterates
over all the states, parses each working copy, and applies
all the selected rules
to it.
The working
copies are then parsed and adjusted after each rule
execution. Important: on
this step, the
original sources remain intact. As a final step, the
developer can (un)select
changes and, when
ready, click on “finish” the computed refactorings are
persisted on the original
sources.
Some
refactoring rules have requirements e.g. minimum Java
version, thus jSparrow’s
pipeline contains
functionalities to discard or recompute the refactoring of
certain rules on
certain files.
jSparrow UI description
The UI provides an interactive refactoring process at each step of the pipeline.
The UI components of the jSparrow Eclipse Plugin include:
• The jSparrow dashboard, which automatically opens as a
tab and is a way for us to communicate new
releases and special offers
• jSparrow extension points i.e. in the context menu, in
the
toolbox, and in the
Eclipse preference page.
• (On file, right click) The jSparrow Select Rules
wizard
serves for choosing
the rules for refactoring, or for providing the
configuration required for Field
Renaming, Standard
Logger, or Removing Unused Code rule.
• (After applying rules) The Preview wizard serves for
reviewing,
selecting, or
deselecting the computed refactoring. The Preview wizards
includes a diff view so that you can review the original and
the refactored files.
• (In the code editor) jSparrow markers and its
refactoring suggestions.
• The jSparrow Preference page and its subpages, i.e.,
Profiles,
License, and Markers.
• Other dialog boxes, e.g., informational dialog
boxes.
Rule Profiles possibilities include:
Categorizing Rules
jSparrow Eclipse Plug-in gives users the ability to group
rules in profiles
for easier application of desired rules. This was created to
allow individual preferences and to
support companies’ standards.
Rules can be grouped into profiles to ease the search when
applying. To create a new profile with
desired rules choose the Preferences option in the Window
menu.
To create a new profile choose the Selected profile option
and click on the New… button. The field
“Name” is mandatory and has to be unique. On the left side,
a
list of all the possible rules is displayed. Select and add
all rules you want to
have in your new profile. At least one rule has to be added.
How
to add Profiles
Markers description:
Quick-fixes
The jSparrow Markers make use of the JDT support for
so-called Quick Fixes. Markers give the users
ability to click on and choose an automatic fix to various
problems. The jSparrow Markers work like
the Quick Fixes of Sonarlint and JDTSpelling.
There are currently 92 jSparrow Markers
available. Markers are not enabled on default; To activate a
marker go to Eclipse’s preference page -> Markers and
then
select markers you want.
Markes are included for free in the base product and are
available after restarting Eclipse IDE after installing
jSparrow.
How
to de-activate Markers
Logging description:
Interactive Rule
The ‘System out to logging’ rule is an interactive Rule and
it introduces the replacement of System.out statements
(println, error, e.printstacktrace) with a logging
statement.
This rule requires the configuration of a logging
environment (log4j, slf4j).
Interactive Rules can only be used with a Premium License.
Configurations
Remove Unused Code description:
Interactive Rule
The ‘Remove Unused Methods
‘ rule is an interactive Rule which finds type of
declarations that are never used
and removes them. Users can choose to remove types that are
only used in test sources, together with their corresponding
tests. Any annotation except for @Deprecated and
@SuppressWarnings prevents the type declaration from being
considered unused.
Interactive Rules can only be used with a Premium License.
Configurations
Rename Fields description:
Interactive Rule
The ‘Rename Fields
‘ rule is an interactive Rule.
This rule finds fields that do not comply with the Java
Naming Conventions and renames them according to your
choices.
Interactive Rules can only be used with a Premium License.
Configurations
Technical FAQs
-
A jSparrow rule is a definition of many small composed refactoring steps performed by jSparrow. One rule by itself can only change a very specific area within your code.
E.g., the ‘Use Functional Interface’ rule transforms anonymous classes to lambda expressions when possible.
Free Trial
The more rules you apply to your project, the more significant the changes to your code will be.All jSparrow rules are described and illustrated with code examples in the jSparrow documentation space.
-
The jSparrow Eclipse Plugin (JEP) is the integration of jSparrow in the Eclipse IDE. JEP has a rich user interface and allows customers to have full control over the refactorings they perform on the source base. JEP is available in Eclipse Marketplace and is compatible with all the latest Eclipse versions starting from Eclipse Photon.
-
jSparrow focuses on providing ready-to-use well-tested refactoring rules. We are open to recommendations. If any customer request is considered a fine addition to our existing rule-set it will be prioritized on our roadmap.
-
-
The jSparrow Maven Plugin (JMP) is a continuous integration tool to apply automatic refactorings. JMP provides a standalone version of jSparrow which contains nearly the same functionalities as the jSparrow Eclipse Plugin but works without an UI. The necessary configurations can be provided through yml files.
-
Yes, you can include the jSparrow Maven Plugin in a Jenkins build process. The configuration is highly customizable and depends very much on your environment. For more information, see Integrating jSparrow Maven Plugin in Jenkins.
-
-
The jSparrow GitHub Cloud App (MVP) Creates a pull request to GitHub which invokes jSparrow – Rest POST call which sends url to git and which changeset to check. jSparrow then fetches code from GitHub using the JGit library and GitHub App authentication. Then jSparrow makes changes to the code which gets pushed back to GitHub using the JGit library.
-
The new Java 6-month release cadence has shown to be successful at least regarding the introduction of new modern language features to the Java language. For example, Java Records, Pattern Matching for Instanceof, Text Blocks, and Switch Expressions are now formalized as standard features. Many more new APIs and internal JDK improvements are released and will continue to be released with each semiannual JDK update.
By upgrading to the latest JDK, one may immediately get a more efficient, more secure, and lighter JVM. Additionally, this opens the possibility to employ the new language features into the existing source base. For example, by using automated refactoring tools, a fair amount of old language constructs like Anonymous Classes, Switch statements, Try-Catch statements, etc, can be replaced with more up-to-date alternatives like Lambda Expressions, Switch Expressions, Try-With-Resources, etc. On the other hand, by delaying the upgrade, users would deprive themselves of the important improvements on the late JDK versions. Thus, accumulating more technical debt.
-
A refactored code is simpler, and it does increase system responsiveness. Users can operate faster and have reduced waiting times and error messages. Another benefit is also reduced power consumption. Many case studies repeatedly prove that refactoring leads to improved performance for systems, with all the added benefits such as higher work efficiency, saved resources, and optimized budgets and costs. Particularly in Java, some new language constructs are more efficient than their outdated alternatives.
-
Nowadays, agile software development is prevalent and dominant, and agile teams are extending their code from one release to another. However, without continuous refactoring, such a process is hard to maintain: it becomes more and more challenging to operate on a code that otherwise could become intensely cluttered, hard to read, and unorganized. It also creates unhealthy, unstructured dependencies from packages and classes, overly significant dependencies on specific classes, and bad allocations of class responsibilities. And these are just some of the most common hundreds of issues that arise from unclear and disorganized code.
The extreme programming (XP) practices, which are part of the Agile frameworks used by IT companies, also exclusively include the following list of steps, which also involve refactoring:
- Code Unit test first
- Pair program
- Setup a dedicated integration computer (build machine)
- Run acceptance tests
- Refactoring
-
With Java’s evolution and the new features introduced, coding standards have changed. Lambdas and streams were game-changers in Java 8. Later on, Java 9 brought significant features which not only helped developers to modularize the code but also improved the performance of the JVM and added more modern language flavors to Java. Let’s take an example from a real world project and see how we can transform it into today’s Java:
Code example from real world project The purpose of this code is to generate a list of String values from a given input and concatenate them into one single value. A while loop is used to iterate through all elements of the generated list and append them into a StringBuilder. In the end, the StringBuilder is converted into a single String value and returned.
StringBuilder sb = new StringBuilder();List< String> list = generateList(input);int i = 0; while (i< list.size()) {String t = list.get(i);sb.append(t); i++; } return sb.toString();
Transform the while loop into an enhanced for-loop The first improvement we can do to this code, is to eliminate some boilerplate code by transforming the while loop into an enhanced for loop (introduced since Java 5). Internally, the javac compiler converts the enhanced for-loop into a while loop with an iterator. The performance of this code is not going to be affected by this transformation.
StringBuilder sb = new StringBuilder();List<String> list = generateList(input);for(String t : list) {sb.append(t); } return sb.toString();
Transform the enhanced for-loop into a stream We can continue further and simplify the code by converting the enhanced for-loop into a stream. Arguably, the cost of creating the stream will pay off when working with large collections.
StringBuilder sb = new StringBuilder();List<String> list = generateList(input);list.forEach(t -> sb.append(t));return sb.toString();
Use method references The lambda expression in the forEach can be further simplified into a method reference.
StringBuilder sb = new StringBuilder();List<String> list = generateList(input);list.forEach(sb::append); return sb.toString();
Using String Joiner The code above is still using a StringBuilder for the sole purpose of concatenating the values of a list. Since the concatenation of the values does not contain any complex logic, we can simplify the code further by using a StringJoiner:
List<String> list = generateList(input);return String.join("", list);
See Another Example (YT Video) -
Please go to jSparrow documentation space to see a detailed step-by-step description.
-
-
Automatic code refactoring is to increase code quality automatically rather than manually. Automatic refactoring usually happens in the IDE environment or in the dev-ops tool chain where a developer can highlight a code. It can also be taken further by replacing old language constructs with new up-to-date alternatives, resolving security issues, eliminating duplicates, eliminating usages of deprecated code, migrating the versions of third-party libraries, changing the name of methods, renaming argument variables, or reducing the number of arguments.
jSparrow is the only tool capable of automatically refactoring your code.
Pricing-
Also known as Merciless refactoring or the Boy scout rule: a refactoring that is ceaseless and integrated into the work of a developer’s team. The boy scout rule states that you have to leave the playground cleaner than you’ve found it.
In continuous refactoring, you include refactoring as part of your daily tasks, and you keep the balance between it and adding new features. This requires good team communication, good organization, and very often a ‘collective code’, where everybody can improve the work of somebody else. Many teams are worried about that approach because it also includes the risk of failing. It does, however, have the opportunity for continuous improvement, which could return huge benefits, such as high quality and low costs.
-
Refactoring is a process of restructuring and reordering an existing source code, without affecting its external forms of action and behavior. It usually does so by transforming functions and rethinking algorithms. In simpler terms, refactoring is changing software internally (code) without affecting the software externally (software UI, UX, etc.)
-
Get Started with jSparrow
Captain jSparrow
Install jSparrow for first-hand experienceNo hidden payments – no card required