ProcessorErrors.kt revision efaf86afac3163868eda7f91a1c04e3f6e6d7520
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
1919b41105359a52aeb80070dec40247241231f05dYigit Boyarimport com.android.support.room.Query
201600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyarimport com.android.support.room.vo.Field
2119b41105359a52aeb80070dec40247241231f05dYigit Boyar
2219b41105359a52aeb80070dec40247241231f05dYigit Boyarobject ProcessorErrors {
2319b41105359a52aeb80070dec40247241231f05dYigit Boyar    val MISSING_QUERY_ANNOTATION = "Query methods must be annotated with ${Query::class.java}"
2419b41105359a52aeb80070dec40247241231f05dYigit Boyar    val CANNOT_RESOLVE_RETURN_TYPE = "Cannot resolve return type for %s"
2519b41105359a52aeb80070dec40247241231f05dYigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_QUERY_METHODS = "Cannot use unbound generics in query " +
260f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            "queryMethods. It must be bound to a type through base Dao class."
27de33ce4068e2678c03fa6fd62f4770be89f79adcYigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_ENTITY_FIELDS = "Cannot use unbound fields in entities."
280f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar    val CANNOT_USE_UNBOUND_GENERICS_IN_DAO_CLASSES = "Cannot use unbound generics in Dao classes." +
290f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " If you are trying to create a base DAO, create a normal class, extend it with type" +
300f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " params then mark the subclass with @Dao."
311600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    val CANNOT_FIND_GETTER_FOR_FIELD = "Cannot find getter for field."
321600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    val CANNOT_FIND_SETTER_FOR_FIELD = "Cannot find setter for field."
33e6325fbeaa2e6759496ea2ca9a4d3d958df690d7Yigit Boyar    val MISSING_PRIMARY_KEY = "An entity must have at least 1 field annotated with @PrimaryKey"
340f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar    val DAO_MUST_BE_AN_ABSTRACT_CLASS_OR_AN_INTERFACE = "Dao class must be an abstract class or" +
350f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar            " an interface"
368bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DATABASE_MUST_BE_ANNOTATED_WITH_DATABASE = "Database must be annotated with @Database"
37250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
38250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
398bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DAO_MUST_BE_ANNOTATED_WITH_DAO = "Dao class must be annotated with @Dao"
408bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val ENTITY_MUST_BE_ANNOTATED_WITH_ENTITY = "Entity class must be annotated with @Entity"
418bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar    val DATABASE_ANNOTATION_MUST_HAVE_LIST_OF_ENTITIES = "@Database annotation must specify list" +
428bad027c789d3fb3da8e68fa0154f2a24ccc2865Yigit Boyar            " of entities"
430fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar    val COLUMN_NAME_CANNOT_BE_EMPTY = "Column name cannot be blank. If you don't want to set it" +
440fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar            ", just remove the @ColumnName annotation."
450fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar
460fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar    val ENTITY_TABLE_NAME_CANNOT_BE_EMPTY = "Entity table name cannot be blank. If you don't want" +
470fc66ddc60bdc71d5466bb1db1a218e5a3d9c1fcYigit Boyar            " to set it, just remove the tableName property."
480f77cff2005ccc6263b9902b3ea56fe01161ba51Yigit Boyar
49250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    val CANNOT_CONVERT_QUERY_PARAMETER_TO_STRING = "Query method parameters should either be a" +
50250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            " type that can be converted into String or a List / Array that contains such type."
51250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
52250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    val QUERY_PARAMETERS_CANNOT_START_WITH_UNDERSCORE = "Query method parameters cannot start" +
53250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            " with underscore (_)."
548e543c445cb5559e579f54c1ac00d0ca83ec3fbbYigit Boyar
55efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    val CANNOT_FIND_QUERY_RESULT_ADAPTER = "Not sure how to convert a Cursor to this method's " +
56efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar            "return type"
57efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
58250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val TOO_MANY_MATCHING_GETTERS = "Ambiguous getter for %s. All of the following " +
59250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            "match: %s. You can @Ignore the ones that you don't want to match."
60efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
61efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    fun tooManyMatchingGetters(field: Field, methodNames: List<String>): String {
621600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar        return TOO_MANY_MATCHING_GETTERS.format(field, methodNames.joinToString(", "))
631600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    }
641600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar
65250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val TOO_MANY_MATCHING_SETTERS = "Ambiguous setter for %s. All of the following " +
66250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            "match: %s. You can @Ignore the ones that you don't want to match."
67efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
68efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar    fun tooManyMatchingSetter(field: Field, methodNames: List<String>): String {
691600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar        return TOO_MANY_MATCHING_SETTERS.format(field, methodNames.joinToString(", "))
701600cc11df868b62b6ae3995d94a3ec0b86559adYigit Boyar    }
71250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
72250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val MISSING_PARAMETER_FOR_BIND = "Each bind variable in the query must have a" +
73250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar            " matching method parameter. Cannot find method parameters for %s."
74efaf86afac3163868eda7f91a1c04e3f6e6d7520Yigit Boyar
75250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    fun missingParameterForBindVariable(bindVarName: List<String>): String {
76250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar        return MISSING_PARAMETER_FOR_BIND.format(bindVarName.joinToString(", "))
77250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    }
78250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
79250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    private val UNUSED_QUERY_METHOD_PARAMETER = "Unused parameter%s: %s"
80250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    fun unusedQueryMethodParameter(unusedParams: List<String>): String {
81250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar        return UNUSED_QUERY_METHOD_PARAMETER.format(
82250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar                if (unusedParams.size > 1) "s" else "",
83250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar                unusedParams.joinToString(","))
84250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar    }
85250a3e6dc5d50c533575b7d276730b89eecc7c19Yigit Boyar
8619b41105359a52aeb80070dec40247241231f05dYigit Boyar}
87