ProcessorErrors.kt revision dc18ce63fe07921b1080e48d3e597e2b5240d17a
119b41105359a52aeb80070dec40247241231f05dYigit Boyar/* 219b41105359a52aeb80070dec40247241231f05dYigit Boyar * Copyright (C) 2016 The Android Open Source Project 319b41105359a52aeb80070dec40247241231f05dYigit Boyar * 419b41105359a52aeb80070dec40247241231f05dYigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 519b41105359a52aeb80070dec40247241231f05dYigit Boyar * you may not use this file except in compliance with the License. 619b41105359a52aeb80070dec40247241231f05dYigit Boyar * You may obtain a copy of the License at 719b41105359a52aeb80070dec40247241231f05dYigit Boyar * 819b41105359a52aeb80070dec40247241231f05dYigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 919b41105359a52aeb80070dec40247241231f05dYigit Boyar * 1019b41105359a52aeb80070dec40247241231f05dYigit Boyar * Unless required by applicable law or agreed to in writing, software 1119b41105359a52aeb80070dec40247241231f05dYigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 1219b41105359a52aeb80070dec40247241231f05dYigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1319b41105359a52aeb80070dec40247241231f05dYigit Boyar * See the License for the specific language governing permissions and 1419b41105359a52aeb80070dec40247241231f05dYigit Boyar * limitations under the License. 1519b41105359a52aeb80070dec40247241231f05dYigit Boyar */ 1619b41105359a52aeb80070dec40247241231f05dYigit Boyar 1719b41105359a52aeb80070dec40247241231f05dYigit Boyarpackage com.android.support.room.processor 1819b41105359a52aeb80070dec40247241231f05dYigit Boyar 19958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyarimport com.android.support.room.Delete 204f0db7db556b473393dfc31bba5ea67def574877Yigit Boyarimport com.android.support.room.Insert 2119b41105359a52aeb80070dec40247241231f05dYigit Boyarimport com.android.support.room.Query 2274b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyarimport com.android.support.room.Update 23291985054e698c918df1c735d1042b63b9e97219Yigit Boyarimport com.android.support.room.ext.RoomTypeNames 24275e7088223c097c1a2df718455bede42bc9efedYigit Boyarimport com.android.support.room.vo.CustomTypeConverter 251600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyarimport com.android.support.room.vo.Field 2688865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyarimport com.squareup.javapoet.TypeName 27275e7088223c097c1a2df718455bede42bc9efedYigit Boyarimport javax.lang.model.element.Element 2819b41105359a52aeb80070dec40247241231f05dYigit Boyar 2919b41105359a52aeb80070dec40247241231f05dYigit Boyarobject ProcessorErrors { 3019b41105359a52aeb80070dec40247241231f05dYigit Boyar val MISSING_QUERY_ANNOTATION = "Query methods must be annotated with ${Query::class.java}" 314f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val MISSING_INSERT_ANNOTATION = "Insertion methods must be annotated with ${Insert::class.java}" 32958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar val MISSING_DELETE_ANNOTATION = "Deletion methods must be annotated with ${Delete::class.java}" 3374b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val MISSING_UPDATE_ANNOTATION = "Update methods must be annotated with ${Update::class.java}" 34333b4b5e49c48adf7fb928d445b6f7f276b54a02Yigit Boyar val INVALID_ON_CONFLICT_VALUE = "On conflict value must be one of @OnConflictStrategy values." 354f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val INVALID_INSERTION_METHOD_RETURN_TYPE = "Methods annotated with @Insert can return either" + 364f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar " void, long, long[] or List<Long>." 374f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val ABSTRACT_METHOD_IN_DAO_MISSING_ANY_ANNOTATION = "Abstract method in DAO must be annotated" + 384f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar " with ${Query::class.java} AND ${Insert::class.java}" 39958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar val CANNOT_USE_MORE_THAN_ONE_DAO_METHOD_ANNOTATION = "A DAO method can be annotated with only" + 40958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar " one of the following:" + DaoProcessor.PROCESSED_ANNOTATIONS.joinToString(",") { 41958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar it.java.simpleName 42958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar } 4319b41105359a52aeb80070dec40247241231f05dYigit Boyar val CANNOT_RESOLVE_RETURN_TYPE = "Cannot resolve return type for %s" 444f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val CANNOT_USE_UNBOUND_GENERICS_IN_QUERY_METHODS = "Cannot use unbound generics in query" + 454f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar " methods. It must be bound to a type through base Dao class." 464f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val CANNOT_USE_UNBOUND_GENERICS_IN_INSERTION_METHODS = "Cannot use unbound generics in" + 474f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar " insertion methods. It must be bound to a type through base Dao class." 48de33ce4068e2678c03fa6fd62f4770be89f79adcYigit Boyar val CANNOT_USE_UNBOUND_GENERICS_IN_ENTITY_FIELDS = "Cannot use unbound fields in entities." 490f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar val CANNOT_USE_UNBOUND_GENERICS_IN_DAO_CLASSES = "Cannot use unbound generics in Dao classes." + 500f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar " If you are trying to create a base DAO, create a normal class, extend it with type" + 510f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar " params then mark the subclass with @Dao." 521600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar val CANNOT_FIND_GETTER_FOR_FIELD = "Cannot find getter for field." 531600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar val CANNOT_FIND_SETTER_FOR_FIELD = "Cannot find setter for field." 54e6325fbeaa2e6759496ea2ca9a4d3d958df690d7Yigit Boyar val MISSING_PRIMARY_KEY = "An entity must have at least 1 field annotated with @PrimaryKey" 550f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar val DAO_MUST_BE_AN_ABSTRACT_CLASS_OR_AN_INTERFACE = "Dao class must be an abstract class or" + 560f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar " an interface" 578bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar val DATABASE_MUST_BE_ANNOTATED_WITH_DATABASE = "Database must be annotated with @Database" 588bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar val DAO_MUST_BE_ANNOTATED_WITH_DAO = "Dao class must be annotated with @Dao" 598bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar val ENTITY_MUST_BE_ANNOTATED_WITH_ENTITY = "Entity class must be annotated with @Entity" 608bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar val DATABASE_ANNOTATION_MUST_HAVE_LIST_OF_ENTITIES = "@Database annotation must specify list" + 618bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar " of entities" 620fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar val COLUMN_NAME_CANNOT_BE_EMPTY = "Column name cannot be blank. If you don't want to set it" + 63275e7088223c097c1a2df718455bede42bc9efedYigit Boyar ", just remove the @ColumnInfo annotation or use @ColumnInfo.INHERIT_FIELD_NAME." 640fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar 650fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar val ENTITY_TABLE_NAME_CANNOT_BE_EMPTY = "Entity table name cannot be blank. If you don't want" + 660fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar " to set it, just remove the tableName property." 670f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar 68275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val CANNOT_BIND_QUERY_PARAMETER_INTO_STMT = "Query method parameters should either be a" + 69275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " type that can be converted into a database column or a List / Array that contains" + 70275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " such type. You can consider adding a Type Adapter for this." 71250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar 724f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val QUERY_PARAMETERS_CANNOT_START_WITH_UNDERSCORE = "Query/Insert method parameters cannot " + 734f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar "start with underscore (_)." 748e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar 75efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar val CANNOT_FIND_QUERY_RESULT_ADAPTER = "Not sure how to convert a Cursor to this method's " + 76efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar "return type" 77efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar 784f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val INSERTION_DOES_NOT_HAVE_ANY_PARAMETERS_TO_INSERT = "Method annotated with" + 794f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar " @Insert but does not have any parameters to insert." 804f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar 814f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar val INSERTION_METHOD_PARAMETERS_MUST_HAVE_THE_SAME_ENTITY_TYPE = "Parameter types in " + 824f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar "insertion methods must be the same type. If you want to insert entities from " + 834f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar "different types atomically, use a transaction." 844f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar 8574b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val DELETION_MISSING_PARAMS = "Method annotated with" + 86958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar " @Delete but does not have any parameters to delete." 87958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar 8874b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val DELETION_MULTIPLE_ENTITY_TYPES = "Parameter types in " + 89958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar "deletion methods must be the same type. If you want to delete entities from " + 90958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar "different types atomically, use a transaction." 91958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar 9274b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val UPDATE_MISSING_PARAMS = "Method annotated with" + 9374b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar " @Update but does not have any parameters to update." 9474b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar 9574b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val UPDATE_MULTIPLE_ENTITY_TYPES = "Parameter types in " + 9674b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar "update methods must be the same type. If you want to update entities from " + 9774b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar "different types atomically, use a transaction." 9874b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar 99958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar val CANNOT_FIND_ENTITY_FOR_SHORTCUT_QUERY_PARAMETER = "Type of the parameter must be a class " + 100958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar "annotated with @Entity or a collection/array of it." 1014f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar 102291985054e698c918df1c735d1042b63b9e97219Yigit Boyar val DB_MUST_EXTEND_ROOM_DB = "Classes annotated with @Database should extend " + 103291985054e698c918df1c735d1042b63b9e97219Yigit Boyar RoomTypeNames.ROOM_DB 104291985054e698c918df1c735d1042b63b9e97219Yigit Boyar 105846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar val LIVE_DATA_QUERY_WITHOUT_SELECT = "LiveData return type can only be used with SELECT" + 106846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar " queries." 107846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar 108250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar private val TOO_MANY_MATCHING_GETTERS = "Ambiguous getter for %s. All of the following " + 109250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar "match: %s. You can @Ignore the ones that you don't want to match." 110efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar 111efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar fun tooManyMatchingGetters(field: Field, methodNames: List<String>): String { 1121600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar return TOO_MANY_MATCHING_GETTERS.format(field, methodNames.joinToString(", ")) 1131600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar } 1141600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar 115250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar private val TOO_MANY_MATCHING_SETTERS = "Ambiguous setter for %s. All of the following " + 116250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar "match: %s. You can @Ignore the ones that you don't want to match." 117efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar 118efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar fun tooManyMatchingSetter(field: Field, methodNames: List<String>): String { 1191600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar return TOO_MANY_MATCHING_SETTERS.format(field, methodNames.joinToString(", ")) 1201600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar } 121250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar 122275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val CANNOT_FIND_COLUMN_TYPE_ADAPTER = "Cannot figure out how to save this field into" + 123275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " database. You can consider adding a type converter for it." 124275e7088223c097c1a2df718455bede42bc9efedYigit Boyar 125275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val CANNOT_FIND_STMT_BINDER = "Cannot figure out how to bind this field into a statement." 126275e7088223c097c1a2df718455bede42bc9efedYigit Boyar 127275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val CANNOT_FIND_CURSOR_READER = "Cannot figure out how to read this field from a cursor." 128275e7088223c097c1a2df718455bede42bc9efedYigit Boyar 129250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar private val MISSING_PARAMETER_FOR_BIND = "Each bind variable in the query must have a" + 130250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar " matching method parameter. Cannot find method parameters for %s." 131efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar 132250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar fun missingParameterForBindVariable(bindVarName: List<String>): String { 133250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar return MISSING_PARAMETER_FOR_BIND.format(bindVarName.joinToString(", ")) 134250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar } 135250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar 136250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar private val UNUSED_QUERY_METHOD_PARAMETER = "Unused parameter%s: %s" 137250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar fun unusedQueryMethodParameter(unusedParams: List<String>): String { 138250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar return UNUSED_QUERY_METHOD_PARAMETER.format( 139250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar if (unusedParams.size > 1) "s" else "", 140250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar unusedParams.joinToString(",")) 141250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar } 142af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar 143af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar private val DUPLICATE_TABLES = "Table name \"%s\" is used by multiple entities: %s" 14413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar fun duplicateTableNames(tableName: String, entityNames: List<String>): String { 145af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar return DUPLICATE_TABLES.format(tableName, entityNames.joinToString(", ")) 146af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar } 147958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar 148958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar val DELETION_METHODS_MUST_RETURN_VOID_OR_INT = "Deletion methods must either return void or" + 149958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar " return int (the number of deleted rows)." 15088865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar 15174b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar val UPDATE_METHODS_MUST_RETURN_VOID_OR_INT = "Update methods must either return void or" + 15274b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar " return int (the number of updated rows)." 15374b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar 15488865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar val DAO_METHOD_CONFLICTS_WITH_OTHERS = "Dao method has conflicts." 15588865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar 15613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar fun duplicateDao(dao: TypeName, methodNames: List<String>): String { 15788865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar return """ 158275e7088223c097c1a2df718455bede42bc9efedYigit Boyar All of these functions [${methodNames.joinToString(", ")}] return the same DAO 159275e7088223c097c1a2df718455bede42bc9efedYigit Boyar class [$dao]. 16013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar A database can use a DAO only once so you should remove ${methodNames.size - 1} of 16113a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar these conflicting DAO methods. If you are implementing any of these to fulfill an 16213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar interface, don't make it abstract, instead, implement the code that calls the 16313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar other one. 16413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar """.trimIndent().replace(System.lineSeparator(), " ") 16513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar } 16613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar 16713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar fun cursorPojoMismatch(pojoTypeName: TypeName, 16813a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar unusedColumns: List<String>, allColumns: List<String>, 16913a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar unusedFields: List<Field>, allFields: List<Field>): String { 17013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar val unusedColumnsWarning = if (unusedColumns.isNotEmpty()) { """ 171275e7088223c097c1a2df718455bede42bc9efedYigit Boyar The query returns some columns [${unusedColumns.joinToString(", ")}] which are not 172275e7088223c097c1a2df718455bede42bc9efedYigit Boyar use by $pojoTypeName. You can use @ColumnInfo annotation on the fields to specify 17313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar the mapping. 17413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar """.trimIndent().replace(System.lineSeparator(), " ") 17513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar } else { 17613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar "" 17713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar } 17813a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar val unusedFieldsWarning = if (unusedFields.isNotEmpty()) { """ 17913a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar $pojoTypeName has some fields 180275e7088223c097c1a2df718455bede42bc9efedYigit Boyar [${unusedFields.joinToString(", ") { it.columnName }}] which are not returned by the 18113a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar query. If they are not supposed to be read from the result, you can mark them with 18213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar @Ignore annotation. 18313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar """.trimIndent().replace(System.lineSeparator(), " ") 18413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar } else { 18513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar "" 18613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar } 18713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar return """ 18813a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar $unusedColumnsWarning 18913a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar $unusedFieldsWarning 19013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar You can suppress this warning by annotating the method with 19113a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). 19213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar Columns returned by the query: ${allColumns.joinToString(", ")}. 19313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar Fields in $pojoTypeName: ${allFields.joinToString(", ") { it.columnName }}. 19413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar """.trimIndent().replace(System.lineSeparator(), " ") 19588865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar } 19688865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar 197275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_UNBOUND_GENERIC = "Cannot use unbound generics in Type Converters." 198275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_BAD_RETURN_TYPE = "Invalid return type for a type converter." 199275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_MUST_RECEIVE_1_PARAM = "Type converters must receive 1 parameter." 200275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_EMPTY_CLASS = "Class is referenced as a converter but it does not have any" + 201275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " converter methods." 202275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_MISSING_NOARG_CONSTRUCTOR = "Classes that are used as TypeConverters must" + 203275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " have no-argument public constructors." 204275e7088223c097c1a2df718455bede42bc9efedYigit Boyar val TYPE_CONVERTER_MUST_BE_PUBLIC = "Type converters must be public." 205275e7088223c097c1a2df718455bede42bc9efedYigit Boyar 206275e7088223c097c1a2df718455bede42bc9efedYigit Boyar fun duplicateTypeConverters(converters : List<CustomTypeConverter>) : String { 207275e7088223c097c1a2df718455bede42bc9efedYigit Boyar return "Multiple methods define the same conversion. Conflicts with these:" + 208275e7088223c097c1a2df718455bede42bc9efedYigit Boyar " ${converters.joinToString(", ") { it.toString() }}" 209275e7088223c097c1a2df718455bede42bc9efedYigit Boyar } 21096cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar 21196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar // TODO must print field paths. 21296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar val POJO_FIELD_HAS_DUPLICATE_COLUMN_NAME = "Field has non-unique column name." 21396cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar 21496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar fun pojoDuplicateFieldNames(columnName : String, fieldPaths : List<String>) : String { 21596cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar return "Multiple fields have the same columnName: $columnName." + 21696cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar " Field names: ${fieldPaths.joinToString(", ")}." 21796cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar } 21896cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar 21996cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar fun decomposedPrimaryKeyIsDropped(entityQName: String, fieldName : String) : String { 22096cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar return "Primary key constraint on $fieldName is ignored when being merged into " + 22196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar entityQName 22296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar } 223dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 224dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar val INDEX_COLUMNS_CANNOT_BE_EMPTY = "List of columns in an index cannot be empty" 225dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 226dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun indexColumnDoesNotExist(columnName : String, allColumns : List<String>) : String { 227dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "$columnName referenced in the index does not exists in the Entity." + 228dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " Available column names:${allColumns.joinToString(", ")}" 229dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 230dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 231dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun duplicateIndexInEntity(indexName : String) : String { 232dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "There are multiple indices with name $indexName. This happen if you've declared" + 233dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " the same index multiple times or different indices have the same name. See" + 234dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " @Index documentation for details." 235dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 236dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 237dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun duplicateIndexInDatabase(indexName: String, indexPaths : List<String>) : String { 238dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "There are multiple indices with name $indexName. You should rename " + 239dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar "${indexPaths.size - 1} of these to avoid the conflict:" + 240dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar "${indexPaths.joinToString(", ")}." 241dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 242dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 243dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun droppedDecomposedFieldIndex(fieldPath : String, grandParent : String) : String { 244dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "The index will be dropped when being merged into $grandParent" + 245dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar "($fieldPath). You must re-declare it in $grandParent if you want to index this" + 246dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " field in $grandParent." 247dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 248dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 249dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar val FIELD_WITH_DECOMPOSE_AND_COLUMN_INFO = "You cannot annotate a Decomposed field" + 250dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " with ColumnInfo. Its sub fields are the columns." 251dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 252dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun droppedDecomposedIndex(entityName : String, fieldPath: String, grandParent: String) 253dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar : String { 254dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "Indices defined in $entityName will be dropped when it is merged into" + 255dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " $grandParent ($fieldPath). You can re-declare them in $grandParent." 256dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 257dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 258dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun droppedSuperClassIndex(childEntity : String, superEntity : String) : String { 259dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "Indices defined in $superEntity will NOT be re-used in $childEntity. If you want" + 260dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " to inherit them, you must re-declare them in $childEntity." + 261dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " Alternatively, you can set inheritSuperIndices to true in the @Entity annotation." 262dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 263dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar 264dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar fun droppedSuperClassFieldIndex(fieldName : String, childEntity : String, 265dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar superEntity : String) : String { 266dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar return "Index defined on field `$fieldName` in $superEntity will NOT be re-used in" + 267dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " $childEntity. " + 268dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar "If you want to inherit it, you must re-declare it in $childEntity." + 269dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar " Alternatively, you can set inheritSuperIndices to true in the @Entity annotation." 270dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar } 27119b41105359a52aeb80070dec40247241231f05dYigit Boyar} 272