<commit_before>package org.jetbrains.plugins.scala
package codeInsight.intention.argument

import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import com.intellij.psi.util.PsiTreeUtil
import collection.{Seq, Iterator}
import lang.psi.api.expr.{ScExpression, ScAssignStmt, ScArgumentExprList}
import lang.psi.types.nonvalue.Parameter

/**
 * <NAME>
 */

class AddNameToArgumentIntention extends PsiElementBaseIntentionAction {
  def getFamilyName = "Use named arguments"

  override def getText = "Use named arguments for current and subsequent arguments"

  def isAvailable(project: Project, editor: Editor, element: PsiElement) = {
    check(project, editor, element).isDefined
  }

  override def invoke(project: Project, editor: Editor, element: PsiElement) {
    if (!element.isValid) return
    check(project, editor, element) match {
      case Some(x) => x()
      case None =>
    }
  }

  private def check(project: Project, editor: Editor, element: PsiElement): Option[() => Unit] = {
    val containingArgList: Option[ScArgumentExprList] = element.parents.collectFirst {
      case al: ScArgumentExprList if !al.isBraceArgs => al
    }
    containingArgList match {
      case Some(al) =>
        val index = al.exprs.indexWhere(argExpr => PsiTreeUtil.isAncestor(argExpr, element, false))
        index match {
          case -1 => None
          case i =>
            val argExprsToNamify = al.exprs.drop(index)
            val argsAndMatchingParams: Seq[(ScExpression, Option[Parameter])] = argExprsToNamify.map {
              arg => (arg, al.parameterOf(arg))
            }
            argsAndMatchingParams.headOption match {
              case Some((assign: ScAssignStmt, Some(param))) if assign.getLExpression.getText == param.name =>
                None
              case None | Some((_, None)) =>
                None
              case _ =>
                val doIt = () => {
                  argsAndMatchingParams.foreach {
                    case (argExpr: ScAssignStmt, Some(param)) if argExpr.getLExpression.getText == param.name =>
                    case (argExpr, Some(param)) =>
                      val newArgExpr = ScalaPsiElementFactory.createExpressionFromText(param.name + " = " + argExpr.getText, element.getManager)
                      argExpr.replace(newArgExpr)
                    case _ =>
                  }
                }
                Some(doIt)
            }
        }
      case None => None
    }
  }
}<commit_msg>Don't offer add name intention for varargs.<commit_after>package org.jetbrains.plugins.scala
package codeInsight.intention.argument

import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import com.intellij.psi.util.PsiTreeUtil
import collection.{Seq, Iterator}
import lang.psi.api.expr.{ScExpression, ScAssignStmt, ScArgumentExprList}
import lang.psi.types.nonvalue.Parameter

/**
 * <NAME>
 */

class AddNameToArgumentIntention extends PsiElementBaseIntentionAction {
  def getFamilyName = "Use named arguments"

  override def getText = "Use named arguments for current and subsequent arguments"

  def isAvailable(project: Project, editor: Editor, element: PsiElement) = {
    check(project, editor, element).isDefined
  }

  override def invoke(project: Project, editor: Editor, element: PsiElement) {
    if (!element.isValid) return
    check(project, editor, element) match {
      case Some(x) => x()
      case None =>
    }
  }

  private def check(project: Project, editor: Editor, element: PsiElement): Option[() => Unit] = {
    val containingArgList: Option[ScArgumentExprList] = element.parents.collectFirst {
      case al: ScArgumentExprList if !al.isBraceArgs => al
    }
    containingArgList match {
      case Some(al) =>
        val index = al.exprs.indexWhere(argExpr => PsiTreeUtil.isAncestor(argExpr, element, false))
        index match {
          case -1 => None
          case i =>
            val argExprsToNamify = al.exprs.drop(index)
            val argsAndMatchingParams: Seq[(ScExpression, Option[Parameter])] = argExprsToNamify.map {
              arg => (arg, al.parameterOf(arg))
            }
            val isRepeated = argsAndMatchingParams.exists {
              case (_, Some(param)) if param.isRepeated => true
              case _ => false
            }
            argsAndMatchingParams.headOption match {
              case _ if isRepeated => None
              case Some((assign: ScAssignStmt, Some(param))) if assign.getLExpression.getText == param.name =>
                None
              case None | Some((_, None)) =>
                None
              case _ =>
                val doIt = () => {
                  argsAndMatchingParams.foreach {
                    case (argExpr: ScAssignStmt, Some(param)) if argExpr.getLExpression.getText == param.name =>
                    case (argExpr, Some(param)) =>
                      val newArgExpr = ScalaPsiElementFactory.createExpressionFromText(param.name + " = " + argExpr.getText, element.getManager)
                      argExpr.replace(newArgExpr)
                    case _ =>
                  }
                }
                Some(doIt)
            }
        }
      case None => None
    }
  }
}
{'fraction_non_alphanumeric': 0.09875678515146209, 'fraction_numerical': 0.0003502013657853266, 'mean_word_length': 2.485051860890787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2410193', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1576, 'n_words': 352}