ProcessorErrors.kt revision a64756a18111a7312b3fa03b76d13381a8907176
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
24092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyarimport com.android.support.room.parser.SQLTypeAffinity
25275e7088223c097c1a2df718455bede42bc9efedYigit Boyarimport com.android.support.room.vo.CustomTypeConverter
261600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyarimport com.android.support.room.vo.Field
2788865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyarimport com.squareup.javapoet.TypeName
2819b41105359a52aeb80070dec40247241231f05dYigit Boyar
2919b41105359a52aeb80070dec40247241231f05dYigit Boyarobject ProcessorErrors {
302c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    private fun String.trim(): String {
312c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar        return this.trimIndent().replace(System.lineSeparator(), " ")
322c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    }
3319b41105359a52aeb80070dec40247241231f05dYigit Boyar    val MISSING_QUERY_ANNOTATION = "Query methods must be annotated with ${Query::class.java}"
344f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val MISSING_INSERT_ANNOTATION = "Insertion methods must be annotated with ${Insert::class.java}"
35958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar    val MISSING_DELETE_ANNOTATION = "Deletion methods must be annotated with ${Delete::class.java}"
3674b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val MISSING_UPDATE_ANNOTATION = "Update methods must be annotated with ${Update::class.java}"
37333b4b5e49c48adf7fb928d445b6f7f276b54a02Yigit Boyar    val INVALID_ON_CONFLICT_VALUE = "On conflict value must be one of @OnConflictStrategy values."
384f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val INVALID_INSERTION_METHOD_RETURN_TYPE = "Methods annotated with @Insert can return either" +
394f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            " void, long, long[] or List<Long>."
40f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar
41f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar    fun insertionMethodReturnTypeMismatch(definedReturn : TypeName,
42f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar                                          expectedReturnTypes : List<TypeName>) : String {
43f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar        return "Method returns $definedReturn but it should return one of the following: `" +
44f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar                expectedReturnTypes.joinToString(", ") + "`. If you want to return the list of" +
45f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar                " row ids from the query, your insertion method can receive only 1 parameter."
46f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar    }
47f5f2cf6b9ed63915448e81551e4b7bb72a26030eYigit Boyar
484f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val ABSTRACT_METHOD_IN_DAO_MISSING_ANY_ANNOTATION = "Abstract method in DAO must be annotated" +
494f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            " with ${Query::class.java} AND ${Insert::class.java}"
50958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar    val CANNOT_USE_MORE_THAN_ONE_DAO_METHOD_ANNOTATION = "A DAO method can be annotated with only" +
51958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            " one of the following:" + DaoProcessor.PROCESSED_ANNOTATIONS.joinToString(",") {
52958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar        it.java.simpleName
53958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar    }
5419b41105359a52aeb80070dec40247241231f05dYigit Boyar    val CANNOT_RESOLVE_RETURN_TYPE = "Cannot resolve return type for %s"
554f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_QUERY_METHODS = "Cannot use unbound generics in query" +
564f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            " methods. It must be bound to a type through base Dao class."
574f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_INSERTION_METHODS = "Cannot use unbound generics in" +
584f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            " insertion methods. It must be bound to a type through base Dao class."
59de33ce4068e2678c03fa6fd62f4770be89f79adcYigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_ENTITY_FIELDS = "Cannot use unbound fields in entities."
600f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_DAO_CLASSES = "Cannot use unbound generics in Dao classes." +
610f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " If you are trying to create a base DAO, create a normal class, extend it with type" +
620f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " params then mark the subclass with @Dao."
631600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    val CANNOT_FIND_GETTER_FOR_FIELD = "Cannot find getter for field."
641600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    val CANNOT_FIND_SETTER_FOR_FIELD = "Cannot find setter for field."
65e6325fbeaa2e6759496ea2ca9a4d3d958df690d7Yigit Boyar    val MISSING_PRIMARY_KEY = "An entity must have at least 1 field annotated with @PrimaryKey"
662c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    val AUTO_INCREMENTED_PRIMARY_KEY_IS_NOT_INT = "If a primary key is annotated with" +
672c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            " autoGenerate, its type must be int, Integer, long or Long."
682c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    val AUTO_INCREMENT_DECOMPOSED_HAS_MULTIPLE_FIELDS = "When @PrimaryKey annotation is used on a" +
692c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            " field annotated with @Decompose, the decomposed class should have only 1 field."
702c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar
712c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun multiplePrimaryKeyAnnotations(primaryKeys: List<String>): String {
722c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar        return """
732c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                You cannot have multiple primary keys defined in an Entity. If you
742c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                want to declare a composite primary key, you should use @Entity#primaryKeys and
752c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                not use @PrimaryKey. Defined Primary Keys:
762c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                ${primaryKeys.joinToString(", ")}""".trim()
772c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    }
782c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar
792c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun primaryKeyColumnDoesNotExist(columnName: String, allColumns: List<String>): String {
802c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar        return "$columnName referenced in the primary key does not exists in the Entity." +
812c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                " Available column names:${allColumns.joinToString(", ")}"
822c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    }
832c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar
840f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar    val DAO_MUST_BE_AN_ABSTRACT_CLASS_OR_AN_INTERFACE = "Dao class must be an abstract class or" +
850f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " an interface"
868bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DATABASE_MUST_BE_ANNOTATED_WITH_DATABASE = "Database must be annotated with @Database"
878bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DAO_MUST_BE_ANNOTATED_WITH_DAO = "Dao class must be annotated with @Dao"
888bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val ENTITY_MUST_BE_ANNOTATED_WITH_ENTITY = "Entity class must be annotated with @Entity"
898bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DATABASE_ANNOTATION_MUST_HAVE_LIST_OF_ENTITIES = "@Database annotation must specify list" +
908bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar            " of entities"
910fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar    val COLUMN_NAME_CANNOT_BE_EMPTY = "Column name cannot be blank. If you don't want to set it" +
92275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            ", just remove the @ColumnInfo annotation or use @ColumnInfo.INHERIT_FIELD_NAME."
930fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar
940fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar    val ENTITY_TABLE_NAME_CANNOT_BE_EMPTY = "Entity table name cannot be blank. If you don't want" +
950fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar            " to set it, just remove the tableName property."
960f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar
97275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val CANNOT_BIND_QUERY_PARAMETER_INTO_STMT = "Query method parameters should either be a" +
98275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            " type that can be converted into a database column or a List / Array that contains" +
99275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            " such type. You can consider adding a Type Adapter for this."
100250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
1014f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val QUERY_PARAMETERS_CANNOT_START_WITH_UNDERSCORE = "Query/Insert method parameters cannot " +
1024f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            "start with underscore (_)."
1038e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar
104efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    val CANNOT_FIND_QUERY_RESULT_ADAPTER = "Not sure how to convert a Cursor to this method's " +
105efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar            "return type"
106efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
1074f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val INSERTION_DOES_NOT_HAVE_ANY_PARAMETERS_TO_INSERT = "Method annotated with" +
1084f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            " @Insert but does not have any parameters to insert."
1094f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar
1104f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar    val INSERTION_METHOD_PARAMETERS_MUST_HAVE_THE_SAME_ENTITY_TYPE = "Parameter types in " +
1114f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            "insertion methods must be the same type. If you want to insert entities from " +
1124f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar            "different types atomically, use a transaction."
1134f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar
11474b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val DELETION_MISSING_PARAMS = "Method annotated with" +
115958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            " @Delete but does not have any parameters to delete."
116958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar
11774b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val DELETION_MULTIPLE_ENTITY_TYPES = "Parameter types in " +
118958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            "deletion methods must be the same type. If you want to delete entities from " +
119958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            "different types atomically, use a transaction."
120958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar
12174b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val UPDATE_MISSING_PARAMS = "Method annotated with" +
12274b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar            " @Update but does not have any parameters to update."
12374b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar
12474b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val UPDATE_MULTIPLE_ENTITY_TYPES = "Parameter types in " +
12574b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar            "update methods must be the same type. If you want to update entities from " +
12674b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar            "different types atomically, use a transaction."
12774b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar
128958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar    val CANNOT_FIND_ENTITY_FOR_SHORTCUT_QUERY_PARAMETER = "Type of the parameter must be a class " +
129958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            "annotated with @Entity or a collection/array of it."
1304f0db7db556b473393dfc31bba5ea67def574877Yigit Boyar
131291985054e698c918df1c735d1042b63b9e97219Yigit Boyar    val DB_MUST_EXTEND_ROOM_DB = "Classes annotated with @Database should extend " +
132291985054e698c918df1c735d1042b63b9e97219Yigit Boyar            RoomTypeNames.ROOM_DB
133291985054e698c918df1c735d1042b63b9e97219Yigit Boyar
134846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar    val LIVE_DATA_QUERY_WITHOUT_SELECT = "LiveData return type can only be used with SELECT" +
135846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar            " queries."
136846dfcf52e22de6d912f8ece05ff939c2c9bd154Yigit Boyar
137250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val TOO_MANY_MATCHING_GETTERS = "Ambiguous getter for %s. All of the following " +
138250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            "match: %s. You can @Ignore the ones that you don't want to match."
139efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
140efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    fun tooManyMatchingGetters(field: Field, methodNames: List<String>): String {
1411600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar        return TOO_MANY_MATCHING_GETTERS.format(field, methodNames.joinToString(", "))
1421600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    }
1431600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar
144250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val TOO_MANY_MATCHING_SETTERS = "Ambiguous setter for %s. All of the following " +
145250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            "match: %s. You can @Ignore the ones that you don't want to match."
146efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
147efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    fun tooManyMatchingSetter(field: Field, methodNames: List<String>): String {
1481600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar        return TOO_MANY_MATCHING_SETTERS.format(field, methodNames.joinToString(", "))
1491600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    }
150250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
151275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val CANNOT_FIND_COLUMN_TYPE_ADAPTER = "Cannot figure out how to save this field into" +
152275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            " database. You can consider adding a type converter for it."
153275e7088223c097c1a2df718455bede42bc9efedYigit Boyar
154275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val CANNOT_FIND_STMT_BINDER = "Cannot figure out how to bind this field into a statement."
155275e7088223c097c1a2df718455bede42bc9efedYigit Boyar
156275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val CANNOT_FIND_CURSOR_READER = "Cannot figure out how to read this field from a cursor."
157275e7088223c097c1a2df718455bede42bc9efedYigit Boyar
158250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val MISSING_PARAMETER_FOR_BIND = "Each bind variable in the query must have a" +
159250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            " matching method parameter. Cannot find method parameters for %s."
160efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
161250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    fun missingParameterForBindVariable(bindVarName: List<String>): String {
162250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar        return MISSING_PARAMETER_FOR_BIND.format(bindVarName.joinToString(", "))
163250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    }
164250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
165250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val UNUSED_QUERY_METHOD_PARAMETER = "Unused parameter%s: %s"
166250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    fun unusedQueryMethodParameter(unusedParams: List<String>): String {
167250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar        return UNUSED_QUERY_METHOD_PARAMETER.format(
168250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar                if (unusedParams.size > 1) "s" else "",
169250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar                unusedParams.joinToString(","))
170250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    }
171af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar
172af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar    private val DUPLICATE_TABLES = "Table name \"%s\" is used by multiple entities: %s"
17313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar    fun duplicateTableNames(tableName: String, entityNames: List<String>): String {
174af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar        return DUPLICATE_TABLES.format(tableName, entityNames.joinToString(", "))
175af2292b2f53204a3004f53201f51908d70d8090eYigit Boyar    }
176958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar
177958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar    val DELETION_METHODS_MUST_RETURN_VOID_OR_INT = "Deletion methods must either return void or" +
178958df7dd95c2cecf93cacef6998a4d7e8d39b7efYigit Boyar            " return int (the number of deleted rows)."
17988865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar
18074b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar    val UPDATE_METHODS_MUST_RETURN_VOID_OR_INT = "Update methods must either return void or" +
18174b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar            " return int (the number of updated rows)."
18274b28faea4bcc4b7fab113a61a066d22dfae7258Yigit Boyar
18388865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar    val DAO_METHOD_CONFLICTS_WITH_OTHERS = "Dao method has conflicts."
18488865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar
18513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar    fun duplicateDao(dao: TypeName, methodNames: List<String>): String {
18688865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar        return """
187275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                All of these functions [${methodNames.joinToString(", ")}] return the same DAO
188275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                class [$dao].
18913a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                A database can use a DAO only once so you should remove ${methodNames.size - 1} of
19013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                these conflicting DAO methods. If you are implementing any of these to fulfill an
19113a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                interface, don't make it abstract, instead, implement the code that calls the
19213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                other one.
1932c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                """.trim()
19413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar    }
19513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar
19613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar    fun cursorPojoMismatch(pojoTypeName: TypeName,
19713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                           unusedColumns: List<String>, allColumns: List<String>,
19813a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                           unusedFields: List<Field>, allFields: List<Field>): String {
1992c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar        val unusedColumnsWarning = if (unusedColumns.isNotEmpty()) {
2002c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            """
201275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                The query returns some columns [${unusedColumns.joinToString(", ")}] which are not
202275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                use by $pojoTypeName. You can use @ColumnInfo annotation on the fields to specify
20313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                the mapping.
2042c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            """.trim()
20513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar        } else {
20613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            ""
20713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar        }
2082c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar        val unusedFieldsWarning = if (unusedFields.isNotEmpty()) {
2092c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            """
21013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                $pojoTypeName has some fields
211275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                [${unusedFields.joinToString(", ") { it.columnName }}] which are not returned by the
21213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                query. If they are not supposed to be read from the result, you can mark them with
21313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar                @Ignore annotation.
2142c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            """.trim()
21513a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar        } else {
21613a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            ""
21713a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar        }
21813a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar        return """
21913a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            $unusedColumnsWarning
22013a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            $unusedFieldsWarning
22113a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            You can suppress this warning by annotating the method with
22213a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH).
22313a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            Columns returned by the query: ${allColumns.joinToString(", ")}.
22413a2048db98b1cc2dbd1692b73b794527975a446Yigit Boyar            Fields in $pojoTypeName: ${allFields.joinToString(", ") { it.columnName }}.
2252c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar            """.trim()
22688865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar    }
22788865f77c35657a2bc545a718ca16a648fc8b62eYigit Boyar
228275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_UNBOUND_GENERIC = "Cannot use unbound generics in Type Converters."
229275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_BAD_RETURN_TYPE = "Invalid return type for a type converter."
230275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_MUST_RECEIVE_1_PARAM = "Type converters must receive 1 parameter."
231275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_EMPTY_CLASS = "Class is referenced as a converter but it does not have any" +
232275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            " converter methods."
233275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_MISSING_NOARG_CONSTRUCTOR = "Classes that are used as TypeConverters must" +
234275e7088223c097c1a2df718455bede42bc9efedYigit Boyar            " have no-argument public constructors."
235275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    val TYPE_CONVERTER_MUST_BE_PUBLIC = "Type converters must be public."
236275e7088223c097c1a2df718455bede42bc9efedYigit Boyar
2372c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun duplicateTypeConverters(converters: List<CustomTypeConverter>): String {
238275e7088223c097c1a2df718455bede42bc9efedYigit Boyar        return "Multiple methods define the same conversion. Conflicts with these:" +
239275e7088223c097c1a2df718455bede42bc9efedYigit Boyar                " ${converters.joinToString(", ") { it.toString() }}"
240275e7088223c097c1a2df718455bede42bc9efedYigit Boyar    }
24196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
24296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    // TODO must print field paths.
24396cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    val POJO_FIELD_HAS_DUPLICATE_COLUMN_NAME = "Field has non-unique column name."
24496cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
2452c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun pojoDuplicateFieldNames(columnName: String, fieldPaths: List<String>): String {
24696cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar        return "Multiple fields have the same columnName: $columnName." +
24796cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar                " Field names: ${fieldPaths.joinToString(", ")}."
24896cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    }
24996cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar
2502c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun decomposedPrimaryKeyIsDropped(entityQName: String, fieldName: String): String {
25196cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar        return "Primary key constraint on $fieldName is ignored when being merged into " +
25296cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar                entityQName
25396cc740203eaa752fc85ca7ca722a8de550ae88cYigit Boyar    }
254dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
255dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    val INDEX_COLUMNS_CANNOT_BE_EMPTY = "List of columns in an index cannot be empty"
256dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2572c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun indexColumnDoesNotExist(columnName: String, allColumns: List<String>): String {
258dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "$columnName referenced in the index does not exists in the Entity." +
259dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " Available column names:${allColumns.joinToString(", ")}"
260dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
261dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2622c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun duplicateIndexInEntity(indexName: String): String {
263dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "There are multiple indices with name $indexName. This happen if you've declared" +
264dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " the same index multiple times or different indices have the same name. See" +
265dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " @Index documentation for details."
266dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
267dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2682c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun duplicateIndexInDatabase(indexName: String, indexPaths: List<String>): String {
269dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "There are multiple indices with name $indexName. You should rename " +
270dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                "${indexPaths.size - 1} of these to avoid the conflict:" +
271dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                "${indexPaths.joinToString(", ")}."
272dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
273dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2742c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun droppedDecomposedFieldIndex(fieldPath: String, grandParent: String): String {
275dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "The index will be dropped when being merged into $grandParent" +
276dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                "($fieldPath). You must re-declare it in $grandParent if you want to index this" +
277dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " field in $grandParent."
278dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
279dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2802c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun droppedDecomposedIndex(entityName: String, fieldPath: String, grandParent: String)
281dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar            : String {
282dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "Indices defined in $entityName will be dropped when it is merged into" +
283dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " $grandParent ($fieldPath). You can re-declare them in $grandParent."
284dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
285dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2862c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun droppedSuperClassIndex(childEntity: String, superEntity: String): String {
287dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "Indices defined in $superEntity will NOT be re-used in $childEntity. If you want" +
288dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " to inherit them, you must re-declare them in $childEntity." +
289dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " Alternatively, you can set inheritSuperIndices to true in the @Entity annotation."
290dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
291dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar
2922c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar    fun droppedSuperClassFieldIndex(fieldName: String, childEntity: String,
2932c6462f129bf43965ed8b054b026f6a28fe6fd8fYigit Boyar                                    superEntity: String): String {
294dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar        return "Index defined on field `$fieldName` in $superEntity will NOT be re-used in" +
295dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " $childEntity. " +
296dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                "If you want to inherit it, you must re-declare it in $childEntity." +
297dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar                " Alternatively, you can set inheritSuperIndices to true in the @Entity annotation."
298dc18ce63fe07921b1080e48d3e597e2b5240d17aYigit Boyar    }
299092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
300092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    val RELATION_NOT_COLLECTION = "Fields annotated with @Relation must be a List or Set."
301092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
302092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    fun relationCannotFindEntityField(entityName : String, fieldName : String,
303092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                                      availableFields : List<String>) : String {
304092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        return "Cannot find the child entity field `$fieldName` in $entityName." +
305092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                " Options: ${availableFields.joinToString(", ")}"
306092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    }
307092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
308092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    fun relationCannotFindParentEntityField(entityName : String, fieldName : String,
309092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                                            availableFields : List<String>) : String {
310092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        return "Cannot find the parent entity field `$fieldName` in $entityName." +
311092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                " Options: ${availableFields.joinToString(", ")}"
312092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    }
313092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
314092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    val RELATION_IN_ENTITY = "Entities cannot have relations."
315092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
316092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    val CANNOT_FIND_TYPE = "Cannot find type."
317092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
318092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    fun relationAffinityMismatch(parentField : String, childField : String,
319092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                                 parentAffinity : SQLTypeAffinity?,
320092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                                 childAffinity : SQLTypeAffinity?) : String {
321092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        return """
322092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        The affinity of parent field ($parentField : $parentAffinity) does not match the type
323092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        affinity of the child field ($childField : $childAffinity).
324092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        """.trim()
325092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    }
326092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
327092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    val CANNOT_USE_MORE_THAN_ONE_POJO_FIELD_ANNOTATION = "A field can be annotated with only" +
328092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar            " one of the following:" + PojoProcessor.PROCESSED_ANNOTATIONS.joinToString(",") {
329092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        it.java.simpleName
330092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    }
331092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar
332092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    fun relationBadProject(entityQName : String, missingColumnNames : List<String>,
333092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar                           availableColumnNames : List<String>) : String {
334092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        return """
335092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        $entityQName does not have the following columns: ${missingColumnNames.joinToString(",")}.
336092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        Available columns are: ${availableColumnNames.joinToString(",")}
337092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar        """.trim()
338092164e5501d0a254001225acd9dca42e5fa57e9Yigit Boyar    }
339a64756a18111a7312b3fa03b76d13381a8907176Yigit Boyar
340a64756a18111a7312b3fa03b76d13381a8907176Yigit Boyar    val MISSING_SCHEMA_EXPORT_DIRECTORY = "Schema export directory is not provided to the" +
341a64756a18111a7312b3fa03b76d13381a8907176Yigit Boyar            " annotation processor so we cannot export the schema. You can either provide" +
342a64756a18111a7312b3fa03b76d13381a8907176Yigit Boyar            " `room.schemaLocation` annotation processor argument OR set exportSchema to false."
34319b41105359a52aeb80070dec40247241231f05dYigit Boyar}
344