3.2 Eclipse Components Used in
Subcontractor
Eclipse is a popular Integrated Development
Environment (IDE) with graphical user interfaces
that facilitates the development process. The main
language that is supported in Eclipse is Java, but
there are other languages such as C++, C#, Perl,
PHP, and JavaScript that can be supplemented using
plugins (Eclipse, 2017).
One reason for choosing Eclipse is that it is an
open source application that is built upon plugins.
Thus, it is more straightforward to extend an IDE
with a plugin than establishing a new IDE
implementing the functionality of Subcontractor. In
addition, according to RebelLabs’ report in 2012
(ZeroTurnaround, 2012), Eclipse is the most used
IDE for Java programming. Eclipse provides libraries
that have the benefit of accessing and modifying the
source code.
Figure 3 demonstrates the Eclipse architecture
and the relationships between the plugin
Subcontractor and Eclipse elements, which are
presented in the following subsections. Figure 3 is
based on the diagram that is presented in (Eclipse,
2017) with modification and extension to cover the
scope of Subcontractor.
3.2.1 Plugin Development Environment
One of the neat functionalities in Eclipse is
expandability. The user can add/extend a feature in
Eclipse by adding a plugin. The Plugin Development
Environment (PDE) is a plugin that can facilitate
building other plugins, features, and Rich Client
Platform (RCP) applications. When PDE is installed
in the Eclipse platform, new functionalities can be
added to support the plugin life cycle, such as
establishing, debugging, running, maintaining, and
publishing a plugin. As shown in Figure 3, PDE
extends the functionalities of JDT, and the
developed Subcontractor tool extends the
capabilities of PDE, JDT, and OpenJML. Plugins
can provide a variety of functional and non-
functional requirements such as testing,
diagramming, compiling, and more (Eclipse, 2017).
The Eclipse marketplace website (Eclipse
marketplace, 2017) has a myriad of plugins. The
main advantage of having plugins is that it makes
the component of this environment loosely coupled.
Moreover, it maintains lightweight core application,
since the user has the choice to install only the
needed plugins.
3.2.2 Java Development Tools
Subcontractor uses the core of Java Development
Tools (JDT) library to access and modify source
code. In JDT core, the source code is represented by
two different forms, a Java model or abstract syntax
tree (AST). AST is an alternative to the Document
Object Model (DOM) tree of an XML file. AST is
more informative than a Java model. As a result, it
takes longer to be created than the Java model
(Eclipse JDT, 2017). Subcontractor handles the
source code using AST because the other approach,
the Java model, does not contain enough details
about the source code. For example, in the Java
model, the name, signature, and return type of a
method can be retrieved. However, the content of
that method cannot be provided, which is an
important component for Subcontractor to analyze
and to find the if-statements and loop-statements.
In Subcontractor, the AST of the source code can
be traversed by extending ASTVisitor. Afterwards,
an ASTNode can be accessed using a visit() method.
Visitor pattern is one of the popular design patterns
in software engineering. The visitor pattern can be
used to represent an operation for different elements
instead of representing the same operation for every
element. One advantage of this pattern is that the
operation can be extended without changing the
elements. Another benefit of using the visitor pattern
is that the operation is separated from the structure
(Barclay and Savage, 2003).
Subcontractor uses OpenJML preconditions,
postconditions, and assert statements that reside in
comments. Comment, Expression, Statement and
VariableDeclaration are different types of an
ASTNode. According to Eclipse documentation
(Eclipse AST, 2004), the nodes in AST could be any
part of the code except the whitespaces and the
comments. In Subcontractor, it is problematic to deal
with comments since the AST is not preserving
information about the comments. This issue can be
addressed through calling accept() method for each
comment in the list that is returned from
getCommentList().
In Subcontractor, after forming the subcontracts,
the code needs to be edited to insert these
subcontracts. One approach to editing the abstract
syntax tree is prettyprinting, which is simple and
easy to implement, as it does not maintain the
locations of the comment and the source code in the
modification process. The second approach uses
textual edits. In this approach, each node has a
corresponding offset and length. When changes are
made, the modifications are applied to the AST