1/* 2 * Copyright (C) 2016 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 17package android.arch.persistence.room.vo 18 19import com.squareup.javapoet.ClassName 20import com.squareup.javapoet.TypeName 21import javax.lang.model.element.TypeElement 22import javax.lang.model.type.DeclaredType 23 24data class Dao(val element : TypeElement, val type : DeclaredType, 25 val queryMethods: List<QueryMethod>, 26 val insertionMethods : List<InsertionMethod>, 27 val deletionMethods : List<DeletionMethod>, 28 val updateMethods : List<UpdateMethod>, 29 val transactionMethods : List<TransactionMethod>, 30 val constructorParamType : TypeName?) { 31 // parsed dao might have a suffix if it is used in multiple databases. 32 private var suffix : String? = null 33 fun setSuffix(newSuffix : String) { 34 if (this.suffix != null) { 35 throw IllegalStateException("cannot set suffix twice") 36 } 37 this.suffix = if (newSuffix == "") "" else "_$newSuffix" 38 } 39 40 val typeName : ClassName by lazy { ClassName.get(element) } 41 42 val shortcutMethods : List<ShortcutMethod> by lazy { 43 deletionMethods + updateMethods 44 } 45 46 private val implClassName by lazy { 47 if (suffix == null) { 48 suffix = "" 49 } 50 "${typeName.simpleName()}${suffix}_Impl" 51 } 52 53 val implTypeName by lazy { 54 ClassName.get(typeName.packageName(), implClassName) 55 } 56} 57