|
| 1 | +/* |
| 2 | + * Copyright 2022 UnitTestBot contributors (utbot.org) |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * <p> |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * <p> |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.jacodb.ets.proto |
| 18 | + |
| 19 | +import org.jacodb.ets.model.EtsEntity |
| 20 | +import org.jacodb.ets.model.EtsExpr |
| 21 | +import org.jacodb.ets.model.EtsRawEntity |
| 22 | +import org.jacodb.ets.model.EtsValue |
| 23 | +import model.RawValue as ProtoRawValue |
| 24 | +import model.Value as ProtoValue |
| 25 | + |
| 26 | +fun EtsEntity.toProto(): ProtoValue = accept(EtsEntityToProto) |
| 27 | + |
| 28 | +internal object EtsEntityToProto : |
| 29 | + EtsEntity.Visitor<ProtoValue>, |
| 30 | + EtsValue.Visitor.Default<ProtoValue>, |
| 31 | + EtsExpr.Visitor.Default<ProtoValue> { |
| 32 | + |
| 33 | + override fun visit(value: EtsRawEntity): ProtoValue { |
| 34 | + val rawValue = ProtoRawValue( |
| 35 | + kind = value.kind, |
| 36 | + type = value.type.toProto(), |
| 37 | + ) |
| 38 | + return ProtoValue(raw_value = rawValue) |
| 39 | + } |
| 40 | + |
| 41 | + override fun defaultVisit(value: EtsValue): ProtoValue = value.toProto() |
| 42 | + override fun defaultVisit(expr: EtsExpr): ProtoValue = expr.toProto() |
| 43 | +} |
0 commit comments