Browse files

Some refactoring in the Move Refactoring, adapt call from Move Partic…

…ipant.
  • Loading branch information...
1 parent b82bffe commit f8776e5ee93e6a5860e0d5ff2bf6b15a6cae4998 @misto misto committed Jul 3, 2012
View
51 org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/move/MoveClassAction.scala
@@ -77,7 +77,34 @@ class MoveClassAction extends RefactoringAction {
}
override def createChange(pm: IProgressMonitor): CompositeChange = {
+
+ val (textChanges, newFileChanges) = createRefactoringChanges(pm)
+
+ new CompositeChange(getName) {
+
+ scalaChangesToEclipseChanges(textChanges) foreach add
+
+ newFileChanges match {
+
+ // If there's no new file to create, we move the current file.
+ case Nil =>
+ add(new MoveResourceChange(file.getResource, target.getCorrespondingResource.asInstanceOf[IFolder]))
+ // Otherwise, create a new file with the changes's content.
+ case newFile :: rest =>
+ val pth = target.getPath.append(preparationResult.right.get.get.name.toString + ".scala")
+ add(new CreateFileChange(pth, newFile.text, file.getResource.asInstanceOf[IFile].getCharset))
+ }
+ }
+ }
+
+ override def getPages = {
+ val selectedImpl = preparationResult.right.toOption flatMap (_.map(_.name.toString))
+ List(new ui.MoveClassRefactoringConfigurationPage(file.getResource(), selectedImpl, target_=, setMoveSingleImpl))
+ }
+
+ private[move] def createRefactoringChanges(pm: IProgressMonitor) = {
+
val (index, cleanupHandler) = {
val toMove = refactoring.statsToMove(selection(), refactoringParameters) collect {
case impl: refactoring.global.ImplDef => impl.name.toString
@@ -100,32 +127,10 @@ class MoveClassAction extends RefactoringAction {
(textChanges, change :: newFilesChanges)
}
}
-
- val change = new CompositeChange(getName) {
-
- scalaChangesToEclipseChanges(textChanges) foreach add
-
- newFileChanges match {
-
- // If there's no new file to create, we move the current file.
- case Nil =>
- add(new MoveResourceChange(file.getResource, target.getCorrespondingResource.asInstanceOf[IFolder]))
-
- // Otherwise, create a new file with the changes's content.
- case newFile :: rest =>
- val pth = target.getPath.append(preparationResult.right.get.get.name.toString + ".scala")
- add(new CreateFileChange(pth, newFile.text, file.getResource.asInstanceOf[IFile].getCharset))
- }
- }
cleanup()
- change
- }
-
- override def getPages = {
- val selectedImpl = preparationResult.right.toOption flatMap (_.map(_.name.toString))
- List(new ui.MoveClassRefactoringConfigurationPage(file.getResource(), selectedImpl, target_=, setMoveSingleImpl))
+ (textChanges, newFileChanges)
}
}
}
View
5 org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/move/ScalaMoveParticipant.scala
@@ -59,10 +59,9 @@ class ScalaMoveParticipant extends MoveParticipant {
// but we skip our part. Really? Test! Add warning to the status.
pm.setCanceled(false)
} else {
+
change = new CompositeChange("Move Scala Class") {
- val changes = moveRefactoring.performRefactoring() collect {
- case tc: TextChange => tc
- }
+ val changes = moveRefactoring.createRefactoringChanges(pm)._1
moveRefactoring.scalaChangesToEclipseChanges(changes) foreach add
}
}

0 comments on commit f8776e5

Please sign in to comment.