commonMain.com.shakelang.util.jvmlib.infos.constants.ConstantMethodrefInfo.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jvmlib-jvm Show documentation
Show all versions of jvmlib-jvm Show documentation
A library for jvm stuff in java
The newest version!
package com.shakelang.util.jvmlib.infos.constants
import com.shakelang.util.io.streaming.input.DataInputStream
import com.shakelang.util.io.streaming.input.InputStream
import com.shakelang.util.io.streaming.input.dataStream
import com.shakelang.util.io.streaming.output.DataOutputStream
class ConstantMethodrefInfo(private val cri: UShort, val ntri: UShort) : ConstantInfo(), ConstantUser {
lateinit var classRef: ConstantClassInfo
lateinit var nameTypeRef: ConstantNameAndTypeInfo
val classRefIndex: UShort get() = classRef.index
val nameTypeRefIndex: UShort get() = nameTypeRef.index
override val uses: Array get() = arrayOf(classRef, nameTypeRef)
override val tag: Byte get() = ConstantMethodrefInfo.tag
override val tagName: String get() = name
override fun toJson() = super.toJson()
.with("class_ref", classRefIndex.toInt())
.with("name_type_ref", nameTypeRefIndex.toInt())
override fun init(pool: ConstantPool) {
super.init(pool)
classRef = pool.getClass(cri)
nameTypeRef = pool.getNameAndType(ntri)
}
override fun dump(out: DataOutputStream) {
out.writeByte(tag)
out.writeUnsignedShort(classRefIndex)
out.writeUnsignedShort(nameTypeRefIndex)
}
companion object {
fun contentsFromStream(stream: DataInputStream): ConstantMethodrefInfo {
val classRef = stream.readUnsignedShort()
val nameTypeRef = stream.readUnsignedShort()
return ConstantMethodrefInfo(classRef, nameTypeRef)
}
fun contentsFromStream(stream: InputStream) = contentsFromStream(stream.dataStream)
fun fromStream(stream: DataInputStream) =
if (stream.readByte() != tag) {
throw IllegalArgumentException("Invalid tag for ConstantMethodrefInfo")
} else {
contentsFromStream(stream)
}
fun fromStream(stream: InputStream) = fromStream(stream.dataStream)
fun contentsFromBytes(bytes: ByteArray) = contentsFromStream(bytes.dataStream())
fun fromBytes(bytes: ByteArray) = fromStream(bytes.dataStream())
const val name = "constant_methodref_info"
const val tag = ConstantTags.CONSTANT_METHOD_REF
}
}