Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SCL-4152. Removed unnecessary parentheses.

  • Loading branch information...
commit f9bbec91c128ee164d0e5a87bb4d48d39d7d4a12 1 parent 0927505
@kseniasautina kseniasautina authored
View
34 src/org/jetbrains/plugins/scala/codeInsight/intention/types/ToggleTypeAnnotation.scala
@@ -21,7 +21,7 @@ class ToggleTypeAnnotation extends PsiElementBaseIntentionAction {
def getFamilyName = ScalaBundle.message("intention.type.annotation.toggle.family")
def isAvailable(project: Project, editor: Editor, element: PsiElement) = {
- if(element == null) {
+ if (element == null) {
false
} else {
def message(key: String) {
@@ -36,10 +36,10 @@ class ToggleTypeAnnotation extends PsiElementBaseIntentionAction {
}
def complete(strategy: Strategy, element: PsiElement): Boolean = {
- for{function <- element.parentsInFile.findByType(classOf[ScFunctionDefinition])
- if function.hasAssign
- body <- function.body
- if (!body.isAncestorOf(element))} {
+ for {function <- element.parentsInFile.findByType(classOf[ScFunctionDefinition])
+ if function.hasAssign
+ body <- function.body
+ if (!body.isAncestorOf(element))} {
if (function.returnTypeElement.isDefined)
strategy.removeFromFunction(function)
@@ -49,12 +49,12 @@ class ToggleTypeAnnotation extends PsiElementBaseIntentionAction {
return true
}
- for{value <- element.parentsInFile.findByType(classOf[ScPatternDefinition])
- if (value.expr.toOption.map(!_.isAncestorOf(element)).getOrElse(true))
- if (value.pList.allPatternsSimple)
- bindings = value.bindings
- if (bindings.size == 1)
- binding <- bindings} {
+ for {value <- element.parentsInFile.findByType(classOf[ScPatternDefinition])
+ if (value.expr.toOption.map(!_.isAncestorOf(element)).getOrElse(true))
+ if (value.pList.allPatternsSimple)
+ bindings = value.bindings
+ if (bindings.size == 1)
+ binding <- bindings} {
if (value.typeElement.isDefined)
strategy.removeFromValue(value)
@@ -64,12 +64,12 @@ class ToggleTypeAnnotation extends PsiElementBaseIntentionAction {
return true
}
- for{variable <- element.parentsInFile.findByType(classOf[ScVariableDefinition])
- if (variable.expr.toOption.map(!_.isAncestorOf(element)).getOrElse(true))
- if (variable.pList.allPatternsSimple)
- bindings = variable.bindings
- if (bindings.size == 1)
- binding <- bindings} {
+ for {variable <- element.parentsInFile.findByType(classOf[ScVariableDefinition])
+ if (variable.expr.toOption.map(!_.isAncestorOf(element)).getOrElse(true))
+ if (variable.pList.allPatternsSimple)
+ bindings = variable.bindings
+ if (bindings.size == 1)
+ binding <- bindings} {
if (variable.typeElement.isDefined)
strategy.removeFromVariable(variable)
View
14 src/org/jetbrains/plugins/scala/codeInsight/intention/types/Update.scala
@@ -8,9 +8,10 @@ import org.jetbrains.plugins.scala.lang.psi.types.ScType
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import org.jetbrains.plugins.scala.extensions._
import lang.psi.ScalaPsiUtil
-import lang.psi.api.expr.ScFunctionExpr
-import lang.psi.api.statements.params.{ScParameterClause, ScParameter}
import lang.psi.api.base.patterns.{ScWildcardPattern, ScBindingPattern, ScTypedPattern}
+import lang.psi.api.statements.params.{ScParameterClause, ScParameter}
+import lang.psi.api.expr.{ScInfixExpr, ScFunctionExpr}
+import com.intellij.psi.util.PsiTreeUtil
/**
* Pavel.Fatin, 28.04.2010
@@ -89,7 +90,14 @@ object Update extends Strategy {
def removeFromParameter(param: ScParameter) {
val newParam = ScalaPsiElementFactory.createParameterFromText(param.name, param.getManager)
- param.replace(newParam)
+ val newClause = ScalaPsiElementFactory.createClauseForFunctionExprFromText(newParam.getText, param.getManager)
+ val expr : ScFunctionExpr = PsiTreeUtil.getParentOfType(param, classOf[ScFunctionExpr], false)
+ if (expr != null && expr.parameters.size == 1 &&
+ (expr.params.clauses(0).getText.startsWith("(") && expr.params.clauses(0).getText.endsWith(")"))) {
+ expr.params.clauses(0).replace(newClause)
+ } else {
+ param.replace(newParam)
+ }
}
def addTypeAnnotation(t: ScType, context: PsiElement, anchor: PsiElement) {
View
9 src/org/jetbrains/plugins/scala/lang/psi/impl/ScalaPsiElementFactory.scala
@@ -80,6 +80,15 @@ object ScalaPsiElementFactory {
fun.paramClauses.clauses.apply(0)
}
+ def createClauseForFunctionExprFromText(clauseText: String, manager: PsiManager): ScParameterClause = {
+ val text = clauseText + " => null"
+ val dummyFile = PsiFileFactory.getInstance(manager.getProject).
+ createFileFromText(DUMMY + ScalaFileType.SCALA_FILE_TYPE.getDefaultExtension,
+ ScalaFileType.SCALA_FILE_TYPE, text).asInstanceOf[ScalaFile]
+ val fun = dummyFile.getFirstChild.asInstanceOf[ScFunctionExpr]
+ fun.params.clauses(0)
+ }
+
def createImplicitClauseFromTextWithContext(clauseText: String, manager: PsiManager,
context: PsiElement): ScParameterClause = {
val text = clauseText
Please sign in to comment.
Something went wrong with that request. Please try again.