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.text 18 19 import com.android.tools.metalava.model.ClassItem 20 import com.android.tools.metalava.model.ClassKind 21 import com.android.tools.metalava.model.ClassTypeItem 22 import com.android.tools.metalava.model.ModifierList 23 import com.android.tools.metalava.reporter.FileLocation 24 25 /** 26 * Characteristics of a class apart from its members. 27 * 28 * This is basically everything that could appear on the line defining the class in the API 29 * signature file. 30 */ 31 internal data class ClassCharacteristics( 32 /** The position of the class definition within the API signature file. */ 33 val fileLocation: FileLocation, 34 35 /** Name including package and full name. */ 36 val qualifiedName: String, 37 38 /** 39 * Full name, this is in addition to [qualifiedName] as it is possible for two classed to have 40 * the same qualified name but different full names. e.g. `a.b.c.D.E` in package `a.b.c` has a 41 * full name of `D.E` but in a package `a.b` has a full name of `c.D.E`. While those names would 42 * break naming conventions and so would be unlikely they are possible. 43 */ 44 val fullName: String, 45 46 /** The kind of the class. */ 47 val classKind: ClassKind, 48 49 /** The modifiers. */ 50 val modifiers: ModifierList, 51 52 /** The super class type . */ 53 val superClassType: ClassTypeItem?, 54 // TODO(b/323168612): Add interface type strings. 55 ) { 56 /** 57 * Checks if the [other] from different signature file can be merged with this 58 * [ClassCharacteristics]. For instance, `current.txt` and `system-current.txt` may contain 59 * equal class definitions with different class methods. This method is used to determine if the 60 * two [ClassItem]s can be safely merged in such scenarios. 61 * 62 * @param other [ClassCharacteristics] to be checked if it is compatible with [this] and can be 63 * merged 64 * @return a Boolean value representing if [cls] is compatible with [this] 65 */ isCompatiblenull66 fun isCompatible(other: ClassCharacteristics): Boolean { 67 // TODO(b/323168612): Check super interface types and super class type of the two 68 // TextClassItem 69 return fullName == other.fullName && 70 classKind == other.classKind && 71 modifiers.equivalentTo(null, other.modifiers) 72 } 73 74 companion object { ofnull75 fun of(classItem: ClassItem): ClassCharacteristics = 76 ClassCharacteristics( 77 fileLocation = classItem.fileLocation, 78 qualifiedName = classItem.qualifiedName(), 79 fullName = classItem.fullName(), 80 classKind = classItem.classKind, 81 modifiers = classItem.modifiers, 82 superClassType = classItem.superClassType(), 83 ) 84 } 85 } 86