<commit_before>package org.jetbrains.plugins.scala.worksheet.ammonite

import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions.implementation.iterator.ParentsIterator
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScReferenceExpression
import org.jetbrains.plugins.scala.worksheet.GotoOriginalHandlerUtil

/**
  * User: Dmitry.Naydanov
  * Date: 03.08.17.
  */
class AmmoniteGotoHandler extends GotoDeclarationHandler {
  override def getGotoDeclarationTargets(sourceElement: PsiElement, offset: Int, editor: Editor): Array[PsiElement] = {
    if (sourceElement == null) return PsiElement.EMPTY_ARRAY
    
    sourceElement.getContainingFile match {
      case ammoniteFile: ScalaFile if AmmoniteUtil.isAmmoniteFile(ammoniteFile) =>
      case _ => return PsiElement.EMPTY_ARRAY 
    }
    
    sourceElement.getParent match {
      case ref: ScReferenceExpression => 
        ref.resolve() match {
          case scalaPsi: ScalaPsiElement if GotoOriginalHandlerUtil.findPsi(scalaPsi.getContainingFile).isDefined => 
            new ParentsIterator(scalaPsi, false).collectFirst {
              case p if GotoOriginalHandlerUtil.findPsi(p).isDefined => GotoOriginalHandlerUtil.findPsi(p).get
            }.toArray
          case _ => PsiElement.EMPTY_ARRAY
        }
      case _ => PsiElement.EMPTY_ARRAY<commit_msg>Ammonite: process references in imports for GoToHandler #SCL-12586 fixed<commit_after>package org.jetbrains.plugins.scala.worksheet.ammonite

import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.scala.extensions.implementation.iterator.ParentsIterator
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiElement
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement
import org.jetbrains.plugins.scala.worksheet.GotoOriginalHandlerUtil

/**
  * User: Dmitry.Naydanov
  * Date: 03.08.17.
  */
class AmmoniteGotoHandler extends GotoDeclarationHandler {
  override def getGotoDeclarationTargets(sourceElement: PsiElement, offset: Int, editor: Editor): Array[PsiElement] = {
    if (sourceElement == null) return PsiElement.EMPTY_ARRAY
    
    sourceElement.getContainingFile match {
      case ammoniteFile: ScalaFile if AmmoniteUtil.isAmmoniteFile(ammoniteFile) =>
      case _ => return PsiElement.EMPTY_ARRAY 
    }
    
    sourceElement.getParent match {
      case ref: ScReferenceElement => 
        ref.resolve() match {
          case scalaPsi: ScalaPsiElement if GotoOriginalHandlerUtil.findPsi(scalaPsi.getContainingFile).isDefined => 
            new ParentsIterator(scalaPsi, false).collectFirst {
              case p if GotoOriginalHandlerUtil.findPsi(p).isDefined => GotoOriginalHandlerUtil.findPsi(p).get
            }.toArray
          case _ => PsiElement.EMPTY_ARRAY
        }
      case _ => PsiElement.EMPTY_ARRAY
{'fraction_non_alphanumeric': 0.08576587421005116, 'fraction_numerical': 0.00511585916340656, 'mean_word_length': 4.210031347962382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7252449', 'n_tokens_mistral': 1026, 'n_tokens_neox': 980, 'n_words': 161}