diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index efa6304beea..9d1c5057554 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -323,7 +323,7 @@ public class ClosureCodegen extends MemberCodegen { Type[] myParameterTypes = bridge.getArgumentTypes(); List calleeParameters = CollectionsKt.plus( - org.jetbrains.kotlin.utils.CollectionsKt.singletonOrEmptyList(funDescriptor.getExtensionReceiverParameter()), + CollectionsKt.listOfNotNull(funDescriptor.getExtensionReceiverParameter()), funDescriptor.getValueParameters() ); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt index e8bcb0c3623..3ed195c944c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt @@ -63,7 +63,7 @@ class KotlinBinaryClassCache : Disposable { } val aClass = ApplicationManager.getApplication().runReadAction(Computable { - //noinspection deprecation + @Suppress("DEPRECATION") VirtualFileKotlinClass.create(file, fileContent) }) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt b/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt index fa2e37d29a7..bdc899913d0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt @@ -95,7 +95,6 @@ fun ModuleContext(module: ModuleDescriptor, project: Project): ModuleContext = fun GlobalContext.withProject(project: Project): ProjectContext = ProjectContextImpl(project, this) fun ProjectContext.withModule(module: ModuleDescriptor): ModuleContext = ModuleContextImpl(module, this) -@JvmOverloads fun ContextForNewModule( projectContext: ProjectContext, moduleName: Name, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtFile.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtFile.java index c7c0e6f1e6a..25196ce00af 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtFile.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtFile.java @@ -21,13 +21,13 @@ import com.intellij.lang.ASTNode; import com.intellij.lang.FileASTNode; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.FileContentUtilCore; import com.intellij.util.IncorrectOperationException; import kotlin.collections.ArraysKt; +import kotlin.collections.CollectionsKt; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +39,6 @@ import org.jetbrains.kotlin.parsing.KotlinParserDefinition; import org.jetbrains.kotlin.psi.stubs.KotlinFileStub; import org.jetbrains.kotlin.psi.stubs.elements.KtPlaceHolderStubElementType; import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; -import org.jetbrains.kotlin.utils.CollectionsKt; import java.util.Arrays; import java.util.Collections; @@ -279,7 +278,7 @@ public class KtFile extends PsiFileBase implements KtDeclarationContainer, KtAnn PsiElement result = super.setName(name); boolean willBeScript = name.endsWith(KotlinParserDefinition.STD_SCRIPT_EXT); if (isScript() != willBeScript) { - FileContentUtilCore.reparseFiles(CollectionsKt.singletonOrEmptyList(getVirtualFile())); + FileContentUtilCore.reparseFiles(CollectionsKt.listOfNotNull(getVirtualFile())); } return result; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.kt index 1fcb0968d8d..9792763b6b7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.kt @@ -37,8 +37,6 @@ import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice -operator fun BindingContext.get(slice: ReadOnlySlice, key: K): V? = get(slice, key) - fun KtReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? { val targetLabel = getTargetLabel() if (targetLabel != null) return context[LABEL_TARGET, targetLabel]?.let { context[FUNCTION, it] } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt b/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt index 1285459fe37..97439e4147a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinitionFromAnnotatedTemplate.kt @@ -95,7 +95,7 @@ open class KotlinScriptDefinitionFromAnnotatedTemplate( } fun makeScriptContents() = BasicScriptContents(file, getAnnotations = { - val classLoader = (template as Any)::class.java.classLoader + val classLoader = template::class.java.classLoader try { getAnnotationEntries(file, project) .mapNotNull { psiAnn -> diff --git a/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt b/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt index 463fa2d6c07..b4bc5b59adc 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/checkers/LoggingStorageManager.kt @@ -102,13 +102,8 @@ class LoggingStorageManager( return CallData(outerInstance, containingField, enclosingEntity, arguments, result) } - private fun enclosingEntity(_class: Class): GenericDeclaration? { - val result = _class.enclosingConstructor - ?: _class.enclosingMethod - ?: _class.enclosingClass - - return result as GenericDeclaration? - } + private fun enclosingEntity(klass: Class): GenericDeclaration? = + klass.enclosingConstructor ?: klass.enclosingMethod ?: klass.enclosingClass private fun Class<*>.getAllDeclaredFields(): List { val result = arrayListOf() diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index 1856b5ddd44..b62baf3d802 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -144,7 +144,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo this.isImpl = isImpl; } - public void setHiddenToOvercomeSignatureClash(boolean hiddenToOvercomeSignatureClash) { + private void setHiddenToOvercomeSignatureClash(boolean hiddenToOvercomeSignatureClash) { isHiddenToOvercomeSignatureClash = hiddenToOvercomeSignatureClash; } @@ -339,7 +339,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo } @Nullable - protected KotlinType getExtensionReceiverParameterType() { + private KotlinType getExtensionReceiverParameterType() { if (extensionReceiverParameter == null) return null; return extensionReceiverParameter.getType(); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 6c0ceabe2fb..ee201c45484 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -216,7 +216,7 @@ public class TypeUtils { for (TypeParameterDescriptor parameterDescriptor : parameters) { result.add(new TypeProjectionImpl(parameterDescriptor.getDefaultType())); } - return org.jetbrains.kotlin.utils.CollectionsKt.toReadOnlyList(result); + return CollectionsKt.toList(result); } @NotNull diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt index 136e333ccaa..7ed137d4a8d 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -20,15 +20,6 @@ import java.lang.reflect.Modifier import java.util.* import java.util.concurrent.ConcurrentHashMap -@Deprecated("Use listOfNotNull(this) or this.let(::listOfNotNull) instead", ReplaceWith("listOfNotNull(this)")) -fun T?.singletonOrEmptyList(): List = if (this != null) Collections.singletonList(this) else Collections.emptyList() - -@Deprecated("Use listOf(this) or this.let(::listOf) instead", ReplaceWith("listOf(this)")) -fun T.singletonList(): List = Collections.singletonList(this) - -@Deprecated("Use this?.let(::setOf).orEmpty() instead", ReplaceWith("this?.let(::setOf).orEmpty()")) -fun T?.singletonOrEmptySet(): Set = if (this != null) Collections.singleton(this) else Collections.emptySet() - inline fun Sequence<*>.firstIsInstanceOrNull(): T? { for (element in this) if (element is T) return element return null @@ -79,9 +70,6 @@ fun sequenceOfLazyValues(vararg elements: () -> T): Sequence = elements.a fun Pair.swap(): Pair = Pair(second, first) -@Deprecated("Use takeIf() instead.", ReplaceWith("this.takeIf(predicate)")) -fun T.check(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null - inline fun Any?.safeAs(): T? = this as? T inline fun Any?.cast(): T = this as T inline fun Any?.assertedCast(message: () -> String): T = this as? T ?: throw AssertionError(message()) diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt index 731768bb4d7..764b5927db7 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt @@ -57,14 +57,11 @@ inline fun > C.ifEmpty(body: () -> C): C = if (isEmpty()) bo inline fun Array.ifEmpty(body: () -> Array): Array = if (isEmpty()) body() else this -@Deprecated("Use listOfNotNull instead", ReplaceWith("listOfNotNull(item)")) -fun emptyOrSingletonList(item: T?): List = listOfNotNull(item) - fun MutableCollection.addIfNotNull(t: T?) { if (t != null) add(t) } -suspend fun SequenceBuilder.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit +suspend fun SequenceBuilder.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit fun newHashMapWithExpectedSize(expectedSize: Int): HashMap = HashMap(capacity(expectedSize)) @@ -81,14 +78,6 @@ fun newLinkedHashSetWithExpectedSize(expectedSize: Int): LinkedHashSet = private fun capacity(expectedSize: Int): Int = if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1 -@Deprecated("Use toList(), it provides the same behavior for Collection", ReplaceWith("this.toList()")) -fun Collection.toReadOnlyList(): List = - when (size) { - 0 -> emptyList() - 1 -> listOf(first()) - else -> ArrayList(this) - } - fun ArrayList.compactIfPossible(): List = when (size) { 0 -> emptyList() @@ -96,10 +85,6 @@ fun ArrayList.compactIfPossible(): List = else -> apply { trimToSize() } } -@Deprecated("Use listOfNotNull(this) or this.let(::listOfNotNull) instead", ReplaceWith("listOfNotNull(this)")) -fun T?.singletonOrEmptyList(): List = - if (this != null) listOf(this) else emptyList() - fun List.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int { for (index in startFrom..lastIndex) { if (predicate(this[index])) return index diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt index 16d5410f34b..89c10791fc1 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt @@ -127,7 +127,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { generateBitwiseOperators(className, since = if (kind == PrimitiveType.BYTE || kind == PrimitiveType.SHORT) "1.1" else null) } - generateConversions(kind) + generateConversions() out.println("}\n") } @@ -220,7 +220,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { out.println() } - private fun generateConversions(kind: PrimitiveType) { + private fun generateConversions() { for (otherKind in PrimitiveType.exceptBoolean) { val name = otherKind.capitalized out.println(" public override fun to$name(): $name") diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index edd288950d3..25844f3b671 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -19,8 +19,6 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder import com.intellij.psi.PsiElement import com.intellij.psi.stubs.StubElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor -import org.jetbrains.kotlin.builtins.getFunctionalClassKind import org.jetbrains.kotlin.builtins.isBuiltinFunctionClass import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens @@ -41,7 +39,6 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance import org.jetbrains.kotlin.serialization.deserialization.* import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer -import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList import java.util.* // TODO: see DescriptorRendererOptions.excludedTypeAnnotationClasses for decompiler diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt index d0ee3bf80f4..e1816fee977 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt @@ -45,7 +45,6 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.utils.addIfNotNull -import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet import java.util.* interface InheritanceItemsSearcher { @@ -118,7 +117,7 @@ class SmartCompletion( if (operationToken == KtTokens.EQ || operationToken in COMPARISON_TOKENS) { val left = parent.left if (left is KtReferenceExpression) { - return@lazy bindingContext[BindingContext.REFERENCE_TARGET, left].singletonOrEmptySet() + return@lazy bindingContext[BindingContext.REFERENCE_TARGET, left]?.let(::setOf).orEmpty() } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt index 992b84bf057..a12329f7f43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/memberInfo/KotlinMemberInfo.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.renderer.DescriptorRendererModifier import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull -import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet class KotlinMemberInfo @JvmOverloads constructor( member: KtNamedDeclaration, @@ -44,7 +43,7 @@ class KotlinMemberInfo @JvmOverloads constructor( ) : MemberInfoBase(member) { companion object { private val RENDERER = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.withOptions { - modifiers = DescriptorRendererModifier.INNER.singletonOrEmptySet() + modifiers = setOf(DescriptorRendererModifier.INNER) } } @@ -105,4 +104,4 @@ fun MemberInfo.toKotlinMemberInfo(): KotlinMemberInfo? { return KotlinMemberInfo(declaration, declaration is KtClass && overrides != null).apply { this.isToAbstract = this@toKotlinMemberInfo.isToAbstract } -} \ No newline at end of file +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java index 0ee70431be1..b1ce13aaf90 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java @@ -33,6 +33,7 @@ import com.intellij.testFramework.LightProjectDescriptor; import com.sun.jdi.Location; import com.sun.jdi.ReferenceType; import kotlin.Unit; +import kotlin.collections.CollectionsKt; import kotlin.io.FilesKt; import kotlin.jvm.functions.Function1; import kotlin.sequences.SequencesKt; @@ -54,7 +55,6 @@ import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.TestJdkKind; -import org.jetbrains.kotlin.utils.CollectionsKt; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import java.io.File; @@ -280,7 +280,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight @Override public List classesByName(String name) { - return CollectionsKt.emptyOrSingletonList(referencesByName.get(name)); + return CollectionsKt.listOfNotNull(referencesByName.get(name)); } } }