Skip to content

Commit

Permalink
Refactorings in AddValOrDefProposal
Browse files Browse the repository at this point in the history
The supertype BasicCompletionProposal is added
  • Loading branch information
kiritsuku committed Oct 4, 2014
1 parent b6e85fd commit c48d59e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import scala.tools.refactoring.implementations.{ AddMethod, AddField, AddMethodT
import scala.reflect.internal.util.SourceFile
import tools.nsc.interactive.Global
import scala.tools.refactoring.common.TextChange
import org.scalaide.core.quickassist.BasicCompletionProposal

trait AddValOrDefProposal extends IJavaCompletionProposal {
abstract class AddValOrDefProposal extends BasicCompletionProposal(
relevance = 90,
displayString = "",
image = JavaPluginImages.DESC_MISC_PUBLIC.createImage()) {
protected val returnType: ReturnType
protected val target: AddMethodTarget

Expand Down Expand Up @@ -47,12 +51,6 @@ trait AddValOrDefProposal extends IJavaCompletionProposal {
}

protected def addRefactoring: (SourceFile, Global) => List[TextChange]

override def getRelevance = 90
override def getSelection(document: IDocument): Point = null
override def getAdditionalProposalInfo(): String = null
override def getImage(): Image = JavaPluginImages.DESC_MISC_PUBLIC.createImage()
override def getContextInformation: IContextInformation = null
}

trait AddFieldProposal {
Expand All @@ -64,7 +62,7 @@ trait AddFieldProposal {

protected def addFieldRefactoring =
(scalaSourceFile: SourceFile, compiler: Global) => {
val refactoring = new AddField { val global = compiler }
val refactoring = new AddField { override val global = compiler }
//if we're here, className should be defined because of the check in isApplicable
refactoring.addField(scalaSourceFile.file, className.get, defName, isVar, returnType, target)
}
Expand All @@ -80,17 +78,17 @@ trait AddMethodProposal {

protected def addMethodRefactoring =
(scalaSourceFile: SourceFile, compiler: Global) => {
val refactoring = new AddMethod { val global = compiler }
val refactoring = new AddMethod { override val global = compiler }
//if we're here, className should be defined because of the check in isApplicable
refactoring.addMethod(scalaSourceFile.file, className.get, defName, parameters, typeParameters, returnType, target)
}

def getDefInfo(parameters: ParameterList, returnType: ReturnType) = {
def getDefInfo(parameters: ParameterList, returnType: ReturnType): (String, String) = {
val prettyParameterList = (for (parameterList <- parameters) yield {
parameterList.map(_._2).mkString(", ")
}).mkString("(", ")(", ")")

val returnTypeStr = returnType.map(": " + _).getOrElse("")
(prettyParameterList, returnTypeStr)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ object AbstractMemberProposal {
}
}

trait AbstractMemberProposal extends AddMethodProposal with AddFieldProposal with AddValOrDefProposal {
trait AbstractMemberProposal extends AddValOrDefProposal with AddMethodProposal with AddFieldProposal {
protected val compiler: Global
import compiler._

val targetSourceFile: Option[ScalaSourceFile]
override val targetSourceFile: Option[ScalaSourceFile]
protected val abstractMethod: MethodSymbol
protected val implDef: ImplDef
protected val target: AddMethodTarget
override protected val target: AddMethodTarget

private def initValOrDef: (TypeParameterList, ParameterList, ReturnType, Boolean, Boolean) = {
def processType(tp: Type) =
Expand All @@ -59,11 +59,11 @@ trait AbstractMemberProposal extends AddMethodProposal with AddFieldProposal wit
(typeParams, paramss, retType, isDef, isVar)
}

val abstrInfo = initValOrDef
override protected val (typeParameters: TypeParameterList, parameters: ParameterList, returnType: ReturnType, _, isVar) = abstrInfo
private val abstrInfo = initValOrDef
override protected val (typeParameters: TypeParameterList, parameters: ParameterList, returnType: ReturnType, _, isVar: Boolean) = abstrInfo
val isDef: Boolean = abstrInfo._4
val defName = abstractMethod.nameString
val className = Option(implDef.name.decode)
override val defName: String = abstractMethod.nameString
override val className: Option[String] = Option(implDef.name.decode)

override protected def addRefactoring = if (isDef) addMethodRefactoring else addFieldRefactoring

Expand All @@ -72,4 +72,4 @@ trait AbstractMemberProposal extends AddMethodProposal with AddFieldProposal wit
val typeParametersList = if (!typeParameters.isEmpty) typeParameters.mkString("[", ",", "]") else ""
s"Implement ${if (isDef) s"${compiler.nme.DEFkw}" else if (isVar) s"${compiler.nme.VARkw}" else s"${compiler.nme.VALkw}"} '${abstractMethod.nameString}$typeParametersList$prettyParameterList$returnTypeStr'"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.scalaide.core.internal.quickfix.AddValOrDefProposal
import org.scalaide.core.compiler.IScalaPresentationCompiler.Implicits._

case class CreateMethodProposal(fullyQualifiedEnclosingType: Option[String], defName: String,
target: AddMethodTarget, compilationUnit: ICompilationUnit, pos: Position) extends AddMethodProposal with AddValOrDefProposal {
target: AddMethodTarget, compilationUnit: ICompilationUnit, pos: Position) extends AddValOrDefProposal with AddMethodProposal {

private val UnaryMethodNames = "+-!~".map("unary_" + _)

Expand Down

0 comments on commit c48d59e

Please sign in to comment.