1 /* 2 * Copyright 2020 Google LLC 3 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.google.devtools.ksp.symbol.impl.kotlin 19 20 import com.google.devtools.ksp.KSObjectCache 21 import com.google.devtools.ksp.symbol.KSAnnotation 22 import com.google.devtools.ksp.symbol.KSName 23 import com.google.devtools.ksp.symbol.KSNode 24 import com.google.devtools.ksp.symbol.KSValueArgument 25 import com.google.devtools.ksp.symbol.KSVisitor 26 import com.google.devtools.ksp.symbol.Location 27 import com.google.devtools.ksp.symbol.NonExistLocation 28 import com.google.devtools.ksp.symbol.Origin 29 30 class KSValueArgumentLiteImpl private constructor( 31 override val name: KSName, 32 override val value: Any?, 33 override val parent: KSNode?, 34 override val origin: Origin 35 ) : KSValueArgumentImpl() { 36 companion object : KSObjectCache<Triple<KSName, Any?, KSNode>, KSValueArgumentLiteImpl>() { 37 getCachednull38 fun getCached(name: KSName, value: Any?, parent: KSNode, origin: Origin = Origin.KOTLIN) = cache 39 .getOrPut(Triple(name, value, parent)) { 40 KSValueArgumentLiteImpl(name, value, parent, origin) 41 } 42 } 43 44 override val location: Location = NonExistLocation 45 46 override val annotations: Sequence<KSAnnotation> = emptySequence() 47 48 override val isSpread: Boolean = false 49 } 50 51 abstract class KSValueArgumentImpl : KSValueArgument { hashCodenull52 override fun hashCode(): Int { 53 return name.hashCode() * 31 + value.hashCode() 54 } 55 equalsnull56 override fun equals(other: Any?): Boolean { 57 if (other !is KSValueArgument) 58 return false 59 60 return other.name == this.name && other.value == this.value 61 } 62 acceptnull63 override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R { 64 return visitor.visitValueArgument(this, data) 65 } 66 toStringnull67 override fun toString(): String { 68 return "${name?.asString() ?: ""}:$value" 69 } 70 } 71