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{Automated Composition of Refactorings}
60 \def\subtitle{Implementing and evaluating a search-based Extract and Move Method refactoring}
62 \author{Erlend Kristiansen}
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 {\small \emph{Erlend Kristiansen, 2014}}
109 \vspace*{\baselineskip}
112 \section{Definitions}
115 \frametitle{Refactoring, as defined in the literature}
118 \emph{Refactoring} (noun): a change made to the internal structure
119 of software to make it easier to understand and cheaper to modify without
120 changing its observable behavior.~\cite[p.~53]{refactoring}
125 \frametitle{An alternative definition of refactoring}
128 A \emph{refactoring} is a transformation
129 done to a program without altering its external behavior.
134 \frametitle{Primitive and composite refactorings}
136 A \emph{primitive refactoring} is a refactoring that cannot be expressed in
137 terms of other refactorings.
142 A \emph{composite refactoring} is a refactoring that can be expressed in
143 terms of two or more other refactorings.
147 \mysection{Motivation}
149 \begin{frame}[fragile]
150 \def\charwidth{4.5pt}
151 \def\indent{2*\charwidth}
152 \def\rightColX{32*\charwidth*0}
153 \def\lineheight{\baselineskip}
154 \def\mintedtop{22.5pt}
156 \begin{minipage}[t]{0.45\textwidth}
157 \begin{tikzpicture}[overlay, yscale=-1]
158 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
160 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
161 +(16*\charwidth,2*\lineheight);
163 \begin{minted}[linenos,samepage,frame=topline,label={Bad},framesep=\mintedframesep]{java}
179 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
180 \begin{tikzpicture}[overlay, yscale=-1]
181 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
183 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
184 +(16*\charwidth,\lineheight);
186 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
187 +(19*\charwidth,4*\lineheight);
189 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
192 \begin{minted}[linenos,samepage,frame=topline,label={Good},framesep=\mintedframesep]{java}
217 \item Get rid of long navigation paths.
218 \item Move operations closer to the data they manipulate.
219 \item Reduce coupling.
220 \item Increase maintainability.
226 \mysection{The primitive refactorings}
228 \begin{frame}[fragile]
229 \frametitle{The Extract Method refactoring}
230 Extract a fragment of code into a new method.
232 \def\charwidth{4.5pt}
233 \def\indent{2*\charwidth}
234 \def\rightColX{32*\charwidth*0}
235 \def\lineheight{\baselineskip}
236 \def\mintedtop{6.5pt}
238 \begin{minipage}[t]{0.45\textwidth}
239 \begin{tikzpicture}[overlay, yscale=-1]
240 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
242 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
243 +(16*\charwidth,2*\lineheight);
245 \begin{minted}[linenos,samepage]{java}
254 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
255 \begin{tikzpicture}[overlay, yscale=-1]
256 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
258 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
259 +(16*\charwidth,\lineheight);
261 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*5) rectangle
262 +(19*\charwidth,4*\lineheight);
264 \draw[-latex,red] (-3,1.8) -- (-0.1,\mintedtop+\lineheight*6);
267 \begin{minted}[linenos,samepage]{java}
285 \begin{frame}[fragile]
286 \frametitle{The Move Method refactoring}
287 Move a method from one class to another.
289 \def\charwidth{4.5pt}
290 \def\indent{2*\charwidth}
291 \def\rightColX{32*\charwidth*0}
292 \def\lineheight{\baselineskip}
293 \def\mintedtop{6.5pt}
295 \begin{minipage}[t]{0.45\textwidth}
296 \begin{tikzpicture}[overlay, yscale=-1]
297 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
299 \draw[overlaybox] (0,\mintedtop+\lineheight*5) rectangle
300 +(19*\charwidth,4*\lineheight);
302 \begin{minted}[linenos,samepage]{java}
317 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
318 \begin{tikzpicture}[overlay, yscale=-1]
319 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
321 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
322 +(16*\charwidth,\lineheight);
324 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
325 +(19*\charwidth,4*\lineheight);
327 \draw[-latex,red] (-2.8,2.9) -- (-0.1,\mintedtop+\lineheight*9.5);
330 \begin{minted}[linenos,samepage]{java}
351 \mysection{The Extract and Move Method refactoring}
353 \begin{frame}[fragile]
354 \def\charwidth{4.5pt}
355 \def\indent{2*\charwidth}
356 \def\rightColX{32*\charwidth*0}
357 \def\lineheight{\baselineskip}
358 \def\mintedtop{22.5pt}
360 \begin{minipage}[t]{0.45\textwidth}
361 \begin{tikzpicture}[overlay, yscale=-1]
362 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
364 \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle
365 +(16*\charwidth,2*\lineheight);
367 \begin{minted}[linenos,samepage,frame=topline,label={Before},framesep=\mintedframesep]{java}
383 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
384 \begin{tikzpicture}[overlay, yscale=-1]
385 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
387 \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle
388 +(16*\charwidth,\lineheight);
390 \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle
391 +(19*\charwidth,4*\lineheight);
393 \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
396 \begin{minted}[linenos,samepage,frame=topline,label={After},framesep=\mintedframesep]{java}
420 \def\secondlevelmark{\textbullet}
422 \item Composed of \ExtractMethod and \MoveMethod.
423 \item Conceptually, one ``atomic'' operation.
425 \item Implemented as an Eclipse plugin.
427 \begin{itemize} \itemsep3pt
428 \item[\secondlevelmark] The primitive refactorings are supplied by the
430 \item[\secondlevelmark] The composition work had to be done by us.
431 \item[\secondlevelmark] Not seamless (find the extracted method, move
440 \mysection{Research questions}
443 Main research question:
445 Is it possible to automate the analysis and execution of the
446 \ExtractAndMoveMethod refactoring, and do so for all of the code of a larger
452 \item Can we do this efficiently?
453 \item Can we perform changes safely?
454 \item Can we improve the quality of source code?
455 \item How can the automation of the refactoring be helpful?
462 \mysection{Automating the refactoring}
464 \begin{frame}[fragile]
465 For any given method: We want to find the best candidate for the
466 \ExtractAndMoveMethod refactoring, if any exist.
468 \begin{minipage}[b]{0.33\textwidth}
470 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
471 \def\charwidth{4.5pt}
472 \def\indent{2*\charwidth}
473 \def\rightColX{32*\charwidth*0}
474 \def\lineheight{\baselineskip}
475 \def\mintedtop{6.5pt}
477 \begin{tikzpicture}[overlay, yscale=-1]
478 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
479 \draw[overlaybox] (0,\mintedtop+\lineheight*3) rectangle
480 +(16*\charwidth,2*\lineheight);
482 \node[draw opacity=0, text=red] at (20*\charwidth,\mintedtop+\lineheight*4)
483 {\fontsize{40}{60}\selectfont ?};
485 \begin{minted}[samepage]{java}
499 \begin{frame}[fragile]
500 \begin{minipage}[t]{0.5\textwidth}
501 \def\charwidth{4.75pt}
502 \def\indent{2*\charwidth}
503 \def\lineheight{\baselineskip}
504 \def\mintedtop{5.8pt}
506 \begin{tikzpicture}[overlay, yscale=-1]
507 \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
508 \draw[overlaybox] (2*\indent,\mintedtop+12*\lineheight) rectangle
509 +(14*\charwidth,2*\lineheight);
511 \draw[overlaybox] (9*\charwidth,\mintedtop+\lineheight) rectangle
512 +(\charwidth,\lineheight);
514 \node[draw opacity=0, text=red] at (12.1*\indent,\mintedtop+12.9*\lineheight)
517 \node[draw opacity=0, text=red] at (11.5*\indent,\mintedtop+4*\lineheight)
520 \draw[-latex,red] (11.5*\indent-5*\charwidth,\mintedtop+3.7*\lineheight) --
521 (10.2*\charwidth,\mintedtop+1.5*\lineheight);
524 \begin{minted}[linenos,samepage]{java}
526 A a; B b; boolean bool;
527 void method(int val) {
546 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
549 A \textbf{candidate} consists of a \emph{text selection} and a \emph{move
552 A \textbf{valid text selection} is a text selection that contains all of one
553 or more consecutive program statements. It is the input to the \ExtractMethod
556 A \textbf{move target} is a variable (local or field), whose type is the
557 destination class in the \MoveMethod refactoring.
566 \frametitle{Searching}
567 Usually, search-based refactoring is based on metrics.
569 \item Refactor a lot.
570 \item Choose the best candidate based on measurements.
573 Our refactoring is based on heuristics.
575 \item Up-front analysis.
576 \item A set of assumptions defining what is considered the best candidate.
577 \item No need to actually perform changes (before deciding).
578 \item Search through all valid selections to find the best candidate.
585 \frametitle{Choosing a refactoring candidate}
587 \item Search through all selections to find the possible candidates.
588 \item Find the best move target for all the candidates.
589 \item Choose the best among the possible candidates.
590 \item Based on the lengths of the navigation paths and the occurrence
597 \mysection{Demonstration}
599 \mysection{Case studies}
602 Case studies performed on the \code{org.eclipse.jdt.ui} and
603 \code{no.uio.ifi.refaktor} projects. The resulting code was analyzed with
605 \vspace*{\baselineskip}
607 The Eclipse JDT UI project:
609 \item Over 300,000 lines of code.
610 \item 2,552 methods out of 27,667 methods chosen to be refactored.
611 \item Approx. 100 minutes.
619 \frametitle{The case studies are inconclusive}
621 \item Measurements show some deterioration regarding coupling.
622 \item All improvement not measured, only strict coupling between classes.
623 \item Examples exist where coupling is improved.
624 \item More examples exist where dependencies are introduced.
629 \mysection{Demonstration continued}
631 \mysection{Conclusions}
635 \item Automation is possible.
636 \item Efficient enough for some kinds of use.
637 \item Difficult not to break source code.
638 \item Code is not improved in most cases.
639 \item Not particularly useful in its current state.
644 \mysection{Future work}
648 \item Complete analysis.
649 \item Make refactoring safer.
650 \item Improve heuristics to avoid introducing new dependencies.
656 \frametitle{References}