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.jsoniter
21 
22 import com.github.plokhotnyuk.jsoniter_scala.core._
23 import enumeratum.values.{StringEnum, StringEnumEntry}
24 
25 import scala.collection.mutable.HashMap
26 
27 @SuppressWarnings(Array("org.wartremover.warts.LeakingSealed"))
28 trait JsoniterEnum[T <: StringEnumEntry] extends StringEnum[T] {
29 
30   @SuppressWarnings(Array("org.wartremover.warts.MutableDataStructures"))
31   private val kvs: HashMap[String, T] = this.values.map(v => (v.value, v)).to(HashMap)
32 
33   @SuppressWarnings(Array("org.wartremover.warts.Null", "org.wartremover.warts.AsInstanceOf"))
34   implicit val codec: JsonValueCodec[T] =
35     new JsonValueCodec[T] {
36 
37       def decodeValue(in: JsonReader, default: T): T =
38         kvs(in.readString(null))
39 
40       def encodeValue(wrapper: T, out: JsonWriter): Unit =
41         out.writeVal(wrapper.value)
42 
43       def nullValue: T = null.asInstanceOf[T]
44     }
45 }
Line Stmt Id Pos Tree Symbol Tests Code
31 5197 1208 - 1215 ApplyImplicitView scala.collection.MapFactory.toFactory org.make.api.operation.operationofquestionservicetest,org.make.core.operation.operationofquestiontest,org.make.api.avro.avrocompatibilitytest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest collection.this.MapFactory.toFactory[String, T, [K, V]scala.collection.mutable.HashMap[K,V]](scala.collection.mutable.HashMap)
31 3309 1170 - 1216 Apply scala.collection.IterableOnceOps.to org.make.api.operation.operationofquestionservicetest,org.make.api.avro.avrocompatibilitytest,org.make.core.operation.operationofquestiontest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest this.values.map[(String, T)](((v: T) => scala.Tuple2.apply[String, T](v.value, v))).to[scala.collection.mutable.HashMap[String,T]](collection.this.MapFactory.toFactory[String, T, [K, V]scala.collection.mutable.HashMap[K,V]](scala.collection.mutable.HashMap))
31 1745 1208 - 1215 Select scala.collection.mutable.HashMap org.make.api.operation.operationofquestionservicetest,org.make.api.avro.avrocompatibilitytest,org.make.core.operation.operationofquestiontest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest scala.collection.mutable.HashMap
31 584 1192 - 1199 Select enumeratum.values.ValueEnumEntry.value org.make.api.operation.operationofquestionservicetest,org.make.api.avro.avrocompatibilitytest,org.make.core.operation.operationofquestiontest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest v.value
31 3831 1191 - 1203 Apply scala.Tuple2.apply org.make.api.operation.operationofquestionservicetest,org.make.api.avro.avrocompatibilitytest,org.make.core.operation.operationofquestiontest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest scala.Tuple2.apply[String, T](v.value, v)
35 1721 1359 - 1362 Apply org.make.core.jsoniter.JsoniterEnum.$anon.<init> org.make.api.operation.operationofquestionservicetest,org.make.core.operation.operationofquestiontest,org.make.api.avro.avrocompatibilitytest,org.scalatest.testsuite,org.make.api.user.persistentuserservicecomponenttest,org.make.api.sessionhistory.sessionhistorycoordinatortest new $anon()
38 5481 1447 - 1471 Apply scala.collection.mutable.HashMap.apply org.make.core.proposal.indexed.proposaltest JsoniterEnum.this.kvs.apply(in.readString(null))
38 2099 1451 - 1470 Apply com.github.plokhotnyuk.jsoniter_scala.core.JsonReader.readString org.make.core.proposal.indexed.proposaltest in.readString(null)
41 3588 1553 - 1566 Select enumeratum.values.ValueEnumEntry.value org.make.core.proposal.indexed.proposaltest wrapper.value
41 1577 1540 - 1567 Apply com.github.plokhotnyuk.jsoniter_scala.core.JsonWriter.writeVal org.make.core.proposal.indexed.proposaltest out.writeVal(wrapper.value)
43 453 1594 - 1598 Literal <nosymbol> org.make.core.proposal.indexed.proposaltest null
43 3760 1594 - 1614 TypeApply scala.Any.asInstanceOf org.make.core.proposal.indexed.proposaltest null.asInstanceOf[T]