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