• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18 
19 /**
20  * Represents a Kotlin type alias (https://kotlinlang.org/docs/type-aliases.html), which provides an
21  * alternative name for an existing type.
22  */
23 interface TypeAliasItem : SelectableItem, TypeParameterListOwner {
24     /** The underlying type for which this type alias is an alternative name. */
25     val aliasedType: TypeItem
26 
27     /** The fully qualified name of this type alias (including the package name). */
28     val qualifiedName: String
29 
30     /** The simple name of this type alias (not including the package name). */
31     val simpleName: String
32 
33     /**
34      * The parent [PackageItem] of this type alias (type aliases can only be defined at the package
35      * level, not nested in other kinds of [Item]s).
36      */
parentnull37     override fun parent(): PackageItem = containingPackage()
38 
39     override fun containingPackage(): PackageItem
40 
41     override fun type(): TypeItem = aliasedType
42 
43     override val effectivelyDeprecated: Boolean
44         get() = originallyDeprecated
45 
46     override fun accept(visitor: ItemVisitor) {
47         visitor.visit(this)
48     }
49 
50     /** Type aliases cannot be defined within classes, this is always null. */
containingClassnull51     override fun containingClass(): ClassItem? = null
52 
53     override fun baselineElementId(): String = qualifiedName
54 
55     override fun equalsToItem(other: Any?): Boolean {
56         if (this === other) return true
57         if (other !is TypeAliasItem) return false
58 
59         return qualifiedName == other.qualifiedName
60     }
61 
hashCodeForItemnull62     override fun hashCodeForItem(): Int = qualifiedName.hashCode()
63 
64     override fun toStringForItem(): String = "typealias $qualifiedName"
65 
66     override fun findCorrespondingItemIn(
67         codebase: Codebase,
68         superMethods: Boolean,
69         duplicate: Boolean
70     ): TypeAliasItem? {
71         return codebase.findTypeAlias(qualifiedName)
72     }
73 
74     /** A type alias's type cannot be reset, this will error. */
setTypenull75     override fun setType(type: TypeItem) =
76         error("Cannot call setType(TypeItem) on TypeAliasItem: $this")
77 }
78