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
17 package androidx.room.ext
18
19 import com.squareup.javapoet.ArrayTypeName
20 import com.squareup.javapoet.ClassName
21 import com.squareup.javapoet.TypeName
22 import javax.lang.model.type.TypeMirror
23 import kotlin.reflect.KClass
24
25 val L = "\$L"
26 val T = "\$T"
27 val N = "\$N"
28 val S = "\$S"
29
KClassnull30 fun KClass<*>.typeName() = ClassName.get(this.java)
31 fun KClass<*>.arrayTypeName() = ArrayTypeName.of(typeName())
32 fun TypeMirror.typeName() = TypeName.get(this)
33
34 object SupportDbTypeNames {
35 val DB: ClassName = ClassName.get("androidx.sqlite.db", "SupportSQLiteDatabase")
36 val SQLITE_STMT: ClassName =
37 ClassName.get("androidx.sqlite.db", "SupportSQLiteStatement")
38 val SQLITE_OPEN_HELPER: ClassName =
39 ClassName.get("androidx.sqlite.db", "SupportSQLiteOpenHelper")
40 val SQLITE_OPEN_HELPER_CALLBACK: ClassName =
41 ClassName.get("androidx.sqlite.db", "SupportSQLiteOpenHelper.Callback")
42 val SQLITE_OPEN_HELPER_CONFIG: ClassName =
43 ClassName.get("androidx.sqlite.db", "SupportSQLiteOpenHelper.Configuration")
44 val QUERY: ClassName =
45 ClassName.get("androidx.sqlite.db", "SupportSQLiteQuery")
46 }
47
48 object RoomTypeNames {
49 val STRING_UTIL: ClassName = ClassName.get("androidx.room.util", "StringUtil")
50 val ROOM_DB: ClassName = ClassName.get("androidx.room", "RoomDatabase")
51 val ROOM_DB_CONFIG: ClassName = ClassName.get("androidx.room",
52 "DatabaseConfiguration")
53 val INSERTION_ADAPTER: ClassName =
54 ClassName.get("androidx.room", "EntityInsertionAdapter")
55 val DELETE_OR_UPDATE_ADAPTER: ClassName =
56 ClassName.get("androidx.room", "EntityDeletionOrUpdateAdapter")
57 val SHARED_SQLITE_STMT: ClassName =
58 ClassName.get("androidx.room", "SharedSQLiteStatement")
59 val INVALIDATION_TRACKER: ClassName =
60 ClassName.get("androidx.room", "InvalidationTracker")
61 val INVALIDATION_OBSERVER: ClassName =
62 ClassName.get("androidx.room.InvalidationTracker", "Observer")
63 val ROOM_SQL_QUERY: ClassName =
64 ClassName.get("androidx.room", "RoomSQLiteQuery")
65 val OPEN_HELPER: ClassName =
66 ClassName.get("androidx.room", "RoomOpenHelper")
67 val OPEN_HELPER_DELEGATE: ClassName =
68 ClassName.get("androidx.room", "RoomOpenHelper.Delegate")
69 val TABLE_INFO: ClassName =
70 ClassName.get("androidx.room.util", "TableInfo")
71 val TABLE_INFO_COLUMN: ClassName =
72 ClassName.get("androidx.room.util", "TableInfo.Column")
73 val TABLE_INFO_FOREIGN_KEY: ClassName =
74 ClassName.get("androidx.room.util", "TableInfo.ForeignKey")
75 val TABLE_INFO_INDEX: ClassName =
76 ClassName.get("androidx.room.util", "TableInfo.Index")
77 val LIMIT_OFFSET_DATA_SOURCE: ClassName =
78 ClassName.get("androidx.room.paging", "LimitOffsetDataSource")
79 }
80
81 object PagingTypeNames {
82 val DATA_SOURCE: ClassName =
83 ClassName.get("androidx.paging", "DataSource")
84 val POSITIONAL_DATA_SOURCE: ClassName =
85 ClassName.get("androidx.paging", "PositionalDataSource")
86 val DATA_SOURCE_FACTORY: ClassName =
87 ClassName.get("androidx.paging", "DataSource.Factory")
88 }
89
90 object LifecyclesTypeNames {
91 val LIVE_DATA: ClassName = ClassName.get("androidx.lifecycle", "LiveData")
92 val COMPUTABLE_LIVE_DATA: ClassName = ClassName.get("androidx.lifecycle",
93 "ComputableLiveData")
94 }
95
96 object AndroidTypeNames {
97 val CURSOR: ClassName = ClassName.get("android.database", "Cursor")
98 val ARRAY_MAP: ClassName = ClassName.get("androidx.collection", "ArrayMap")
99 val BUILD: ClassName = ClassName.get("android.os", "Build")
100 }
101
102 object CommonTypeNames {
103 val LIST = ClassName.get("java.util", "List")
104 val SET = ClassName.get("java.util", "Set")
105 val STRING = ClassName.get("java.lang", "String")
106 val INTEGER = ClassName.get("java.lang", "Integer")
107 val OPTIONAL = ClassName.get("java.util", "Optional")
108 }
109
110 object GuavaBaseTypeNames {
111 val OPTIONAL = ClassName.get("com.google.common.base", "Optional")
112 }
113
114 object GuavaUtilConcurrentTypeNames {
115 val LISTENABLE_FUTURE = ClassName.get("com.google.common.util.concurrent", "ListenableFuture")
116 }
117
118 object RxJava2TypeNames {
119 val FLOWABLE = ClassName.get("io.reactivex", "Flowable")
120 val MAYBE = ClassName.get("io.reactivex", "Maybe")
121 val SINGLE = ClassName.get("io.reactivex", "Single")
122 }
123
124 object ReactiveStreamsTypeNames {
125 val PUBLISHER = ClassName.get("org.reactivestreams", "Publisher")
126 }
127
128 object RoomGuavaTypeNames {
129 val GUAVA_ROOM = ClassName.get("androidx.room.guava", "GuavaRoom")
130 }
131
132 object RoomRxJava2TypeNames {
133 val RX_ROOM = ClassName.get("androidx.room", "RxRoom")
134 val RX_EMPTY_RESULT_SET_EXCEPTION = ClassName.get("androidx.room",
135 "EmptyResultSetException")
136 }
137
TypeNamenull138 fun TypeName.defaultValue(): String {
139 return if (!isPrimitive) {
140 "null"
141 } else if (this == TypeName.BOOLEAN) {
142 "false"
143 } else {
144 "0"
145 }
146 }
147