1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.core
21 
22 import cats.instances.string._
23 import com.github.plokhotnyuk.jsoniter_scala.core._
24 
25 trait StringValue {
26   def value: String
27 }
28 
29 object StringValue {
30 
31   implicit def catsOrder[T <: StringValue]: cats.Order[T] = cats.Order.by(_.value)
32   implicit def ordering[T <: StringValue]: Ordering[T] = Ordering.by(_.value)
33 
34   @SuppressWarnings(Array("org.wartremover.warts.Null", "org.wartremover.warts.Throw"))
35   def makeCodec[T <: StringValue](create: String => T): JsonValueCodec[T] =
36     new JsonValueCodec[T] {
37 
38       def decodeValue(in: JsonReader, default: T): T =
39         create(in.readString(null))
40 
41       def encodeValue(stringValue: T, out: JsonWriter): Unit =
42         out.writeVal(stringValue.value)
43 
44       @SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf"))
45       def nullValue: T = null.asInstanceOf[T]
46     }
47 }
Line Stmt Id Pos Tree Symbol Tests Code
31 164 977 - 999 ApplyToImplicitArgs cats.kernel.Order.by org.scalatest.testsuite cats.`package`.Order.by[T, String](((x$1: T) => x$1.value))(cats.instances.`package`.string.catsKernelStdOrderForString)
31 77 991 - 998 Select org.make.core.StringValue.value org.scalatest.testsuite x$1.value
31 273 990 - 990 Select cats.kernel.instances.StringInstances.catsKernelStdOrderForString org.scalatest.testsuite cats.instances.`package`.string.catsKernelStdOrderForString
32 184 1057 - 1077 ApplyToImplicitArgs scala.math.Ordering.by org.make.api.crmtemplates.admincrmlanguagetemplatesapitest scala.`package`.Ordering.by[T, String](((x$2: T) => x$2.value))(math.this.Ordering.String)
32 82 1069 - 1076 Select org.make.core.StringValue.value org.make.api.crmtemplates.admincrmlanguagetemplatesapitest x$2.value
32 299 1068 - 1068 Select scala.math.Ordering.String org.make.api.crmtemplates.admincrmlanguagetemplatesapitest math.this.Ordering.String
36 96 1247 - 1250 Apply org.make.core.StringValue.$anon.<init> org.make.api.avro.avrocompatibilitytest,org.make.core.operation.operationofquestiontest,org.make.api.idea.ideasearchenginetest,org.make.api.technical.webflow.desertest,org.make.api.technical.streamutilstest,org.make.api.sequence.sequencecacheactortest,org.make.api.technical.retryablefuturetest,org.make.api.user.persistentuserservicecomponenttest,org.make.api.technical.directives.clientdirectivestest,org.make.api.crmtemplates.crmtemplatesservicetest,org.make.api.sessionhistory.sessionhistorycoordinatortest new $anon()
39 265 1335 - 1362 Apply scala.Function1.apply org.make.core.proposal.indexed.proposaltest create.apply(in.readString(null))
39 60 1342 - 1361 Apply com.github.plokhotnyuk.jsoniter_scala.core.JsonReader.readString org.make.core.proposal.indexed.proposaltest in.readString(null)
42 73 1435 - 1466 Apply com.github.plokhotnyuk.jsoniter_scala.core.JsonWriter.writeVal org.make.core.proposal.indexed.proposaltest out.writeVal(stringValue.value)
42 195 1448 - 1465 Select org.make.core.StringValue.value org.make.core.proposal.indexed.proposaltest stringValue.value
45 163 1562 - 1582 TypeApply scala.Any.asInstanceOf org.make.core.proposal.indexed.proposaltest null.asInstanceOf[T]
45 279 1562 - 1566 Literal <nosymbol> org.make.core.proposal.indexed.proposaltest null