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