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.DefaultModifierList 20 import com.android.tools.metalava.model.MethodItem 21 import com.android.tools.metalava.model.ParameterItem 22 import com.android.tools.metalava.model.TypeItem 23 import com.android.tools.metalava.model.TypeParameterBindings 24 import com.android.tools.metalava.reporter.FileLocation 25 26 const val UNKNOWN_DEFAULT_VALUE = "__unknown_default_value__" 27 28 internal class TextParameterItem( 29 codebase: TextCodebase, 30 private var name: String, 31 private var publicName: String?, 32 private val hasDefaultValue: Boolean, 33 private var defaultValueBody: String? = UNKNOWN_DEFAULT_VALUE, 34 override val parameterIndex: Int, 35 private var type: TypeItem, 36 modifiers: DefaultModifierList, 37 fileLocation: FileLocation 38 ) : 39 // TODO: We need to pass in parameter modifiers here (synchronized etc) 40 TextItem(codebase, fileLocation, modifiers = modifiers), 41 ParameterItem { 42 43 internal lateinit var containingMethod: TextMethodItem 44 isVarArgsnull45 override fun isVarArgs(): Boolean { 46 return modifiers.isVarArg() 47 } 48 typenull49 override fun type(): TypeItem = type 50 51 override fun name(): String = name 52 53 override fun publicName(): String? = publicName 54 55 override fun hasDefaultValue(): Boolean = hasDefaultValue 56 57 override fun isDefaultValueKnown(): Boolean = defaultValueBody != UNKNOWN_DEFAULT_VALUE 58 59 override fun defaultValue(): String? = defaultValueBody 60 61 override fun containingMethod(): MethodItem = containingMethod 62 63 override fun equals(other: Any?): Boolean { 64 if (this === other) return true 65 if (other !is ParameterItem) return false 66 67 return parameterIndex == other.parameterIndex 68 } 69 hashCodenull70 override fun hashCode(): Int = parameterIndex 71 72 internal fun duplicate(typeVariableMap: TypeParameterBindings): TextParameterItem { 73 return TextParameterItem( 74 codebase, 75 name, 76 publicName, 77 hasDefaultValue, 78 defaultValueBody, 79 parameterIndex, 80 type.convertType(typeVariableMap), 81 modifiers.duplicate(), 82 fileLocation 83 ) 84 } 85 } 86