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.MethodItem
22 import com.android.tools.metalava.model.ParameterItem
23 
24 const val NO_DEFAULT_VALUE = "__no_default_value__"
25 
26 class TextParameterItem(
27     codebase: TextCodebase,
28     private val containingMethod: TextMethodItem,
29     private var name: String,
30     private var publicName: String?,
31     private var defaultValue: String? = NO_DEFAULT_VALUE,
32     override val parameterIndex: Int,
33     private var type: TextTypeItem,
34     modifiers: TextModifiers,
35     position: SourcePositionInfo
36 )
37 // TODO: We need to pass in parameter modifiers here (synchronized etc)
38     : TextItem(codebase, position, modifiers = modifiers), ParameterItem {
39 
40     init {
41         modifiers.setOwner(this)
42     }
43 
isVarArgsnull44     override fun isVarArgs(): Boolean {
45         return type.toString().contains("...")
46     }
47 
48     override var included: Boolean = true
typenull49     override fun type(): TextTypeItem = type
50     override fun name(): String = name
51     override fun publicName(): String? = publicName
52     override fun hasDefaultValue(): Boolean = defaultValue != NO_DEFAULT_VALUE
53     override fun defaultValue(): String? = defaultValue
54     override fun containingMethod(): MethodItem = containingMethod
55 
56     override fun equals(other: Any?): Boolean {
57         if (this === other) return true
58         if (other !is ParameterItem) return false
59 
60         return parameterIndex == other.parameterIndex
61     }
62 
hashCodenull63     override fun hashCode(): Int = parameterIndex
64 
65     override fun toString(): String = "parameter ${name()}"
66 }
67