1 /* <lambda>null2 * Copyright (C) 2017 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 interface PackageItem : Item { 20 /** 21 * The overview documentation associated with the package; retrieved from an `overview.html` 22 * file. 23 */ 24 val overviewDocumentation: String? 25 get() = null 26 27 /** The qualified name of this package */ 28 fun qualifiedName(): String 29 30 /** All top level classes in this package */ 31 fun topLevelClasses(): Sequence<ClassItem> 32 33 /** All top level classes **and inner classes** in this package */ 34 fun allClasses(): Sequence<ClassItem> { 35 return topLevelClasses().asSequence().flatMap { it.allClasses() } 36 } 37 38 override fun type(): TypeItem? = null 39 40 override fun findCorrespondingItemIn( 41 codebase: Codebase, 42 superMethods: Boolean, 43 duplicate: Boolean, 44 ) = codebase.findPackage(qualifiedName()) 45 46 val isDefault 47 get() = qualifiedName().isEmpty() 48 49 override fun parent(): PackageItem? = 50 if (qualifiedName().isEmpty()) null else containingPackage() 51 52 override fun containingPackage(): PackageItem? { 53 val name = qualifiedName() 54 val lastDot = name.lastIndexOf('.') 55 return if (lastDot != -1) { 56 codebase.findPackage(name.substring(0, lastDot)) 57 } else { 58 null 59 } 60 } 61 62 override val effectivelyDeprecated: Boolean 63 get() = originallyDeprecated 64 65 /** Whether this package is empty */ 66 fun empty() = topLevelClasses().none() 67 68 override fun baselineElementId() = qualifiedName() 69 70 override fun accept(visitor: ItemVisitor) { 71 visitor.visit(this) 72 } 73 74 override fun toStringForItem() = "package ${qualifiedName()}" 75 76 companion object { 77 val comparator: Comparator<PackageItem> = Comparator { a, b -> 78 a.qualifiedName().compareTo(b.qualifiedName()) 79 } 80 } 81 } 82