Skip to content
Browse files

Merge pull request #86 from dankilman/master

Feature/plug existing refactoring actions to quickfix proposals
  • Loading branch information...
2 parents 4e46679 + c3b8c87 commit ef0c9d07ba06daebe2a18a4cac69cab4f8044680 @dragos dragos committed Apr 6, 2012
View
12 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ExtractLocalProposal.scala
@@ -0,0 +1,12 @@
+package scala.tools.eclipse.quickfix
+
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal
+import org.eclipse.jface.text.IDocument
+import org.eclipse.jface.text.contentassist.IContextInformation
+import org.eclipse.swt.graphics.Image
+import org.eclipse.swt.graphics.Point
+import scala.tools.eclipse.refactoring.ExtractLocalAction
+
+object ExtractLocalProposal
+ extends ProposalRefactoringActionAdapter(
+ new ExtractLocalAction, "Extract to local value")
View
12 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ExtractMethodProposal.scala
@@ -0,0 +1,12 @@
+package scala.tools.eclipse.quickfix
+
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal
+import org.eclipse.jface.text.IDocument
+import org.eclipse.jface.text.contentassist.IContextInformation
+import org.eclipse.swt.graphics.Image
+import org.eclipse.swt.graphics.Point
+import scala.tools.eclipse.refactoring.ExtractMethodAction
+
+object ExtractMethodProposal
+ extends ProposalRefactoringActionAdapter(
+ new ExtractMethodAction, "Extract method")
View
13 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/InlineLocalProposal.scala
@@ -0,0 +1,13 @@
+package scala.tools.eclipse.quickfix
+
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal
+import org.eclipse.jface.text.IDocument
+import org.eclipse.jface.text.contentassist.IContextInformation
+import org.eclipse.swt.graphics.Image
+import org.eclipse.swt.graphics.Point
+import scala.tools.eclipse.refactoring.ExtractLocalAction
+import scala.tools.eclipse.refactoring.InlineLocalAction
+
+object InlineLocalProposal
+ extends ProposalRefactoringActionAdapter(
+ new InlineLocalAction, "Inline local value")
View
45 ...cala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ProposalRefactoringActionAdapter.scala
@@ -0,0 +1,45 @@
+package scala.tools.eclipse.quickfix
+
+import scala.tools.eclipse.refactoring.RefactoringAction
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal
+import org.eclipse.jface.text.IDocument
+import org.eclipse.jface.text.contentassist.IContextInformation
+import org.eclipse.swt.graphics.Image
+import org.eclipse.swt.graphics.Point
+import scala.tools.eclipse.refactoring.ActionAdapter
+import scala.tools.eclipse.refactoring.rename.RenameAction
+import scala.tools.eclipse.refactoring.ScalaIdeRefactoring
+import scala.tools.eclipse.logging.HasLogger
+
+abstract class ProposalRefactoringActionAdapter(
+ action: ActionAdapter,
+ displayString: String,
+ relevance: Int = 100)
+ extends IJavaCompletionProposal {
+
+ override def apply(document: IDocument): Unit = {
+ // document is not used because the refactoring actions use the current editor
+ // TODO not sure if this null here is very safe
+ action.run(null)
+ }
+
+ override def getRelevance = relevance
+ override def getDisplayString(): String = displayString
+ override def getSelection(document: IDocument): Point = null
+ override def getAdditionalProposalInfo(): String = null
+ override def getImage(): Image = null
+ override def getContextInformation: IContextInformation = null
+
+ def isValidProposal : Boolean = {
+ val ra = action match {
+ case refactoringAction: RefactoringAction => refactoringAction
+ case renameAction : RenameAction => renameAction.getRenameAction
+ }
+ ra.createScalaIdeRefactoringForCurrentEditorAndSelection match {
+ // TODO not sure if this null here is very safe
+ case Some(refactoring) => !refactoring.checkInitialConditions(null).hasWarning
+ case None => false
+ }
+ }
+
+}
View
7 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/RenameProposal.scala
@@ -0,0 +1,7 @@
+package scala.tools.eclipse.quickfix
+
+import scala.tools.eclipse.refactoring.rename.RenameAction
+
+object RenameProposal
+ extends ProposalRefactoringActionAdapter(
+ new RenameAction, "Rename value")
View
11 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ScalaQuickAssistProcessor.scala
@@ -57,12 +57,17 @@ class ScalaQuickAssistProcessor extends org.eclipse.jdt.ui.text.java.IQuickAssis
}
private def suggestAssist(compilationUnit: ICompilationUnit, problemMessage: String, location: Position): List[IJavaCompletionProposal] = {
-
- problemMessage match {
+ List(
+ ExtractLocalProposal,
+ InlineLocalProposal,
+ RenameProposal,
+ ExtractMethodProposal
+ ).filter(_.isValidProposal) :::
+ (problemMessage match {
case ImplicitConversionFound(s) => List(new ImplicitConversionExpandingProposal(s, location))
case ImplicitArgFound(s) => List(new ImplicitArgumentExpandingProposal(s, location))
case _ => Nil
- }
+ })
}
}
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/rename/RenameAction.scala
@@ -29,12 +29,12 @@ import scala.tools.refactoring.common.{ ConsoleTracing, InteractiveScalaCompiler
class RenameAction extends ActionAdapter {
override def run(action: IAction) {
- val renameAction = {
- if (isLocalRename) new LocalRenameAction else new GlobalRenameAction
- }
+ val renameAction = getRenameAction
renameAction.run(action)
}
+ def getRenameAction = if (isLocalRename) new LocalRenameAction else new GlobalRenameAction
+
/**
* Using the currently opened file and selection, determines whether the
* selected SymbolTree is only locally visible or not.

0 comments on commit ef0c9d0

Please sign in to comment.
Something went wrong with that request. Please try again.