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 javax.lang.model.element.ExecutableElement
20 
21 /**
22  * For each Entity / Pojo we process has a constructor. It might be the empty constructor or a
23  * constructor with fields.
24  */
25 data class Constructor(val element: ExecutableElement, val params: List<Param>) {
26 
hasFieldnull27     fun hasField(field: Field): Boolean {
28         return params.any {
29             when (it) {
30                 is FieldParam -> it.field === field
31                 is EmbeddedParam -> it.embedded.field === field
32                 else -> false
33             }
34         }
35     }
36 
37     class FieldParam(val field: Field) : Param(ParamType.FIELD) {
lognull38         override fun log(): String = field.getPath()
39     }
40 
41     class EmbeddedParam(val embedded: EmbeddedField) : Param(ParamType.EMBEDDED) {
42         override fun log(): String = embedded.field.getPath()
43     }
44 
45     abstract class Param(val type: ParamType) {
lognull46         abstract fun log(): String
47     }
48 
49     enum class ParamType {
50         FIELD,
51         EMBEDDED
52     }
53 }
54