1 /* 2 * Copyright (C) 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 com.android.tools.metalava.model.item 18 19 import com.android.tools.metalava.model.ApiVariantSelectorsFactory 20 import com.android.tools.metalava.model.BaseModifierList 21 import com.android.tools.metalava.model.ItemDocumentationFactory 22 import com.android.tools.metalava.model.ItemLanguage 23 import com.android.tools.metalava.model.PackageItem 24 import com.android.tools.metalava.model.TypeAliasItem 25 import com.android.tools.metalava.model.TypeItem 26 import com.android.tools.metalava.model.TypeParameterList 27 import com.android.tools.metalava.reporter.FileLocation 28 29 open class DefaultTypeAliasItem( 30 codebase: DefaultCodebase, 31 fileLocation: FileLocation, 32 modifiers: BaseModifierList, 33 documentationFactory: ItemDocumentationFactory, 34 variantSelectorsFactory: ApiVariantSelectorsFactory, 35 final override val aliasedType: TypeItem, 36 final override val qualifiedName: String, 37 final override val typeParameterList: TypeParameterList, 38 private val containingPackage: DefaultPackageItem, 39 ) : 40 TypeAliasItem, 41 DefaultSelectableItem( 42 codebase = codebase, 43 fileLocation = fileLocation, 44 // Type aliases only exist in Kotlin 45 itemLanguage = ItemLanguage.KOTLIN, 46 modifiers = modifiers, 47 documentationFactory = documentationFactory, 48 variantSelectorsFactory = variantSelectorsFactory, 49 ) { 50 51 init { 52 // Register the new type alias with the codebase and package. Leaking `this` is ok as it 53 // only uses its qualified name, which has been initialized. 54 codebase.addTypeAlias(@Suppress("LeakingThis") this) 55 containingPackage.addTypeAlias(@Suppress("LeakingThis") this) 56 57 // If this type alias is emittable then make sure its package is too. 58 if (emit) { 59 containingPackage.emit = true 60 } 61 } 62 63 override val simpleName: String = qualifiedName.substringAfterLast(".") 64 containingPackagenull65 override fun containingPackage(): PackageItem = containingPackage 66 } 67