Opened up implementation for extract interface
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/composite/CompositeRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/composite/CompositeRefactoring.java
index 1ab23a6..f29aee0 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/composite/CompositeRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/composite/CompositeRefactoring.java
@@ -68,7 +68,7 @@
/**
* The created changes (element type: <<code>ICompilationUnit</code>,
- * <code>AbstractTextEditChange</code>>)
+ * <code>CompositeTextFileChange</code>>)
*/
private final Map fChanges= new HashMap();
@@ -381,20 +381,31 @@
} else if (change instanceof CompilationUnitChange) {
final CompilationUnitChange unitChange= (CompilationUnitChange) change;
- final ICompilationUnit unit= unitChange.getCompilationUnit().getPrimary();
- if (!fChanges.containsKey(unit)) {
+ registerCompilationUnitChange(unitChange);
+ }
+ }
- final CompositeTextFileChange newChange= new CompositeCompilationUnitChange(unit.getElementName(), unit);
- newChange.addChange(unitChange);
+ /**
+ * Registers a compilation unit change.
+ *
+ * @param change
+ * the change to register
+ */
+ protected void registerCompilationUnitChange(final CompilationUnitChange change) {
- fChanges.put(unit, newChange);
+ final ICompilationUnit unit= change.getCompilationUnit().getPrimary();
+ if (!fChanges.containsKey(unit)) {
- } else {
+ final CompositeTextFileChange newChange= new CompositeCompilationUnitChange(unit.getElementName(), unit);
+ newChange.addChange(change);
- final CompositeTextFileChange existingChange= (CompositeTextFileChange) fChanges.get(unit);
- if (existingChange != null)
- existingChange.addChange(unitChange);
- }
+ fChanges.put(unit, newChange);
+
+ } else {
+
+ final CompositeTextFileChange existingChange= (CompositeTextFileChange) fChanges.get(unit);
+ if (existingChange != null)
+ existingChange.addChange(change);
}
}
@@ -472,25 +483,38 @@
final CompilationUnitChange unitChange= (CompilationUnitChange) change;
final TextEdit edit= unitChange.getEdit();
- if (edit != null) {
-
- final TextEdit cloned= edit.copy();
-
- final ICompilationUnit unit= unitChange.getCompilationUnit();
- final IDocument document= new Document(unit.getBuffer().getContents());
-
- try {
- cloned.apply(document, 0);
- } catch (MalformedTreeException exception) {
- JavaPlugin.log(exception);
- } catch (BadLocationException exception) {
- JavaPlugin.log(exception);
- }
-
- unit.getBuffer().setContents(document.get());
- JavaModelUtil.reconcile(unit);
- }
+ if (edit != null)
+ updateWorkingCopy(unitChange.getCompilationUnit(), edit.copy());
}
- // Nothing to update here
}
-}
+
+ /**
+ * Updates the specified working copy with the text edit.
+ * <p>
+ * The passed text edit should be a copy, since it is altered during the
+ * working copy update process.
+ * </p>
+ *
+ * @param unit
+ * the working copy to update
+ * @param edit
+ * the text edit to apply
+ * @throws JavaModelException
+ * if the working copy does not exist
+ */
+ protected void updateWorkingCopy(final ICompilationUnit unit, final TextEdit edit) throws JavaModelException {
+
+ final IDocument document= new Document(unit.getBuffer().getContents());
+
+ try {
+ edit.apply(document, 0);
+ } catch (MalformedTreeException exception) {
+ JavaPlugin.log(exception);
+ } catch (BadLocationException exception) {
+ JavaPlugin.log(exception);
+ }
+
+ unit.getBuffer().setContents(document.get());
+ JavaModelUtil.reconcile(unit);
+ }
+}
\ No newline at end of file