<commit_before>package org.jetbrains.plugins.scala.lang.surroundWith.surrounders.expression

/**
* @author <NAME>
* Date: 28.04.2008
*/

import com.intellij.psi.PsiElement
import com.intellij.lang.ASTNode
import com.intellij.openapi.util.TextRange


import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl
import lang.psi.api.expr._
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.PsiWhiteSpace;

class ScalaWithMatchSurrounder extends ScalaExpressionSurrounder {
  override def isApplicable(elements : Array[PsiElement]) : Boolean = {
    if (elements.length > 1) return false
    for (val element <- elements)
      if (!isApplicable(element)) return false
    return true
  }
  override def isApplicable(element : PsiElement) : Boolean = {
    element match {
      case _ : ScExpression | _: PsiWhiteSpace => {
        true
      }
      case e => {
        e.getNode.getElementType == ScalaTokenTypes.tLINE_TERMINATOR
      }
    }
  }
  override def getExpressionTemplateAsString (expr : ASTNode) = {
    val exprAsString = "while (true) { \n " + expr.getText + "\n" + "}"

    if (!isNeedBraces(expr)) exprAsString
    else "(" + exprAsString + ")"
  }

  override def getTemplateAsString(elements: Array[PsiElement]): String = {
    return super.getTemplateAsString(elements) + " match {\ncase a  =>\n}"
  }

  override def getTemplateDescription = "match"

  override def getSurroundSelectionRange (withMatchNode : ASTNode ) : TextRange = {
    val whileStmt = withMatchNode.getPsi.asInstanceOf[ScMatchStmt]
<commit_msg>fixed match bug<commit_after>package org.jetbrains.plugins.scala.lang.surroundWith.surrounders.expression

/**
* @author <NAME>
* Date: 28.04.2008
*/

import com.intellij.psi.PsiElement
import com.intellij.lang.ASTNode
import com.intellij.openapi.util.TextRange


import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElementImpl
import lang.psi.api.expr._
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.PsiWhiteSpace;

class ScalaWithMatchSurrounder extends ScalaExpressionSurrounder {
  override def isApplicable(elements : Array[PsiElement]) : Boolean = {
    if (elements.length > 1) return false
    for (val element <- elements)
      if (!isApplicable(element)) return false
    return true
  }
  override def isApplicable(element : PsiElement) : Boolean = {
    element match {
      case _ : ScExpression | _: PsiWhiteSpace => {
        true
      }
      case e => {
        e.getNode.getElementType == ScalaTokenTypes.tLINE_TERMINATOR
      }
    }
  }
  override def getExpressionTemplateAsString (expr : ASTNode) = {
    val exprAsString = "while (true) { \n " + expr.getText + "\n" + "}"

    if (!isNeedBraces(expr)) exprAsString
    else "(" + exprAsString + ")"
  }

  override def getTemplateAsString(elements: Array[PsiElement]): String = {
    return super.getTemplateAsString(elements) + " match {\ncase a  =>\n}"
  }

  override def getTemplateDescription = "match"

  override def getSurroundSelectionRange (withMatchNode : ASTNode ) : TextRange = {
    val whileStmt = withMatchNode.getPsi.asInstanceOf[ScMatchStmt]
    //val r = whileStmt.getNode.getLastChildNode.getTreePrev.getFirstChildNode
{'fraction_non_alphanumeric': 0.10852478839177751, 'fraction_numerical': 0.005441354292623942, 'mean_word_length': 3.8805309734513274, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '6967133', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1039, 'n_words': 209}