1 /* 2 * Copyright (C) 2017 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.vo 18 19 import androidx.room.ext.typeName 20 import androidx.room.processor.EntityProcessor 21 import com.google.auto.common.MoreElements 22 import com.squareup.javapoet.TypeName 23 import javax.lang.model.element.TypeElement 24 import javax.lang.model.type.DeclaredType 25 26 /** 27 * A class is turned into a Pojo if it is used in a query response. 28 */ 29 open class Pojo( 30 val element: TypeElement, 31 val type: DeclaredType, 32 val fields: List<Field>, 33 val embeddedFields: List<EmbeddedField>, 34 val relations: List<Relation>, 35 val constructor: Constructor? = null) { <lambda>null36 val typeName: TypeName by lazy { type.typeName() } 37 38 /** 39 * All table names that are somehow accessed by this Pojo. 40 * Might be via Embedded or Relation. 41 */ accessedTableNamesnull42 fun accessedTableNames(): List<String> { 43 val entityAnnotation = MoreElements.getAnnotationMirror(element, 44 androidx.room.Entity::class.java).orNull() 45 return if (entityAnnotation != null) { 46 listOf(EntityProcessor.extractTableName(element, entityAnnotation)) 47 } else { 48 embeddedFields.flatMap { 49 it.pojo.accessedTableNames() 50 } + relations.map { 51 it.entity.tableName 52 } 53 } 54 } 55 } 56