196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar/*
296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * Copyright (C) 2017 The Android Open Source Project
396cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar *
496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
596cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * you may not use this file except in compliance with the License.
696cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * You may obtain a copy of the License at
796cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar *
896cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
996cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar *
1096cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * Unless required by applicable law or agreed to in writing, software
1196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
1296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1396cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * See the License for the specific language governing permissions and
1496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar * limitations under the License.
1596cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar */
1696cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
17ba069d50913c3fb250bb60ec310439db36895337Alan Viverettepackage androidx.room.vo
1896cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
19ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.annotation.NonNull
20ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.room.ext.hasAnnotation
2196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
2296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar/**
234d4bae3f216e55f824d7d7fbfe2f8861906ee3e2Yigit Boyar * Used when a field is embedded inside an Entity or Pojo.
2496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar */
255124503104860e68981cc3e3092b95932586f66fYigit Boyar// used in cache matching, must stay as a data class or implement equals
266f1f5567abe765d30fda9c8fedce5617ecdeda9cAurimas Liutikasdata class EmbeddedField(val field: Field, val prefix: String = "",
276f1f5567abe765d30fda9c8fedce5617ecdeda9cAurimas Liutikas                         val parent: EmbeddedField?) {
2896cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    val getter by lazy { field.getter }
2996cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    val setter by lazy { field.setter }
3096cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    val nonNull = field.element.hasAnnotation(NonNull::class)
3196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    lateinit var pojo: Pojo
324d4bae3f216e55f824d7d7fbfe2f8861906ee3e2Yigit Boyar    val mRootParent: EmbeddedField by lazy {
334d4bae3f216e55f824d7d7fbfe2f8861906ee3e2Yigit Boyar        parent?.mRootParent ?: this
3496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    }
3596cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
36b2bfd37e6320e795bffafe24cfdc6a1d1b3da035Yuichi Araki    fun isNonNullRecursively(): Boolean {
37b2bfd37e6320e795bffafe24cfdc6a1d1b3da035Yuichi Araki        return field.nonNull && (parent == null || parent.isNonNullRecursively())
38b2bfd37e6320e795bffafe24cfdc6a1d1b3da035Yuichi Araki    }
3996cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar}
40