com.squareup.inject.assisted.processor.NamedKey.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assisted-inject-processor Show documentation
Show all versions of assisted-inject-processor Show documentation
Assisted injection for JSR 330
package com.squareup.inject.assisted.processor
import javax.lang.model.element.VariableElement
import javax.lang.model.type.TypeMirror
private val namedKeyComparator = compareBy({ it.key }, { it.name })
/** Represents a [Key] associated with a name. */
data class NamedKey(
val key: Key,
val name: String
) : Comparable {
override fun toString() = "$key $name"
override fun compareTo(other: NamedKey) = namedKeyComparator.compare(this, other)
}
/** Create a [NamedKey] from this type, any qualifier annotation, and the name. */
fun VariableElement.asNamedKey(mirror: TypeMirror = asType()) = NamedKey(asKey(mirror), simpleName.toString())