diff options
author | Tobias Widmer | 2006-04-27 16:52:22 +0000 |
---|---|---|
committer | Tobias Widmer | 2006-04-27 16:52:22 +0000 |
commit | ccac0ac9d94aa6c9ee8d580b574692194400284d (patch) | |
tree | ddf2cc23fd13eba97f8e2e48f594870363f4d3d0 /org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java | |
parent | a999b966a8db848de7a905f57b1518bf9c764eaa (diff) | |
download | eclipse.jdt.ui-ccac0ac9d94aa6c9ee8d580b574692194400284d.tar.gz eclipse.jdt.ui-ccac0ac9d94aa6c9ee8d580b574692194400284d.tar.xz eclipse.jdt.ui-ccac0ac9d94aa6c9ee8d580b574692194400284d.zip |
133609 Java Model Exception: A.java does not exist when Extract Supertype
135057 [refactoring] Extract superclass wizard does not display cus correctly
Diffstat (limited to 'org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java')
-rw-r--r-- | org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java index 4b3f7297cb..499ab0f12b 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java @@ -49,6 +49,7 @@ import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeParameter; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.dom.AST; @@ -502,6 +503,13 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor /** * {@inheritDoc} */ + protected void finalize() throws Throwable { + resetWorkingCopies(); + } + + /** + * {@inheritDoc} + */ public final String getComment() { return fComment; } @@ -687,6 +695,17 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor return null; } + protected ICompilationUnit getSharedWorkingCopy(final ICompilationUnit unit, final IProgressMonitor monitor) throws JavaModelException { + try { + ICompilationUnit copy= unit.findWorkingCopy(fOwner); + if (copy == null) + copy= unit.getWorkingCopy(fOwner, null, monitor); + return copy; + } finally { + monitor.done(); + } + } + /** * Returns whether type occurrences in instanceof's should be rewritten. * @@ -772,6 +791,47 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor } /** + * Resets the working copies. + */ + protected void resetWorkingCopies() { + final ICompilationUnit[] units= JavaCore.getWorkingCopies(fOwner); + for (int index= 0; index < units.length; index++) { + final ICompilationUnit unit= units[index]; + try { + unit.discardWorkingCopy(); + } catch (Exception exception) { + // Do nothing + } + } + } + + /** + * Resets the working copies. + * + * @param unit + * the compilation unit to discard + */ + protected void resetWorkingCopies(final ICompilationUnit unit) { + final ICompilationUnit[] units= JavaCore.getWorkingCopies(fOwner); + for (int index= 0; index < units.length; index++) { + if (!units[index].equals(unit)) { + try { + units[index].discardWorkingCopy(); + } catch (Exception exception) { + // Do nothing + } + } else { + try { + units[index].getBuffer().setContents(unit.getPrimary().getBuffer().getContents()); + JavaModelUtil.reconcile(units[index]); + } catch (JavaModelException exception) { + JavaPlugin.log(exception); + } + } + } + } + + /** * Creates the necessary text edits to replace the subtype occurrence by a * supertype. * @@ -1249,4 +1309,4 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor monitor.done(); } } -} +}
\ No newline at end of file |