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.google.devtools.ksp.symbol.KSPropertyDeclaration
20 import com.google.devtools.ksp.symbol.KSTypeParameter
21 import com.google.devtools.ksp.symbol.KSTypeReference
22 import com.google.devtools.ksp.symbol.KSValueParameter
23 
24 // TODO(b/403525399): Add support for checking optional property.
25 /** A wrapper class to store the property declaration in a class. */
26 data class AppFunctionPropertyDeclaration(val name: String, val type: KSTypeReference) {
27     /** Creates an [AppFunctionPropertyDeclaration] from [KSPropertyDeclaration]. */
28     constructor(
29         property: KSPropertyDeclaration
30     ) : this(checkNotNull(property.simpleName).asString(), property.type)
31 
32     /** Creates an [AppFunctionPropertyDeclaration] from [KSValueParameter]. */
33     constructor(
34         valueParameter: KSValueParameter
35     ) : this(checkNotNull(valueParameter.name).asString(), valueParameter.type)
36 
37     /** Indicates whether the [type] is a generic type or not. */
<lambda>null38     val isGenericType: Boolean by lazy { type.resolve().declaration is KSTypeParameter }
39 }
40