1 /* 2 * Copyright (C) 2023 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.turbine 18 19 import com.android.tools.metalava.model.ClassTypeItem 20 import com.android.tools.metalava.model.ConstructorItem 21 import com.android.tools.metalava.model.DefaultModifierList 22 import com.android.tools.metalava.model.DefaultTypeParameterList 23 import com.android.tools.metalava.model.TypeParameterList 24 import com.android.tools.metalava.reporter.FileLocation 25 import com.google.turbine.binder.sym.MethodSymbol 26 27 internal class TurbineConstructorItem( 28 codebase: TurbineBasedCodebase, 29 fileLocation: FileLocation, 30 private val name: String, 31 methodSymbol: MethodSymbol, 32 containingClass: TurbineClassItem, 33 returnType: ClassTypeItem, 34 modifiers: DefaultModifierList, 35 typeParameters: TypeParameterList, 36 documentation: String, 37 private val defaultValue: String, 38 ) : 39 TurbineMethodItem( 40 codebase, 41 fileLocation, 42 methodSymbol, 43 containingClass, 44 returnType, 45 modifiers, 46 typeParameters, 47 documentation, 48 defaultValue, 49 ), 50 ConstructorItem { 51 namenull52 override fun name(): String = name 53 54 override var superConstructor: ConstructorItem? = null 55 56 override fun isConstructor(): Boolean = true 57 58 companion object { 59 fun createDefaultConstructor( 60 codebase: TurbineBasedCodebase, 61 containingClass: TurbineClassItem, 62 symbol: MethodSymbol 63 ): TurbineConstructorItem { 64 val name = containingClass.simpleName() 65 val modifiers = DefaultModifierList(codebase, DefaultModifierList.PACKAGE_PRIVATE, null) 66 modifiers.setVisibilityLevel(containingClass.modifiers.getVisibilityLevel()) 67 val typeParameterList = DefaultTypeParameterList(emptyList()) 68 69 val ctorItem = 70 TurbineConstructorItem( 71 codebase, 72 // Use the location of the containing class for the implicit default 73 // constructor. 74 containingClass.fileLocation, 75 name, 76 symbol, 77 containingClass, 78 containingClass.type(), 79 modifiers, 80 typeParameterList, 81 "", 82 "", 83 ) 84 ctorItem.parameters = emptyList() 85 ctorItem.throwableTypes = emptyList() 86 return ctorItem 87 } 88 } 89 } 90