<commit_before>package scala.meta.trees

import com.intellij.debugger.engine.JVMNameUtil
import com.intellij.psi._
import com.intellij.psi.impl.file.PsiPackageImpl
import com.intellij.psi.impl.source.DummyHolder
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._
import org.jetbrains.plugins.scala.lang.psi.api.statements._
import org.jetbrains.plugins.scala.lang.psi.api.statements.params._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.packaging.ScPackaging
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager
import org.jetbrains.plugins.scala.lang.psi.{api => p, impl, types => ptype}
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult
import org.scalameta.collections._

import scala.annotation.tailrec
import scala.language.postfixOps
import scala.meta.internal.{ast => m, semantic => h}
import scala.meta.trees.error._

trait SymbolTable {
  self: TreeConverter =>

  private val symbolCache = TwoWayCache[PsiElement, h.Symbol]()

  def localSymbolDelim = "*"

  def isLocal(elem: PsiElement): Boolean = {
    elem match {
      case e: ScTypeDefinition => e.isLocal
      case e: ScBindingPattern if e.containingClass == null => true
      case pp: params.ScParameter => true
      case tp: ScTypeParam => true
      case _ => false
    }
  }

  def fqnameToSymbol(fqName: String, toDrop: Int = 1): h.Symbol = {
    fqName
      .split('.')
      .dropRight(toDrop)
      .foldLeft(h.Symbol.RootPackage.asInstanceOf[h.Symbol])((parent, name) => h.Symbol.Global(parent, name, h.Signature.Term))
  }

  def symbolToFqname(sym: h.Symbol): String = {
    def rec(s: h.Symbol): String = {
      s match {
        case h.Symbol.RootPackage => ""
        case h.Symbol.EmptyPackage => ""
        case h.Symbol.Global(parent, name, _) => rec(parent) + "." + name
      }
    }
    rec(sym)
  }

  def ownerSymbol(elem: PsiElement): h.Symbol = {
    elem match {
      case mm: ScMember =>
        if (mm.containingClass == null) h.Symbol.EmptyPackage else toSymbol(mm.containingClass)
      case bp: ScBindingPattern =>
        if (bp.containingClass == null) h.Symbol.EmptyPackage else toSymbol(bp.containingClass)
      case pc: PsiMember =>
        if (pc.getContainingClass == null) h.Symbol.EmptyPackage else toSymbol(pc.getContainingClass)
      case other => other ?!
    }
  }<commit_msg>metahost: add symbol generation with explicit parent<commit_after>package scala.meta.trees

import com.intellij.debugger.engine.JVMNameUtil
import com.intellij.psi._
import com.intellij.psi.impl.file.PsiPackageImpl
import com.intellij.psi.impl.source.DummyHolder
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.psi.api.base.patterns._
import org.jetbrains.plugins.scala.lang.psi.api.statements._
import org.jetbrains.plugins.scala.lang.psi.api.statements.params._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.packaging.ScPackaging
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager
import org.jetbrains.plugins.scala.lang.psi.{api => p, impl, types => ptype}
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveResult
import org.scalameta.collections._

import scala.annotation.tailrec
import scala.language.postfixOps
import scala.meta.internal.{ast => m, semantic => h}
import scala.meta.trees.error._

trait SymbolTable {
  self: TreeConverter =>

  private val symbolCache = TwoWayCache[PsiElement, h.Symbol]()

  def localSymbolDelim = "*"

  def isLocal(elem: PsiElement): Boolean = {
    elem match {
      case e: ScTypeDefinition => e.isLocal
      case e: ScBindingPattern if e.containingClass == null => true
      case pp: params.ScParameter => true
      case tp: ScTypeParam => true
      case _ => false
    }
  }

  def fqnameToSymbol(fqName: String, toDrop: Int = 1): h.Symbol = {
    fqName
      .split('.')
      .dropRight(toDrop)
      .foldLeft(h.Symbol.RootPackage.asInstanceOf[h.Symbol])((parent, name) => h.Symbol.Global(parent, name, h.Signature.Term))
  }

  def symbolToFqname(sym: h.Symbol): String = {
    def rec(s: h.Symbol): String = {
      s match {
        case h.Symbol.RootPackage => ""
        case h.Symbol.EmptyPackage => ""
        case h.Symbol.Global(parent, name, _) => rec(parent) + "." + name
      }
    }
    rec(sym)
  }

  def ownerSymbol(elem: PsiElement): h.Symbol = {
    elem match {
      case mm: ScMember =>
        if (mm.containingClass == null) h.Symbol.EmptyPackage else toSymbol(mm.containingClass)
      case bp: ScBindingPattern =>
        if (bp.containingClass == null) h.Symbol.EmptyPackage else toSymbol(bp.containingClass)
      case pc: PsiMember =>
        if (pc.getContainingClass == null) h.Symbol.EmptyPackage else toSymbol(pc.getContainingClass)
      case other => other ?!
    }
  }

  // used for generating symbols when no direct access to parent is avaliable(e.g. ScType)
  def toSymbolWtihParent(name: String, parent: PsiElement, signature: h.Signature) = {
    h.Symbol.Global(toSymbol(parent), name, signature)
  }
{'fraction_non_alphanumeric': 0.12191103789126853, 'fraction_numerical': 0.0003660992128866923, 'mean_word_length': 3.6462585034013606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '2963488', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1754, 'n_words': 345}