]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/change/executors/RefactoringExecutor.java
486508d597929e3849bee0b6cc01b65dca9318be
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / change / executors / RefactoringExecutor.java
1 package no.uio.ifi.refaktor.change.executors;
2
3 import org.eclipse.core.runtime.CoreException;
4 import org.eclipse.core.runtime.IProgressMonitor;
5 import org.eclipse.core.runtime.NullProgressMonitor;
6 import no.uio.ifi.refaktor.analyze.candidates.ExtractLocalVariableCandidate;
7 import no.uio.ifi.refaktor.analyze.candidates.RefactorCandidate;
8 import no.uio.ifi.refaktor.change.changers.ExtractLocalVariableWithAssertsChanger;
9 import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
10 import no.uio.ifi.refaktor.factories.RefactoringFactory;
11 import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
12
13 /**
14  * RefactoringExecutor spesific for Extract Local variable refactoring
15  * 
16  * 
17  * TODO Might be changed
18  * 
19  * 
20  * @author Anna Eilertsen
21  *
22  */
23 public class RefactoringExecutor<Candidate extends RefactorCandidate> implements Executor{
24
25         /**
26          * Text selection containing the expression we want to refactor, and only that
27          */
28         private CompilationUnitTextSelection textSelection;
29         private String newName;
30         private RefactoringFactory<Candidate> factory;
31
32         public RefactoringExecutor(Candidate analysisResult, RefactoringFactory<Candidate> factory) {
33                 this.factory = factory;
34                 this.textSelection = analysisResult.getTextSelection();
35                 this.newName = analysisResult.generateName();
36         }
37
38         @Override
39         public void execute(IProgressMonitor monitor) throws CoreException {
40                 //TODO should be generic
41                 RefaktorChanger changer = factory.getChanger(textSelection, newName);
42                 changer.checkPreconditions();
43                 try {
44                         changer.execute(new NullProgressMonitor());
45                 } catch (CoreException e) {
46                         e.printStackTrace();
47                 }
48         }
49
50 }