<commit_before>package org.jetbrains.plugins.scala.lang.psi

import com.intellij.util.IncorrectOperationException
import api.toplevel.typedef.ScTypeDefinition
import api.toplevel.imports.ScImportStmt
import com.intellij.extapi.psi.PsiFileBase
import com.intellij.lang.Language
import com.intellij.psi._
import com.intellij.psi.scope.PsiScopeProcessor
import org.jetbrains.plugins.scala.ScalaFileType
import com.intellij.psi.tree.TokenSet
import org.jetbrains.annotations.Nullable
import org.jetbrains.plugins.scala.icons.Icons
import com.intellij.lang.ASTNode
import com.intellij.psi.tree.IElementType
import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes
import psi.api.toplevel._
import psi.api.toplevel.typedef._
import psi.api.toplevel.packaging._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._
import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement
import org.jetbrains.plugins.scala.lang.psi.impl._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports._

import _root_.scala.collection.mutable._


class ScalaFile(viewProvider: FileViewProvider) extends PsiFileBase(viewProvider, ScalaFileType.SCALA_FILE_TYPE.getLanguage())
        with ScalaPsiElement with ScToplevelElement with PsiClassOwner with ScImportsHolder {

  override def getViewProvider = viewProvider
  override def getFileType = ScalaFileType.SCALA_FILE_TYPE
  override def toString = "ScalaFile"

  def setPackageName(name: String) = {
    //todo
  }

  def getPackagings = findChildrenByClass(classOf[ScPackaging])

  def getPackageName =
    packageStatement match {
      case None => ""
      case Some(stat) => stat.getPackageName
    }

  def importStatemntsInHeader: Seq[ScImportStmt] = {
    var end = false
    val buf = new ArrayBuffer[ScImportStmt]
    for (child <- getChildren if !end) {
      child match {
        case x: ScImportStmt => buf += x
        case _: ScTypeDefinition | _: ScPackaging => end = true
        case _ =>
      }
    }
    return buf.toSeq
  }

  def packageStatement = findChild(classOf[ScPackageStatement])

  override def getClasses = getTypeDefinitions.map(t => t : PsiClass)

  def getTopStatements: Array[ScTopStatement] = findChildrenByClass(classOf[ScTopStatement])

  def icon = Icons.FILE_TYPE_LOGO

  override def processDeclarations(processor: PsiScopeProcessor,
                                  state: ResolveState,
                                  lastParent: PsiElement,
                                  place: PsiElement): Boolean = {
    import org.jetbrains.plugins.scala.lang.resolve._

    if (!super[ScImportsHolder].processDeclarations(processor,
      state, lastParent, place)) return false

    place match {
      case ref: ScStableCodeReferenceElement if ref.refName == "_root_" => {
        val top = JavaPsiFacade.getInstance(getProject()).findPackage("")
        if (top != null && !processor.execute(top, state.put(ResolverEnv.nameKey, "_root_"))) return false
        state.put(ResolverEnv.nameKey, null)
      }
      case _ => {
        var curr = JavaPsiFacade.getInstance(getProject).findPackage(getPackageName)
        while (curr != null) {
          if (!curr.processDeclarations(processor, state, null, place)) return false
          curr = curr.getParentPackage
        }
      }
    }

    for (implObj <- ImplicitlyImported.objects) {
      val clazz = JavaPsiFacade.getInstance(getProject).findClass(implObj, getResolveScope)
      if (clazz != null && !clazz.processDeclarations(processor, state, null, place)) return false
    }

    import toplevel.synthetic.SyntheticClasses

    for (synth <- SyntheticClasses.get(getProject).getAll) {
      if (!processor.execute(synth, state)) return false;
    }

    for (implP <- ImplicitlyImported.packages) {
      val pack = JavaPsiFacade.getInstance(getProject()).findPackage(implP)
      if (pack != null && !pack.processDeclarations(processor, state, null, place)) return false
    }

    true
  }

  def addImportForClass(clazz: PsiClass) {
    val newImport = ScalaPsiElementFactory.createImportStatementFromClass(this, clazz, this.getManager)
    val resolve = ScalaPsiElementFactory.getResolveForClassQualifier(this, clazz, getManager)
    val sameExpressions: Array[ScImportExpr] = (for (importStmt <- importStatemntsInHeader; importExpr <- importStmt.importExprs<commit_msg>todo rewrite importStatementsInHeader<commit_after>package org.jetbrains.plugins.scala.lang.psi

import com.intellij.util.IncorrectOperationException
import api.toplevel.typedef.ScTypeDefinition
import api.toplevel.imports.ScImportStmt
import com.intellij.extapi.psi.PsiFileBase
import com.intellij.lang.Language
import com.intellij.psi._
import com.intellij.psi.scope.PsiScopeProcessor
import org.jetbrains.plugins.scala.ScalaFileType
import com.intellij.psi.tree.TokenSet
import org.jetbrains.annotations.Nullable
import org.jetbrains.plugins.scala.icons.Icons
import com.intellij.lang.ASTNode
import com.intellij.psi.tree.IElementType
import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes
import psi.api.toplevel._
import psi.api.toplevel.typedef._
import psi.api.toplevel.packaging._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef._
import org.jetbrains.plugins.scala.lang.psi.api.base.ScStableCodeReferenceElement
import org.jetbrains.plugins.scala.lang.psi.impl._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports._

import _root_.scala.collection.mutable._


class ScalaFile(viewProvider: FileViewProvider) extends PsiFileBase(viewProvider, ScalaFileType.SCALA_FILE_TYPE.getLanguage())
        with ScalaPsiElement with ScToplevelElement with PsiClassOwner with ScImportsHolder {

  override def getViewProvider = viewProvider
  override def getFileType = ScalaFileType.SCALA_FILE_TYPE
  override def toString = "ScalaFile"

  def setPackageName(name: String) = {
    //todo
  }

  def getPackagings = findChildrenByClass(classOf[ScPackaging])

  def getPackageName =
    packageStatement match {
      case None => ""
      case Some(stat) => stat.getPackageName
    }

  def importStatementsInHeader: Seq[ScImportStmt] = {
    var end = false
    val buf = new ArrayBuffer[ScImportStmt]
    for (child <- getChildren if !end) {
      child match {
        case x: ScImportStmt => buf += x
        case _: ScTypeDefinition | _: ScPackaging => end = true
        case _ =>
      }
    }
    return buf.toSeq
  }

  def packageStatement = findChild(classOf[ScPackageStatement])

  override def getClasses = getTypeDefinitions.map(t => t : PsiClass)

  def getTopStatements: Array[ScTopStatement] = findChildrenByClass(classOf[ScTopStatement])

  def icon = Icons.FILE_TYPE_LOGO

  override def processDeclarations(processor: PsiScopeProcessor,
                                  state: ResolveState,
                                  lastParent: PsiElement,
                                  place: PsiElement): Boolean = {
    import org.jetbrains.plugins.scala.lang.resolve._

    if (!super[ScImportsHolder].processDeclarations(processor,
      state, lastParent, place)) return false

    place match {
      case ref: ScStableCodeReferenceElement if ref.refName == "_root_" => {
        val top = JavaPsiFacade.getInstance(getProject()).findPackage("")
        if (top != null && !processor.execute(top, state.put(ResolverEnv.nameKey, "_root_"))) return false
        state.put(ResolverEnv.nameKey, null)
      }
      case _ => {
        var curr = JavaPsiFacade.getInstance(getProject).findPackage(getPackageName)
        while (curr != null) {
          if (!curr.processDeclarations(processor, state, null, place)) return false
          curr = curr.getParentPackage
        }
      }
    }

    for (implObj <- ImplicitlyImported.objects) {
      val clazz = JavaPsiFacade.getInstance(getProject).findClass(implObj, getResolveScope)
      if (clazz != null && !clazz.processDeclarations(processor, state, null, place)) return false
    }

    import toplevel.synthetic.SyntheticClasses

    for (synth <- SyntheticClasses.get(getProject).getAll) {
      if (!processor.execute(synth, state)) return false;
    }

    for (implP <- ImplicitlyImported.packages) {
      val pack = JavaPsiFacade.getInstance(getProject()).findPackage(implP)
      if (pack != null && !pack.processDeclarations(processor, state, null, place)) return false
    }

    true
  }

  def addImportForClass(clazz: PsiClass) {
    val newImport = ScalaPsiElementFactory.createImportStatementFromClass(this, clazz, this.getManager)
    val resolve = ScalaPsiElementFactory.getResolveForClassQualifier(this, clazz, getManager)
    val sameExpressions: Array[ScImportExpr] = (for (importStmt <- importStatementsInHeader; importExpr <- importStmt.importExprs
{'fraction_non_alphanumeric': 0.09492223238792315, 'fraction_numerical': 0.0, 'mean_word_length': 3.7347049269085004, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440447', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2589, 'n_words': 509}