diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinClassFileIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinClassFileIndex.kt deleted file mode 100644 index 3e84244d913..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinClassFileIndex.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.vfilefinder - -import com.intellij.ide.highlighter.JavaClassFileType -import com.intellij.openapi.diagnostic.Logger -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.util.indexing.* -import com.intellij.util.io.KeyDescriptor -import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache -import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass -import org.jetbrains.kotlin.name.FqName - -import java.io.DataInput -import java.io.DataOutput -import java.io.IOException -import java.util.Collections - -public class KotlinClassFileIndex : ScalarIndexExtension() { - - override fun getName(): ID { - return KEY - } - - override fun getIndexer(): DataIndexer { - return INDEXER - } - - override fun getKeyDescriptor(): KeyDescriptor { - return KEY_DESCRIPTOR - } - - override fun getInputFilter(): FileBasedIndex.InputFilter { - return INPUT_FILTER - } - - override fun dependsOnFileContent(): Boolean { - return true - } - - override fun getVersion(): Int { - return VERSION - } - - companion object { - - private val LOG = Logger.getInstance(javaClass()) - private val VERSION = 2 - public val KEY: ID = ID.create(javaClass().getCanonicalName()) - - private val KEY_DESCRIPTOR = object : KeyDescriptor { - throws(IOException::class) - override fun save(out: DataOutput, value: FqName) { - out.writeUTF(value.asString()) - } - - throws(IOException::class) - override fun read(`in`: DataInput): FqName { - return FqName(`in`.readUTF()) - } - - override fun getHashCode(value: FqName): Int { - return value.asString().hashCode() - } - - override fun isEqual(val1: FqName?, val2: FqName?): Boolean { - return if (val1 == null) val2 == null else val1 == val2 - } - } - - private val INPUT_FILTER = object : FileBasedIndex.InputFilter { - override fun acceptInput(file: VirtualFile): Boolean { - return file.getFileType() == JavaClassFileType.INSTANCE - } - } - public val INDEXER: DataIndexer = object : DataIndexer { - override fun map(inputData: FileContent): Map { - try { - val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(inputData.getFile()) - if (kotlinClass != null && kotlinClass.getClassHeader().isCompatibleAbiVersion) { - return Collections.singletonMap(kotlinClass.getClassId().asSingleFqName(), null) - } - } - catch (e: Throwable) { - LOG.warn("Error while indexing file " + inputData.getFileName(), e) - } - - return emptyMap() - } - } - } -} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileIndexes.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileIndexes.kt new file mode 100644 index 00000000000..93d2de6558b --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileIndexes.kt @@ -0,0 +1,114 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.vfilefinder + +import com.intellij.ide.highlighter.JavaClassFileType +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.util.indexing.* +import com.intellij.util.io.KeyDescriptor +import org.jetbrains.kotlin.idea.decompiler.KotlinJavaScriptMetaFileType +import org.jetbrains.kotlin.idea.decompiler.navigation.JsMetaFileUtils +import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache +import org.jetbrains.kotlin.name.FqName +import java.io.DataInput +import java.io.DataOutput +import java.util.Collections + +private val KEY_DESCRIPTOR = object : KeyDescriptor { + override fun save(output: DataOutput, value: FqName) = output.writeUTF(value.asString()) + + override fun read(input: DataInput) = FqName(input.readUTF()) + + override fun getHashCode(value: FqName) = value.asString().hashCode() + + override fun isEqual(val1: FqName?, val2: FqName?) = val1 == val2 +} + +private fun indexer(log: Logger, f: (VirtualFile) -> FqName?) = + DataIndexer { + try { + val fqName = f(it.getFile()) + if (fqName != null) { + Collections.singletonMap(fqName, null) + } + else { + emptyMap() + } + } + catch (e: Throwable) { + log.warn("Error while indexing file " + it.getFileName(), e) + emptyMap() + } + } + +public class KotlinClassFileIndex : ScalarIndexExtension() { + override fun getName() = KEY + + override fun getIndexer() = INDEXER + + override fun getKeyDescriptor() = KEY_DESCRIPTOR + + override fun getInputFilter() = INPUT_FILTER + + override fun dependsOnFileContent() = true + + override fun getVersion() = VERSION + + companion object { + public val KEY: ID = ID.create(javaClass().getCanonicalName()) + + private val LOG = Logger.getInstance(javaClass()) + + private val VERSION = 2 + + private val INPUT_FILTER = FileBasedIndex.InputFilter { file -> file.getFileType() == JavaClassFileType.INSTANCE } + + private val INDEXER = indexer(LOG) { file -> + val kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(file) + if (kotlinClass != null && kotlinClass.getClassHeader().isCompatibleAbiVersion) kotlinClass.getClassId().asSingleFqName() else null + } + } +} + +public class KotlinJavaScriptMetaFileIndex : ScalarIndexExtension() { + override fun getName() = KEY + + override fun getIndexer() = INDEXER + + override fun getKeyDescriptor() = KEY_DESCRIPTOR + + override fun getInputFilter() = INPUT_FILTER + + override fun dependsOnFileContent() = true + + override fun getVersion() = VERSION + + companion object { + public val KEY: ID = ID.create(javaClass().getCanonicalName()) + + private val LOG = Logger.getInstance(javaClass()) + + private val VERSION = 1 + + private val INPUT_FILTER = FileBasedIndex.InputFilter { file -> file.getFileType() == KotlinJavaScriptMetaFileType } + + private val INDEXER = indexer(LOG) { file -> + if (file.getFileType() == KotlinJavaScriptMetaFileType) JsMetaFileUtils.getClassFqName(file) else null + } + } +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index b353d30624e..a29b2dcb1c1 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -471,6 +471,7 @@ +