Fix IntArrayList deprecation warning in JvmDependenciesIndexImpl
Copy relevant parts of deprecated IntelliJ's IntArrayList to a new util class. Also fix some minor IDE inspections.
This commit is contained in:
@@ -20,10 +20,10 @@ import com.intellij.ide.highlighter.JavaClassFileType
|
|||||||
import com.intellij.ide.highlighter.JavaFileType
|
import com.intellij.ide.highlighter.JavaFileType
|
||||||
import com.intellij.openapi.vfs.VfsUtilCore
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.util.containers.IntArrayList
|
|
||||||
import gnu.trove.THashMap
|
import gnu.trove.THashMap
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.utils.IntArrayList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
// speeds up finding files/classes in classpath/java source roots
|
// speeds up finding files/classes in classpath/java source roots
|
||||||
@@ -121,7 +121,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
|
|||||||
// NOTE: indices manipulation instead of using caches.reversed() is here for performance reasons
|
// NOTE: indices manipulation instead of using caches.reversed() is here for performance reasons
|
||||||
for (cacheIndex in caches.lastIndex downTo 0) {
|
for (cacheIndex in caches.lastIndex downTo 0) {
|
||||||
val cacheRootIndices = caches[cacheIndex].rootIndices
|
val cacheRootIndices = caches[cacheIndex].rootIndices
|
||||||
for (i in 0..cacheRootIndices.size() - 1) {
|
for (i in 0 until cacheRootIndices.size()) {
|
||||||
val rootIndex = cacheRootIndices[i]
|
val rootIndex = cacheRootIndices[i]
|
||||||
if (rootIndex <= processedRootsUpTo) continue // roots with those indices have been processed by now
|
if (rootIndex <= processedRootsUpTo) continue // roots with those indices have been processed by now
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processedRootsUpTo = if (cacheRootIndices.isEmpty) processedRootsUpTo else cacheRootIndices.get(cacheRootIndices.size() - 1)
|
processedRootsUpTo = if (cacheRootIndices.isEmpty) processedRootsUpTo else cacheRootIndices[cacheRootIndices.size() - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request is FindClassRequest) {
|
if (request is FindClassRequest) {
|
||||||
@@ -156,7 +156,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {
|
|||||||
cachesPath: List<Cache>
|
cachesPath: List<Cache>
|
||||||
): VirtualFile? {
|
): VirtualFile? {
|
||||||
if (rootIndex >= maxIndex) {
|
if (rootIndex >= maxIndex) {
|
||||||
for (i in (fillCachesAfter + 1)..(cachesPath.size - 1)) {
|
for (i in (fillCachesAfter + 1) until cachesPath.size) {
|
||||||
// we all know roots that contain this package by now
|
// we all know roots that contain this package by now
|
||||||
cachesPath[i].rootIndices.add(maxIndex)
|
cachesPath[i].rootIndices.add(maxIndex)
|
||||||
cachesPath[i].rootIndices.trimToSize()
|
cachesPath[i].rootIndices.trimToSize()
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.utils
|
||||||
|
|
||||||
|
// Based on com.intellij.util.containers.IntArrayList.
|
||||||
|
class IntArrayList(initialCapacity: Int) {
|
||||||
|
private var data = IntArray(initialCapacity)
|
||||||
|
private var size = 0
|
||||||
|
|
||||||
|
fun trimToSize() {
|
||||||
|
if (size < data.size) {
|
||||||
|
data = data.copyOf(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ensureCapacity(minCapacity: Int) {
|
||||||
|
if (minCapacity > data.size) {
|
||||||
|
data = data.copyOf(maxOf(data.size * 3 / 2 + 1, minCapacity))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun size(): Int = size
|
||||||
|
|
||||||
|
val isEmpty: Boolean get() = size == 0
|
||||||
|
|
||||||
|
operator fun get(index: Int): Int = data[index]
|
||||||
|
|
||||||
|
fun add(o: Int) {
|
||||||
|
ensureCapacity(size + 1)
|
||||||
|
data[size++] = o
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String =
|
||||||
|
(0 until size).joinToString(", ", "[", "]") { this[it].toString() }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user