From f1f76af6e9a34a0e93cb96831da4e99d1e433526 Mon Sep 17 00:00:00 2001 From: Artem Khvastunov Date: Thu, 31 May 2018 12:33:21 +0200 Subject: [PATCH] clean up prebuilt indices --- .../src/com/intellij/index/PrebuiltIndex.kt | 6 ++-- .../index/PrebuiltIndexAwareIdIndexer.kt | 6 ++-- .../com/intellij/psi/stubs/PrebuiltStubs.kt | 32 ++++++------------- .../src/org/jetbrains/index/IndexGenerator.kt | 10 ++---- .../jetbrains/index/id/IdIndexGenerator.kt | 4 +-- .../jetbrains/index/stubs/StubsGenerator.kt | 19 ++--------- 6 files changed, 22 insertions(+), 55 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/index/PrebuiltIndex.kt b/platform/lang-impl/src/com/intellij/index/PrebuiltIndex.kt index cd338d784d35..d4e6641524f4 100644 --- a/platform/lang-impl/src/com/intellij/index/PrebuiltIndex.kt +++ b/platform/lang-impl/src/com/intellij/index/PrebuiltIndex.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.index import com.google.common.hash.HashCode @@ -81,7 +81,7 @@ abstract class PrebuiltIndexProviderBase : Disposable { open fun openIndexStorage(indexesRoot: File): PersistentHashMap? { return object : PersistentHashMap( - File(indexesRoot, indexName + ".input"), + File(indexesRoot, "$indexName.input"), HashCodeDescriptor.instance, indexExternalizer) { override fun isReadOnly(): Boolean { @@ -92,7 +92,7 @@ abstract class PrebuiltIndexProviderBase : Disposable { @Throws(IOException::class) private fun copyPrebuiltIndicesToIndexRoot(prebuiltIndicesRoot: File): File { - val indexRoot = File(IndexInfrastructure.getPersistentIndexRoot(), "prebuilt/" + dirName) + val indexRoot = File(IndexInfrastructure.getPersistentIndexRoot(), "prebuilt/$dirName") FileUtil.copyDir(prebuiltIndicesRoot, indexRoot, FileFilter { f -> f.name.startsWith(indexName) }) diff --git a/platform/lang-impl/src/com/intellij/index/PrebuiltIndexAwareIdIndexer.kt b/platform/lang-impl/src/com/intellij/index/PrebuiltIndexAwareIdIndexer.kt index 1158a4f85f4d..5ea2cf81a769 100644 --- a/platform/lang-impl/src/com/intellij/index/PrebuiltIndexAwareIdIndexer.kt +++ b/platform/lang-impl/src/com/intellij/index/PrebuiltIndexAwareIdIndexer.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.index import com.intellij.openapi.diagnostic.Logger @@ -17,7 +17,7 @@ import java.io.DataOutput abstract class PrebuiltIndexAwareIdIndexer : PrebuiltIndexProviderBase>(), LexingIdIndexer { companion object { private val LOG = Logger.getInstance("#com.intellij.index.PrebuiltIndexAwareIdIndexer") - val ID_INDEX_FILE_NAME: String = "id-index" + const val ID_INDEX_FILE_NAME: String = "id-index" } override val indexName: String get() = ID_INDEX_FILE_NAME @@ -57,7 +57,7 @@ class IdIndexMapDataExternalizer : DataExternalizer> { for (i in 0 until size) { val wordHash = DataInputOutputUtil.readINT(`in`) val value = DataInputOutputUtil.readINT(`in`) - map.put(IdIndexEntry(wordHash), value) + map[IdIndexEntry(wordHash)] = value } return map } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/PrebuiltStubs.kt b/platform/lang-impl/src/com/intellij/psi/stubs/PrebuiltStubs.kt index f4e46195cf5a..7a6472c9db9c 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/PrebuiltStubs.kt +++ b/platform/lang-impl/src/com/intellij/psi/stubs/PrebuiltStubs.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.stubs import com.google.common.hash.HashCode @@ -38,7 +24,7 @@ import java.io.File * @author traff */ -val EP_NAME: String = "com.intellij.filetype.prebuiltStubsProvider" +const val EP_NAME: String = "com.intellij.filetype.prebuiltStubsProvider" object PrebuiltStubsProviders : FileTypeExtension(EP_NAME) @@ -98,24 +84,24 @@ abstract class PrebuiltStubsProviderBase : PrebuiltIndexProviderBase? { - val versionInFile = FileUtil.loadFile(File(indexesRoot, indexName + ".version")) + val versionInFile = FileUtil.loadFile(File(indexesRoot, "$indexName.version")) - if (Integer.parseInt(versionInFile) == stubVersion) { - mySerializationManager = SerializationManagerImpl(File(indexesRoot, indexName + ".names")) + return if (Integer.parseInt(versionInFile) == stubVersion) { + mySerializationManager = SerializationManagerImpl(File(indexesRoot, "$indexName.names")) Disposer.register(ApplicationManager.getApplication(), mySerializationManager!!) - return super.openIndexStorage(indexesRoot) + super.openIndexStorage(indexesRoot) } else { LOG.error("Prebuilt stubs version mismatch: $versionInFile, current version is $stubVersion") - return null + null } } diff --git a/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt b/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt index 9538de7b548f..ce4926b4801a 100644 --- a/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt +++ b/tools/index-tools/src/org/jetbrains/index/IndexGenerator.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.index import com.google.common.hash.HashCode @@ -36,7 +36,7 @@ abstract class IndexGenerator(private val indexStorageFilePath: String) { println("Writing indices to ${storage.baseFile.absolutePath}") - try { + storage.use { val map = HashMap>() for (file in roots) { @@ -52,9 +52,6 @@ abstract class IndexGenerator(private val indexStorageFilePath: String) { println("${stats.indexed.get()} entries written, ${stats.skipped.get()} skipped") } } - finally { - storage.close() - } } private fun indexFile(file: VirtualFile, @@ -79,8 +76,7 @@ abstract class IndexGenerator(private val indexStorageFilePath: String) { stats.indexed.incrementAndGet() if (CHECK_HASH_COLLISIONS) { - map.put(hashCode, - Pair(fileContent.contentAsText.toString(), value)) + map[hashCode] = Pair(fileContent.contentAsText.toString(), value) } } else { diff --git a/tools/index-tools/src/org/jetbrains/index/id/IdIndexGenerator.kt b/tools/index-tools/src/org/jetbrains/index/id/IdIndexGenerator.kt index 32082c82af3b..7512a94673de 100644 --- a/tools/index-tools/src/org/jetbrains/index/id/IdIndexGenerator.kt +++ b/tools/index-tools/src/org/jetbrains/index/id/IdIndexGenerator.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.index.id import com.google.common.hash.HashCode @@ -22,7 +22,7 @@ open class IdIndexGenerator(private val idIndexStorageFilePath: String) : IndexG } override fun createStorage(stubsStorageFilePath: String): PersistentHashMap> { - return PersistentHashMap(File(idIndexStorageFilePath + ".input"), + return PersistentHashMap(File("$idIndexStorageFilePath.input"), HashCodeDescriptor.instance, IdIndexMapDataExternalizer()) } diff --git a/tools/index-tools/src/org/jetbrains/index/stubs/StubsGenerator.kt b/tools/index-tools/src/org/jetbrains/index/stubs/StubsGenerator.kt index d9052b6674a2..e07566133073 100644 --- a/tools/index-tools/src/org/jetbrains/index/stubs/StubsGenerator.kt +++ b/tools/index-tools/src/org/jetbrains/index/stubs/StubsGenerator.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /** * @author traff */ @@ -39,14 +25,13 @@ import org.jetbrains.index.IndexGenerator import java.io.File import java.util.* - /** * Generates stubs and stores them in one persistent hash map */ open class StubsGenerator(private val stubsVersion: String, private val stubsStorageFilePath: String) : IndexGenerator(stubsStorageFilePath) { - private val serializationManager = SerializationManagerImpl(File(stubsStorageFilePath + ".names")) + private val serializationManager = SerializationManagerImpl(File("$stubsStorageFilePath.names")) fun buildStubsForRoots(roots: List) { try {