]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/refaktor-before/src/no/uio/ifi/refaktor/refactorings/RefaktorRefactoring.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / refaktor-before / src / no / uio / ifi / refaktor / refactorings / RefaktorRefactoring.java
1 package no.uio.ifi.refaktor.refactorings;
2
3 import org.eclipse.core.resources.IProject;
4 import org.eclipse.core.resources.ResourcesPlugin;
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.core.runtime.OperationCanceledException;
8 import org.eclipse.jdt.core.IJavaProject;
9 import org.eclipse.jdt.core.IType;
10 import org.eclipse.jdt.core.JavaCore;
11 import org.eclipse.jdt.core.JavaModelException;
12 import org.eclipse.ltk.core.refactoring.Refactoring;
13 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
14
15 public abstract class RefaktorRefactoring extends Refactoring {
16
17         protected Refactoring refactoring;
18         protected String projectName;
19
20         public RefaktorRefactoring() {
21                 this.refactoring = null;
22         }
23
24         protected abstract void setRefactoring() throws CoreException;
25
26         @Override
27         public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException,
28         OperationCanceledException {
29                 System.err.println(getName() + ".checkInitialConditions");
30                 return getRefactoring().checkInitialConditions(monitor);
31         }
32
33         @Override
34         public RefactoringStatus checkFinalConditions(IProgressMonitor monitor) throws CoreException,
35         OperationCanceledException {
36                 System.err.println(getName() + ".checkFinalConditions");
37                 return getRefactoring().checkFinalConditions(monitor);
38         }
39
40         protected Refactoring getRefactoring() throws JavaModelException, CoreException {
41                 if (this.refactoring == null)
42                         setRefactoring();
43                 assert this.refactoring != null;
44                 return this.refactoring;
45         }
46
47         protected IType getIType(String typeName, String projectName) throws CoreException {
48                 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
49                 project.open(null);
50
51                 IJavaProject javaProject = JavaCore.create(project);
52                 return javaProject.findType(typeName);
53         }
54
55         @Override
56         public String getName() {
57                 return this.getClass().getSimpleName();
58         }
59
60         protected String getProjectName() {
61                 return this.projectName;
62         }
63
64         protected void setProjectName(String projectName) {
65                 this.projectName = projectName;
66         }
67
68 }