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.model.ClassTypeItem
20 import com.android.tools.metalava.model.ConstructorItem
21 import com.android.tools.metalava.model.DefaultModifierList
22 import com.android.tools.metalava.reporter.FileLocation
23 
24 internal class TextConstructorItem(
25     codebase: TextCodebase,
26     name: String,
27     containingClass: TextClassItem,
28     modifiers: DefaultModifierList,
29     returnType: ClassTypeItem,
30     parameters: List<TextParameterItem>,
31     fileLocation: FileLocation
32 ) :
33     TextMethodItem(
34         codebase,
35         name,
36         containingClass,
37         modifiers,
38         returnType,
39         parameters,
40         fileLocation
41     ),
42     ConstructorItem {
43 
44     override var superConstructor: ConstructorItem? = null
45 
isConstructornull46     override fun isConstructor(): Boolean = true
47 
48     companion object {
49         fun createDefaultConstructor(
50             codebase: TextCodebase,
51             containingClass: TextClassItem,
52             fileLocation: FileLocation,
53         ): TextConstructorItem {
54             val name = containingClass.simpleName
55             // The default constructor is package private because while in Java a class without
56             // a constructor has a default public constructor in a signature file a class
57             // without a constructor has no public constructors.
58             val modifiers = DefaultModifierList(codebase, DefaultModifierList.PACKAGE_PRIVATE, null)
59 
60             val item =
61                 TextConstructorItem(
62                     codebase = codebase,
63                     name = name,
64                     containingClass = containingClass,
65                     modifiers = modifiers,
66                     returnType = containingClass.type(),
67                     parameters = emptyList(),
68                     fileLocation = fileLocation,
69                 )
70             return item
71         }
72     }
73 }
74