2 \documentclass[USenglish,9pt]{beamer}
3 \usepackage[utf8]{inputenc}
4 \usepackage[T1]{fontenc}
6 \usepackage{babel,textcomp}
7 \usepackage[style=alphabetic,backend=biber,doi=false,isbn=false]{biblatex}
8 \usepackage{babel,textcomp,csquotes}
14 \usetikzlibrary{shapes,snakes,trees,arrows,shadows,positioning,calc}
17 %\usepackage[hidelinks]{hyperref}
21 \usepackage{mathtools}
27 \usemintedstyle{default}
31 \theoremstyle{definition}
32 \newtheorem*{wordDef}{Definition}
33 \newtheorem*{mytheorem}{Theorem}
34 \newcommand{\mydefinition}[1]{\begin{wordDef}#1\end{wordDef}}
36 \newcommand{\citing}[1]{~\cite{#1}}
38 \newcommand{\code}[1]{\texttt{\textbf{#1}}}
39 \newcommand{\type}[1]{\code{#1}}
40 \newcommand{\method}[1]{\type{#1}}
41 \newcommand{\var}[1]{\type{#1}}
43 \newcommand{\name}[1]{#1}
44 \newcommand{\tit}[1]{\emph{#1}}
45 \newcommand{\refa}[1]{\emph{#1}}
46 \newcommand{\pattern}[1]{\emph{#1}}
47 \newcommand{\metr}[1]{\emph{#1}}
48 \newcommand{\ExtractMethod}{\refa{Extract Method}\xspace}
49 \newcommand{\MoveMethod}{\refa{Move Method}\xspace}
50 \newcommand{\ExtractAndMoveMethod}{\refa{Extract and Move Method}\xspace}
52 \newcommand{\mysection}[1]{
55 \begin{center}{\Huge #1}\end{center}
59 \def\mintedframesep{11pt}
61 \def\thetitle{Search-based Composed Refactorings}
62 \def\subtitle{Implementing and evaluating a search-based Extract and Move Method refactoring}
64 \author{Erlend Kristiansen, Volker Stolz}
68 \setbeamertemplate{headline}{%
69 \ifnum\insertframenumber>1
72 \begin{beamercolorbox}[wd=\paperwidth,ht=5ex,dp=1.125ex]{palette
74 \insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
81 \def\insertsectionnavigationhorizontal#1#2#3{%
83 \def\slideentry##1##2##3##4##5##6{}%
86 \setlength\tmp@parbox{#1}%
87 \addtolength\tmp@parbox{-.6cm}%
88 \parbox{\tmp@parbox}{\raggedleft%
89 \usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
90 \setbox\beamer@sectionbox=\hbox{}%
91 \ht\beamer@sectionbox=1.875ex%
92 \dp\beamer@sectionbox=0.75ex%
93 \hskip-1.875ex plus-1fill\dohead%
94 \box\beamer@sectionbox}\hfil\hskip.3cm%
99 \setbeamertemplate{navigation symbols}{}
101 \bibliography{bibliography/master-thesis-erlenkr-bibliography}
106 \frametitle{\thetitle}
108 % \vspace*{\baselineskip}
110 { \emph{Erlend Kristiansen, Universitetet i Oslo}}
114 { \emph{\underline{Volker Stolz, H\o gskolen i Bergen}}}
115 \vspace*{\baselineskip}
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 \frametitle{Outline and Motivation}
123 \item What are refactorings?
124 \item What are their problems?
125 \item How can we help?
126 \item Experiment and evaluation
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %\section{Definitions}
134 \frametitle{Refactoring, as defined in the literature}
137 \emph{Refactoring} (noun): a change made to the internal structure
138 of software to make it easier to understand and cheaper to modify without
139 changing its observable behavior.~{\bf [Fowler]}
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 \frametitle{Why are they necessary?}
147 \includegraphics[scale=0.3]{../nik2014/abs-motivation.png}
151 \item anecdotal evidence from our own project
152 \item ``refactoring smells'' that should be avoided by programmers
153 % \item (infrastructure developed here can be used for survey on repositories)
156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 \frametitle{An alternative definition of refactoring}
161 A \emph{refactoring} is a transformation
162 done to a program without altering its external behavior.
167 \frametitle{Primitive and composite refactorings}
169 A \emph{primitive refactoring} is a refactoring that cannot be expressed in
170 terms of other refactorings.
175 A \emph{composite refactoring} is a refactoring that can be expressed in
176 terms of two or more other refactorings.
182 \begin{frame}[fragile]
183 \def\charwidth{4.5pt}
184 \def\indent{2*\charwidth}
185 \def\rightColX{32*\charwidth*0}
186 \def\lineheight{\baselineskip}
187 \def\mintedtop{22.5pt}
189 \begin{minipage}[t]{0.45\textwidth}
190 \begin{tikzpicture}[overlay, yscale=-1]
191 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
193 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
194 +(16*\charwidth,2*\lineheight);
196 \begin{minted}[linenos,samepage,frame=topline,label={Bad},framesep=\mintedframesep]{java}
212 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
213 \begin{tikzpicture}[overlay, yscale=-1]
214 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
216 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
217 +(16*\charwidth,\lineheight);
219 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
220 +(19*\charwidth,4*\lineheight);
222 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
225 \begin{minted}[linenos,samepage,frame=topline,label={Good},framesep=\mintedframesep]{java}
248 \begin{frame}{What our refactoring is going to do for you}
250 \item Get rid of long navigation paths.
251 \item Move operations closer to the data they manipulate.
252 \item Reduce coupling.
253 \item Increase maintainability.
261 \mysection{The primitive refactorings}
263 \begin{frame}[fragile]
264 \frametitle{The Extract Method refactoring}
265 Extract a fragment of code into a new method.
267 \def\charwidth{4.5pt}
268 \def\indent{2*\charwidth}
269 \def\rightColX{32*\charwidth*0}
270 \def\lineheight{\baselineskip}
271 \def\mintedtop{6.5pt}
273 \begin{minipage}[t]{0.45\textwidth}
274 \begin{tikzpicture}[overlay, yscale=-1]
275 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
277 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
278 +(16*\charwidth,2*\lineheight);
280 \begin{minted}[linenos,samepage]{java}
289 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
290 \begin{tikzpicture}[overlay, yscale=-1]
291 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
293 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
294 +(16*\charwidth,\lineheight);
296 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*5) rectangle
297 +(19*\charwidth,4*\lineheight);
299 \draw[-latex,red] (-3,1.8) -- (-0.1,\mintedtop+\lineheight*6);
302 \begin{minted}[linenos,samepage]{java}
320 \begin{frame}[fragile]
321 \frametitle{The Move Method refactoring}
322 Move a method from one class to another.
324 \def\charwidth{4.5pt}
325 \def\indent{2*\charwidth}
326 \def\rightColX{32*\charwidth*0}
327 \def\lineheight{\baselineskip}
328 \def\mintedtop{6.5pt}
330 \begin{minipage}[t]{0.45\textwidth}
331 \begin{tikzpicture}[overlay, yscale=-1]
332 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
334 \draw[overlaybox] (0,\mintedtop+\lineheight*5) rectangle
335 +(19*\charwidth,4*\lineheight);
337 \begin{minted}[linenos,samepage]{java}
352 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
353 \begin{tikzpicture}[overlay, yscale=-1]
354 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
356 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
357 +(16*\charwidth,\lineheight);
359 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
360 +(19*\charwidth,4*\lineheight);
362 \draw[-latex,red] (-2.8,2.9) -- (-0.1,\mintedtop+\lineheight*9.5);
365 \begin{minted}[linenos,samepage]{java}
386 \mysection{The Extract and Move Method refactoring}
388 \begin{frame}[fragile]
389 \def\charwidth{4.5pt}
390 \def\indent{2*\charwidth}
391 \def\rightColX{32*\charwidth*0}
392 \def\lineheight{\baselineskip}
393 \def\mintedtop{22.5pt}
395 \begin{minipage}[t]{0.45\textwidth}
396 \begin{tikzpicture}[overlay, yscale=-1]
397 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
399 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
400 +(16*\charwidth,2*\lineheight);
402 \begin{minted}[linenos,samepage,frame=topline,label={Before},framesep=\mintedframesep]{java}
418 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
419 \begin{tikzpicture}[overlay, yscale=-1]
420 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
422 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
423 +(16*\charwidth,\lineheight);
425 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
426 +(19*\charwidth,4*\lineheight);
428 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
431 \begin{minted}[linenos,samepage,frame=topline,label={After},framesep=\mintedframesep]{java}
455 \def\secondlevelmark{\textbullet}
457 \item Composed of \ExtractMethod and \MoveMethod.
458 \item Conceptually, one ``atomic'' operation.
460 \item Implemented as an Eclipse plugin.
462 \begin{itemize} \itemsep3pt
463 \item[\secondlevelmark] The primitive refactorings are supplied by the
465 \item[\secondlevelmark] The composition work had to be done by us.
466 \item[\secondlevelmark] Not seamless (find the extracted method, move
475 %\mysection{Research questions}
478 Main research question:
480 Is it possible to automate the analysis and execution of the
481 \ExtractAndMoveMethod refactoring, and do so for all of the code of a larger
487 \item Can we do this efficiently?
488 \item Can we perform changes safely?
489 \item Can we improve the quality of source code?
490 \item How can the automation of the refactoring be helpful?
497 \begin{frame}[fragile]{Automating the refactoring}
498 For any given method: We want to find the best candidate for the
499 \ExtractAndMoveMethod refactoring, if any exist.
501 \begin{minipage}[b]{0.33\textwidth}
503 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
504 \def\charwidth{4.5pt}
505 \def\indent{2*\charwidth}
506 \def\rightColX{32*\charwidth*0}
507 \def\lineheight{\baselineskip}
508 \def\mintedtop{6.5pt}
510 \begin{tikzpicture}[overlay, yscale=-1]
511 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
512 \draw[overlaybox] (0,\mintedtop+\lineheight*3) rectangle
513 +(16*\charwidth,2*\lineheight);
515 \node[draw opacity=0, text=red] at (20*\charwidth,\mintedtop+\lineheight*4)
516 {\fontsize{40}{60}\selectfont ?};
518 \begin{minted}[samepage]{java}
532 \begin{frame}[fragile]
533 \begin{minipage}[t]{0.5\textwidth}
534 \def\charwidth{4.75pt}
535 \def\indent{2*\charwidth}
536 \def\lineheight{\baselineskip}
537 \def\mintedtop{5.8pt}
539 \begin{tikzpicture}[overlay, yscale=-1]
540 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
541 \draw[overlaybox] (2*\indent,\mintedtop+12*\lineheight) rectangle
542 +(14*\charwidth,2*\lineheight);
544 \draw[overlaybox] (9*\charwidth,\mintedtop+\lineheight) rectangle
545 +(\charwidth,\lineheight);
547 \node[draw opacity=0, text=red] at (12.1*\indent,\mintedtop+12.9*\lineheight)
550 \node[draw opacity=0, text=red] at (11.5*\indent,\mintedtop+4*\lineheight)
553 \draw[-latex,red] (11.5*\indent-5*\charwidth,\mintedtop+3.7*\lineheight) --
554 (10.2*\charwidth,\mintedtop+1.5*\lineheight);
557 \begin{minted}[linenos,samepage]{java}
559 A a; B b; boolean bool;
560 void method(int val) {
579 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
582 A \textbf{candidate} consists of a \emph{text selection} and a \emph{move
585 A \textbf{valid text selection} is a text selection that contains all of one
586 or more consecutive program statements. It is the input to the \ExtractMethod
589 A \textbf{move target} is a variable (local or field), whose type is the
590 destination class in the \MoveMethod refactoring.
599 \frametitle{Searching}
600 Usually, search-based refactoring is based on metrics.
602 \item Refactor a lot.
603 \item Choose the best candidate based on measurements.
606 Our refactoring is based on heuristics.
608 \item Up-front analysis.
609 \item A set of assumptions defining what is considered the best candidate.
610 \item No need to actually perform changes (before deciding).
611 \item Search through all valid selections to find the best candidate.
618 \frametitle{Choosing a refactoring candidate}
620 \item Search through all selections to find the possible candidates.
621 \item Find the best move target for all the candidates.
622 \item Choose the best among the possible candidates.
623 \item Based on the lengths of the navigation paths and the occurrence
629 \begin{frame}{Case studies}
630 Case studies performed on the \code{org.eclipse.jdt.ui} and
631 \code{no.uio.ifi.refaktor} projects. The resulting code was analyzed with
633 \vspace*{\baselineskip}
635 The Eclipse JDT UI project:
637 \item Over 300,000 lines of code.
638 \item 2,552 methods out of 27,667 methods chosen to be refactored.
639 \item Approx. 100 minutes.
646 \frametitle{Quality Metrics}
649 \caption[SonarQube analysis results for Eclipse JDT UI.]{Results for
650 analyzing the Eclipse JDT UI project, before and after the refactoring, with
651 \name{SonarQube} (bold numbers are better.)}
654 % \begin{tabularx}{\textwidth}{@{}>{\bfseries}L{1.5}R{0.25}R{0.25}@{}}
655 \begin{tabularx}{\textwidth}{@{}>{}lrr@{}}
657 \textbf{Number of issues for each rule} & \textbf{Before} & \textbf{After} \\
659 Avoid too complex class & 81 & \textbf{79} \\
660 Classes should not be coupled to too many\\
661 \quad other classes (Single Responsibility Principle) & \textbf{1,098} & 1,199 \\
662 Control flow statements\\ \quad should not be nested too deeply & 1,375 &
664 Methods should not be too complex & 1,518 & \textbf{1,452} \\
665 Methods should not have too many lines & 3,396 & \textbf{3,291} \\
666 NPath Complexity & 348 & \textbf{329} \\
667 % Too many methods & \textbf{454} & 520 \\
669 Complexity per function & 3.6 & \textbf{3.3} \\
670 % Total number of issues & 8,270 & \textbf{8,155} \\
671 % Per class & \textbf{29.5} & 30.4 \\
672 % Per file & \textbf{44.0} & 45.3 \\
674 % Total complexity & \textbf{84,765} & 87,257 \\
677 % \spancols{3}{Numbers of each type of entity analyzed} \\
679 % Files & 1,926 & 1,926 \\
680 % Classes & 2,875 & 2,875 \\
681 % Functions & 23,744 & 26,332 \\
682 % Accessors & 1,296 & 1,019 \\
683 % Statements & 162,768 & 165,145 \\
684 % Lines of code & 320,941 & 329,112 \\
686 % Technical debt (in days) & \textbf{1,003.4} & 1,032.7 \\
693 \frametitle{The case studies are inconclusive}
695 \item Measurements show some deterioration regarding coupling.
696 \item All improvement not measured, only strict coupling between classes.
697 \item Examples exist where coupling is improved.
698 \item More examples exist where dependencies are introduced.
700 \item Needs more work!
704 \section{Conclusions}
706 \begin{frame}{Conclusions and future work}
708 \item Automation is possible.
709 \item Efficient enough for some kinds of use.
710 \item Difficult not to break source code.
711 \item Naive application introduces additional coupling.\\[2ex]
712 \item[] {\bf Future work:}
713 \item Better analysis (less crashes/broken output).
714 \item Improve heuristics to avoid introducing new dependencies.
715 \item Online suggestions?
716 \item Make refactoring safer.