1 /*
2  * Copyright 2018 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.navigation.safe.args.generator
18 
19 import androidx.navigation.safe.args.generator.models.Action
20 import androidx.navigation.safe.args.generator.models.Argument
21 
22 object NavParserErrors {
23     val UNNAMED_DESTINATION =
24         "Destination with arguments or actions must have " + "'name' or 'id' attributes."
25 
invalidDefaultValueReferencenull26     fun invalidDefaultValueReference(value: String) =
27         "Failed to parse defaultValue " +
28             "'$value' as reference. Reference must be in format @[+][package:]res_type/resource_name"
29 
30     fun nullDefaultValueReference(name: String?) =
31         "android:defaultValue is @null, but '$name' " +
32             "is of type \"reference\". Use \"0\" to signify a empty reference id"
33 
34     fun invalidDefaultValue(value: String, type: NavType) =
35         "Failed to parse defaultValue " + "'$value' as $type"
36 
37     fun invalidId(value: String) =
38         "Failed to parse $value as id. 'id' must be in the format:" +
39             " @[+][package:]id/resource_name "
40 
41     fun defaultValueObjectType(type: String?) =
42         "'$type' " + "doesn't allow default values other than @null"
43 
44     fun defaultNullButNotNullable(name: String?) =
45         "android:defaultValue is @null, but '$name' " +
46             "is not nullable. Add app:nullable=\"true\" to the argument to make it nullable."
47 
48     fun typeIsNotNullable(typeName: String?) =
49         "'$typeName' is a simple type " +
50             "and cannot be nullable. Remove app:nullable=\"true\" from the argument."
51 
52     fun sameSanitizedNameArguments(sanitizedName: String, args: List<Argument>) =
53         "Multiple same name arguments. The named arguments: " +
54             "[${args.joinToString(", ") { it.name }}] result in the generator using " +
55             "the same name: '$sanitizedName'."
56 
57     fun sameSanitizedNameActions(sanitizedName: String, actions: List<Action>) =
58         "Multiple same name actions. The action ids: " +
59             "[${actions.joinToString(", ") { it.id.name }}] result in the " +
60             "generator using the same name: '$sanitizedName'."
61 
62     fun deprecatedTypeAttrUsed(name: String) =
63         "The 'type' attribute used by argument '$name' is deprecated. " +
64             "Please change all instances of 'type' in navigation resources to 'argType'."
65 
66     val MISSING_GRAPH_ATTR = "Missing 'graph' attribute in <include> tag."
67 
68     fun invalidNavReference(value: String) =
69         "Failed to parse '$value' as a navigation reference." +
70             " Reference must be in format @[package:]navigation/resource_name"
71 }
72