<commit_before>package com.eharmony.matching.aloha.semantics.compiled.plugin.proto.codegen

import com.eharmony.matching.aloha.semantics.compiled.plugin.proto.accessor._
import MapType._


private[proto] object CodeGenerators {
//    private[this] def toCamelCase(s: String) = s.split("_+").map(_.toLowerCase.capitalize) mkString ""
    private[this] def toCamelCase(s: String) = s.split("_+").map(_.capitalize) mkString ""

    implicit object RequiredCodeGenerator extends RequiredAccessorCodeGenerator[Required] {
        override def generateGet(r: Required) = "get" + toCamelCase(r.field.getName)
    }

    implicit object DerefReqCodeGenerator extends RequiredAccessorCodeGenerator[DerefReq] {
        override def generateGet(d: DerefReq) = "get" + toCamelCase(d.field.getName) + "(" + d.index + ")"
    }

    implicit object RepeatedCodeGenerator extends RequiredAccessorCodeGenerator[Repeated] {
        override def generateGet(r: Repeated) = "get" + toCamelCase(r.field.getName) + "List"
    }

    implicit object OptionalCodeGenerator extends OptionalAccessorCodeGenerator[Optional] {
        override def generateGet(o: Optional) = "get" + toCamelCase(o.field.getName)
        override def generateHas(o: Optional) = "has" + toCamelCase(o.field.getName)
    }

    implicit object DerefOptCodeGenerator extends OptionalAccessorCodeGenerator[DerefOpt] {
        override def generateGet(d: DerefOpt) = "get" + toCamelCase(d.field.getName) + "(" + d.index + ")"
        override def generateHas(d: DerefOpt) = "get" + toCamelCase(d.field.getName) + "Count > " + d.index
    }

    implicit object ReqCodeGenerator extends RequiredAccessorCodeGenerator[Req] {
        override def generateGet(r: Req) = r match {
            case r: Repeated => RepeatedCodeGenerator.generateGet(r)<commit_msg>Added fix for camel-case mismatch for characters following numbers in protocol buffer field names.<commit_after>package com.eharmony.matching.aloha.semantics.compiled.plugin.proto.codegen

import com.eharmony.matching.aloha.semantics.compiled.plugin.proto.accessor._
import MapType._


private[proto] object CodeGenerators {

    /** Camel-case a protocol buffer field name (so we can generate code for the getters / setters).  This is a
      * slightly atypical version of camel-case.  The original version was just:
      *
      * {{{
      * private[this] def toCamelCase(s: String) = s.split("_+").map(_.capitalize) mkString ""
      * }}}
      *
      * But this disagrees with Google's protocol buffer implementation of camel-case that capitalizes
      * letters appearing directly after a number.  So, the following protocol buffer specification:
      *
      * {{{
      * optional bool comm_7d_c = 7;
      * }}}
      *
      * creates getter:
      *
      * {{{
      * public boolean getComm7DC(){ // ...
      * }}}
      *
      * Therefore, we have to do the slight craziness to match.
      * @param s input String to be camel-cased.
      * @return a camel-cased String
      */
    private[this] def toCamelCase(s: String) = {
        if (s.isEmpty) s
        else {
            val v = s.toVector
            v.drop(1).foldLeft(Vector(s.toString.capitalize.head)) { case(s, x) =>
                val l = s.last
                s :+ (if (l == '_' || (0x30 <= l && l <= 0x39)) x.toString.capitalize.head else x)
            }.filter(_ != '_').mkString
        }
    }

    implicit object RequiredCodeGenerator extends RequiredAccessorCodeGenerator[Required] {
        override def generateGet(r: Required) = "get" + toCamelCase(r.field.getName)
    }

    implicit object DerefReqCodeGenerator extends RequiredAccessorCodeGenerator[DerefReq] {
        override def generateGet(d: DerefReq) = "get" + toCamelCase(d.field.getName) + "(" + d.index + ")"
    }

    implicit object RepeatedCodeGenerator extends RequiredAccessorCodeGenerator[Repeated] {
        override def generateGet(r: Repeated) = "get" + toCamelCase(r.field.getName) + "List"
    }

    implicit object OptionalCodeGenerator extends OptionalAccessorCodeGenerator[Optional] {
        override def generateGet(o: Optional) = "get" + toCamelCase(o.field.getName)
        override def generateHas(o: Optional) = "has" + toCamelCase(o.field.getName)
    }

    implicit object DerefOptCodeGenerator extends OptionalAccessorCodeGenerator[DerefOpt] {
        override def generateGet(d: DerefOpt) = "get" + toCamelCase(d.field.getName) + "(" + d.index + ")"
        override def generateHas(d: DerefOpt) = "get" + toCamelCase(d.field.getName) + "Count > " + d.index
    }

    implicit object ReqCodeGenerator extends RequiredAccessorCodeGenerator[Req] {
        override def generateGet(r: Req) = r match {
            case r: Repeated => RepeatedCodeGenerator.generateGet(r)
{'fraction_non_alphanumeric': 0.11097126075099643, 'fraction_numerical': 0.0020977554017201595, 'mean_word_length': 3.3071364046973803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5533321', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1389, 'n_words': 333}