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 UNKNOWN_DEFAULT_VALUE = "__unknown_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 val hasDefaultValue: Boolean, 30 private var defaultValueBody: String? = UNKNOWN_DEFAULT_VALUE, 31 override val parameterIndex: Int, 32 private var type: TextTypeItem, 33 modifiers: TextModifiers, 34 position: SourcePositionInfo 35 ) : 36 // TODO: We need to pass in parameter modifiers here (synchronized etc) 37 TextItem(codebase, position, modifiers = modifiers), ParameterItem { 38 39 init { 40 modifiers.setOwner(this) 41 } 42 isVarArgsnull43 override fun isVarArgs(): Boolean { 44 return type.toString().contains("...") 45 } 46 47 override val synthetic: Boolean get() = containingMethod.isEnumSyntheticMethod() typenull48 override fun type(): TextTypeItem = type 49 override fun name(): String = name 50 override fun publicName(): String? = publicName 51 override fun hasDefaultValue(): Boolean = hasDefaultValue 52 override fun isDefaultValueKnown(): Boolean = defaultValueBody != UNKNOWN_DEFAULT_VALUE 53 override fun defaultValue(): String? = defaultValueBody 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