1 /*
2  * Copyright 2025 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.appfunctions.compiler.core
18 
19 import com.squareup.kotlinpoet.ClassName
20 
21 /** Helper class to introspect AppFunction symbols. */
22 object IntrospectionHelper {
23     // Package names
24     const val APP_FUNCTIONS_AGGREGATED_DEPS_PACKAGE_NAME = "appfunctions_aggregated_deps"
25     const val SERIALIZABLE_PROXY_PACKAGE_NAME = "androidx.appfunctions.internal.serializableproxies"
26     const val APP_FUNCTIONS_INTERNAL_PACKAGE_NAME = "androidx.appfunctions.internal"
27     private const val APP_FUNCTIONS_PACKAGE_NAME = "androidx.appfunctions"
28     private const val APP_FUNCTIONS_METADATA_PACKAGE_NAME = "androidx.appfunctions.metadata"
29 
30     // Annotation classes
31     object AppFunctionAnnotation {
32         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunction")
33         const val PROPERTY_IS_ENABLED = "isEnabled"
34     }
35 
36     object AppFunctionSchemaDefinitionAnnotation {
37         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionSchemaDefinition")
38         const val PROPERTY_CATEGORY = "category"
39         const val PROPERTY_NAME = "name"
40         const val PROPERTY_VERSION = "version"
41     }
42 
43     object AppFunctionSerializableAnnotation {
44         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionSerializable")
45     }
46 
47     object AppFunctionSerializableProxyAnnotation {
48         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionSerializableProxy")
49         const val PROPERTY_TARGET_CLASS = "targetClass"
50     }
51 
52     object AppFunctionSchemaCapability {
53         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionSchemaCapability")
54     }
55 
56     object AppFunctionComponentRegistryAnnotation {
57         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionComponentRegistry")
58         const val PROPERTY_COMPONENT_CATEGORY = "componentCategory"
59         const val PROPERTY_COMPONENT_NAMES = "componentNames"
60 
61         object Category {
62             const val INVENTORY = "INVENTORY"
63             const val INVOKER = "INVOKER"
64             const val FUNCTION = "FUNCTION"
65         }
66     }
67 
68     // Classes
69     val APP_FUNCTION_INVENTORY_CLASS =
70         ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "AppFunctionInventory")
71     val APP_FUNCTION_METADATA_CLASS =
72         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "CompileTimeAppFunctionMetadata")
73     val APP_FUNCTION_FUNCTION_NOT_FOUND_EXCEPTION_CLASS =
74         ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionFunctionNotFoundException")
75     val APP_FUNCTION_SCHEMA_METADATA_CLASS =
76         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionSchemaMetadata")
77     val APP_FUNCTION_PARAMETER_METADATA_CLASS =
78         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionParameterMetadata")
79     val APP_FUNCTION_DATA_TYPE_METADATA =
80         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionDataTypeMetadata")
81     val APP_FUNCTION_PRIMITIVE_TYPE_METADATA_CLASS =
82         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionPrimitiveTypeMetadata")
83     val APP_FUNCTION_OBJECT_TYPE_METADATA_CLASS =
84         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionObjectTypeMetadata")
85     val APP_FUNCTION_ARRAY_TYPE_METADATA_CLASS =
86         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionArrayTypeMetadata")
87     val APP_FUNCTION_REFERENCE_TYPE_METADATA_CLASS =
88         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionReferenceTypeMetadata")
89     val APP_FUNCTION_ALL_OF_TYPE_METADATA_CLASS =
90         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionAllOfTypeMetadata")
91     val APP_FUNCTION_COMPONENTS_METADATA_CLASS =
92         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionComponentsMetadata")
93     val APP_FUNCTION_RESPONSE_METADATA_CLASS =
94         ClassName(APP_FUNCTIONS_METADATA_PACKAGE_NAME, "AppFunctionResponseMetadata")
95 
96     object ConfigurableAppFunctionFactoryClass {
97         val CLASS_NAME =
98             ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "ConfigurableAppFunctionFactory")
99 
100         object CreateEnclosingClassMethod {
101             const val METHOD_NAME = "createEnclosingClass"
102         }
103     }
104 
105     object AppFunctionContextClass {
106         val CLASS_NAME = ClassName(APP_FUNCTIONS_PACKAGE_NAME, "AppFunctionContext")
107         const val CONTEXT_PROPERTY_NAME = "context"
108     }
109 
110     object AppFunctionInvokerClass {
111         val CLASS_NAME = ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "AppFunctionInvoker")
112         const val SUPPORTED_FUNCTION_IDS_PROPERTY_NAME = "supportedFunctionIds"
113 
114         object UnsafeInvokeMethod {
115             const val METHOD_NAME = "unsafeInvoke"
116             const val APPLICATION_CONTEXT_PARAM_NAME = "appFunctionContext"
117             const val FUNCTION_ID_PARAM_NAME = "functionIdentifier"
118             const val PARAMETERS_PARAM_NAME = "parameters"
119         }
120     }
121 
122     object AppFunctionSerializableFactoryClass {
123         val CLASS_NAME =
124             ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "AppFunctionSerializableFactory")
125 
126         object FromAppFunctionDataMethod {
127             const val METHOD_NAME = "fromAppFunctionData"
128             const val APP_FUNCTION_DATA_PARAM_NAME = "appFunctionData"
129         }
130 
131         object ToAppFunctionDataMethod {
132             const val METHOD_NAME = "toAppFunctionData"
133             const val APP_FUNCTION_SERIALIZABLE_PARAM_NAME = "appFunctionSerializable"
134         }
135 
136         object TypeParameterClass {
137             val CLASS_NAME =
138                 ClassName(
139                     APP_FUNCTIONS_INTERNAL_PACKAGE_NAME,
140                     "AppFunctionSerializableFactory",
141                     "TypeParameter"
142                 )
143 
144             object PrimitiveTypeParameterClass {
145                 val CLASS_NAME =
146                     ClassName(
147                         APP_FUNCTIONS_INTERNAL_PACKAGE_NAME,
148                         "AppFunctionSerializableFactory",
149                         "TypeParameter",
150                         "PrimitiveTypeParameter"
151                     )
152 
153                 val PROPERTY_CLAZZ_NAME = "clazz"
154             }
155 
156             object ListTypeParameterClass {
157                 val CLASS_NAME =
158                     ClassName(
159                         APP_FUNCTIONS_INTERNAL_PACKAGE_NAME,
160                         "AppFunctionSerializableFactory",
161                         "TypeParameter",
162                         "ListTypeParameter"
163                     )
164 
165                 val PROPERTY_ITEM_CLAZZ_NAME = "itemClazz"
166             }
167         }
168     }
169 
170     object AggregatedAppFunctionInventoryClass {
171         val CLASS_NAME =
172             ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "AggregatedAppFunctionInventory")
173 
174         const val PROPERTY_INVENTORIES_NAME = "inventories"
175     }
176 
177     object AggregatedAppFunctionInvokerClass {
178         val CLASS_NAME =
179             ClassName(APP_FUNCTIONS_INTERNAL_PACKAGE_NAME, "AggregatedAppFunctionInvoker")
180 
181         const val PROPERTY_INVOKERS_NAME = "invokers"
182     }
183 }
184