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}
12 \usetikzlibrary{shapes,snakes,trees,arrows,shadows,positioning,calc}
15 %\usepackage[hidelinks]{hyperref}
19 \usepackage{mathtools}
25 \usemintedstyle{default}
29 \theoremstyle{definition}
30 \newtheorem*{wordDef}{Definition}
31 \newtheorem*{mytheorem}{Theorem}
32 \newcommand{\mydefinition}[1]{\begin{wordDef}#1\end{wordDef}}
34 \newcommand{\citing}[1]{~\cite{#1}}
36 \newcommand{\code}[1]{\texttt{\textbf{#1}}}
37 \newcommand{\type}[1]{\code{#1}}
38 \newcommand{\method}[1]{\type{#1}}
39 \newcommand{\var}[1]{\type{#1}}
41 \newcommand{\name}[1]{#1}
42 \newcommand{\tit}[1]{\emph{#1}}
43 \newcommand{\refa}[1]{\emph{#1}}
44 \newcommand{\pattern}[1]{\emph{#1}}
45 \newcommand{\metr}[1]{\emph{#1}}
46 \newcommand{\ExtractMethod}{\refa{Extract Method}\xspace}
47 \newcommand{\MoveMethod}{\refa{Move Method}\xspace}
48 \newcommand{\ExtractAndMoveMethod}{\refa{Extract and Move Method}\xspace}
50 \newcommand{\mysection}[1]{
53 \begin{center}{\Huge #1}\end{center}
57 \def\mintedframesep{11pt}
59 \def\thetitle{Search-based Composed Refactorings}
60 \def\subtitle{Implementing and evaluating a search-based Extract and Move Method refactoring}
62 \author{Erlend Kristiansen, Volker Stolz}
66 \setbeamertemplate{headline}{%
67 \ifnum\insertframenumber>1
70 \begin{beamercolorbox}[wd=\paperwidth,ht=5ex,dp=1.125ex]{palette
72 \insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
79 \def\insertsectionnavigationhorizontal#1#2#3{%
81 \def\slideentry##1##2##3##4##5##6{}%
84 \setlength\tmp@parbox{#1}%
85 \addtolength\tmp@parbox{-.6cm}%
86 \parbox{\tmp@parbox}{\raggedleft%
87 \usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
88 \setbox\beamer@sectionbox=\hbox{}%
89 \ht\beamer@sectionbox=1.875ex%
90 \dp\beamer@sectionbox=0.75ex%
91 \hskip-1.875ex plus-1fill\dohead%
92 \box\beamer@sectionbox}\hfil\hskip.3cm%
97 \setbeamertemplate{navigation symbols}{}
99 \bibliography{bibliography/master-thesis-erlenkr-bibliography}
104 \frametitle{\thetitle}
106 % \vspace*{\baselineskip}
108 { \emph{Erlend Kristiansen, Universitetet i Oslo}}
112 { \emph{\underline{Volker Stolz, H\o gskolen i Bergen}}}
113 \vspace*{\baselineskip}
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 \frametitle{Outline and Motivation}
121 \item What are refactorings?
122 \item What are their problems?
123 \item How can we help?
124 \item Experiment and evaluation
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %\section{Definitions}
132 \frametitle{Refactoring, as defined in the literature}
135 \emph{Refactoring} (noun): a change made to the internal structure
136 of software to make it easier to understand and cheaper to modify without
137 changing its observable behavior.~{\bf [Fowler]}
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 \frametitle{Why are they necessary?}
145 \includegraphics[scale=0.3]{abs-motivation.png}
149 \item anecdotal evidence from our own project
150 \item ``refactoring smells'' that should be avoided by programmers
151 % \item (infrastructure developed here can be used for survey on repositories)
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 \frametitle{An alternative definition of refactoring}
159 A \emph{refactoring} is a transformation
160 done to a program without altering its external behavior.
165 \frametitle{Primitive and composite refactorings}
167 A \emph{primitive refactoring} is a refactoring that cannot be expressed in
168 terms of other refactorings.
173 A \emph{composite refactoring} is a refactoring that can be expressed in
174 terms of two or more other refactorings.
180 \begin{frame}[fragile]
181 \def\charwidth{4.5pt}
182 \def\indent{2*\charwidth}
183 \def\rightColX{32*\charwidth*0}
184 \def\lineheight{\baselineskip}
185 \def\mintedtop{22.5pt}
187 \begin{minipage}[t]{0.45\textwidth}
188 \begin{tikzpicture}[overlay, yscale=-1]
189 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
191 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
192 +(16*\charwidth,2*\lineheight);
194 \begin{minted}[linenos,samepage,frame=topline,label={Bad},framesep=\mintedframesep]{java}
210 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
211 \begin{tikzpicture}[overlay, yscale=-1]
212 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
214 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
215 +(16*\charwidth,\lineheight);
217 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
218 +(19*\charwidth,4*\lineheight);
220 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
223 \begin{minted}[linenos,samepage,frame=topline,label={Good},framesep=\mintedframesep]{java}
246 \begin{frame}{What our refactoring is going to do for you}
248 \item Get rid of long navigation paths.
249 \item Move operations closer to the data they manipulate.
250 \item Reduce coupling.
251 \item Increase maintainability.
259 \mysection{The primitive refactorings}
261 \begin{frame}[fragile]
262 \frametitle{The Extract Method refactoring}
263 Extract a fragment of code into a new method.
265 \def\charwidth{4.5pt}
266 \def\indent{2*\charwidth}
267 \def\rightColX{32*\charwidth*0}
268 \def\lineheight{\baselineskip}
269 \def\mintedtop{6.5pt}
271 \begin{minipage}[t]{0.45\textwidth}
272 \begin{tikzpicture}[overlay, yscale=-1]
273 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
275 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
276 +(16*\charwidth,2*\lineheight);
278 \begin{minted}[linenos,samepage]{java}
287 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
288 \begin{tikzpicture}[overlay, yscale=-1]
289 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
291 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
292 +(16*\charwidth,\lineheight);
294 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*5) rectangle
295 +(19*\charwidth,4*\lineheight);
297 \draw[-latex,red] (-3,1.8) -- (-0.1,\mintedtop+\lineheight*6);
300 \begin{minted}[linenos,samepage]{java}
318 \begin{frame}[fragile]
319 \frametitle{The Move Method refactoring}
320 Move a method from one class to another.
322 \def\charwidth{4.5pt}
323 \def\indent{2*\charwidth}
324 \def\rightColX{32*\charwidth*0}
325 \def\lineheight{\baselineskip}
326 \def\mintedtop{6.5pt}
328 \begin{minipage}[t]{0.45\textwidth}
329 \begin{tikzpicture}[overlay, yscale=-1]
330 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
332 \draw[overlaybox] (0,\mintedtop+\lineheight*5) rectangle
333 +(19*\charwidth,4*\lineheight);
335 \begin{minted}[linenos,samepage]{java}
350 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
351 \begin{tikzpicture}[overlay, yscale=-1]
352 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
354 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
355 +(16*\charwidth,\lineheight);
357 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
358 +(19*\charwidth,4*\lineheight);
360 \draw[-latex,red] (-2.8,2.9) -- (-0.1,\mintedtop+\lineheight*9.5);
363 \begin{minted}[linenos,samepage]{java}
384 \mysection{The Extract and Move Method refactoring}
386 \begin{frame}[fragile]
387 \def\charwidth{4.5pt}
388 \def\indent{2*\charwidth}
389 \def\rightColX{32*\charwidth*0}
390 \def\lineheight{\baselineskip}
391 \def\mintedtop{22.5pt}
393 \begin{minipage}[t]{0.45\textwidth}
394 \begin{tikzpicture}[overlay, yscale=-1]
395 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
397 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
398 +(16*\charwidth,2*\lineheight);
400 \begin{minted}[linenos,samepage,frame=topline,label={Before},framesep=\mintedframesep]{java}
416 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
417 \begin{tikzpicture}[overlay, yscale=-1]
418 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
420 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
421 +(16*\charwidth,\lineheight);
423 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
424 +(19*\charwidth,4*\lineheight);
426 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
429 \begin{minted}[linenos,samepage,frame=topline,label={After},framesep=\mintedframesep]{java}
453 \def\secondlevelmark{\textbullet}
455 \item Composed of \ExtractMethod and \MoveMethod.
456 \item Conceptually, one ``atomic'' operation.
458 \item Implemented as an Eclipse plugin.
460 \begin{itemize} \itemsep3pt
461 \item[\secondlevelmark] The primitive refactorings are supplied by the
463 \item[\secondlevelmark] The composition work had to be done by us.
464 \item[\secondlevelmark] Not seamless (find the extracted method, move
473 %\mysection{Research questions}
476 Main research question:
478 Is it possible to automate the analysis and execution of the
479 \ExtractAndMoveMethod refactoring, and do so for all of the code of a larger
485 \item Can we do this efficiently?
486 \item Can we perform changes safely?
487 \item Can we improve the quality of source code?
488 \item How can the automation of the refactoring be helpful?
495 \begin{frame}[fragile]{Automating the refactoring}
496 For any given method: We want to find the best candidate for the
497 \ExtractAndMoveMethod refactoring, if any exist.
499 \begin{minipage}[b]{0.33\textwidth}
501 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
502 \def\charwidth{4.5pt}
503 \def\indent{2*\charwidth}
504 \def\rightColX{32*\charwidth*0}
505 \def\lineheight{\baselineskip}
506 \def\mintedtop{6.5pt}
508 \begin{tikzpicture}[overlay, yscale=-1]
509 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
510 \draw[overlaybox] (0,\mintedtop+\lineheight*3) rectangle
511 +(16*\charwidth,2*\lineheight);
513 \node[draw opacity=0, text=red] at (20*\charwidth,\mintedtop+\lineheight*4)
514 {\fontsize{40}{60}\selectfont ?};
516 \begin{minted}[samepage]{java}
530 \begin{frame}[fragile]
531 \begin{minipage}[t]{0.5\textwidth}
532 \def\charwidth{4.75pt}
533 \def\indent{2*\charwidth}
534 \def\lineheight{\baselineskip}
535 \def\mintedtop{5.8pt}
537 \begin{tikzpicture}[overlay, yscale=-1]
538 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
539 \draw[overlaybox] (2*\indent,\mintedtop+12*\lineheight) rectangle
540 +(14*\charwidth,2*\lineheight);
542 \draw[overlaybox] (9*\charwidth,\mintedtop+\lineheight) rectangle
543 +(\charwidth,\lineheight);
545 \node[draw opacity=0, text=red] at (12.1*\indent,\mintedtop+12.9*\lineheight)
548 \node[draw opacity=0, text=red] at (11.5*\indent,\mintedtop+4*\lineheight)
551 \draw[-latex,red] (11.5*\indent-5*\charwidth,\mintedtop+3.7*\lineheight) --
552 (10.2*\charwidth,\mintedtop+1.5*\lineheight);
555 \begin{minted}[linenos,samepage]{java}
557 A a; B b; boolean bool;
558 void method(int val) {
577 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
580 A \textbf{candidate} consists of a \emph{text selection} and a \emph{move
583 A \textbf{valid text selection} is a text selection that contains all of one
584 or more consecutive program statements. It is the input to the \ExtractMethod
587 A \textbf{move target} is a variable (local or field), whose type is the
588 destination class in the \MoveMethod refactoring.
597 \frametitle{Searching}
598 Usually, search-based refactoring is based on metrics.
600 \item Refactor a lot.
601 \item Choose the best candidate based on measurements.
604 Our refactoring is based on heuristics.
606 \item Up-front analysis.
607 \item A set of assumptions defining what is considered the best candidate.
608 \item No need to actually perform changes (before deciding).
609 \item Search through all valid selections to find the best candidate.
616 \frametitle{Choosing a refactoring candidate}
618 \item Search through all selections to find the possible candidates.
619 \item Find the best move target for all the candidates.
620 \item Choose the best among the possible candidates.
621 \item Based on the lengths of the navigation paths and the occurrence
627 \begin{frame}{Case studies}
628 Case studies performed on the \code{org.eclipse.jdt.ui} and
629 \code{no.uio.ifi.refaktor} projects. The resulting code was analyzed with
631 \vspace*{\baselineskip}
633 The Eclipse JDT UI project:
635 \item Over 300,000 lines of code.
636 \item 2,552 methods out of 27,667 methods chosen to be refactored.
637 \item Approx. 100 minutes.
645 \frametitle{The case studies are inconclusive}
647 \item Measurements show some deterioration regarding coupling.
648 \item All improvement not measured, only strict coupling between classes.
649 \item Examples exist where coupling is improved.
650 \item More examples exist where dependencies are introduced.
652 \item Needs more work!
656 \section{Conclusions}
658 \begin{frame}{Conclusions and future work}
660 \item Automation is possible.
661 \item Efficient enough for some kinds of use.
662 \item Difficult not to break source code.
663 \item Naive application introduces additional coupling.\\[2ex]
664 \item[] {\bf Future work:}
665 \item Better analysis (less crashes/broken output).
666 \item Improve heuristics to avoid introducing new dependencies.
667 \item Online suggestions?
668 \item Make refactoring safer.