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

import com.intellij.codeInsight.TargetElementEvaluator
import com.intellij.psi.{PsiElement, PsiReference}
import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition
import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult

/**
 * Nikolay.Tropin
 * 9/2/13
 */
class ScalaTargetElementEvaluator extends TargetElementEvaluator {

  def includeSelfInGotoImplementation(element: PsiElement): Boolean = true

  def getElementByReference(ref: PsiReference, flags: Int): PsiElement = ref.getElement match {
    case isUnapplyFromVal(binding) => binding
    case _ => null
  }

  private val isUnapplyFromVal = new {
    def unapply(ref: ScStableCodeReferenceElement): Option[(ScBindingPattern)] = {
      if (ref == null) return null
      ref.bind() match {
        case Some(resolve@ScalaResolveResult(fun: ScFunctionDefinition, _))
          if Set("unapply", "unapplySeq").contains(fun.name) =>
          resolve.innerResolveResult match {
            case Some(ScalaResolveResult(binding: ScBindingPattern, _)) => Some(binding)
            case _ => None
          }
        case _ => None
      }
    }
  }
}<commit_msg>Caret adjustment for all scala identifiers<commit_after>package org.jetbrains.plugins.scala
package codeInsight

import com.intellij.codeInsight.TargetElementEvaluatorEx
import com.intellij.psi.{PsiFile, PsiElement, PsiReference}
import org.jetbrains.plugins.scala.lang.psi.api.base.patterns.ScBindingPattern
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition
import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult
import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes

/**
 * Nikolay.Tropin
 * 9/2/13
 */
class ScalaTargetElementEvaluator extends TargetElementEvaluatorEx {

  def includeSelfInGotoImplementation(element: PsiElement): Boolean = true

  def getElementByReference(ref: PsiReference, flags: Int): PsiElement = ref.getElement match {
    case isUnapplyFromVal(binding) => binding
    case _ => null
  }

  private val isUnapplyFromVal = new {
    def unapply(ref: ScStableCodeReferenceElement): Option[(ScBindingPattern)] = {
      if (ref == null) return null
      ref.bind() match {
        case Some(resolve@ScalaResolveResult(fun: ScFunctionDefinition, _))
          if Set("unapply", "unapplySeq").contains(fun.name) =>
          resolve.innerResolveResult match {
            case Some(ScalaResolveResult(binding: ScBindingPattern, _)) => Some(binding)
            case _ => None
          }
        case _ => None
      }
    }
  }

  def isIdentifierPart(file: PsiFile, text: CharSequence, offset: Int): Boolean = {
    val child: PsiElement = file.findElementAt(offset)
    child != null && ScalaTokenTypes.IDENTIFIER_TOKEN_SET.contains(child.getNode.getElementType )
  }
}
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.002572347266881029, 'mean_word_length': 4.142148760330579, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5938991', 'n_tokens_mistral': 956, 'n_tokens_neox': 927, 'n_words': 167}