1 /* 2 * Copyright (C) 2024 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 /** A [MemberItem] that can be inherited from one class to another. */ 20 interface InheritableItem : MemberItem { 21 22 /** True if this member was inherited from an ancestor class or interface. */ 23 val inheritedFromAncestor 24 get() = inheritedFrom != null 25 26 /** 27 * If this member is inherited from a super class (typically via [duplicate]) this field points 28 * to the original class it was inherited from 29 */ 30 val inheritedFrom: ClassItem? 31 32 /** 33 * Duplicates this member item. 34 * 35 * This is only used when comparing two [Codebase]s, in which case it is called to inherit a 36 * member from a super class/interface when it exists in the other [Codebase]. The resulting 37 * [InheritableItem] is expected to behave as if it was part of the [targetContainingClass] but 38 * is otherwise identical to `this`, e.g. if [targetContainingClass] is [hidden] then so should 39 * the returned [InheritableItem]. 40 * 41 * The [inheritedFrom] property in the returned [InheritableItem] is set to [containingClass] of 42 * this [InheritableItem]. 43 * 44 * @param targetContainingClass the [ClassItem] that will be used as 45 * [InheritableItem.containingClass]. Note, this may be from a different [Codebase] 46 * implementation than the [InheritableItem] so implementations must be careful to avoid an 47 * unconditional downcast. 48 */ duplicatenull49 fun duplicate(targetContainingClass: ClassItem): InheritableItem 50 } 51