1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 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 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 androidx.room.compiler.codegen.impl 18 19 import androidx.room.compiler.codegen.XCodeBlock 20 import androidx.room.compiler.codegen.XSpec 21 import androidx.room.compiler.codegen.XTypeName 22 import androidx.room.compiler.codegen.java.JavaCodeBlock 23 import androidx.room.compiler.codegen.kotlin.KotlinCodeBlock 24 25 internal class XCodeBlockImpl( 26 val java: JavaCodeBlock, 27 val kotlin: KotlinCodeBlock, 28 ) : XSpec(), XCodeBlock { 29 30 internal class Builder( 31 val java: JavaCodeBlock.Builder, 32 val kotlin: KotlinCodeBlock.Builder, 33 ) : XSpec.Builder(), XCodeBlock.Builder { 34 private val delegates: List<XCodeBlock.Builder> = listOf(java, kotlin) 35 addnull36 override fun add(code: XCodeBlock) = apply { delegates.forEach { it.add(code) } } 37 addnull38 override fun add(format: String, vararg args: Any?) = apply { 39 delegates.forEach { it.add(format, *args) } 40 } 41 addStatementnull42 override fun addStatement(format: String, vararg args: Any?) = apply { 43 delegates.forEach { it.addStatement(format, *args) } 44 } 45 addLocalVariablenull46 override fun addLocalVariable( 47 name: String, 48 typeName: XTypeName, 49 isMutable: Boolean, 50 assignExpr: XCodeBlock? 51 ) = apply { 52 delegates.forEach { it.addLocalVariable(name, typeName, isMutable, assignExpr) } 53 } 54 <lambda>null55 override fun beginControlFlow(controlFlow: String, vararg args: Any?) = apply { 56 delegates.forEach { it.beginControlFlow(controlFlow, *args) } 57 } 58 nextControlFlownull59 override fun nextControlFlow(controlFlow: String, vararg args: Any?) = apply { 60 delegates.forEach { it.nextControlFlow(controlFlow, *args) } 61 } 62 <lambda>null63 override fun endControlFlow() = apply { delegates.forEach { it.endControlFlow() } } 64 <lambda>null65 override fun indent() = apply { delegates.forEach { it.indent() } } 66 <lambda>null67 override fun unindent() = apply { delegates.forEach { it.unindent() } } 68 buildnull69 override fun build() = XCodeBlockImpl(java.build(), kotlin.build()) 70 } 71 } 72