<commit_before>package scala.models

import lib.Text._
import scala.generator.{Namespaces, PrimitiveWrapper, ScalaDatatype, ScalaModel, ScalaPrimitive, ScalaService, ScalaUnion, ScalaUnionType}

case class Play2JsonCommon(ssd: ScalaService) {

  def toJsonObjectMethodName(ns: Namespaces, name: String): String = {
    val method = s"json${ssd.name}${name}ToJsonObject"
    ns.base == ssd.namespaces.base match {
      case true => method
      case false => Seq(ns.json, method).mkString(".")
    }
  }

  def implicitWriter(name: String, qualifiedName: String, methodName: String) = {
    Seq(
      s"${implicitWriterDef(name)} = {",
      s"  new play.api.libs.json.Writes[$qualifiedName] {",
      s"    def writes(obj: $qualifiedName) = {",
      s"      $methodName(obj)",
      "    }",
      "  }",
      "}"
    ).mkString("\n")
  }

  def implicitReaderDef(name: String): String = {
    s"implicit def ${implicitReaderName(name)}: play.api.libs.json.Reads[$name]"
  }
<commit_msg>Make JsObject method consistently named across services<commit_after>package scala.models

import lib.Text._
import scala.generator.{Namespaces, PrimitiveWrapper, ScalaDatatype, ScalaModel, ScalaPrimitive, ScalaService, ScalaUnion, ScalaUnionType}

case class Play2JsonCommon(ssd: ScalaService) {

  /**
    * Never use the service name in the method name. We never import
    * this method implicitly and we need to be able to reference
    * method names defined for other services.
    */
  def toJsonObjectMethodName(ns: Namespaces, name: String): String = {
    val method = s"jsObject${name}"
    ns.base == ssd.namespaces.base match {
      case true => method
      case false => Seq(ns.json, method).mkString(".")
    }
  }

  def implicitWriter(name: String, qualifiedName: String, methodName: String) = {
    Seq(
      s"${implicitWriterDef(name)} = {",
      s"  new play.api.libs.json.Writes[$qualifiedName] {",
      s"    def writes(obj: $qualifiedName) = {",
      s"      $methodName(obj)",
      "    }",
      "  }",
      "}"
    ).mkString("\n")
  }

  def implicitReaderDef(name: String): String = {
    s"implicit def ${implicitReaderName(name)}: play.api.libs.json.Reads[$name]"
  }

{'fraction_non_alphanumeric': 0.13733515234197363, 'fraction_numerical': 0.0009095043201455207, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7316283', 'n_tokens_mistral': 725, 'n_tokens_neox': 703, 'n_words': 161}