xref: /aosp_15_r20/tools/metalava/metalava-model/src/main/java/com/android/tools/metalava/model/ClassContentItem.kt (revision 115816f9299ab6ddd6b9673b81f34e707f6bacab)
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 /**
20  * An [Item] that can be the content of a [ClassItem].
21  *
22  * i.e.
23  * * Nested [ClassItem]s.
24  * * Class members:
25  *     * Constructors
26  *     * Methods
27  *     * Fields
28  *     * Properties
29  * * Parameters
30  *
31  * Basically, every [Item] except [PackageItem].
32  */
33 interface ClassContentItem : Item {
34 
35     /**
36      * The origin of this item.
37      *
38      * If this [Item] was copied from a class in the class path into a source class then this will
39      * return [ClassOrigin.CLASS_PATH].
40      */
41     val origin: ClassOrigin
42         get() =
43             if (codebase.isFromClassPath()) ClassOrigin.CLASS_PATH
44             else
45                 containingClass()?.origin
46                     ?:
47                     // This should never happen as this will only be called for a top level class
48                     // and
49                     // ClassItem implementation should override this method.
50                     error("unknown origin")
51 }
52