code cleanup: fileIndexes
This commit is contained in:
@@ -30,7 +30,7 @@ import java.io.DataOutput
|
|||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
|
||||||
abstract class KotlinFileIndexBase<T>(private val classOfIndex: Class<T>) : ScalarIndexExtension<FqName>() {
|
abstract class KotlinFileIndexBase<T>(private val classOfIndex: Class<T>) : ScalarIndexExtension<FqName>() {
|
||||||
public val KEY: ID<FqName, Void> = ID.create(classOfIndex.getCanonicalName())
|
public val KEY: ID<FqName, Void> = ID.create(classOfIndex.canonicalName)
|
||||||
|
|
||||||
private val KEY_DESCRIPTOR : KeyDescriptor<FqName> = object : KeyDescriptor<FqName> {
|
private val KEY_DESCRIPTOR : KeyDescriptor<FqName> = object : KeyDescriptor<FqName> {
|
||||||
override fun save(output: DataOutput, value: FqName) = output.writeUTF(value.asString())
|
override fun save(output: DataOutput, value: FqName) = output.writeUTF(value.asString())
|
||||||
@@ -51,9 +51,9 @@ abstract class KotlinFileIndexBase<T>(private val classOfIndex: Class<T>) : Scal
|
|||||||
override fun getKeyDescriptor() = KEY_DESCRIPTOR
|
override fun getKeyDescriptor() = KEY_DESCRIPTOR
|
||||||
|
|
||||||
protected fun indexer(f: (VirtualFile) -> FqName?): DataIndexer<FqName, Void, FileContent> =
|
protected fun indexer(f: (VirtualFile) -> FqName?): DataIndexer<FqName, Void, FileContent> =
|
||||||
DataIndexer<FqName, Void, FileContent> {
|
DataIndexer {
|
||||||
try {
|
try {
|
||||||
val fqName = f(it.getFile())
|
val fqName = f(it.file)
|
||||||
if (fqName != null) {
|
if (fqName != null) {
|
||||||
Collections.singletonMap<FqName, Void>(fqName, null)
|
Collections.singletonMap<FqName, Void>(fqName, null)
|
||||||
}
|
}
|
||||||
@@ -62,17 +62,17 @@ abstract class KotlinFileIndexBase<T>(private val classOfIndex: Class<T>) : Scal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
LOG.warn("Error while indexing file " + it.getFileName(), e)
|
LOG.warn("Error while indexing file " + it.fileName, e)
|
||||||
emptyMap()
|
emptyMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(javaClass<KotlinClassFileIndex>()) {
|
public object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(KotlinClassFileIndex::class.java) {
|
||||||
|
|
||||||
override fun getIndexer() = INDEXER
|
override fun getIndexer() = INDEXER
|
||||||
|
|
||||||
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> file.getFileType() == JavaClassFileType.INSTANCE }
|
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> file.fileType == JavaClassFileType.INSTANCE }
|
||||||
|
|
||||||
override fun getVersion() = VERSION
|
override fun getVersion() = VERSION
|
||||||
|
|
||||||
@@ -80,21 +80,21 @@ public object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(j
|
|||||||
|
|
||||||
private val INDEXER = indexer() { file ->
|
private val INDEXER = indexer() { file ->
|
||||||
val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(file)
|
val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(file)
|
||||||
if (kotlinClass != null && kotlinClass.getClassHeader().isCompatibleAbiVersion) kotlinClass.getClassId().asSingleFqName() else null
|
if (kotlinClass != null && kotlinClass.classHeader.isCompatibleAbiVersion) kotlinClass.classId.asSingleFqName() else null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object KotlinJavaScriptMetaFileIndex : KotlinFileIndexBase<KotlinJavaScriptMetaFileIndex>(javaClass<KotlinJavaScriptMetaFileIndex>()) {
|
public object KotlinJavaScriptMetaFileIndex : KotlinFileIndexBase<KotlinJavaScriptMetaFileIndex>(KotlinJavaScriptMetaFileIndex::class.java) {
|
||||||
|
|
||||||
override fun getIndexer() = INDEXER
|
override fun getIndexer() = INDEXER
|
||||||
|
|
||||||
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> file.getFileType() == KotlinJavaScriptMetaFileType }
|
override fun getInputFilter() = FileBasedIndex.InputFilter { file -> file.fileType == KotlinJavaScriptMetaFileType }
|
||||||
|
|
||||||
override fun getVersion() = VERSION
|
override fun getVersion() = VERSION
|
||||||
|
|
||||||
private val VERSION = 1
|
private val VERSION = 1
|
||||||
|
|
||||||
private val INDEXER = indexer() { file ->
|
private val INDEXER = indexer() { file ->
|
||||||
if (file.getFileType() == KotlinJavaScriptMetaFileType) JsMetaFileUtils.getClassFqName(file) else null
|
if (file.fileType == KotlinJavaScriptMetaFileType) JsMetaFileUtils.getClassFqName(file) else null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user