Minor, refactor KotlinMetadataVersionIndexBase.createBinaryVersion
Make it a protected method instead of a property passed in the constructor
This commit is contained in:
@@ -26,8 +26,11 @@ import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import java.util.*
|
||||
|
||||
object KotlinJsMetadataVersionIndex : KotlinMetadataVersionIndexBase<KotlinJsMetadataVersionIndex, JsMetadataVersion>(
|
||||
KotlinJsMetadataVersionIndex::class.java, { version, _ -> JsMetadataVersion(*version) }
|
||||
KotlinJsMetadataVersionIndex::class.java
|
||||
) {
|
||||
override fun createBinaryVersion(versionArray: IntArray, extraBoolean: Boolean?): JsMetadataVersion =
|
||||
JsMetadataVersion(*versionArray)
|
||||
|
||||
override fun getIndexer() = INDEXER
|
||||
|
||||
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> JavaScript.EXTENSION == file.extension }
|
||||
@@ -44,8 +47,8 @@ object KotlinJsMetadataVersionIndex : KotlinMetadataVersionIndexBase<KotlinJsMet
|
||||
KotlinJavascriptMetadataUtils.parseMetadata(inputData.contentAsText, metadataList)
|
||||
for (metadata in metadataList) {
|
||||
val version = metadata.version.takeIf { it.isCompatible() }
|
||||
// Version is set to something weird
|
||||
?: JsMetadataVersion.INVALID_VERSION
|
||||
// Version is set to something weird
|
||||
?: JsMetadataVersion.INVALID_VERSION
|
||||
result[version] = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,11 @@ import org.jetbrains.org.objectweb.asm.ClassVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
object KotlinJvmMetadataVersionIndex : KotlinMetadataVersionIndexBase<KotlinJvmMetadataVersionIndex, JvmMetadataVersion>(
|
||||
KotlinJvmMetadataVersionIndex::class.java,
|
||||
{ version, isStrictSemantics -> JvmMetadataVersion(version, isStrictSemantics = isStrictSemantics!!) }
|
||||
KotlinJvmMetadataVersionIndex::class.java
|
||||
) {
|
||||
override fun createBinaryVersion(versionArray: IntArray, extraBoolean: Boolean?): JvmMetadataVersion =
|
||||
JvmMetadataVersion(versionArray, isStrictSemantics = extraBoolean!!)
|
||||
|
||||
override fun getIndexer() = INDEXER
|
||||
|
||||
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> file.fileType == StdFileTypes.CLASS }
|
||||
|
||||
@@ -29,11 +29,7 @@ import java.io.DataOutput
|
||||
/**
|
||||
* Important! This is not a stub-based index. And it has its own version
|
||||
*/
|
||||
abstract class KotlinMetadataVersionIndexBase<T, V : BinaryVersion>(
|
||||
private val classOfIndex: Class<T>,
|
||||
protected val createBinaryVersion: (IntArray, Boolean?) -> V
|
||||
) : ScalarIndexExtension<V>() {
|
||||
|
||||
abstract class KotlinMetadataVersionIndexBase<T, V : BinaryVersion>(private val classOfIndex: Class<T>) : ScalarIndexExtension<V>() {
|
||||
override fun getName(): ID<V, Void> = ID.create<V, Void>(classOfIndex.canonicalName)
|
||||
|
||||
override fun getKeyDescriptor(): KeyDescriptor<V> = object : KeyDescriptor<V> {
|
||||
@@ -43,7 +39,7 @@ abstract class KotlinMetadataVersionIndexBase<T, V : BinaryVersion>(
|
||||
|
||||
override fun read(input: DataInput): V {
|
||||
val size = DataInputOutputUtil.readINT(input)
|
||||
val versionArray = (0..size - 1).map { DataInputOutputUtil.readINT(input) }.toIntArray()
|
||||
val versionArray = (0 until size).map { DataInputOutputUtil.readINT(input) }.toIntArray()
|
||||
val extraBoolean = if (isExtraBooleanNeeded()) DataInputOutputUtil.readINT(input) == 1 else null
|
||||
return createBinaryVersion(versionArray, extraBoolean)
|
||||
}
|
||||
@@ -62,17 +58,18 @@ abstract class KotlinMetadataVersionIndexBase<T, V : BinaryVersion>(
|
||||
|
||||
override fun dependsOnFileContent() = true
|
||||
|
||||
protected abstract fun createBinaryVersion(versionArray: IntArray, extraBoolean: Boolean?): V
|
||||
|
||||
protected open fun isExtraBooleanNeeded(): Boolean = false
|
||||
protected open fun getExtraBoolean(version: V): Boolean = throw UnsupportedOperationException()
|
||||
|
||||
protected val LOG: Logger = Logger.getInstance(classOfIndex)
|
||||
protected val log: Logger = Logger.getInstance(classOfIndex)
|
||||
|
||||
protected inline fun tryBlock(inputData: FileContent, body: () -> Unit) {
|
||||
try {
|
||||
body()
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
LOG.warn("Could not index ABI version for file " + inputData.file + ": " + e.message)
|
||||
} catch (e: Throwable) {
|
||||
log.warn("Could not index ABI version for file " + inputData.file + ": " + e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user