18e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar/*
28e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * Copyright (C) 2016 The Android Open Source Project
38e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar *
48e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
58e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * you may not use this file except in compliance with the License.
68e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * You may obtain a copy of the License at
78e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar *
88e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
98e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar *
108e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * Unless required by applicable law or agreed to in writing, software
118e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
128e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * See the License for the specific language governing permissions and
148e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * limitations under the License.
158e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar */
168e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar
17bdc4c86d3dff74f6634a38e2f7b316b0e823a2c8Alan Viverettepackage androidx.room.solver.types
188e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar
19bdc4c86d3dff74f6634a38e2f7b316b0e823a2c8Alan Viveretteimport androidx.room.ext.L
20bdc4c86d3dff74f6634a38e2f7b316b0e823a2c8Alan Viveretteimport androidx.room.ext.T
21bdc4c86d3dff74f6634a38e2f7b316b0e823a2c8Alan Viveretteimport androidx.room.ext.typeName
22bdc4c86d3dff74f6634a38e2f7b316b0e823a2c8Alan Viveretteimport androidx.room.solver.CodeGenScope
238e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar
248e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar/**
258e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar * combines 2 type converters
268e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar */
276f1f5567abe765d30fda9c8fedce5617ecdeda9cAurimas Liutikasclass CompositeTypeConverter(val conv1: TypeConverter, val conv2: TypeConverter) : TypeConverter(
288e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar        conv1.from, conv2.to) {
29fb4fcc8caf2a1908843bd18298447ff6fc498896Yigit Boyar    override fun convert(inputVarName: String, outputVarName: String, scope: CodeGenScope) {
308e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar        scope.builder().apply {
318e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar            val tmp = scope.getTmpVar()
328e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar            addStatement("final $T $L", conv1.to.typeName(), tmp)
33fb4fcc8caf2a1908843bd18298447ff6fc498896Yigit Boyar            conv1.convert(inputVarName, tmp, scope)
34fb4fcc8caf2a1908843bd18298447ff6fc498896Yigit Boyar            conv2.convert(tmp, outputVarName, scope)
358e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar        }
368e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar    }
378e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar}
38