Minor, remove/simplify unnecessary utilities in util.runtime
This commit is contained in:
+1
-4
@@ -44,7 +44,6 @@ import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
||||
import org.jetbrains.kotlin.utils.recursePostOrder
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.io.File
|
||||
@@ -99,9 +98,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
|
||||
val moduleDescriptor = resolver.descriptorForModule(builtInModule)
|
||||
|
||||
// We don't use FileUtil because it spawns JNA initialization, which fails because we don't have (and don't want to have) its
|
||||
// native libraries in the compiler jar (libjnidispatch.so / jnidispatch.dll / ...)
|
||||
destDir.recursePostOrder { it.delete() }
|
||||
destDir.deleteRecursively()
|
||||
|
||||
if (!destDir.mkdirs()) {
|
||||
System.err.println("Could not make directories: " + destDir)
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.util.containers.MultiMap
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.compiler.plugin.*
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
@@ -60,7 +59,7 @@ public object PluginCliParser {
|
||||
commandLineProcessors.addAll(BundledCompilerPlugins.commandLineProcessors)
|
||||
|
||||
for (processor in commandLineProcessors) {
|
||||
val declaredOptions = processor.pluginOptions.valuesToMap { it.name }
|
||||
val declaredOptions = processor.pluginOptions.toMapBy { it.name }
|
||||
val optionsToValues = MultiMap<CliOption, CliOptionValue>()
|
||||
|
||||
for (optionValue in optionValuesByPlugin[processor.pluginId].orEmpty()) {
|
||||
|
||||
+1
-2
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
|
||||
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
||||
val classId = annotation.getClassId()
|
||||
@@ -78,7 +77,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
val constructors = getAnnotationClass().getConstructors()
|
||||
if (constructors.isEmpty()) return mapOf()
|
||||
|
||||
val nameToArg = javaAnnotation.getArguments().valuesToMap { it.name }
|
||||
val nameToArg = javaAnnotation.getArguments().toMapBy { it.name }
|
||||
|
||||
return constructors.first().getValueParameters().keysToMapExceptNulls { valueParameter ->
|
||||
var javaAnnotationArgument = nameToArg[valueParameter.getName()]
|
||||
|
||||
+2
-2
@@ -604,11 +604,11 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private val nestedClassIndex = c.storageManager.createLazyValue {
|
||||
jClass.getInnerClasses().valuesToMap { c -> c.getName() }
|
||||
jClass.innerClasses.toMapBy { c -> c.name }
|
||||
}
|
||||
|
||||
private val enumEntryIndex = c.storageManager.createLazyValue {
|
||||
jClass.getFields().filter { it.isEnumEntry() }.valuesToMap { f -> f.getName() }
|
||||
jClass.fields.filter { it.isEnumEntry }.toMapBy { f -> f.name }
|
||||
}
|
||||
|
||||
private val nestedClasses = c.storageManager.createMemoizedFunctionWithNullableValues {
|
||||
|
||||
+8
-6
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMember
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.util.*
|
||||
|
||||
interface MemberIndex {
|
||||
fun findMethodsByName(name: Name): Collection<JavaMethod>
|
||||
@@ -55,8 +57,8 @@ open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember
|
||||
memberFilter(m) && !DescriptorResolverUtils.isObjectMethodInInterface(m)
|
||||
}
|
||||
|
||||
private val methods = jClass.getMethods().asSequence().filter(methodFilter).groupBy { m -> m.getName() }
|
||||
private val fields = jClass.getFields().asSequence().filter(memberFilter).valuesToMap { m -> m.getName() }
|
||||
private val methods = jClass.methods.asSequence().filter(methodFilter).groupBy { m -> m.name }
|
||||
private val fields = jClass.fields.asSequence().filter(memberFilter).toMapBy { m -> m.name }
|
||||
|
||||
override fun findMethodsByName(name: Name): Collection<JavaMethod> = methods[name] ?: listOf()
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> =
|
||||
|
||||
@@ -1,29 +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.utils
|
||||
|
||||
import java.util.*
|
||||
|
||||
class HammingComparator<T>(private val referenceString: String, private val asString: T.() -> String) : Comparator<T> {
|
||||
private fun countDifference(s1: String): Int {
|
||||
return (0..Math.min(s1.lastIndex, referenceString.lastIndex)).count { s1[it] != referenceString[it] }
|
||||
}
|
||||
|
||||
override fun compare(lookupItem1: T, lookupItem2: T): Int {
|
||||
return countDifference(lookupItem1.asString()) - countDifference(lookupItem2.asString())
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.jetbrains.kotlin.utils.addToStdlib
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
import java.util.Collections
|
||||
import java.util.NoSuchElementException
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
public fun <T: Any> T?.singletonOrEmptyList(): List<T> = if (this != null) Collections.singletonList(this) else Collections.emptyList()
|
||||
|
||||
@@ -16,52 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.utils
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
public fun <K, V> Sequence<V>.valuesToMap(key: (V) -> K): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
for (v in this) {
|
||||
map[key(v)] = v
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
public fun <K, V> Sequence<K>.keysToMap(value: (K) -> V): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
for (k in this) {
|
||||
map[k] = value(k)
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
public fun <K, V: Any> Sequence<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
for (k in this) {
|
||||
val v = value(k)
|
||||
if (v != null) {
|
||||
map[k] = v
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
public fun <K, V> Iterable<V>.valuesToMap(key: (V) -> K): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
for (v in this) {
|
||||
map[key(v)] = v
|
||||
}
|
||||
return map
|
||||
}
|
||||
import java.util.*
|
||||
|
||||
public fun <K, V> Iterable<K>.keysToMap(value: (K) -> V): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
for (k in this) {
|
||||
map[k] = value(k)
|
||||
}
|
||||
return map
|
||||
return toMapBy({ it }, value)
|
||||
}
|
||||
|
||||
public fun <K, V: Any> Iterable<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
|
||||
@@ -87,7 +45,7 @@ public inline fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpt
|
||||
|
||||
public inline fun <T> Array<out T>.ifEmpty(body: () -> Array<out T>): Array<out T> = if (isEmpty()) body() else this
|
||||
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null) listOf() else listOf(item)
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = listOfNotNull(item)
|
||||
|
||||
public fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) {
|
||||
if (t != null) add(t)
|
||||
@@ -102,7 +60,7 @@ public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
|
||||
}
|
||||
|
||||
public fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
||||
when (size()) {
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(first())
|
||||
else -> ArrayList(this)
|
||||
@@ -110,8 +68,3 @@ public fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
||||
|
||||
public fun <T: Any> T?.singletonOrEmptyList(): List<T> =
|
||||
if (this != null) listOf(this) else emptyList()
|
||||
|
||||
public fun <T> MutableList<T>.removeLast(condition: (T) -> Boolean): T? {
|
||||
val index = indexOfLast(condition)
|
||||
return if (index >= 0) removeAt(index) else null
|
||||
}
|
||||
|
||||
@@ -1,30 +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.utils
|
||||
|
||||
import java.io.File
|
||||
|
||||
// Similar to kotlin.io.recurse, but processes each directory after its children
|
||||
public fun File.recursePostOrder(block: (File) -> Unit): Unit {
|
||||
val children = this.listFiles()
|
||||
if (children != null) {
|
||||
for (child in children) {
|
||||
child.recursePostOrder(block)
|
||||
}
|
||||
}
|
||||
block(this)
|
||||
}
|
||||
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
import org.jetbrains.kotlin.utils.HammingComparator
|
||||
import org.jetbrains.kotlin.utils.ifEmpty
|
||||
import java.util.*
|
||||
|
||||
@@ -133,3 +132,13 @@ class RenameUnresolvedReferenceFix(element: KtNameReferenceExpression): KotlinQu
|
||||
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate())
|
||||
}
|
||||
}
|
||||
|
||||
private class HammingComparator<T>(private val referenceString: String, private val asString: T.() -> String) : Comparator<T> {
|
||||
private fun countDifference(s1: String): Int {
|
||||
return (0..Math.min(s1.lastIndex, referenceString.lastIndex)).count { s1[it] != referenceString[it] }
|
||||
}
|
||||
|
||||
override fun compare(lookupItem1: T, lookupItem2: T): Int {
|
||||
return countDifference(lookupItem1.asString()) - countDifference(lookupItem2.asString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.idea.refactoring.j2k
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor.Kind
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallerUsage
|
||||
import org.jetbrains.kotlin.idea.refactoring.j2k
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import org.jetbrains.kotlin.utils.removeLast
|
||||
import java.util.*
|
||||
|
||||
public open class KotlinChangeInfo(
|
||||
@@ -335,6 +334,11 @@ public open class KotlinChangeInfo(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> MutableList<T>.removeLast(condition: (T) -> Boolean): T? {
|
||||
val index = indexOfLast(condition)
|
||||
return if (index >= 0) removeAt(index) else null
|
||||
}
|
||||
|
||||
public fun getOrCreateJavaChangeInfos(): List<JavaChangeInfo>? {
|
||||
fun initCurrentSignatures(currentPsiMethods: List<PsiMethod>): List<JvmOverloadSignature> {
|
||||
val parameterInfoToPsi = methodDescriptor.original.parameters.zip(originalParameters).toMap()
|
||||
|
||||
Reference in New Issue
Block a user