<commit_before>package org.jetbrains.plugins.scala
package lang
package psi
package api
package toplevel
package typedef

import base.ScPrimaryConstructor
import impl.ScalaPsiElementFactory
import lexer.ScalaTokenTypes
import com.intellij.psi.{PsiMethod, PsiElement}
import statements.params.{ScParameterClause, ScParameters}
import statements.{ScFunction, ScFunctionDefinition, ScParameterOwner}
import caches.CachesUtil
import com.intellij.psi.util.PsiModificationTracker

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

trait ScClass extends ScTypeDefinition with ScParameterOwner {
  def constructor: Option[ScPrimaryConstructor]

  def secondaryConstructors: Seq[ScFunction] = {
    functions.filter(_.isConstructor)
  }

  def constructors: Array[PsiMethod] = {
    (secondaryConstructors ++ constructor.toSeq).toArray
  }

  def clauses: Option[ScParameters] = constructor match {
    case Some(x: ScPrimaryConstructor) => Some(x.parameterList)
    case None => None
  }

  def addEmptyParens() {
    clauses match {
      case Some(c) =>
        val clause = ScalaPsiElementFactory.createClauseFromText("()", getManager)
        c.addClause(clause)
      case _ =>
    }
  }

  def fakeCompanionModule: Option[ScObject] = {
    ScalaPsiUtil.getBaseCompanionModule(this) match {
      case Some(td: ScObject) => None
      case _ if !isCase => None
      case _ =>
        CachesUtil.get(this, CachesUtil.FAKE_CLASS_COMPANION,
          new CachesUtil.MyProvider[ScClass, Option[ScObject]](this, (clazz: ScClass) => {
            val texts = clazz.getSyntheticMethodsText

            val extendsText = {
              try {
                if (typeParameters.isEmpty) {
                  val typeElementText =
                    constructor.get.effectiveParameterClauses.map {
                      clause =>
                        clause.parameters.map(parameter => {
                          val parameterText = parameter.typeElement.map(_.getText).getOrElse("Nothing")
                          if (parameter.isRepeatedParameter) s"Seq[$parameterText]"
                          else parameterText
                        }).mkString("(", ", ", ")")
                    }.mkString("(", " => ", s" => $name)")
                  val typeElement = ScalaPsiElementFactory.createTypeElementFromText(typeElementText, getManager)
                  s" extends ${typeElement.getText}"
                } else {
                  ""
                }
              } catch {
                case e: Exception => ""
              }
            }
            val accessModifier = clazz.getModifierList.accessModifier.map(_.modifierFormattedText + " ").getOrElse("")
            val objText = accessModifier + "object " + clazz.name + extendsText + "{\n  " + texts._1 + "\n  " + texts._2 + "\n" + "}"
            val next = ScalaPsiUtil.getNextStubOrPsiElement(clazz)
            val obj: ScObject =<commit_msg>Seq -> _root_.scala.Seq according to Jason review remark.<commit_after>package org.jetbrains.plugins.scala
package lang
package psi
package api
package toplevel
package typedef

import base.ScPrimaryConstructor
import impl.ScalaPsiElementFactory
import lexer.ScalaTokenTypes
import com.intellij.psi.{PsiMethod, PsiElement}
import statements.params.{ScParameterClause, ScParameters}
import statements.{ScFunction, ScFunctionDefinition, ScParameterOwner}
import caches.CachesUtil
import com.intellij.psi.util.PsiModificationTracker

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

trait ScClass extends ScTypeDefinition with ScParameterOwner {
  def constructor: Option[ScPrimaryConstructor]

  def secondaryConstructors: Seq[ScFunction] = {
    functions.filter(_.isConstructor)
  }

  def constructors: Array[PsiMethod] = {
    (secondaryConstructors ++ constructor.toSeq).toArray
  }

  def clauses: Option[ScParameters] = constructor match {
    case Some(x: ScPrimaryConstructor) => Some(x.parameterList)
    case None => None
  }

  def addEmptyParens() {
    clauses match {
      case Some(c) =>
        val clause = ScalaPsiElementFactory.createClauseFromText("()", getManager)
        c.addClause(clause)
      case _ =>
    }
  }

  def fakeCompanionModule: Option[ScObject] = {
    ScalaPsiUtil.getBaseCompanionModule(this) match {
      case Some(td: ScObject) => None
      case _ if !isCase => None
      case _ =>
        CachesUtil.get(this, CachesUtil.FAKE_CLASS_COMPANION,
          new CachesUtil.MyProvider[ScClass, Option[ScObject]](this, (clazz: ScClass) => {
            val texts = clazz.getSyntheticMethodsText

            val extendsText = {
              try {
                if (typeParameters.isEmpty) {
                  val typeElementText =
                    constructor.get.effectiveParameterClauses.map {
                      clause =>
                        clause.parameters.map(parameter => {
                          val parameterText = parameter.typeElement.map(_.getText).getOrElse("_root_.scala.Nothing")
                          if (parameter.isRepeatedParameter) s"_root_.scala.Seq[$parameterText]"
                          else parameterText
                        }).mkString("(", ", ", ")")
                    }.mkString("(", " => ", s" => $name)")
                  val typeElement = ScalaPsiElementFactory.createTypeElementFromText(typeElementText, getManager)
                  s" extends ${typeElement.getText}"
                } else {
                  ""
                }
              } catch {
                case e: Exception => ""
              }
            }
            val accessModifier = clazz.getModifierList.accessModifier.map(_.modifierFormattedText + " ").getOrElse("")
            val objText = accessModifier + "object " + clazz.name + extendsText + "{\n  " + texts._1 + "\n  " + texts._2 + "\n" + "}"
            val next = ScalaPsiUtil.getNextStubOrPsiElement(clazz)
            val obj: ScObject =
{'fraction_non_alphanumeric': 0.10248130523453433, 'fraction_numerical': 0.003399048266485384, 'mean_word_length': 2.34375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '6274697', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1597, 'n_words': 320}