1 /* 2 * 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.text 18 19 import com.android.tools.metalava.doclava1.SourcePositionInfo 20 import com.android.tools.metalava.doclava1.TextCodebase 21 import com.android.tools.metalava.model.ClassItem 22 import com.android.tools.metalava.model.PackageItem 23 24 class TextPackageItem( 25 codebase: TextCodebase, 26 private val name: String, 27 modifiers: TextModifiers, 28 position: SourcePositionInfo 29 ) : TextItem(codebase, position, modifiers = modifiers), PackageItem { 30 init { 31 modifiers.setOwner(this) 32 } 33 34 private val classes = ArrayList<TextClassItem>(100) 35 namenull36 fun name() = name 37 38 fun addClass(classInfo: TextClassItem) { 39 classes.add(classInfo) 40 } 41 pruneClassListnull42 internal fun pruneClassList() { 43 val iterator = classes.listIterator() 44 while (iterator.hasNext()) { 45 val cls = iterator.next() 46 if (cls.isInnerClass()) { 47 iterator.remove() 48 } 49 } 50 } 51 classListnull52 internal fun classList(): List<ClassItem> = classes 53 54 override fun topLevelClasses(): Sequence<ClassItem> = classes.asSequence() 55 56 override fun qualifiedName(): String = name 57 58 override fun containingClass(strict: Boolean): ClassItem? = null 59 60 override fun equals(other: Any?): Boolean { 61 if (this === other) return true 62 if (other !is PackageItem) return false 63 64 return name == other.qualifiedName() 65 } 66 hashCodenull67 override fun hashCode(): Int { 68 return name.hashCode() 69 } 70 toStringnull71 override fun toString(): String = "package $name" 72 } 73