Final Year Project Proposal: Code Smell Detection Using JAVA
Final Year Project Proposal: Code Smell Detection Using JAVA
<Submitted by>
AZHAR ZAFAR
HAMZA REHMAN
MUHAMMAD JAHANGIR
MUHAMMAD USMAN JUNAID
<Supervisor>
ISRAR ALI
<Coordinator>
LM Long Method
FE Feature Envy
DC Data Class
QA Quality Assurance
Flowchart:
Section – 1
Reg #: 43714
CGPA: 2.9
Reg #: 43430
CGPA: 3.03
Reg #: 41574
CGPA: 2.5
Academic Organizations:
# Organization Name Role / Contribution
1. Iqra university Resources and supervision
2.
Funding Organizations:
# Organization Name Role / Contribution
1. None None
2.
Key Words:
Project Status:
[✓] New [ ] Modification to previous Project
[ ] Extension of existing project
The Problem:
As a software system evolves over time, it becomes more difficult to maintain. Its design
grows increasingly complex and difficult to follow. Developers spend more than 60% of
their time understanding the code before proceeding with maintenance, resulting in major
costs; as a result, it is important to rearrange the code on a regular basis. When rewriting
code, the most important thing is to verify that the program behaves the same way it did
Refactoring can be overwhelming when it comes to detecting and removing code smells.
Without sufficient expertise and knowledge of the software's design, the chances of
breaking the code and damaging the design are considerable. Refactoring might
inadvertently modify software functionality if done incorrectly. When refactoring is done
correctly, it not only maintains software behavior but also avoids the introduction of new
bugs.
In this project, we focus our attention on code smells and on automatic tools Developed
for their detection Coding smells are structural features of software that can suggest a
code or design issue, making it difficult to improve and maintain. Fowler [Fow99], who
specified 22 different types of smells, first presented the term.
Synopsis:
The main goal for this project is to develop a prototype for the detection and presentation
of code smells in Java source code. Refactoring is a software engineering technique that
is used for restructuring existing source code, altering its internal structure without
changing its external behavior. By applying a series of small behavior-preserving
transformations, a software system’s design, readability and extensibility can be
improved. Code smells are signs that indicate that source code might need refactoring.
Target market for project is The complexity of software systems is rapidly increasing,
which leads software houses to anticipate continuous change. Developers spend more
than 60% of their time understanding the code before proceeding with its maintenance,
leading to massive costs.
These expenses can be reduced by detecting and eliminating code smells in the early
stages of development, help for java developer and automated detect smells in code.
2.1 Introduction
Throughout the Software Design Life Cycle, software undergoes different modifications
(SDLC). By introducing undesired design flaws into the code, these changes cause it to
decrease in quality. In the early stages of the SDLC, developers usually pay little
attention to the overall architecture and system design. Most developers look for quick
and easy solutions for defects rather than an overall system design at later stages of
quality analysis (QA) and maintenance. This is due to a combination of inexperience,
deadline pressure, and management's perception of budgets. Effort spent in improving
system design can be perceived as an upfront cost with little short-term return when
compared to a quick bug fix, even though its long-term payback in terms of reduced
maintenance costs can be worthwhile. These problems lead to the introduction of
various design flaws, which are called code smells. According to Beck, Brant, Fowler,
Opdyke, & Roberts (2000), there are 22 code smells in object-oriented source codes.
Code Smells:
The term “Code Smell” appears to have been coined by Kent, Beck in the late 1990s
(Roperia, 2009). Let us consider an example to understand the meaning of code smell.
An unusual long method in an object-oriented programming language like Java might
indicate a “Long Method” smell. It indicates lack of understanding of or disregard for a
proper object design and the use of simple procedural programming in an object-
oriented language. This is a very common sign of code smell in object-oriented
language. In rare cases this could be normal, but most likely such long-winded methods
perform too much functionality thus making it difficult to understand and maintain. To
solve this problem, such methods should first be split into smaller methods or functions
to promote reusability. As a second step, if an object-oriented language is being used,
the object model should be reviewed as well. However, that does not mean that a long
method is always a code smell problem – it is most likely an indicator of a design issue
in the software than of a problem.
Refactoring:
Refactoring is a solution to the problem that is indicated by code smell. It's a method of
applying a better design to an already-existing, fully or partially functional software
program. It has a higher up-front cost than fast fixes and repair, but the long-term
advantages can be great. Refactoring is a more cost-effective solution than a total
program redesign. Large software is usually designed and tested over a long period of
time. A comprehensive rewrite needs again another lengthy development and testing
cycle. Refactoring existing code allows you to improve the software design and eliminate
code smells without having to build from zero.
The ability to detect code smells correctly is essential for developing a reworking
strategy. The quality of code will improve if the plan is implemented correctly. The
refactoring process is affected by the system's smells, and it has a direct impact on
software maintenance costs. There are a total of 72 refactoring approaches, which are
divided into seven categories (Lassenius, Mantyla, & Vanhanen, 2003). One or more of
these refactoring techniques can be used depending on the code smell. If a class has
been recognized as carrying the "Data Class" smell, we can use the "Extract Method"
approach first, then the "Move Method" from the client class to the data class if the client
class method has several capabilities; otherwise, we can use just the "Extract Method"
technique.
The main objective, which leads us in the development of this project, is Code smell
detection tools could help developers to maintain software quality by applying different
techniques for detecting code smells, and refactoring the some type of smell. Code smell
detection is a tool that analyses Java source code and detects code smell automatically.
The functionality of CSD is limited to detecting five code smells.
2.3 Benefits
Expected Outcomes:
The expected outcome for this project will be a user-friendly tool for anyone and this
project is Code smell detection tools could help developers to maintain software quality.
Key Benefits:
• Code smells point out the developer mistakes, which directly not affect the output
but violate the design principle.
• Code Smells point out the certain points in the source code where developer
violates the rules or laws of designing during development.
• The key benefit of this project is the Easy to understand when software update or
modifications save times improve maintenance and readability.
If a method is long, splitting it into smaller methods is actually a refactoring technique that
improves the design of the source code, making it easier to understand, enhance, and
maintain. To better understand and emphasize the importance of refactoring, we can take
“Duplicate Code” smell as an example. Duplicate code is not just a design issue; it also
leads to incorrect calculations and redundant code and data. Therefore, to ensure the
software works as per specification, it is necessary to refactor duplicate lines of code into
smaller, more manageable methods and invoke these methods from the client code. Thus,
Fowler and Beck defined code smells as symptoms in the source code indicating that
there may be deficiencies in the design and/or programming style of a software system.
They proposed a catalog of 22 code smells to be used as indicators of poor design and
implementation choices. As a catalog, these code smells can also serve as a vehicle to
express what should be avoided to obtain good style and modularity in object-oriented
programming. Code smells usually appear during change activities and when software
bugs are fixed. To tackle this problem, approaches and tools were implemented to support
the identification of code smells.
Table 1. List of Code Smells according to Fowler and Corresponding Alternative Names.
Several tools are available to help detect code smells in program written in various
languages. In this study, we conduct a systematic literature review of published studies
(SLR). The influence of code smells on the occurrence of defects was reported in 16 of
the 18 research that were chosen. We identified 24 code smells with larger influence on
defects based on the analysis of these 16 research, particularly God Class, Comments,
Message Chains, and Feature Envy code smells. It was also possible to identify tools,
techniques, and resources that were used by several studies.
Refactoring Tools:
In early 1990s, Don Roberts and his colleagues developed a refactoring tool called the
Smalltalk Refactoring Browser [76]. This refactoring browser allows the user to perform
many interesting refactoring is automatically (e.g., Rename, Extract/Inline Method,
Add/Remove Parameter). However, this early tool was not popular because it was a
stand-alone tool separate from the integrated development environment (IDE).
Developers found it inconvenient to switch back and forth between the IDE (develop code)
and Refactoring Browser (refactor code).Thus later refactoring tools have been integrated
in the IDEs. The following are refactoring tools for Java.
IntelliJ IDEA:
RefactorIt:
RefactorIt is a commercial software that supports many automatic refactoring’s. It can
cooperate with Sun 1 Studio, Oracle 9i JDeveloper and Borland JBuilder. The supported
refactoring’s are: Rename, Move Class, Move Method, Encapsulate Field, Create Factory
Method, Ex-tract Method, Extract Superclass/Interface, Minimize Access 9Rights, Clean
Imports, Create Constructor, and Pull Up/Push down Members.
JRefactory:
JRefactory is a tool that is first developed by Chris Seguin. However, Mike Atkinson has
taken over the leadership role since late 2002. This tool allows easy application of
refactorings by providing user interface based on UML diagrams as visualization of Java
classes. It can cooperate with JBuilder and Elixir IDEs. JRefactory supports the following
refactoring’s: Move Class, Rename Class, Add an Abstract Superclass, Remove Class,
Push up Field, Pull Down Field, Move Method.
JFactor:
JFactor for VisualAge Java is a commercial product that provide a set of refactoring’s.
Extract Method, Rename Method Variables, Introduce Explaining Variable, Inline Temp,
Inline Method, Re-name Method, Pull Up/Push Down Method, Rename Field, and Pull
Up/Push Down Field, Encapsulate Field, Extract Superclass/Interface.
Eclipse:
Eclipse is a generic development environment by IBM. It also has refactoring support and
some analysis. This project is open source. The current version of Eclipse (Helio version
3.6.1) supports many types of refactoring’s which include Move Method, Rename
Method, Encapsulate Fields and etc.
Refactoring Tools
IntelliJ RefactorIt JRefactory JFactor Eclipse My Project
Technique/ IDEA (Code Smell
Method detection
using JAVA)
Extract Yes Yes No Yes Yes Yes
Method
In Line Yes No No Yes Yes Yes
Method
Replace No No No No No Yes
Method
Replace
temp with No No No No No Yes
Query
Move No Yes Yes No Yes Yes
Method
Push Down Yes Yes Yes Yes Yes Yes
Method
Rename Yes Yes Yes Yes Yes No
Method
Encapsulate Yes Yes No Yes No Yes
Field
Pull Up Yes Yes Yes Yes Yes No
Method
Create No Yes No No No No
Constructor
Extract Super No
classes Yes Yes No Yes Yes
Replace
Parameter
with Explicit No No No No No Yes
Methods
Replace
Delegation Yes No No No No Yes
with
Inheritance
Abstract
Super Class No No Yes No No No
Remove No No Yes No No Yes
Middle Man
Summary:
Code smell detection is a very complex procedure. Careful design analysis of the
Software system is required for detecting the code smell. It is believed that human intuition
is the best way to detect code smell (Roperia, 2009); however, detection becomes more
difficult as system size increases. This creates the need for automated detection,
especially for larger systems. The automatic detection of code smell can be done using
statistical data analysis. However, the detection of all of the 22 smells using statistical
data is not possible (Bhalla, 2009).
https://www.researchgate.net/publication/320262316_On_the_evaluation_of_code_smells_and_d
etection_tools
https://jserd.springeropen.com/articles/10.1186/s40411-017-0041-
1#:~:text=In%20this%20study%2C%20we%20analyze,are%20presented%20and%20discussed%
20below.
https://homepages.cwi.nl/~storm/teaching/reader/LieberherrHolland89.pdf
Section – 4
For our project, we will be using Agile Development Model. The Agile Development
Model refers to an approach to software development based on an iterative approach to
software delivery that, instead of trying to deliver all at once, develops software
incrementally from the beginning of the project. Agile strategies split projects into smaller
iterations or modules that do not require long-term preparation directly. At the start of
the planning process, the project scope and requirements are laid down. Plans are
specifically defined in advance about the number of iterations, the duration, and the
scope of each iteration.
Final Year Project Proposal Page 14 of 28
In the Agile method model, each iteration is regarded as a short time "frame" which
usually lasts from one to four weeks. The division of the whole project into smaller parts
helps to minimize the risk of the project and to reduce the overall criteria for project
delivery time. Each iteration requires a team working through a complete life cycle of
software development, including planning, analyzing requirements, design, coding, and
testing before the client is shown a working product.
In the Agile model, steps involve:
Our tool analyzes Java source code to detect code smell automatically. Our tool
functionality is limited to the detection of five code smells: “Switch Cases,” “Data
Class,” “Middle Man,” “Long Parameter List,” and “Long Method”.
Implementation Platform:
Code Smell Detection is implemented in Java and uses the Abstract Syntax Tree
(AST) parser. Abstract syntax tree is the tree structure representation of the source
code in any programming language. Each node of the syntax tree represents a part of
the abstract syntactic structure of the source code.
Elapsed time
S.
since start of Milestone Deliverable
No.
the project
Group Creation and Proposed
Submission of Group,
1. Week 01 – 04 idea + abstract + design
Proposal, An Approval
Flowchart
Write Project Introduction,
Related Website research
2. Week 05 – 08 Problem Statement and
and evaluate
Literature Review
Write Research approach,
Research Methodology,
3. Week 09 – 12 Milestone and design Milestone
Project Use case, ERD
chart.
Write Functional and Non
Functional Requirements, and
Diagrams and Design and
4. Week 13 – 16 Design Use cases and ERD’s
budgeting
Business canvas model,
Budgeting
Prototyping, poster and
5. Week 17 – 20 Final Report and Poster
Complete Project Report
6. Week 25 – 24 Working on implementation code
Designing and
7. Week 25 – 28 Designing Code Implementation
Development
8. Week 29 – 32 UI Testing, Logic Testing Test System
Product Testing and end user A Product Set up of Test
9. Week 37 – 36
feedback System
Deployment/Delivery of
10. Week 37 – 40 Delivery of Product
Final product
Browse Source
Code File
Developer
Select Long Method
Smell
Refactor
Lack of team members Med High Tools for project management will be
cooperation used to support individual activities.
Laptop Issue High Serious Keep a laptop Backup
Section – 5
Team Structure:
Project Supervisor
Sir Israr Ali
Researcher
Team Leads
Azhar Zafar/Muhammad
Azhar Zafar
Jahangir
Developer Designer
Hamza Rehman/Azhar Zafar Usman Junaid
SQA
Azhar Zafar/Hamza Rehman
Bibliography
Anonymous. (n.d.). Gendarme Rules Smells. Retrieved April 10, 2011, from Mono-Project
ENTER
ESTIMATION
VARIABLES,
BELOW
Business Requirements
328 320
Functional Specifications
328 300
Detailed Design
408 399
Code and Unit Test
408 399
System Testing
328 322
User Acceptance Testing
328 322
Project Manager
168 201.60
-
Project Control Office
168 50
Project Management Office
168 252
COMPUTED
COMPUTED
TASK
WORK EFFORT
DURATION IN
IN DAYS
DAYS
40.0 13.3
37.5 18.8
49.9 4.5
49.9 4.5
41.0 10.3
258.5 61.5
25.2 61.5
21.0 61.5
31.5 61.5
ENTER RISK $
30%
CONTINGENCY 37,426.65
BASELINE
$
PROJECT COST
162,182
ESTIMATE
PROJECT
$
MINIMUM 30%
210,837
ESTIMATE
PROJECT
$
MAXIMUM 50%
243,273
ESTIMATE