\documentclass[USenglish,9pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{babel,textcomp}
\usepackage[style=alphabetic,backend=biber]{biblatex}
\usepackage{babel,textcomp,csquotes}
\usepackage{xspace}

\usepackage{varioref}
%\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}

\usepackage{amsthm}
\usepackage{mathtools}

\usepackage{verbatim}
\usepackage{minted}
\usepackage{multicol}
%\usemintedstyle{bw}
\usemintedstyle{default}

\usetheme{Ifi}

\theoremstyle{definition}
\newtheorem*{wordDef}{Definition}
\newtheorem*{mytheorem}{Theorem}
\newcommand{\mydefinition}[1]{\begin{wordDef}#1\end{wordDef}}

\newcommand{\citing}[1]{~\cite{#1}}

\newcommand{\code}[1]{\texttt{\textbf{#1}}}
\newcommand{\type}[1]{\code{#1}}
\newcommand{\method}[1]{\type{#1}}
\newcommand{\var}[1]{\type{#1}}

\newcommand{\name}[1]{#1}
\newcommand{\tit}[1]{\emph{#1}}
\newcommand{\refa}[1]{\emph{#1}}
\newcommand{\pattern}[1]{\emph{#1}}
\newcommand{\metr}[1]{\emph{#1}}
\newcommand{\ExtractMethod}{\refa{Extract Method}\xspace}
\newcommand{\MoveMethod}{\refa{Move Method}\xspace}
\newcommand{\ExtractAndMoveMethod}{\refa{Extract and Move Method}\xspace}

\def\thetitle{Automated Composition of Refactorings}
\title{\thetitle}
\author{Erlend Kristiansen}

\bibliography{bibliography/master-thesis-erlenkr-bibliography}

\begin{document}

% Frame 1
\begin{frame}
  \frametitle{\thetitle}
  A short demonstration
\end{frame}

% Frame 2
\begin{frame}
  \frametitle{Refactoring}
  Martin Fowler, in his book on refactoring\citing{refactoring}, defines a 
  refactoring:

  \begin{quote}
    \emph{Refactoring} (noun): a change made to the internal structure
    of software to make it easier to understand and cheaper to modify without 
    changing its observable behavior.~\cite[p.~53]{refactoring}
  \end{quote}

  If we leave the motivation behind refactoring out of the definition, it could 
  be rephrased like this:

  \begin{definition}
    A \emph{refactoring} is a transformation
    done to a program without altering its external behavior.
  \end{definition}
\end{frame}

% Frame 3
\begin{frame}
  \frametitle{Composite Refactorings}
  There are \emph{primitive refactorings}. These refactorings cannot be 
  expressed in terms of other refactorings. And there are \emph{composite
  refactorings}:

  \begin{definition}
    A \emph{composite refactoring} is a refactoring that can be expressed in 
    terms of two or more other refactorings.
  \end{definition}
\end{frame}

% Frame 4
\begin{frame}
  \frametitle{The Extract and Move Method refactoring}
  This thesis is concentrating on creating a composite refactoring of the 
  \ExtractMethod and \MoveMethod refactorings. The composition of the two is 
  called the \ExtractAndMoveMethod refactoring.

\end{frame}

% Frame 5
\begin{frame}[fragile]
  \frametitle{The Extract Method refactoring}
  The \refa{Extract Method} refactoring is used to extract a fragment of code 
  from its context and into a new method. A call to the new method is inlined 
  where the fragment was before. It is used to break code into logical units, 
  with names that explain their purpose

  \begin{multicols}{2}
    \begin{minted}[samepage]{java}
  class C {
    void method() {
      // 1: Some code
      // 2: Fragment
      // 3: More code
    }
  }
    \end{minted}

    \columnbreak

    \begin{minted}[samepage]{java}
  class C {
    void method() {
      // 1: Some code
      extractedMethod();
      // 3: More code
    }

    void extractedMethod() {
      // 2: Fragment
    }
  }
    \end{minted}
  \end{multicols}

\end{frame}

% Frame 6
\begin{frame}[fragile]
  \frametitle{The Move Method refactoring}
  The \refa{Move Method} refactoring is used to move a method from one class to 
  another. This is useful if the method is using more features of another class 
  than of the class which it is currently defined. 
  
  \begin{multicols}{2}
    \begin{minted}[samepage]{java}
  class C {
    void method() {
      X x = new X();
      iBelongInX(x);
    }
    void iBelongInX(X x) {
      x.foo(); x.bar();
    }
  }
  
  class X {
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}

    \columnbreak

    \begin{minted}[samepage]{java}
  class C {
    void method() {
      X x = new X();
      x.iBelongInX();
    }
  }

  class X {
    void iBelongInX() {
      foo(); bar();
    }
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}
  \end{multicols}

\end{frame}

% frame 7/1
\begin{frame}[fragile]
  \frametitle{The Composition}

  \begin{multicols}{2}
    \begin{minted}[samepage]{java}
  // Before
  class C {
    void method() {
      X x = new X();
      x.foo(); x.bar();
    }
  }
  
  class X {
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}

    \columnbreak

%    \begin{minted}[samepage]{java}
%  class C {
%    void method() {
%      X x = new X();
%      x.extractedMethod();
%    }
%  }
%
%  class X {
%    void extractedMethod() {
%      foo(); bar();
%    }
%    void foo(){/*...*/}
%    void bar(){/*...*/}
%  }
%    \end{minted}
  \end{multicols}

\end{frame}

% Frame 7/2
\begin{frame}[fragile]
  \frametitle{The Composition}

  \begin{multicols}{2}
    \begin{minted}[samepage]{java}
  // Intermediate step
  class C {
    void method() {
      X x = new X();
      extractedMethod(x);
    }
    void extractedMethod(X x) {
      x.foo(); x.bar();
    }
  }
  
  class X {
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}

    \columnbreak

%    \begin{minted}[samepage]{java}
%  class C {
%    void method() {
%      X x = new X();
%      x.extractedMethod();
%    }
%  }
%
%  class X {
%    void foo(){/*...*/}
%    void bar(){/*...*/}
%  }
%    \end{minted}
  \end{multicols}

\end{frame}

% Frame 7/3
\begin{frame}[fragile]
  \frametitle{The Composition}

  \begin{multicols}{2}
    \begin{minted}[samepage]{java}
  // Before
  class C {
    void method() {
      X x = new X();
      x.foo(); x.bar();
    }
  }
  
  class X {
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}

    \columnbreak

    \begin{minted}[samepage]{java}
  // After
  class C {
    void method() {
      X x = new X();
      x.extractedMethod();
    }
  }

  class X {
    void extractedMethod() {
      foo(); bar();
    }
    void foo(){/*...*/}
    void bar(){/*...*/}
  }
    \end{minted}
  \end{multicols}

\end{frame}

% Frame 8
\begin{frame}
  \frametitle{Automation}

  \begin{itemize}
    \item Search based
    \item Heuristics
    \item Project wide search and perform
  \end{itemize}

\end{frame}

% Frame 9
\begin{frame}
  \frametitle{Demonstration}
  \begin{itemize}
    \item The      
      \code{LastStatementOfSelectionEndsInReturnOrThrow\-Checker.visit(IfStatement 
      node)} method
      \begin{itemize}
        \item Extract and Move on selection
        \item Extract and Move, search based, on method
      \end{itemize}
    \item The \code{no.uio.ifi.refaktor} project
      \begin{itemize}
        \item Extract and Move, search based, over whole project
      \end{itemize}
  \end{itemize}

\end{frame}

\begin{frame}
  \frametitle{What is left}
  \begin{itemize}
    \item Write technical section
    \item Write up argument for correctness
    \item Define the final case study
    \item Run unit tests before and after change
    \item Make more examples
    \item \ldots
  \end{itemize}
 
\end{frame}

% Frame X
\begin{frame}
  \frametitle{Bibliography}
  \printbibliography
\end{frame}

\end{document}
