diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FrameMap.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/FrameMap.kt index 34be1a61bbb..1d93e1f92ac 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FrameMap.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FrameMap.kt @@ -97,7 +97,7 @@ open class FrameMapBase { val descriptors = Lists.newArrayList>() for (descriptor0 in myVarIndex.keys()) { - val descriptor = descriptor0 as T + @Suppress("UNCHECKED_CAST") val descriptor = descriptor0 as T val varIndex = myVarIndex.get(descriptor) val varSize = myVarSizes.get(descriptor) descriptors.add(Trinity.create(descriptor, varIndex, varSize)) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt index 1b57f9fab2f..130d2c5eccd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt @@ -234,7 +234,7 @@ class ScriptCodegen private constructor( hasMain = true } } - is KtProperty, is KtNamedFunction, is KtTypeAlias -> genSimpleMember(declaration) + is KtProperty, is KtTypeAlias -> genSimpleMember(declaration) is KtClassOrObject -> genClassOrObject(declaration) is KtDestructuringDeclaration -> for (entry in declaration.entries) { genSimpleMember(entry) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt index 6d2be6f7290..99bb17ea49c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt @@ -135,10 +135,9 @@ internal fun performRefinedTypeAnalysis(methodNode: MethodNode, thisName: String override fun use(frame: VarExpectedTypeFrame, insn: AbstractInsnNode) { val (expectedType, sources) = expectedTypeAndSourcesByInsnIndex[insn.index()] ?: return - sources.flatMap(SourceValue::insns).forEach { - insn -> - if (insn.isIntLoad()) { - frame.updateExpectedType((insn as VarInsnNode).`var`, expectedType) + sources.flatMap(SourceValue::insns).forEach { insnNode -> + if (insnNode.isIntLoad()) { + frame.updateExpectedType((insnNode as VarInsnNode).`var`, expectedType) } } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt index 17e4da2696b..7b41eee5729 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt @@ -168,12 +168,12 @@ abstract class InlineCodegen( } } + @Suppress("UNREACHABLE_CODE") private fun canSkipStackSpillingOnInline(methodNode: MethodNode): Boolean { - // Temporary disable this optimization until + // TODO: Temporary disable this optimization until // https://issuetracker.google.com/issues/68796377 is fixed // or until d8 substitute dex return false - // Stack spilling before inline function 'f' call is required if: // - 'f' is a suspend function // - 'f' has try-catch blocks diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.kt index 33c0aead82b..dee7db0e1e0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.kt @@ -96,19 +96,19 @@ class LocalVarRemapper(private val params: Parameters, private val additionalShi } fun visitVarInsn(opcode: Int, `var`: Int, mv: InstructionAdapter) { - var opcode = opcode val remapInfo = remap(`var`) val value = remapInfo.value if (value is StackValue.Local) { val isStore = isStoreInstruction(opcode) - if (remapInfo.parameterInfo != null) { + val localOpcode = if (remapInfo.parameterInfo != null) { //All remapped value parameters can't be rewritten except case of default ones. //On remapping default parameter to actual value there is only one instruction that writes to it according to mask value //but if such parameter remapped then it passed and this mask branch code never executed //TODO add assertion about parameter default value: descriptor is required - opcode = value.type.getOpcode(if (isStore) Opcodes.ISTORE else Opcodes.ILOAD) - } - mv.visitVarInsn(opcode, value.index) + value.type.getOpcode(if (isStore) Opcodes.ISTORE else Opcodes.ILOAD) + } else opcode + + mv.visitVarInsn(localOpcode, value.index) if (remapInfo.parameterInfo != null && !isStore) { StackValue.coerce(value.type, remapInfo.parameterInfo.type, mv) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/InFloatingPointRangeLiteralExpressionGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/InFloatingPointRangeLiteralExpressionGenerator.kt index 925e2aa705f..e0b82b633a9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/InFloatingPointRangeLiteralExpressionGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/inExpression/InFloatingPointRangeLiteralExpressionGenerator.kt @@ -58,7 +58,7 @@ class InFloatingPointRangeLiteralExpressionGenerator( // goto jumpLabel // exitLabel: - frameMap.useTmpVar(operandType) { argVar -> + frameMap.useTmpVar(operandType) { _ -> val exitLabel = Label() genJumpIfFalse(v, exitLabel) v.goTo(jumpLabel) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 3ffb749e174..d66cf6a0bc8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -278,8 +278,8 @@ class GenerationState private constructor( ?.let { destination -> SignatureDumpingBuilderFactory(it, File(destination)) } ?: it } ) - .wrapWith(ClassBuilderInterceptorExtension.getInstances(project)) { builderFactory, extension -> - extension.interceptClassBuilderFactory(builderFactory, bindingContext, diagnostics) + .wrapWith(ClassBuilderInterceptorExtension.getInstances(project)) { classBuilderFactory, extension -> + extension.interceptClassBuilderFactory(classBuilderFactory, bindingContext, diagnostics) } this.factory = ClassFileFactory(this, interceptedBuilderFactory) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/InternalCompilerArgument.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/InternalCompilerArgument.kt index d8daa849f51..d896cc7df18 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/InternalCompilerArgument.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/InternalCompilerArgument.kt @@ -59,7 +59,7 @@ class LanguageSettingsParser : AbstractInternalArgumentParser(val state1: IReplStageState, val override val history: IReplStageHistory> = AggregatedReplStateHistory(state1.history, state2.history, lock) override fun > asState(target: Class): StateT = - when { - target.isAssignableFrom(state1::class.java) -> state1 as StateT - target.isAssignableFrom(state2::class.java) -> state2 as StateT - else -> super.asState(target) - } + @Suppress("UNCHECKED_CAST") + when { + target.isAssignableFrom(state1::class.java) -> state1 as StateT + target.isAssignableFrom(state2::class.java) -> state2 as StateT + else -> super.asState(target) + } override fun getNextLineNo() = state1.getNextLineNo() diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/ReplState.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/ReplState.kt index 6e16717e561..45218024c67 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/ReplState.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/ReplState.kt @@ -57,9 +57,10 @@ interface IReplStageState { fun getNextLineNo(): Int = history.peek()?.id?.no?.let { it + 1 } ?: REPL_CODE_LINE_FIRST_NO // TODO: it should be more robust downstream (e.g. use atomic) + @Suppress("UNCHECKED_CAST") fun > asState(target: Class): StateT = - if (target.isAssignableFrom(this::class.java)) this as StateT - else throw IllegalArgumentException("$this is not an expected instance of IReplStageState") + if (target.isAssignableFrom(this::class.java)) this as StateT + else throw IllegalArgumentException("$this is not an expected instance of IReplStageState") } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt index d9eacf1ac06..6ade627586b 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt @@ -53,7 +53,7 @@ abstract class CLICompiler : CLITool() { return exec(errStream, Services.EMPTY, MessageRenderer.PLAIN_FULL_PATHS, args) } - public override fun execImpl(baseMessageCollector: MessageCollector, services: Services, arguments: A): ExitCode { + public override fun execImpl(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode { val performanceManager = performanceManager if (arguments.reportPerf || arguments.dumpPerf != null) { performanceManager.enableCollectingPerformanceStatistics() @@ -61,7 +61,7 @@ abstract class CLICompiler : CLITool() { val configuration = CompilerConfiguration() - val messageCollector = GroupingMessageCollector(baseMessageCollector, arguments.allWarningsAsErrors).also { + val collector = GroupingMessageCollector(messageCollector, arguments.allWarningsAsErrors).also { configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, it) } @@ -69,8 +69,8 @@ abstract class CLICompiler : CLITool() { try { setupCommonArguments(configuration, arguments) setupPlatformSpecificArgumentsAndServices(configuration, arguments, services) - val paths = computeKotlinPaths(messageCollector, arguments) - if (messageCollector.hasErrors()) { + val paths = computeKotlinPaths(collector, arguments) + if (collector.hasErrors()) { return ExitCode.COMPILATION_ERROR } @@ -93,14 +93,14 @@ abstract class CLICompiler : CLITool() { performanceManager.dumpPerformanceReport(File(arguments.dumpPerf!!)) } - return if (messageCollector.hasErrors()) COMPILATION_ERROR else code + return if (collector.hasErrors()) COMPILATION_ERROR else code } catch (e: CompilationCanceledException) { - messageCollector.report(INFO, "Compilation was canceled", null) + collector.report(INFO, "Compilation was canceled", null) return ExitCode.OK } catch (e: RuntimeException) { val cause = e.cause if (cause is CompilationCanceledException) { - messageCollector.report(INFO, "Compilation was canceled", null) + collector.report(INFO, "Compilation was canceled", null) return ExitCode.OK } else { throw e @@ -111,10 +111,10 @@ abstract class CLICompiler : CLITool() { } catch (e: AnalysisResult.CompilationErrorException) { return COMPILATION_ERROR } catch (t: Throwable) { - MessageCollectorUtil.reportException(messageCollector, t) + MessageCollectorUtil.reportException(collector, t) return INTERNAL_ERROR } finally { - messageCollector.flush() + collector.flush() } } diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt index 082ef3eb5d7..ceec3e876f0 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt @@ -134,7 +134,8 @@ class DummyProfiler : Profiler { override fun getCounters(): Map = mapOf(null to SimplePerfCounters()) override fun getTotalCounters(): PerfCounters = SimplePerfCounters() - override final inline fun withMeasure(obj: Any?, body: () -> R): R = body() + @Suppress("OVERRIDE_BY_INLINE") + override inline fun withMeasure(obj: Any?, body: () -> R): R = body() } @@ -149,17 +150,20 @@ abstract class TotalProfiler : Profiler { class WallTotalProfiler : TotalProfiler() { - override final inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallTime(total, body) + @Suppress("OVERRIDE_BY_INLINE") + override inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallTime(total, body) } class WallAndThreadTotalProfiler : TotalProfiler() { - override final inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimes(total, threadMXBean, body) + @Suppress("OVERRIDE_BY_INLINE") + override inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimes(total, threadMXBean, body) } class WallAndThreadAndMemoryTotalProfiler(val withGC: Boolean) : TotalProfiler() { - override final inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, body) + @Suppress("OVERRIDE_BY_INLINE") + override inline fun withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, body) } @@ -169,6 +173,7 @@ class WallAndThreadByClassProfiler() : TotalProfiler() { override fun getCounters(): Map = counters - override final inline fun withMeasure(obj: Any?, body: () -> R): R = - withMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, body) + @Suppress("OVERRIDE_BY_INLINE") + override inline fun withMeasure(obj: Any?, body: () -> R): R = + withMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, body) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt index 03abaee1a01..86a685bb539 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaClassImpl.kt @@ -81,10 +81,9 @@ class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl(psiClass) override val fields: Collection get() { assertNotLightClass() - return fields(psi.fields.filter { field -> - val name = field.name + return fields(psi.fields.filter { // ex. Android plugin generates LightFields for resources started from '.' (.DS_Store file etc) - name != null && Name.isValidIdentifier(name) + Name.isValidIdentifier(it.name) }) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmArrayVariableInLoopAssignmentChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmArrayVariableInLoopAssignmentChecker.kt index 9ee8e379abf..6552c2e0f20 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmArrayVariableInLoopAssignmentChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmArrayVariableInLoopAssignmentChecker.kt @@ -52,6 +52,7 @@ object JvmArrayVariableInLoopAssignmentChecker : AdditionalTypeChecker { val resolvedCall = lhsExpression.getResolvedCall(c.trace.bindingContext) ?: return val variableDescriptor = resolvedCall.resultingDescriptor as? LocalVariableDescriptor ?: return if (variableDescriptor is SyntheticFieldDescriptor) return + @Suppress("DEPRECATION") if (variableDescriptor.isDelegated) return val variableType = variableDescriptor.returnType diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmDefaultSuperCallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmDefaultSuperCallChecker.kt index b8595d0d9b6..443b856c529 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmDefaultSuperCallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmDefaultSuperCallChecker.kt @@ -20,7 +20,8 @@ class JvmDefaultSuperCallChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { val jvmDefaultMode = context.languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode) if (jvmDefaultMode.isEnabled) return - val superExpression = getSuperCallExpression(resolvedCall.call) ?: return + if (getSuperCallExpression(resolvedCall.call) == null) return + val resultingDescriptor = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return if (!resultingDescriptor.hasJvmDefaultAnnotation()) return diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 33a989081e3..7d1b65c47c7 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -385,14 +385,14 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l } } - override fun substitute(originalSubstitutor: TypeSubstitutor): PropertyDescriptor? { - val descriptor = super.substitute(originalSubstitutor) as MyPropertyDescriptor? ?: return null + override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor? { + val descriptor = super.substitute(substitutor) as MyPropertyDescriptor? ?: return null if (descriptor == this) return descriptor val classTypeParameters = (getMethod.containingDeclaration as ClassDescriptor).typeConstructor.parameters val substitutionMap = HashMap() for ((typeParameter, classTypeParameter) in typeParameters.zip(classTypeParameters)) { - val typeProjection = originalSubstitutor.substitution[typeParameter.defaultType] ?: continue + val typeProjection = substitutor.substitution[typeParameter.defaultType] ?: continue substitutionMap[classTypeParameter.typeConstructor] = typeProjection } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt index f3b05fe3e8d..74ac6c4a0c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt @@ -121,6 +121,7 @@ class ResolverForProjectImpl( // Protected by ("projectContext.storageManager.lock") private val moduleInfoByDescriptor = mutableMapOf() + @Suppress("UNCHECKED_CAST") private val moduleInfoToResolvableInfo: Map = modules.flatMap { module -> module.flatten().map { modulePart -> modulePart to module } }.toMap() as Map @@ -326,6 +327,7 @@ class LazyModuleDependencies( yield(moduleDescriptor.builtIns.builtInsModule) } for (dependency in module.dependencies()) { + @Suppress("UNCHECKED_CAST") yield(resolverForProject.descriptorForModule(dependency as M)) } if (module.dependencyOnBuiltIns() == ModuleInfo.DependencyOnBuiltIns.LAST) { @@ -337,12 +339,16 @@ class LazyModuleDependencies( override val allDependencies: List get() = dependencies() override val expectedByDependencies by storageManager.createLazyValue { - module.expectedBy.map { resolverForProject.descriptorForModule(it as M) } + module.expectedBy.map { + @Suppress("UNCHECKED_CAST") + resolverForProject.descriptorForModule(it as M) + } } override val modulesWhoseInternalsAreVisible: Set get() = module.modulesWhoseInternalsAreVisible().mapTo(LinkedHashSet()) { + @Suppress("UNCHECKED_CAST") resolverForProject.descriptorForModule(it as M) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt index a61856ab348..7d61d67ddc1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt @@ -166,6 +166,7 @@ class SyntheticClassOrObjectDescriptor( override fun getPsiOrParent() = _parent.psiOrParent override fun getParent() = _parent.psiOrParent + @Suppress("USELESS_ELVIS") override fun getContainingKtFile() = // in theory `containingKtFile` is `@NotNull` but in practice EA-114080 _parent.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $_parent of ${_parent.javaClass}") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index e2842787ad9..b5d3e248e88 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -439,11 +439,11 @@ class CallCompleter( } var shouldBeMadeNullable = false - expressions.asReversed().forEach { expression -> - if (!(expression is KtParenthesizedExpression || expression is KtLabeledExpression || expression is KtAnnotatedExpression)) { - shouldBeMadeNullable = hasNecessarySafeCall(expression, trace) + expressions.asReversed().forEach { ktExpression -> + if (!(ktExpression is KtParenthesizedExpression || ktExpression is KtLabeledExpression || ktExpression is KtAnnotatedExpression)) { + shouldBeMadeNullable = hasNecessarySafeCall(ktExpression, trace) } - BindingContextUtils.updateRecordedType(updatedType, expression, trace, shouldBeMadeNullable) + BindingContextUtils.updateRecordedType(updatedType, ktExpression, trace, shouldBeMadeNullable) } return trace.getType(argumentExpression) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt index 0d0d5be14f0..d435713f562 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt @@ -360,7 +360,7 @@ class CallExpressionResolver( initialDataFlowInfoForArguments = initialDataFlowInfoForArguments.disequate( receiverDataFlowValue, DataFlowValue.nullValue(builtIns), languageVersionSettings ) - } else if (receiver is ReceiverValue) { + } else { reportUnnecessarySafeCall(context.trace, receiver.type, callOperationNode, receiver) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt index 02b101bee8f..708cef79bef 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt @@ -145,7 +145,7 @@ fun isBinaryRemOperator(call: Call): Boolean { val operator = callElement.operationToken if (operator !is KtToken) return false - val name = OperatorConventions.getNameForOperationSymbol(operator, true, true) + val name = OperatorConventions.getNameForOperationSymbol(operator, true, true) ?: return false return name in OperatorConventions.REM_TO_MOD_OPERATION_NAMES.keys } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueKindUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueKindUtils.kt index 63869c67b98..2881be339f1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueKindUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueKindUtils.kt @@ -41,6 +41,7 @@ internal fun VariableDescriptor.variableKind( return propertyKind(usageModule) } + @Suppress("DEPRECATION") if (this is LocalVariableDescriptor && this.isDelegated) { // Local delegated property: normally unstable, but can be treated as stable in legacy mode return if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitSmartcastsOnLocalDelegatedProperty)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 2784884ccb9..d5ca820299f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -117,6 +117,7 @@ class KotlinToResolvedCallTransformer( forwardCallToInferenceSession(baseResolvedCall, context, stub, tracingStrategy) + @Suppress("UNCHECKED_CAST") return stub as ResolvedCall } @@ -131,7 +132,8 @@ class KotlinToResolvedCallTransformer( } } - val resolvedCall = ktPrimitiveCompleter.completeResolvedCall(candidate, baseResolvedCall.diagnostics) as ResolvedCall + @Suppress("UNCHECKED_CAST") val resolvedCall = + ktPrimitiveCompleter.completeResolvedCall(candidate, baseResolvedCall.diagnostics) as ResolvedCall forwardCallToInferenceSession(baseResolvedCall, context, resolvedCall, tracingStrategy) resolvedCall @@ -580,6 +582,7 @@ class NewResolvedCallImpl( override val argumentMappingByOriginal: Map get() = resolvedCallAtom.argumentMappingByOriginal + @Suppress("UNCHECKED_CAST") override fun getCandidateDescriptor(): D = resolvedCallAtom.candidateDescriptor as D override fun getResultingDescriptor(): D = resultingDescriptor override fun getExtensionReceiver(): ReceiverValue? = extensionReceiver @@ -639,6 +642,7 @@ class NewResolvedCallImpl( } } + @Suppress("UNCHECKED_CAST") resultingDescriptor = run { val candidateDescriptor = resolvedCallAtom.candidateDescriptor val containsCapturedTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains { it is NewCapturedType } ?: false diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt index 7d94161e737..98223758ca7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt @@ -53,6 +53,7 @@ abstract class ManyCandidatesResolver( if (callInfo !is PSIErrorCallInfo<*>) { throw AssertionError("Error call info for $callInfo should be instance of PSIErrorCallInfo") } + @Suppress("UNCHECKED_CAST") errorCallsInfo.add(callInfo as PSIErrorCallInfo) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 498ed603217..a3fba4ef814 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -260,7 +260,10 @@ class NewResolutionOldInference( private fun allCandidatesResult(allCandidates: Collection) = OverloadResolutionResultsImpl.nameNotFound().apply { - this.allCandidates = allCandidates.map { it.resolvedCall as MutableResolvedCall } + this.allCandidates = allCandidates.map { + @Suppress("UNCHECKED_CAST") + it.resolvedCall as MutableResolvedCall + } } private fun convertToOverloadResults( @@ -315,6 +318,7 @@ class NewResolutionOldInference( } } + @Suppress("UNCHECKED_CAST") resolvedCall as MutableResolvedCall } @@ -475,7 +479,7 @@ class NewResolutionOldInference( variable: MyCandidate, invoke: MyCandidate ): MyCandidate { - val resolvedCallImpl = VariableAsFunctionResolvedCallImpl( + @Suppress("UNCHECKED_CAST") val resolvedCallImpl = VariableAsFunctionResolvedCallImpl( invoke.resolvedCall as MutableResolvedCall, variable.resolvedCall as MutableResolvedCall ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 7f4517fd38a..9f901df62bb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver import org.jetbrains.kotlin.resolve.calls.components.InferenceSession import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext -import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter @@ -551,8 +550,7 @@ class PSICallResolver( require(oldCall is CallTransformer.CallForImplicitInvoke) { "Call should be CallForImplicitInvoke, but it is: $oldCall" } - val dispatchReceiver = oldCall.dispatchReceiver!! // dispatch receiver from CallForImplicitInvoke is always not null - return resolveReceiver(context, dispatchReceiver, isSafeCall = false, isForImplicitInvoke = true) + return resolveReceiver(context, oldCall.dispatchReceiver, isSafeCall = false, isForImplicitInvoke = true) } private fun resolveReceiver( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt index c80f965b284..5695315f0f7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt @@ -39,6 +39,7 @@ val KotlinCall.psiKotlinCall: PSIKotlinCall return this as PSIKotlinCall } +@Suppress("UNCHECKED_CAST") fun KotlinCall.getResolvedPsiKotlinCall(trace: BindingTrace): NewResolvedCallImpl? = psiKotlinCall.psiCall.getResolvedCall(trace.bindingContext) as? NewResolvedCallImpl diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.kt index bcee698351b..71dc0011dd0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.LockBasedLazyResolveStorageManager import javax.inject.Inject -open class LazyDeclarationResolver @Deprecated("") constructor( +open class LazyDeclarationResolver constructor( globalContext: GlobalContext, delegationTrace: BindingTrace, private val topLevelDescriptorProvider: TopLevelDescriptorProvider, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt index 4fdb9da2b14..226742d6566 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt @@ -464,8 +464,8 @@ open class LazyClassMemberScope( descriptor.returnType = c.wrappedTypeFactory.createDeferredType(trace, { thisDescriptor.defaultType }) } - override fun recordLookup(name: Name, from: LookupLocation) { - c.lookupTracker.record(from, thisDescriptor, name) + override fun recordLookup(name: Name, location: LookupLocation) { + c.lookupTracker.record(location, thisDescriptor, name) } // Do not add details here, they may compromise the laziness during debugging diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyPackageMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyPackageMemberScope.kt index 2f8d0eda1b4..3ebfdcc1fab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyPackageMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyPackageMemberScope.kt @@ -62,8 +62,8 @@ class LazyPackageMemberScope( // No extra properties } - override fun recordLookup(name: Name, from: LookupLocation) { - c.lookupTracker.record(from, thisDescriptor, name) + override fun recordLookup(name: Name, location: LookupLocation) { + c.lookupTracker.record(location, thisDescriptor, name) } override fun getClassifierNames(): Set? = declarationProvider.getDeclarationNames() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt index 8ae4f1f600b..75e6825fdec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CastDiagnosticsUtil.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker @@ -163,7 +164,7 @@ object CastDiagnosticsUtil { val supertypeWithVariables = TypeCheckingProcedure.findCorrespondingSupertype(subtypeWithVariables, supertype) val variables = subtypeWithVariables.constructor.parameters - val variableConstructors = variables.map { descriptor -> descriptor.typeConstructor }.toSet() + val variableConstructors = variables.map(TypeParameterDescriptor::getTypeConstructor).toSet() val substitution: MutableMap = if (supertypeWithVariables != null) { // Now, let's try to unify Collection and Collection solution is a map from T to Foo diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt index 9cf8357156b..8b3bf7b119c 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt @@ -53,9 +53,8 @@ abstract class ModulesApiHistoryBase(protected val modulesInfo: IncrementalModul } val classFileDirs = classFiles.groupBy { it.parentFile } - for ((dir, files) in classFileDirs) { - val historyEither = getBuildHistoryForDir(dir) - when (historyEither) { + for (dir in classFileDirs.keys) { + when (val historyEither = getBuildHistoryForDir(dir)) { is Either.Success> -> result.addAll(historyEither.value) is Either.Error -> return historyEither } @@ -107,13 +106,13 @@ class ModulesApiHistoryJvm(modulesInfo: IncrementalModuleInfo) : ModulesApiHisto val classFileDirs = classFiles.filter { it.exists() && it.parentFile != null }.groupBy { it.parentFile } val result = HashSet() - for ((dir, files) in classFileDirs) { - val historyEither = getBuildHistoryForDir(dir) - when (historyEither) { + for (dir in classFileDirs.keys) { + when (val historyEither = getBuildHistoryForDir(dir)) { is Either.Success> -> result.addAll(historyEither.value) is Either.Error -> return historyEither } } + return Either.Success(result) } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt index d0902f3f0ff..53864b9523b 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/IrElementTransformerVoidWithContext.kt @@ -121,7 +121,7 @@ abstract class IrElementVisitorVoidWithContext : IrElementVisitorVoid { } override final fun visitField(declaration: IrField) { - val isDelegated = declaration.descriptor.isDelegated + @Suppress("DEPRECATION") val isDelegated = declaration.descriptor.isDelegated if (isDelegated) scopeStack.push(ScopeWithIr(Scope(declaration.symbol), declaration)) visitFieldNew(declaration) if (isDelegated) scopeStack.pop() diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index d6fa308a076..bb6d99ce542 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -19,7 +19,9 @@ package org.jetbrains.kotlin.backend.common.ir import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor import org.jetbrains.kotlin.backend.common.deepCopyWithVariables import org.jetbrains.kotlin.backend.common.descriptors.* -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.Scope @@ -43,7 +45,6 @@ import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementVisitor -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import java.io.StringWriter @@ -160,7 +161,6 @@ fun IrTypeParameter.copyToWithoutSuperTypes( shift: Int = 0, origin: IrDeclarationOrigin = this.origin ): IrTypeParameter { - val source = parent as IrTypeParametersContainer val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source) val symbol = IrTypeParameterSymbolImpl(descriptor) return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also { copied -> @@ -240,7 +240,8 @@ fun IrFunction.copyValueParametersToStatic( ) ) } - source.valueParameters.forEachIndexed { i, oldValueParameter -> + + for (oldValueParameter in source.valueParameters) { target.valueParameters.add( oldValueParameter.copyTo( target, @@ -345,6 +346,7 @@ fun IrClass.createImplicitParameterDeclarationWithWrappedDescriptor() { assert(descriptor.declaredTypeParameters.isEmpty()) } +@Suppress("UNCHECKED_CAST") fun isElseBranch(branch: IrBranch) = branch is IrElseBranch || ((branch.condition as? IrConst)?.value == true) fun IrSimpleFunction.isMethodOfAny() = diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt index 26b06f50515..aee56f8c8e7 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt @@ -183,31 +183,35 @@ class InlineClassLowering(val context: BackendContext) { override fun lower(irFile: IrFile) { irFile.transformChildrenVoid(object : IrElementTransformerVoid() { - override fun visitCall(call: IrCall): IrExpression { - call.transformChildrenVoid(this) - val function = call.symbol.owner + override fun visitCall(expression: IrCall): IrExpression { + expression.transformChildrenVoid(this) + val function = expression.symbol.owner if (function.parent !is IrClass || function.isStaticMethodOfClass || !function.parentAsClass.isInline || (function is IrSimpleFunction && !function.isReal) || (function is IrConstructor && function.isPrimary) ) { - return call + return expression } - return irCall(call, getOrCreateStaticMethod(function), dispatchReceiverAsFirstArgument = (function is IrSimpleFunction)) + return irCall( + expression, + getOrCreateStaticMethod(function), + dispatchReceiverAsFirstArgument = (function is IrSimpleFunction) + ) } - override fun visitDelegatingConstructorCall(call: IrDelegatingConstructorCall): IrExpression { - call.transformChildrenVoid(this) - val function = call.symbol.owner + override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression { + expression.transformChildrenVoid(this) + val function = expression.symbol.owner val klass = function.parentAsClass return when { - !klass.isInline -> call - function.isPrimary -> irCall(call, function) - else -> irCall(call, getOrCreateStaticMethod(function)).apply { - (0 until call.valueArgumentsCount).forEach { - putValueArgument(it, call.getValueArgument(it)!!) + !klass.isInline -> expression + function.isPrimary -> irCall(expression, function) + else -> irCall(expression, getOrCreateStaticMethod(function)).apply { + (0 until expression.valueArgumentsCount).forEach { + putValueArgument(it, expression.getValueArgument(it)!!) } } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt index 161cf0c759a..c3ac1bb835d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt @@ -78,6 +78,7 @@ abstract class AbstractNamedPhaseWrapper && this !in phaseConfig.enabled ) { + @Suppress("UNCHECKED_CAST") return input as Output } @@ -121,7 +122,7 @@ abstract class AbstractNamedPhaseWrapper) { - val phaserStateO = phaserState as PhaserState + @Suppress("UNCHECKED_CAST") val phaserStateO = phaserState as PhaserState for (post in phaserStateO.stickyPostconditions) post(output) } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt index 0a30e1bed8f..0e3673f39c2 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt @@ -17,7 +17,7 @@ private class CompositePhase( ) : CompilerPhase { override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState, context: Context, input: Input): Output { - var currentState = phaserState as PhaserState + @Suppress("UNCHECKED_CAST") var currentState = phaserState as PhaserState var result = phases.first().invoke(phaseConfig, currentState, context, input) for ((previous, next) in phases.zip(phases.drop(1))) { if (next !is SameTypeCompilerPhase<*, *>) { @@ -27,6 +27,7 @@ private class CompositePhase( currentState.stickyPostconditions.addAll(previous.stickyPostconditions) result = next.invoke(phaseConfig, currentState, context, result) } + @Suppress("UNCHECKED_CAST") return result as Output } @@ -36,6 +37,7 @@ private class CompositePhase( override val stickyPostconditions get() = phases.last().stickyPostconditions } +@Suppress("UNCHECKED_CAST") infix fun CompilerPhase.then( other: CompilerPhase ): CompilerPhase { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/FunctionInlining.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/FunctionInlining.kt index 528ae0291f9..4949446f0ed 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/FunctionInlining.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/inline/FunctionInlining.kt @@ -176,8 +176,6 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW } } - val sourceFile = callee.file - val transformer = ParameterSubstitutor() statements.transform { it.transform(transformer, data = null) } statements.addAll(0, evaluationStatements) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt index 045898c5f65..57a5371d2bd 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt @@ -12,8 +12,8 @@ import org.jetbrains.kotlin.js.backend.ast.JsDeclarationScope import org.jetbrains.kotlin.js.backend.ast.JsStatement class IrFileToJsTransformer : BaseIrElementToJsNodeTransformer { - override fun visitFile(declaration: IrFile, context: JsGenerationContext): JsStatement { - val fileContext = context.newDeclaration(JsDeclarationScope(context.currentScope, "scope for file ${declaration.path}")) + override fun visitFile(declaration: IrFile, data: JsGenerationContext): JsStatement { + val fileContext = data.newDeclaration(JsDeclarationScope(data.currentScope, "scope for file ${declaration.path}")) val block = fileContext.currentBlock declaration.declarations.forEach { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt index 1219e12c6bf..7fa28d349ab 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt @@ -10,7 +10,9 @@ import org.jetbrains.kotlin.backend.common.ir.isElseBranch import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext import org.jetbrains.kotlin.ir.backend.js.utils.Namer import org.jetbrains.kotlin.ir.declarations.IrFunction -import org.jetbrains.kotlin.ir.expressions.* +import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.expressions.IrWhen import org.jetbrains.kotlin.js.backend.ast.* fun jsVar(name: JsName, initializer: IrExpression?, context: JsGenerationContext): JsVars { @@ -18,12 +20,12 @@ fun jsVar(name: JsName, initializer: IrExpression?, context: JsGenerationContext return JsVars(JsVars.JsVar(name, jsInitializer)) } -fun IrWhen.toJsNode( - tr: BaseIrElementToJsNodeTransformer, - data: D, +fun IrWhen.toJsNode( + tr: BaseIrElementToJsNodeTransformer, + data: JsGenerationContext, node: (JsExpression, T, T?) -> T ): T? = - branches.foldRight(null) { br, n -> + branches.foldRight(null) { br, n -> val body = br.result.accept(tr, data) if (isElseBranch(br)) body else { @@ -118,9 +120,7 @@ object JsAstUtils { thenStatement: JsStatement, elseStatement: JsStatement? = null ): JsIf { - var elseStatement = elseStatement - elseStatement = if (elseStatement != null) deBlockIfPossible(elseStatement) else null - return JsIf(ifExpression, deBlockIfPossible(thenStatement), elseStatement) + return JsIf(ifExpression, deBlockIfPossible(thenStatement), elseStatement?.let { deBlockIfPossible(it) }) } fun and(op1: JsExpression, op2: JsExpression): JsBinaryOperation { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/AnnotationUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/AnnotationUtils.kt index d78db081584..e118b616390 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/AnnotationUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/AnnotationUtils.kt @@ -21,6 +21,7 @@ object JsAnnotations { val jsQualifierFqn = FqName("kotlin.js.JsQualifier") } +@Suppress("UNCHECKED_CAST") private fun IrCall.getSingleConstStringArgument() = (getValueArgument(0) as IrConst).value diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt index c6f28885e81..310f203ac31 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt @@ -31,7 +31,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory val psi2ir = Psi2IrTranslator(state.languageVersionSettings) val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, extensions = JvmGeneratorExtensions) - val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection) + @Suppress("UNCHECKED_CAST") val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection) JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext, phaseConfig) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt index 03acd44eb0a..4458ebfcdef 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt @@ -96,7 +96,7 @@ class IrInlineCodegen( private fun rememberClosure(irReference: IrFunctionReference, type: Type, parameter: ValueParameterDescriptor): LambdaInfo { //assert(InlineUtil.isInlinableParameterExpression(ktLambda)) { "Couldn't find inline expression in ${expression.text}" } - val expression = irReference.symbol.owner as IrFunction + val expression = irReference.symbol.owner return IrExpressionLambdaImpl( irReference, expression, typeMapper, parameter.isCrossinline, false/*TODO*/, parameter.type.isExtensionFunctionType diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt index f97762c6662..13dd7e01343 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt @@ -177,7 +177,7 @@ class JvmSharedVariablesManager( typeArgumentsCount = typeArgumentsCount, origin = SHARED_VARIABLE_CONSTRUCTOR_CALL_ORIGIN ).apply { - refConstructor.parentAsClass.typeParameters.mapIndexed { i, param -> + List(refConstructor.parentAsClass.typeParameters.size) { i -> putTypeArgument(i, valueType) } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt index 27583e51323..1cad499d940 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/MoveCompanionObjectFieldsLowering.kt @@ -212,10 +212,10 @@ private class FieldReplacer(val replacementMap: Map + replacementMap[expression.symbol]?.let { _ -> IrSetFieldImpl( expression.startOffset, expression.endOffset, - replacementMap[expression.symbol]!!, + replacementMap.getValue(expression.symbol), /* receiver = */ null, visitExpression(expression.value), expression.type, diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt index e3d3b9103d2..fbc062c3d6c 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt @@ -106,7 +106,6 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta // TODO relies on ControlFlowInformationProvider, get rid of it val isUsedAsExpression = get(BindingContext.USED_AS_EXPRESSION, expression) ?: false - val isExhaustive = expression.isExhaustiveWhen() val resultType = when { isUsedAsExpression -> inferredType.toIrType() diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt index eee77450ccc..aa3601bf31a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt @@ -172,7 +172,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator val irType = descriptor.type.toIrType() return if (getMethodDescriptor == null) { - call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + call.callReceiver.call { dispatchReceiverValue, _ -> val fieldSymbol = context.symbolTable.referenceField(descriptor.original) IrGetFieldImpl( startOffset, endOffset, diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index d4671c4d305..73a1e879816 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -156,6 +156,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St private fun getFieldForPropertyReference(originalProperty: PropertyDescriptor) = // NB this is a hack, we really don't know if an arbitrary property has a backing field or not when { + @Suppress("DEPRECATION") originalProperty.isDelegated -> null originalProperty.getter != null -> null else -> context.symbolTable.referenceField(originalProperty) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrLocalDelegatedPropertyImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrLocalDelegatedPropertyImpl.kt index 5bb78268cb2..dbbeb657ace 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrLocalDelegatedPropertyImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrLocalDelegatedPropertyImpl.kt @@ -85,6 +85,7 @@ class IrLocalDelegatedPropertyImpl( descriptor.name, type, descriptor.isVar ) + @Suppress("DEPRECATION") @Deprecated("Creates unbound symbol") constructor( startOffset: Int, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt index 25e30562e11..e9afee2372a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt @@ -39,7 +39,7 @@ class IrPropertyImpl( override val isVar: Boolean = symbol.descriptor.isVar, override val isConst: Boolean = symbol.descriptor.isConst, override val isLateinit: Boolean = symbol.descriptor.isLateInit, - override val isDelegated: Boolean = symbol.descriptor.isDelegated, + @Suppress("DEPRECATION") override val isDelegated: Boolean = symbol.descriptor.isDelegated, override val isExternal: Boolean = symbol.descriptor.isEffectivelyExternal() ) : IrDeclarationBase(startOffset, endOffset, origin), IrProperty { @@ -69,6 +69,7 @@ class IrPropertyImpl( isExternal = isExternal ) + @Suppress("DEPRECATION") @Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING) constructor( startOffset: Int, @@ -86,6 +87,7 @@ class IrPropertyImpl( isExternal = descriptor.isEffectivelyExternal() ) + @Suppress("DEPRECATION") @Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING) constructor( startOffset: Int, @@ -94,6 +96,7 @@ class IrPropertyImpl( descriptor: PropertyDescriptor ) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor) + @Suppress("DEPRECATION") @Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING) constructor( startOffset: Int, @@ -106,6 +109,7 @@ class IrPropertyImpl( this.backingField = backingField } + @Suppress("DEPRECATION") @Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.WARNING) constructor( startOffset: Int, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyProperty.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyProperty.kt index 45ce987622b..3f61df3ab78 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyProperty.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyProperty.kt @@ -57,7 +57,7 @@ class IrLazyProperty( isVar = symbol.descriptor.isVar, isConst = symbol.descriptor.isConst, isLateinit = symbol.descriptor.isLateInit, - isDelegated = symbol.descriptor.isDelegated, + isDelegated = @Suppress("DEPRECATION") symbol.descriptor.isDelegated, isExternal = symbol.descriptor.isEffectivelyExternal(), stubGenerator = stubGenerator, typeTranslator = typeTranslator, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/LazyScopedTypeParametersResolver.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/LazyScopedTypeParametersResolver.kt index bda3bf229a3..0b1985fd395 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/LazyScopedTypeParametersResolver.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/LazyScopedTypeParametersResolver.kt @@ -33,6 +33,6 @@ class LazyScopedTypeParametersResolver(private val symbolTable: ReferenceSymbolT parent.typeParameters.firstOrNull { it.descriptor == typeParameterDescriptor }?.symbol - } ?: null + } } } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt index 918530f1417..21da6367281 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt @@ -93,7 +93,7 @@ class DeclarationStubGenerator( val origin = computeOrigin(descriptor) return symbolTable.declareProperty( UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original, - isDelegated = descriptor.isDelegated + isDelegated = @Suppress("DEPRECATION") descriptor.isDelegated ) { deserializer?.findDeserializedDeclaration(descriptor) ?: IrLazyProperty(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator, bindingContext) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt index 015a41a9e9d..be2040fb49e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt @@ -62,7 +62,7 @@ fun IrMemberAccessExpression.getArguments(): List> { val res = mutableListOf>() - val irFunction = symbol.owner as IrFunction + val irFunction = symbol.owner dispatchReceiver?.let { res += (irFunction.dispatchReceiverParameter!!.symbol to it) @@ -347,6 +347,7 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean { inline fun IrDeclarationContainer.findDeclaration(predicate: (T) -> Boolean): T? = declarations.find { it is T && predicate(it) } as? T +@Suppress("UNCHECKED_CAST") inline fun IrDeclarationContainer.filterDeclarations(predicate: (T) -> Boolean): List = declarations.filter { it is T && predicate(it) } as List diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index e42d653420a..cc3e34c6244 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -334,7 +334,7 @@ open class SymbolTable : ReferenceSymbolTable { endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor, - isDelegated: Boolean = descriptor.isDelegated, + @Suppress("DEPRECATION") isDelegated: Boolean = descriptor.isDelegated, propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol -> IrPropertyImpl(startOffset, endOffset, origin, symbol, isDelegated = isDelegated).apply { metadata = MetadataSource.Property(symbol.descriptor) diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt index b7cba82c8f8..f669fe9cf27 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt @@ -166,7 +166,7 @@ abstract class IrModuleDeserializer( } private fun deserializeSyntheticBody(proto: KotlinIr.IrSyntheticBody, start: Int, end: Int): IrSyntheticBody { - val kind = when (proto.kind) { + val kind = when (proto.kind!!) { KotlinIr.IrSyntheticBodyKind.ENUM_VALUES -> IrSyntheticBodyKind.ENUM_VALUES KotlinIr.IrSyntheticBodyKind.ENUM_VALUEOF -> IrSyntheticBodyKind.ENUM_VALUEOF } @@ -652,7 +652,7 @@ abstract class IrModuleDeserializer( } private fun deserializeConst(proto: KotlinIr.IrConst, start: Int, end: Int, type: IrType): IrExpression = - when (proto.valueCase) { + when (proto.valueCase!!) { NULL -> IrConstImpl.constNull(start, end, type) BOOLEAN @@ -678,7 +678,7 @@ abstract class IrModuleDeserializer( } private fun deserializeOperation(proto: KotlinIr.IrOperation, start: Int, end: Int, type: IrType): IrExpression = - when (proto.operationCase) { + when (proto.operationCase!!) { BLOCK -> deserializeBlock(proto.block, start, end, type) BREAK @@ -766,11 +766,12 @@ abstract class IrModuleDeserializer( val name = deserializeName(proto.name) val variance = deserializeIrTypeVariance(proto.variance) - val parameter = symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin, - symbol.descriptor, { symbol -> - IrTypeParameterImpl(start, end, origin, symbol, name, proto.index, proto.isReified, variance) - } - ) + val parameter = symbolTable.declareGlobalTypeParameter( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin, + symbol.descriptor + ) { + IrTypeParameterImpl(start, end, origin, it, name, proto.index, proto.isReified, variance) + } val superTypes = proto.superTypeList.map { deserializeIrType(it) } parameter.superTypes.addAll(superTypes) @@ -1162,7 +1163,7 @@ abstract class IrModuleDeserializer( val declarator = proto.declarator - val declaration: IrDeclaration = when (declarator.declaratorCase) { + val declaration: IrDeclaration = when (declarator.declaratorCase!!) { IR_ANONYMOUS_INIT -> deserializeIrAnonymousInit(declarator.irAnonymousInit, start, end, origin) IR_CONSTRUCTOR diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleSerializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleSerializer.kt index a2120ea72b5..3778ed9d4c6 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleSerializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleSerializer.kt @@ -967,7 +967,7 @@ open class IrModuleSerializer( } private fun serializeIrProperty(property: IrProperty): KotlinIr.IrProperty { - val index = declarationTable.uniqIdByDeclaration(property) + declarationTable.uniqIdByDeclaration(property) val proto = KotlinIr.IrProperty.newBuilder() .setIsDelegated(property.isDelegated) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt index b4e350505a9..5a5ac5d7fb9 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt @@ -133,7 +133,6 @@ object LightClassUtil { .filter { it.kotlinOrigin === declaration } private fun getWrappingClass(declaration: KtDeclaration): PsiClass? { - var declaration = declaration if (declaration is KtParameter) { val constructorClass = KtPsiUtil.getClassIfParameterIsProperty(declaration) if (constructorClass != null) { @@ -141,15 +140,16 @@ object LightClassUtil { } } - if (declaration is KtPropertyAccessor) { - declaration = declaration.property + var ktDeclaration = declaration + if (ktDeclaration is KtPropertyAccessor) { + ktDeclaration = ktDeclaration.property } - if (declaration is KtConstructor<*>) { - return declaration.getContainingClassOrObject().toLightClass() + if (ktDeclaration is KtConstructor<*>) { + return ktDeclaration.getContainingClassOrObject().toLightClass() } - val parent = declaration.parent + val parent = ktDeclaration.parent if (parent is KtFile) { // top-level declaration diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightPsi.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightPsi.kt index 22531dfc69e..98aeabbf8f2 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightPsi.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightPsi.kt @@ -474,7 +474,7 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor } private fun addReceiverParameter(callable: KtCallableDeclaration, method: KtUltraLightMethod) { - val receiver = callable.receiverTypeReference ?: return + if (callable.receiverTypeReference == null) return method.delegate.addParameter(KtUltraLightReceiverParameter(callable, support, method)) } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/lightAnnotations.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/lightAnnotations.kt index cf01c91b068..1cd8dafe496 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/lightAnnotations.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/lightAnnotations.kt @@ -103,8 +103,7 @@ class KtLightAnnotationForSourceEntry( } private fun getAttributeValue(name: String?, useDefault: Boolean): PsiAnnotationMemberValue? { - val name = name ?: "value" - val callEntry = getCallEntry(name) ?: return null + val callEntry = getCallEntry(name ?: "value") ?: return null val valueArgument = callEntry.value.arguments.firstOrNull() if (valueArgument != null) { @@ -341,7 +340,7 @@ private fun KtElement.getResolvedCall(): ResolvedCall? { } fun convertToLightAnnotationMemberValue(lightParent: PsiElement, argument: KtExpression): PsiAnnotationMemberValue { - val argument = unwrapCall(argument) + @Suppress("NAME_SHADOWING") val argument = unwrapCall(argument) when (argument) { is KtClassLiteralExpression -> { return KtLightPsiClassObjectAccessExpression(argument, lightParent) @@ -395,7 +394,7 @@ private fun unwrapCall(callee: KtExpression): KtExpression = when (callee) { } private fun getAnnotationName(callee: KtExpression): String? { - val callee = unwrapCall(callee) + @Suppress("NAME_SHADOWING") val callee = unwrapCall(callee) val resultingDescriptor = callee.getResolvedCall()?.resultingDescriptor if (resultingDescriptor is ClassConstructorDescriptor) { val ktClass = resultingDescriptor.constructedClass.source.getPsi() as? KtClass diff --git a/compiler/psi/src/org/jetbrains/kotlin/kdoc/parser/KDocKnownTag.kt b/compiler/psi/src/org/jetbrains/kotlin/kdoc/parser/KDocKnownTag.kt index 9759b72a851..9f99a2e4c0e 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/kdoc/parser/KDocKnownTag.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/kdoc/parser/KDocKnownTag.kt @@ -16,8 +16,6 @@ package org.jetbrains.kotlin.kdoc.parser -import com.intellij.openapi.util.text.StringUtil - enum class KDocKnownTag(val isReferenceRequired: Boolean, val isSectionStart: Boolean) { AUTHOR(false, false), THROWS(true, false), @@ -35,12 +33,11 @@ enum class KDocKnownTag(val isReferenceRequired: Boolean, val isSectionStart: Bo companion object { fun findByTagName(tagName: CharSequence): KDocKnownTag? { - var tagName = tagName - if (StringUtil.startsWith(tagName, "@")) { - tagName = tagName.subSequence(1, tagName.length) - } + val name = if (tagName.startsWith('@')) { + tagName.subSequence(1, tagName.length) + } else tagName try { - return valueOf(tagName.toString().toUpperCase()) + return valueOf(name.toString().toUpperCase()) } catch (ignored: IllegalArgumentException) { } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt index dcecc2cbf6a..aa033893b74 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt @@ -28,6 +28,7 @@ object EditCommaSeparatedListHelper { return addItemBefore(list, allItems, item, null, prefix) } + @Suppress("UNCHECKED_CAST") @JvmOverloads fun addItemAfter( list: KtElement, diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index a91e212a564..7afb667f81c 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -292,6 +292,7 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m val file = createFile(text) val declarations = file.declarations assert(declarations.size == 1) { "${declarations.size} declarations in $text" } + @Suppress("UNCHECKED_CAST") return declarations.first() as TDeclaration } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt index 2e28848a5c1..56e36a40de6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.types.AbstractNullabilityChecker import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.AbstractTypeCheckerContext -import org.jetbrains.kotlin.types.checker.* import org.jetbrains.kotlin.types.model.* abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheckerContext(), TypeSystemInferenceExtensionContext { @@ -86,9 +85,9 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck // extract type variable only from type like Captured(out T) private fun extractTypeVariableForSubtype(type: KotlinTypeMarker): KotlinTypeMarker? { - val type = type.asSimpleType()?.asCapturedType() ?: return null + val typeMarker = type.asSimpleType()?.asCapturedType() ?: return null - val projection = type.typeConstructorProjection() + val projection = typeMarker.typeConstructorProjection() return if (projection.getVariance() == TypeVariance.OUT) projection.getType().takeIf { it is SimpleTypeMarker && isMyTypeVariable(it) }?.asSimpleType() else diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt index 46ccc79d3ad..93c0627ff7a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl -import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor import org.jetbrains.kotlin.resolve.calls.inference.substitute import org.jetbrains.kotlin.resolve.calls.results.SimpleConstraintSystem @@ -52,7 +51,12 @@ class SimpleConstraintSystemImpl(constraintInjector: ConstraintInjector, builtIn } override fun addSubtypeConstraint(subType: UnwrappedType, superType: UnwrappedType) { - csBuilder.addSubtypeConstraint(subType, superType, SimpleConstraintSystemConstraintPosition) + csBuilder.addSubtypeConstraint( + subType, + superType, + @Suppress("DEPRECATION") + org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition + ) } override fun hasContradiction() = csBuilder.hasContradiction diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index 677b1e1d4d3..962d5b04cd5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -216,7 +216,7 @@ open class OverloadingConflictResolver( } } if (result == null) return null - if (any { it != result && isNotWorse(it, result!!) }) { + if (any { it != result && isNotWorse(it, result) }) { return null } return result diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeStorage.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeStorage.kt index 34dc986a6f6..007b9736603 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeStorage.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeStorage.kt @@ -121,6 +121,7 @@ abstract class LexicalScopeStorage( val result = ArrayList(1) var rest: IntList? = this do { + @Suppress("UNCHECKED_CAST") result.add(rest!!.last.descriptorByIndex() as TDescriptor) rest = rest.prev } while (rest != null) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCheckLocalVariablesTableTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCheckLocalVariablesTableTest.kt index a3c2b0f0f8f..3b04b212a6b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCheckLocalVariablesTableTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCheckLocalVariablesTableTest.kt @@ -48,7 +48,7 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() { val pathsString = outputFiles.joinToString { it.relativePath } assertNotNull("Couldn't find class file for pattern $classFileRegex in: $pathsString", outputFile) - val actualLocalVariables = readLocalVariable(ClassReader(outputFile!!.asByteArray()), methodName) + val actualLocalVariables = readLocalVariable(ClassReader(outputFile.asByteArray()), methodName) doCompare(wholeFile, files.single().content, actualLocalVariables) } catch (e: Throwable) { diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/serialization/builtins/AdditionalBuiltInsMembersSignatureListsTest.kt b/compiler/tests-java8/tests/org/jetbrains/kotlin/serialization/builtins/AdditionalBuiltInsMembersSignatureListsTest.kt index 63a566015c0..b72178a5f85 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/serialization/builtins/AdditionalBuiltInsMembersSignatureListsTest.kt +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/serialization/builtins/AdditionalBuiltInsMembersSignatureListsTest.kt @@ -59,10 +59,8 @@ class AdditionalBuiltInsMembersSignatureListsTest : KotlinTestWithEnvironment() val lateJdkSignatures = LATE_JDK_SIGNATURES[internalName] ?: emptySet() - jvmDescriptors.forEach { - jvmDescriptor -> - - if (jvmDescriptor in lateJdkSignatures) return@forEach + for (jvmDescriptor in jvmDescriptors) { + if (jvmDescriptor in lateJdkSignatures) continue val stringName = jvmDescriptor.split("(")[0] val functions = diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt index d335d4cc337..6851e08701b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt @@ -78,9 +78,11 @@ class CustomScriptCodegenTest : CodegenTestCase() { } +@Suppress("UNCHECKED_CAST") private fun Class<*>.safeGetAnnotation(ann: KClass): Annotation? = getAnnotation(classLoader.loadClass(ann.qualifiedName) as Class) +@Suppress("UNCHECKED_CAST") private fun java.lang.reflect.Constructor<*>.safeGetAnnotation(ann: KClass): Annotation? = getAnnotation(this.declaringClass.classLoader.loadClass(ann.qualifiedName) as Class) diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 81ac6367506..687cb9cc1c7 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -579,11 +579,11 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { ParallelStartParams.performCompilation -> { val jar = tmpdir.absolutePath + File.separator + "hello.$threadNo.jar" KotlinCompilerClient.compile( - compileServiceSession!!.compileService, - compileServiceSession.sessionId, - CompileService.TargetPlatform.JVM, - arrayOf(File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar), - PrintingMessageCollector(PrintStream(outStreams[threadNo]), MessageRenderer.WITHOUT_PATHS, true)) + compileServiceSession.compileService, + compileServiceSession.sessionId, + CompileService.TargetPlatform.JVM, + arrayOf(File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar), + PrintingMessageCollector(PrintStream(outStreams[threadNo]), MessageRenderer.WITHOUT_PATHS, true)) } else -> 0 // compilation skipped, assuming - successful } diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinClassFinderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinClassFinderTest.kt index b22bf4572d0..c154a315bda 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinClassFinderTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinClassFinderTest.kt @@ -60,10 +60,10 @@ class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() { assertNotNull(psiClass, "Psi class not found for $className") assertTrue(psiClass !is KtLightClass, "Kotlin light classes are not not expected") - val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(JavaClassImpl(psiClass!!)) + val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(JavaClassImpl(psiClass)) assertNotNull(binaryClass, "No binary class for $className") - assertEquals("test/A.B.C", binaryClass?.classId?.toString()) + assertEquals("test/A.B.C", binaryClass.classId.toString()) } private fun createEnvironment(tmpdir: File?): KotlinCoreEnvironment { diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt index e99814d5200..2ba009942a0 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt @@ -66,10 +66,10 @@ class KotlinJavacBasedClassFinderTest : KotlinTestWithEnvironmentManagement() { val found = classFinder.findClass(classId) assertNotNull(found, "Class not found for $className") - val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(found!!) + val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(found) assertNotNull(binaryClass, "No binary class for $className") - assertEquals("test/A.B.C", binaryClass?.classId?.toString()) + assertEquals("test/A.B.C", binaryClass.classId.toString()) } private fun createClassFinder(project: Project) = JavacBasedClassFinder().apply { diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/AbstractVersionRequirementTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/AbstractVersionRequirementTest.kt index 734e2743838..e77b54b3b44 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/AbstractVersionRequirementTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/AbstractVersionRequirementTest.kt @@ -37,8 +37,8 @@ abstract class AbstractVersionRequirementTest : TestCaseWithTmpdir() { val descriptor = module.findUnambiguousDescriptorByFqName(fqName) val requirement = when (descriptor) { - is DeserializedMemberDescriptor -> descriptor.versionRequirements.single() - is DeserializedClassDescriptor -> descriptor.versionRequirements.single() + is DeserializedMemberDescriptor -> descriptor.versionRequirements.singleOrNull() + is DeserializedClassDescriptor -> descriptor.versionRequirements.singleOrNull() else -> throw AssertionError("Unknown descriptor: $descriptor") } ?: throw AssertionError("No VersionRequirement for $descriptor") diff --git a/compiler/tests/org/jetbrains/kotlin/types/AbstractTypeBindingTest.kt b/compiler/tests/org/jetbrains/kotlin/types/AbstractTypeBindingTest.kt index 98431e6242d..4fee743bf07 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/AbstractTypeBindingTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/types/AbstractTypeBindingTest.kt @@ -40,7 +40,7 @@ abstract class AbstractTypeBindingTest : KotlinTestWithEnvironment() { val analyzeResult = JvmResolveUtil.analyze(testKtFile, environment) - val testDeclaration = testKtFile.declarations.last()!! as KtCallableDeclaration + val testDeclaration = testKtFile.declarations.last() as KtCallableDeclaration val typeBinding = testDeclaration.createTypeBindingForReturnType(analyzeResult.bindingContext) diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaTypeParameter.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaTypeParameter.kt index 216326ee2e0..14e432a8b93 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaTypeParameter.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaTypeParameter.kt @@ -31,6 +31,7 @@ class ReflectJavaTypeParameter( return bounds } + @Suppress("USELESS_CAST") override val element: AnnotatedElement? // TypeVariable is AnnotatedElement only in JDK8 get() = typeVariable as? AnnotatedElement diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 9446ddc0473..e77e9951c25 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -404,6 +404,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext { override fun SimpleTypeMarker.replaceArguments(newArguments: List): SimpleTypeMarker { require(this is SimpleType, this::errorMessage) + @Suppress("UNCHECKED_CAST") return this.replace(newArguments as List) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt index 6d628074733..96675a816d9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewKotlinTypeChecker.kt @@ -137,6 +137,7 @@ object NewKotlinTypeChecker : KotlinTypeChecker { constructor: TypeConstructor ): List { return AbstractTypeChecker.run { + @Suppress("UNCHECKED_CAST") findCorrespondingSupertypes(baseType, constructor) as List } } diff --git a/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt b/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt index d07fc71814e..d5a3403c36b 100644 --- a/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt +++ b/core/script.runtime/src/kotlin/script/experimental/location/scriptLocation_deprecated.kt @@ -21,5 +21,5 @@ enum class ScriptExpectedLocation { @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) annotation class ScriptExpectedLocations( - val value: Array = [ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly] + @Suppress("DEPRECATION") val value: Array = [ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly] ) \ No newline at end of file diff --git a/core/script.runtime/src/kotlin/script/templates/annotations_deprecated.kt b/core/script.runtime/src/kotlin/script/templates/annotations_deprecated.kt index 3d813959392..1632f679cc3 100644 --- a/core/script.runtime/src/kotlin/script/templates/annotations_deprecated.kt +++ b/core/script.runtime/src/kotlin/script/templates/annotations_deprecated.kt @@ -19,5 +19,5 @@ open class ScriptTemplateAdditionalCompilerArgumentsProvider(val arguments: Iter @Retention(AnnotationRetention.RUNTIME) annotation class ScriptTemplateAdditionalCompilerArguments( val arguments: Array = [], - val provider: KClass = ScriptTemplateAdditionalCompilerArgumentsProvider::class + @Suppress("DEPRECATION") val provider: KClass = ScriptTemplateAdditionalCompilerArgumentsProvider::class ) diff --git a/generators/builtins/progressions.kt b/generators/builtins/progressions.kt index 1651a92f432..1b9ca8818b2 100644 --- a/generators/builtins/progressions.kt +++ b/generators/builtins/progressions.kt @@ -47,7 +47,6 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) { " if (isEmpty()) -1 else (31 * (31 * first + last) + step)" LONG -> " if (isEmpty()) -1 else (31 * (31 * ${hashLong("first")} + ${hashLong("last")}) + ${hashLong("step")}).toInt()" - else -> throw IllegalArgumentException() } out.println( diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt index ad2ecab266d..72b0ba27b3f 100644 --- a/generators/builtins/unsignedTypes.kt +++ b/generators/builtins/unsignedTypes.kt @@ -371,7 +371,6 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns UnsignedType.UBYTE, UnsignedType.USHORT -> out.println("toInt().toString()") UnsignedType.UINT -> out.println("toLong().toString()") UnsignedType.ULONG -> out.println("ulongToString(data)") - else -> error(type) } out.println() diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/SyntheticKotlinBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/SyntheticKotlinBlock.kt index 2fa894144b4..01be12aab99 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/SyntheticKotlinBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/SyntheticKotlinBlock.kt @@ -60,13 +60,11 @@ class SyntheticKotlinBlock( } val textRange = getTextRange() - if (treeNode != null) { - val psi = treeNode.psi - if (psi != null) { - val file = psi.containingFile - if (file != null) { - return file.text!!.subSequence(textRange.startOffset, textRange.endOffset).toString() + " " + textRange - } + val psi = treeNode.psi + if (psi != null) { + val file = psi.containingFile + if (file != null) { + return file.text!!.subSequence(textRange.startOffset, textRange.endOffset).toString() + " " + textRange } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt index e27038cab7c..e21cde4cc7f 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/KotlinPsiUnifier.kt @@ -199,8 +199,8 @@ class KotlinPsiUnifier( s and when { arg1 == arg2 -> MATCHED arg1 == null || arg2 == null -> UNMATCHED - else -> (arg1.arguments.asSequence().zip(arg2.arguments.asSequence())).fold(MATCHED) { s, p -> - s and matchArguments(p.first, p.second) + else -> (arg1.arguments.asSequence().zip(arg2.arguments.asSequence())).fold(MATCHED) { status, pair -> + status and matchArguments(pair.first, pair.second) } } } @@ -711,7 +711,7 @@ class KotlinPsiUnifier( null } if (status == UNMATCHED) { - declarationPatternsToTargets.removeValue(desc1, desc2) + declarationPatternsToTargets.remove(desc1, desc2) } return status diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LazyLightClassDataHolder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LazyLightClassDataHolder.kt index 5bb6fc8c031..c29f7258746 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LazyLightClassDataHolder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LazyLightClassDataHolder.kt @@ -110,7 +110,7 @@ sealed class LazyLightClassDataHolder( return dummyDelegate!!.fields.map { dummyField -> val fieldOrigin = KtLightFieldImpl.getOrigin(dummyField) - val fieldName = dummyField.name!! + val fieldName = dummyField.name KtLightFieldImpl.lazy(dummyField, fieldOrigin, containingClass) { clsDelegate.findFieldByName(fieldName, false).assertMatches(dummyField, containingClass) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LightMemberOriginForCompiledElement.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LightMemberOriginForCompiledElement.kt index 6437d092cb2..5c879456983 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LightMemberOriginForCompiledElement.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/lightClasses/LightMemberOriginForCompiledElement.kt @@ -60,7 +60,7 @@ data class LightMemberOriginForCompiledField(val psiField: PsiField, val file: K override val originalElement: KtDeclaration? by lazyPub { val desc = MapPsiToAsmDesc.typeDesc(psiField.type) - val signature = MemberSignature.fromFieldNameAndDesc(psiField.name!!, desc) + val signature = MemberSignature.fromFieldNameAndDesc(psiField.name, desc) findDeclarationInCompiledFile(file, psiField, signature) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt index 39e431edaec..84b1e943214 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractApplicabilityBasedInspection.kt @@ -33,6 +33,7 @@ abstract class AbstractApplicabilityBasedInspection( super.visitKtElement(element) if (!elementType.isInstance(element) || element.textLength == 0) return + @Suppress("UNCHECKED_CAST") visitTargetElement(element as TElement, holder, isOnTheFly) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt index 0adcfee9f33..e26fbba5cc4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt @@ -175,7 +175,11 @@ abstract class IntentionBasedInspection private construct override fun isAvailable(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement): Boolean { assert(startElement == endElement) - return intention.applicabilityRange(startElement as TElement) != null && additionalChecker(startElement, this@IntentionBasedInspection) + @Suppress("UNCHECKED_CAST") + return intention.applicabilityRange(startElement as TElement) != null && additionalChecker( + startElement, + this@IntentionBasedInspection + ) } override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { @@ -190,6 +194,7 @@ abstract class IntentionBasedInspection private construct val editor = startElement.findExistingEditor() editor?.caretModel?.moveToOffset(startElement.textOffset) + @Suppress("UNCHECKED_CAST") intention.applyTo(startElement as TElement, editor) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt index bfff0e3aff6..9969201e98f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinUniversalQuickFix.kt @@ -22,6 +22,7 @@ import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project interface KotlinUniversalQuickFix : IntentionAction, LocalQuickFix { + @JvmDefault override fun getName() = text override fun applyFix(project: Project, descriptor: ProblemDescriptor) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/SyntheticPropertyAccessorReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/SyntheticPropertyAccessorReference.kt index 97e7b304e96..fc7364b7cf5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/SyntheticPropertyAccessorReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/SyntheticPropertyAccessorReference.kt @@ -136,7 +136,7 @@ sealed class SyntheticPropertyAccessorReference(expression: KtNameReferenceExpre val fullExpression = expression.getQualifiedExpressionForSelectorOrThis() fullExpression.getAssignmentByLHS()?.let { assignment -> val rhs = assignment.right ?: return expression - val operationToken = assignment.operationToken as? KtSingleValueToken + val operationToken = assignment.operationToken as? KtSingleValueToken ?: return expression val counterpartOp = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[operationToken] val setterArgument = if (counterpartOp != null) { val getterCall = if (getter) fullExpression.createCall(psiFactory, newGetterName) else fullExpression diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt index 750d9109262..59f8d25c672 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IndexUtils.kt @@ -121,4 +121,4 @@ fun indexInternals(stub: KotlinCallableStubBase<*>, sink: IndexSink) { } private val KotlinStubWithFqName<*>.modifierList: KotlinModifierListStub? - get() = findChildStubByType(KtStubElementTypes.MODIFIER_LIST) as? KotlinModifierListStub + get() = findChildStubByType(KtStubElementTypes.MODIFIER_LIST) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasByExpansionShortNameIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasByExpansionShortNameIndex.kt index 7f8dd419f08..806bdb85e3f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasByExpansionShortNameIndex.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTypeAliasByExpansionShortNameIndex.kt @@ -27,7 +27,7 @@ class KotlinTypeAliasByExpansionShortNameIndex : StringStubIndexExtension = KEY override fun get(key: String, project: Project, scope: GlobalSearchScope) = - StubIndex.getElements(KEY, key, project, scope, KtTypeAlias::class.java)!! + StubIndex.getElements(KEY, key, project, scope, KtTypeAlias::class.java) companion object { val KEY = KotlinIndexUtil.createIndexKey(KotlinTypeAliasByExpansionShortNameIndex::class.java) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ApplicationUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ApplicationUtils.kt index eaf30454949..7f3f7ad90bb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ApplicationUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ApplicationUtils.kt @@ -40,7 +40,7 @@ fun Project.executeWriteCommand(name: String, groupId: Any? = null, command: } fun Project.executeCommand(name: String, groupId: Any? = null, command: () -> T): T { - var result: T = null as T + @Suppress("UNCHECKED_CAST") var result: T = null as T CommandProcessor.getInstance().executeCommand(this, { result = command() }, name, groupId) @Suppress("USELESS_CAST") return result as T diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/dumbUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/dumbUtils.kt index 97c1e192e4b..03c4c179705 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/dumbUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/dumbUtils.kt @@ -26,7 +26,7 @@ fun Project.runReadActionInSmartMode(action: () -> T): T { } fun Project.runWithAlternativeResolveEnabled(action: () -> T): T { - var result: T = null as T + @Suppress("UNCHECKED_CAST") var result: T = null as T DumbService.getInstance(this).withAlternativeResolveEnabled { result = action() } @Suppress("USELESS_CAST") return result as T diff --git a/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt b/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt index 18136cc8a6e..ef17be84f86 100644 --- a/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt +++ b/idea/idea-android/idea-android-output-parser/src/org/jetbrains/kotlin/android/KotlinOutputParserHelper.kt @@ -57,8 +57,8 @@ fun parse(lineText: String, reader: OutputLineReader, messages: MutableList= 2) matcher.group(2)?.toInt() ?: 1 else 1 if (line != null) { - val position = SourceFilePosition(file, SourcePosition(line, column, column)) - return addMessage(Message(getMessageKind(severity), message.trim(), position), messages) + val filePosition = SourceFilePosition(file, SourcePosition(line, column, column)) + return addMessage(Message(getMessageKind(severity), message.trim(), filePosition), messages) } } diff --git a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/AndroidGradleModelFacade.kt b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/AndroidGradleModelFacade.kt index 118e5e2bea5..66844edbb00 100644 --- a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/AndroidGradleModelFacade.kt +++ b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/AndroidGradleModelFacade.kt @@ -33,7 +33,7 @@ class AndroidGradleModelFacade : KotlinGradleModelFacade { } override fun getDependencyModules(ideModule: DataNode, gradleIdeaProject: IdeaProject): Collection> { - val ideProject = ideModule.parent as DataNode + @Suppress("UNCHECKED_CAST") val ideProject = ideModule.parent as DataNode ExternalSystemApiUtil.find(ideModule, AndroidProjectKeys.JAVA_MODULE_MODEL)?.let { javaModuleModel -> val moduleNames = javaModuleModel.data.javaModuleDependencies.map { it.moduleName }.toHashSet() return findModulesByNames(moduleNames, gradleIdeaProject, ideProject) @@ -43,6 +43,7 @@ class AndroidGradleModelFacade : KotlinGradleModelFacade { val projects = androidModel.data.mainArtifact.dependencies.projects val projectIds = libraries.mapNotNull { it.projectSafe } + projects return projectIds.mapNotNullTo(LinkedHashSet()) { projectId -> + @Suppress("UNCHECKED_CAST") ExternalSystemApiUtil.findFirstRecursively(ideProject) { (it.data as? ModuleData)?.id == projectId } as DataNode? diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt index e490caeab4a..f62e02e4a81 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt @@ -46,7 +46,7 @@ object PackageDirectiveCompletion { val prefixLength = parameters.offset - expression.textOffset val prefix = expression.text!! val prefixMatcher = PlainPrefixMatcher(prefix.substring(0, prefixLength)) - val result = result.withPrefixMatcher(prefixMatcher) + val resultSet = result.withPrefixMatcher(prefixMatcher) val resolutionFacade = expression.getResolutionFacade() @@ -57,7 +57,7 @@ object PackageDirectiveCompletion { for (variant in variants) { val lookupElement = lookupElementFactory.createLookupElement(variant) if (!lookupElement.lookupString.contains(DUMMY_IDENTIFIER)) { - result.addElement(lookupElement) + resultSet.addElement(lookupElement) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/VariableOrParameterNameWithTypeCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/VariableOrParameterNameWithTypeCompletion.kt index 6f0030d0e6f..d206a8109fa 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/VariableOrParameterNameWithTypeCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/VariableOrParameterNameWithTypeCompletion.kt @@ -123,8 +123,8 @@ class VariableOrParameterNameWithTypeCompletion( val parameterType = descriptor.type if (parameterType.isVisible(visibilityFilter)) { val lookupElement = MyLookupElement.create(name, ArbitraryType(parameterType), withType, lookupElementFactory)!! - val (count, name) = lookupElementToCount[lookupElement] ?: Pair(0, name) - lookupElementToCount[lookupElement] = Pair(count + 1, name) + val (count, s) = lookupElementToCount[lookupElement] ?: Pair(0, name) + lookupElementToCount[lookupElement] = Pair(count + 1, s) } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt index c76af7ef9f9..2321a089c56 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt @@ -84,22 +84,28 @@ object LambdaItems { } private fun createLookupElement( - functionType: KotlinType, - functionExpectedInfos: List, - signaturePresentation: LambdaSignatureTemplates.SignaturePresentation, - explicitParameterTypes: Boolean + functionType: KotlinType, + functionExpectedInfos: List, + signaturePresentation: LambdaSignatureTemplates.SignaturePresentation, + explicitParameterTypes: Boolean ): LookupElement { val lookupString = LambdaSignatureTemplates.lambdaPresentation(functionType, signaturePresentation) return LookupElementBuilder.create(lookupString) - .withInsertHandler({ context, lookupElement -> - val offset = context.startOffset - val placeholder = "{}" - context.document.replaceString(offset, context.tailOffset, placeholder) - val placeholderRange = TextRange(offset, offset + placeholder.length) - LambdaSignatureTemplates.insertTemplate(context, placeholderRange, functionType, explicitParameterTypes, signatureOnly = false) - }) - .suppressAutoInsertion() - .assignSmartCompletionPriority(SmartCompletionItemPriority.LAMBDA) - .addTailAndNameSimilarity(functionExpectedInfos.filter { it.fuzzyType?.type == functionType }) + .withInsertHandler { context, _ -> + val offset = context.startOffset + val placeholder = "{}" + context.document.replaceString(offset, context.tailOffset, placeholder) + val placeholderRange = TextRange(offset, offset + placeholder.length) + LambdaSignatureTemplates.insertTemplate( + context, + placeholderRange, + functionType, + explicitParameterTypes, + signatureOnly = false + ) + } + .suppressAutoInsertion() + .assignSmartCompletionPriority(SmartCompletionItemPriority.LAMBDA) + .addTailAndNameSimilarity(functionExpectedInfos.filter { it.fuzzyType?.type == functionType }) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaSignatureItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaSignatureItems.kt index e1dea2c59cc..69ab9401258 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaSignatureItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaSignatureItems.kt @@ -64,9 +64,9 @@ object LambdaSignatureItems { } private fun createLookupElement( - functionType: KotlinType, - signaturePresentation: LambdaSignatureTemplates.SignaturePresentation, - explicitParameterTypes: Boolean + functionType: KotlinType, + signaturePresentation: LambdaSignatureTemplates.SignaturePresentation, + explicitParameterTypes: Boolean ): LookupElement { val lookupString = LambdaSignatureTemplates.signaturePresentation(functionType, signaturePresentation) val priority = if (explicitParameterTypes) @@ -74,13 +74,19 @@ object LambdaSignatureItems { else SmartCompletionItemPriority.LAMBDA_SIGNATURE return LookupElementBuilder.create(lookupString) - .withInsertHandler({ context, lookupElement -> - val offset = context.startOffset - val placeholder = "{}" - context.document.replaceString(offset, context.tailOffset, placeholder) - LambdaSignatureTemplates.insertTemplate(context, TextRange(offset, offset + placeholder.length), functionType, explicitParameterTypes, signatureOnly = true) - }) - .suppressAutoInsertion() - .assignSmartCompletionPriority(priority) + .withInsertHandler { context, _ -> + val offset = context.startOffset + val placeholder = "{}" + context.document.replaceString(offset, context.tailOffset, placeholder) + LambdaSignatureTemplates.insertTemplate( + context, + TextRange(offset, offset + placeholder.length), + functionType, + explicitParameterTypes, + signatureOnly = true + ) + } + .suppressAutoInsertion() + .assignSmartCompletionPriority(priority) } } \ No newline at end of file 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 ba93269b7d5..3f34ebf436b 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 @@ -169,8 +169,8 @@ class SmartCompletion( val types = descriptor.fuzzyTypesForSmartCompletion(smartCastCalculator, callTypeAndReceiver, resolutionFacade, bindingContext) val infoMatcher = { expectedInfo: ExpectedInfo -> types.matchExpectedInfo(expectedInfo) } - result.addLookupElements(descriptor, expectedInfos, infoMatcher, noNameSimilarityForReturnItself = callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { descriptor -> - lookupElementFactory.createStandardLookupElementsForDescriptor(descriptor, useReceiverTypes = true) + result.addLookupElements(descriptor, expectedInfos, infoMatcher, noNameSimilarityForReturnItself = callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { declarationDescriptor -> + lookupElementFactory.createStandardLookupElementsForDescriptor(declarationDescriptor, useReceiverTypes = true) } if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index 7ba072bd1e4..b31dfaeecff 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -273,8 +273,8 @@ class TypeInstantiationItems( presentation.itemText = itemText presentation.clearTail() - if (signatureText != null) { - presentation.appendTailText(signatureText!!, false) + signatureText?.let { + presentation.appendTailText(it, false) } presentation.appendTailText(" (" + DescriptorUtils.getFqName(classifier.containingDeclaration) + ")", true) } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggestionProvider.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggestionProvider.kt index 33443d7d742..60515e2eaed 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggestionProvider.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggestionProvider.kt @@ -50,7 +50,7 @@ class KotlinNameSuggestionProvider : NameSuggestionProvider { val names = SmartList().apply { val name = element.name if (!name.isNullOrBlank()) { - this += KotlinNameSuggester.getCamelNames(name!!, validator, name.first().isLowerCase()) + this += KotlinNameSuggester.getCamelNames(name, validator, name.first().isLowerCase()) } val callableDescriptor = element.unsafeResolveToDescriptor(BodyResolveMode.PARTIAL) as CallableDescriptor diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/templates.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/templates.kt index 86213d655fb..b4c1a625a4c 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/templates.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/templates.kt @@ -60,7 +60,7 @@ fun getFunctionBodyTextFromTemplate( } return try { - fileTemplate!!.getText(properties) + fileTemplate.getText(properties) } catch (e: ProcessCanceledException) { throw e diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt index 3bccbfb52e3..8fb28ac3f66 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleProjectResolverExtension.kt @@ -111,7 +111,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() when (dependency) { is ExternalProjectDependency -> { if (dependency.configurationName == Dependency.DEFAULT_CONFIGURATION) { - val targetModuleNode = ExternalSystemApiUtil.findFirstRecursively(ideProject) { + @Suppress("UNCHECKED_CAST") val targetModuleNode = ExternalSystemApiUtil.findFirstRecursively(ideProject) { (it.data as? ModuleData)?.id == dependency.projectPath } as DataNode? ?: return@mapNotNullTo null ExternalSystemApiUtil.findAll(targetModuleNode, GradleSourceSetData.KEY) @@ -278,6 +278,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() val fullModuleId = compositePrefix + moduleId + @Suppress("UNCHECKED_CAST") return ideProject.children.find { (it.data as? ModuleData)?.id == fullModuleId } as DataNode? } } diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinTargetDataService.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinTargetDataService.kt index da5b0db1043..170307a4cb5 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinTargetDataService.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinTargetDataService.kt @@ -34,7 +34,7 @@ class KotlinTargetDataService : AbstractProjectDataService, gradleIdeaProject: IdeaProject): Collection> { - val ideProject = ideModule.parent as DataNode + @Suppress("UNCHECKED_CAST") val ideProject = ideModule.parent as DataNode val dependencyModuleNames = ExternalSystemApiUtil.getChildren(ideModule, ProjectKeys.MODULE_DEPENDENCY).map { it.data.target.externalName }.toHashSet() return findModulesByNames(dependencyModuleNames, gradleIdeaProject, ideProject) diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt index 6eea2598666..a74854b18fa 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt @@ -42,6 +42,7 @@ class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() { override fun tearDownFixtures() { codeInsightTestFixture.tearDown() + @Suppress("UNCHECKED_CAST") (this::codeInsightTestFixture as KMutableProperty0).set(null) myTestFixture = null } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt index 4d9815a71da..49de308ed48 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt @@ -259,7 +259,7 @@ abstract class KotlinWithLibraryConfigurator protected constructor() : KotlinPro } collector.addMessage(library.name!! + " library was created") - return library!! + return library } private fun isProjectLibraryPresent(project: Project): Boolean { @@ -397,14 +397,14 @@ abstract class KotlinWithLibraryConfigurator protected constructor() : KotlinPro val project = module.project val collector = createConfigureKotlinNotificationCollector(project) - for (library in findAllUsedLibraries(project).keySet()) { - val runtimeJar = LibraryJarDescriptor.RUNTIME_JAR.findExistingJar(library) ?: continue + for (lib in findAllUsedLibraries(project).keySet()) { + val runtimeJar = LibraryJarDescriptor.RUNTIME_JAR.findExistingJar(lib) ?: continue - val model = library.modifiableModel + val model = lib.modifiableModel val libFilesDir = VfsUtilCore.virtualToIoFile(runtimeJar).parent for (libraryJarDescriptor in libraryJarDescriptors) { - if (libraryJarDescriptor.findExistingJar(library) != null) continue + if (libraryJarDescriptor.findExistingJar(lib) != null) continue val libFile = libraryJarDescriptor.getPathInPlugin() if (!libFile.exists()) continue diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt index 36f350dfb0a..7061fc89e52 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt @@ -39,11 +39,11 @@ class ConfigureKotlinNotification( } } ) { - override fun equals(o: Any?): Boolean { - if (this === o) return true - if (o !is ConfigureKotlinNotification) return false + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is ConfigureKotlinNotification) return false - if (content != o.content) return false + if (content != other.content) return false return true } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt index fb2d5f6200f..ffb4b068afd 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/FileRankingCalculator.kt @@ -122,8 +122,6 @@ abstract class FileRankingCalculator(private val checkClassFqName: Boolean = tru if (function !is KtConstructor<*> && method.name() != descriptor.name.asString()) return LOW - val typeMapper = makeTypeMapper(bindingContext) - return collect( method.isConstructor && function is KtConstructor<*>, method.isAbstract && descriptor.modality == Modality.ABSTRACT, diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt index 987212ef6b4..416989d8ec6 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt @@ -361,6 +361,11 @@ class KotlinFieldBreakpoint( } } + // BUNCH: 182 + override fun getInvalidIcon(isMuted: Boolean): Icon { + return AllIcons.Debugger.Db_invalid_breakpoint + } + override fun getVerifiedIcon(isMuted: Boolean): Icon { return when { isMuted -> AllIcons.Debugger.Db_muted_field_breakpoint diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt index adcfe8614a8..88bdc79dc98 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/compilation/CodeFragmentParameterAnalyzer.kt @@ -294,6 +294,7 @@ class CodeFragmentParameterAnalyzer( is ValueDescriptor -> { parameters.getOrPut(target) { val type = target.type + @Suppress("DEPRECATION") val kind = if (target is LocalVariableDescriptor && target.isDelegated) Kind.DELEGATED else Kind.ORDINARY Smart(Dumb(kind, target.name.asString()), type, target) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/CallUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/CallUtils.kt index c31510a7be5..d9a582dd212 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/CallUtils.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/CallUtils.kt @@ -16,8 +16,6 @@ fun IntermediateStreamCall.withArgs(args: List) = fun TerminatorStreamCall.withArgs(args: List) = TerminatorStreamCallImpl(name, args, typeBefore, resultType, textRange) -fun StreamCall.typeBefore() = - if (StreamCall@ this is TypeBeforeAware) StreamCall@ this.typeBefore else KotlinSequenceTypes.ANY +fun StreamCall.typeBefore() = if (this is TypeBeforeAware) this.typeBefore else KotlinSequenceTypes.ANY -fun StreamCall.typeAfter() = - if (StreamCall@ this is TypeAfterAware) StreamCall@ this.typeAfter else KotlinSequenceTypes.ANY \ No newline at end of file +fun StreamCall.typeAfter() = if (this is TypeAfterAware) this.typeAfter else KotlinSequenceTypes.ANY \ No newline at end of file diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/sequence/KotlinDistinctByHandler.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/sequence/KotlinDistinctByHandler.kt index 4dee756d944..da7181ca0a1 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/sequence/KotlinDistinctByHandler.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/sequence/trace/impl/handler/sequence/KotlinDistinctByHandler.kt @@ -72,7 +72,7 @@ class KotlinDistinctByHandler(callNumber: Int, private val call: IntermediateStr declare(keys2TimesBefore.defaultDeclaration()) declare(transitions.defaultDeclaration()) - integerIteration(keys.size(), block@ this) { + integerIteration(keys.size(), this) { val key = declare(variable(KotlinSequenceTypes.NULLABLE_ANY, "key"), keys.get(loopVariable), false) val lst = list(dsl.types.INT, "lst") declare(lst, keys2TimesBefore.computeIfAbsent(key, lambda("k") { @@ -85,7 +85,7 @@ class KotlinDistinctByHandler(callNumber: Int, private val call: IntermediateStr val afterTime = loopVariable val valueAfter = declare(variable(call.typeAfter, "valueAfter"), time2ValueAfter.get(loopVariable), false) val key = declare(variable(KotlinSequenceTypes.NULLABLE_ANY, "key"), nullExpression, true) - integerIteration(beforeTimes.size(), forEachLoop@ this) { + integerIteration(beforeTimes.size(), this) { ifBranch((valueAfter same beforeValues.get(loopVariable)) and !transitions.contains(beforeTimes.get(loopVariable))) { key assign keys.get(loopVariable) statement { breakIteration() } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt index 0290ced66ff..c39449e68e3 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt @@ -28,7 +28,7 @@ val HISTORY_LABEL_KEY = Key.create("history label") class MakeBackupCompileTask : CompileTask { override fun execute(context: CompileContext?): Boolean { - val project = context!!.project!! + val project = context!!.project val localHistory = LocalHistory.getInstance()!! val label = HISTORY_LABEL_PREFIX + Integer.toHexString(random.nextInt()) diff --git a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt index 64bffa6d5be..5641fbf76a3 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt +++ b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt @@ -178,7 +178,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { val platform = KotlinPlatform.byId(platformId) ?: return null val disambiguationClassifier = getDisambiguationClassifier(gradleTarget) as? String val getPreset = targetClass.getMethodOrNull("getPreset") - var targetPresetName: String? = null + var targetPresetName: String? try { val targetPreset = getPreset?.invoke(gradleTarget) val getPresetName = targetPreset?.javaClass?.getMethodOrNull("getName") @@ -315,7 +315,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { val getOutputFile = compileKotlinTaskClass.getMethodOrNull("getOutputFile") val classesDirs = getClassesDirs(gradleOutput) as? FileCollection ?: return null val resourcesDir = getResourcesDir(gradleOutput) as? File ?: return null - val destinationDir = + @Suppress("UNCHECKED_CAST") val destinationDir = getDestinationDir?.invoke(compileKotlinTask) as? File //TODO: Hack for KotlinNativeCompile ?: (getOutputFile?.invoke(compileKotlinTask) as? Property)?.orNull?.parentFile diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinCreateFromTemplateHandler.kt b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinCreateFromTemplateHandler.kt index 2e72d376c66..6a721bae904 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/KotlinCreateFromTemplateHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/KotlinCreateFromTemplateHandler.kt @@ -27,7 +27,7 @@ class KotlinCreateFromTemplateHandler : DefaultCreateFromTemplateHandler() { override fun prepareProperties(props: MutableMap) { val packageName = props[FileTemplate.ATTRIBUTE_PACKAGE_NAME] as? String if (!packageName.isNullOrEmpty()) { - props[FileTemplate.ATTRIBUTE_PACKAGE_NAME] = packageName!! + props[FileTemplate.ATTRIBUTE_PACKAGE_NAME] = packageName .split('.') .joinToString(".", transform = String::quoteIfNeeded) } diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt index 9b85cfa5e42..ee4489c42e4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/internal/SearchNotPropertyCandidatesAction.kt @@ -39,7 +39,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe class SearchNotPropertyCandidatesAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - val project = e?.project!! + val project = e.project!! val psiFile = e.getData(CommonDataKeys.PSI_FILE) as? KtFile ?: return val desc = psiFile.findModuleDescriptor() @@ -116,15 +116,15 @@ class SearchNotPropertyCandidatesAction : AnAction() { var i = 0 - resultDescriptors.forEach { desc -> - progress("Step 2: ${i++} of ${resultDescriptors.size}", "$desc") - val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, desc) + resultDescriptors.forEach { descriptor -> + progress("Step 2: ${i++} of ${resultDescriptors.size}", "$descriptor") + val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, descriptor) .filterIsInstance() .firstOrNull() ?: return@forEach val abstract = source.modifierList.hasModifierProperty(PsiModifier.ABSTRACT) if (!abstract) { if (!source.isTrivial()) { - descriptorToPsiBinding[desc] = source + descriptorToPsiBinding[descriptor] = source } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt index bf8caac13a6..4dd93a6cfee 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -150,8 +150,8 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor(canGoInside = { it::class.java as Class<*> !in IGNORE_REFERENCES_INSIDE }) { element -> - val reference = element.mainReference ?: return@forEachDescendantOfType + element.forEachDescendantOfType(canGoInside = { it::class.java as Class<*> !in IGNORE_REFERENCES_INSIDE }) { ktElement -> + val reference = ktElement.mainReference ?: return@forEachDescendantOfType val descriptors = resolveReference(reference, bindingContext) //check whether this reference is unambiguous @@ -168,9 +168,9 @@ class KotlinCopyPasteReferenceProcessor : CopyPastePostProcessor ComboBox.selectedItemTyped: T? get() = selectedItem as T? diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt index ab01c0f135f..4de42c0fecd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt @@ -41,7 +41,7 @@ import java.util.* object SuperDeclarationMarkerTooltip : Function { override fun `fun`(element: PsiElement): String? { val ktDeclaration = element.getParentOfType(false) ?: return null - val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration!!) + val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration) if (overriddenDescriptors.isEmpty()) return "" val isAbstract = elementDescriptor!!.modality == Modality.ABSTRACT diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertEnumToSealedClassIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertEnumToSealedClassIntention.kt index 45c14cd0a9a..3491a0ebdc2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertEnumToSealedClassIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertEnumToSealedClassIntention.kt @@ -44,7 +44,7 @@ class ConvertEnumToSealedClassIntention : SelfTargetingRangeIntention(K for (klass in element.withExpectedActuals()) { klass as? KtClass ?: continue - val classDescriptor = klass.resolveToDescriptorIfAny() as? ClassDescriptor ?: continue + val classDescriptor = klass.resolveToDescriptorIfAny() ?: continue val isExpect = classDescriptor.isExpect val isActual = classDescriptor.isActual diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionTypeParameterToReceiverIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionTypeParameterToReceiverIntention.kt index 19485ac38c2..fc6e1d4cdd1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionTypeParameterToReceiverIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionTypeParameterToReceiverIntention.kt @@ -196,7 +196,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent } usageLoop@ for (ref in callable.searchReferencesOrMethodReferences()) { - val refElement = ref.element ?: continue + val refElement = ref.element when (ref) { is KtSimpleReference<*> -> processExternalUsage(conflicts, refElement, usages) is KtReference -> continue@usageLoop diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaToReferenceIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaToReferenceIntention.kt index ed9f2c02e25..59e4edc4f1e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaToReferenceIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertLambdaToReferenceIntention.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.isTypeParameter import org.jetbrains.kotlin.types.typeUtil.isUnit +@Suppress("DEPRECATION") class ConvertLambdaToReferenceInspection : IntentionBasedInspection(ConvertLambdaToReferenceIntention::class) open class ConvertLambdaToReferenceIntention(text: String) : diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReferenceToLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReferenceToLambdaIntention.kt index 737f0da232a..dd9e9d34a46 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReferenceToLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertReferenceToLambdaIntention.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.expressions.DoubleColonLHS +@Suppress("DEPRECATION") class ConvertReferenceToLambdaInspection : IntentionBasedInspection(ConvertReferenceToLambdaIntention::class) class ConvertReferenceToLambdaIntention : SelfTargetingOffsetIndependentIntention( diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTryFinallyToUseCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTryFinallyToUseCallIntention.kt index c03dd4af40f..f44ba54d26c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTryFinallyToUseCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTryFinallyToUseCallIntention.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver import org.jetbrains.kotlin.types.typeUtil.supertypes +@Suppress("DEPRECATION") class ConvertTryFinallyToUseCallInspection : IntentionBasedInspection(ConvertTryFinallyToUseCallIntention::class) { override fun inspectionTarget(element: KtTryExpression) = element.tryKeyword ?: element.tryBlock } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTwoComparisonsToRangeCheckIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTwoComparisonsToRangeCheckIntention.kt index 2115ea1bae5..fe2eddd33e8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTwoComparisonsToRangeCheckIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertTwoComparisonsToRangeCheckIntention.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberType +@Suppress("DEPRECATION") class ConvertTwoComparisonsToRangeCheckInspection : IntentionBasedInspection( ConvertTwoComparisonsToRangeCheckIntention::class ) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/FoldInitializerAndIfToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/FoldInitializerAndIfToElvisIntention.kt index 775498b467d..7bf947e5cab 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/FoldInitializerAndIfToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/FoldInitializerAndIfToElvisIntention.kt @@ -45,6 +45,7 @@ import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull +@Suppress("DEPRECATION") class FoldInitializerAndIfToElvisInspection : IntentionBasedInspection(FoldInitializerAndIfToElvisIntention::class) class FoldInitializerAndIfToElvisIntention : diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt index f30bddbcbce..bc8faf583c4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IterateExpressionIntention.kt @@ -86,11 +86,11 @@ class IterateExpressionIntention : SelfTargetingIntention(KtExpres var forExpression = psiFactory.createExpressionByPattern("for($0 in $1) {\nx\n}", paramPattern, element) as KtForExpression forExpression = element.replaced(forExpression) - CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(forExpression)?.let { forExpression -> - val bodyPlaceholder = (forExpression.body as KtBlockExpression).statements.single() - val parameters = forExpression.destructuringDeclaration?.entries ?: listOf(forExpression.loopParameter!!) + CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(forExpression)?.let { expression -> + val bodyPlaceholder = (expression.body as KtBlockExpression).statements.single() + val parameters = expression.destructuringDeclaration?.entries ?: listOf(expression.loopParameter!!) - val templateBuilder = TemplateBuilderImpl(forExpression) + val templateBuilder = TemplateBuilderImpl(expression) for ((parameter, parameterNames) in (parameters zip names)) { templateBuilder.replaceElement(parameter, ChooseStringExpression(parameterNames)) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/JoinDeclarationAndAssignmentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/JoinDeclarationAndAssignmentIntention.kt index 6d35d5c1503..5a9a503bb71 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/JoinDeclarationAndAssignmentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/JoinDeclarationAndAssignmentIntention.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils +@Suppress("DEPRECATION") class JoinDeclarationAndAssignmentInspection : IntentionBasedInspection( JoinDeclarationAndAssignmentIntention::class, "Can be joined with assignment" diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt index 5d63cfa4629..7e2894622a6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt @@ -48,6 +48,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.KotlinType +@Suppress("DEPRECATION") class ObjectLiteralToLambdaInspection : IntentionBasedInspection(ObjectLiteralToLambdaIntention::class) { override fun problemHighlightType(element: KtObjectLiteralExpression): ProblemHighlightType { val (_, baseType, singleFunction) = extractData(element) ?: return super.problemHighlightType(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt index 3f8c05b493e..747cff474f8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveCurlyBracesFromTemplateIntention.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.core.dropBraces import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.psi.KtBlockStringTemplateEntry +@Suppress("DEPRECATION") class RemoveCurlyBracesFromTemplateInspection : IntentionBasedInspection(RemoveCurlyBracesFromTemplateIntention::class) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyClassBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyClassBodyIntention.kt index d50461c2ded..0b1ce8e8a89 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyClassBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyClassBodyIntention.kt @@ -20,7 +20,6 @@ import com.intellij.codeInspection.CleanupLocalInspectionTool import com.intellij.codeInspection.ProblemHighlightType import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.idea.editor.fixers.range import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* @@ -28,10 +27,11 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +@Suppress("DEPRECATION") class RemoveEmptyClassBodyInspection : - IntentionBasedInspection(RemoveEmptyClassBodyIntention::class), CleanupLocalInspectionTool { + IntentionBasedInspection(RemoveEmptyClassBodyIntention::class), CleanupLocalInspectionTool { override fun problemHighlightType(element: KtClassBody): ProblemHighlightType = - ProblemHighlightType.LIKE_UNUSED_SYMBOL + ProblemHighlightType.LIKE_UNUSED_SYMBOL } class RemoveEmptyClassBodyIntention : SelfTargetingOffsetIndependentIntention(KtClassBody::class.java, "Redundant empty class body") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt index 403acd09e5c..90b370bef2b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.KtQualifiedExpression import org.jetbrains.kotlin.psi.KtValueArgumentList import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments +@Suppress("DEPRECATION") class RemoveEmptyParenthesesFromLambdaCallInspection : IntentionBasedInspection( RemoveEmptyParenthesesFromLambdaCallIntention::class ), CleanupLocalInspectionTool { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyPrimaryConstructorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyPrimaryConstructorIntention.kt index ee2ed1b48bc..74ccb4bbcc9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyPrimaryConstructorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyPrimaryConstructorIntention.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.idea.util.isExpectDeclaration import org.jetbrains.kotlin.psi.KtPrimaryConstructor import org.jetbrains.kotlin.psi.psiUtil.containingClass +@Suppress("DEPRECATION") class RemoveEmptyPrimaryConstructorInspection : IntentionBasedInspection( RemoveEmptyPrimaryConstructorIntention::class ), CleanupLocalInspectionTool { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptySecondaryConstructorBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptySecondaryConstructorBodyIntention.kt index f11003d2c3a..af046744038 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptySecondaryConstructorBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptySecondaryConstructorBodyIntention.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtSecondaryConstructor +@Suppress("DEPRECATION") class RemoveEmptySecondaryConstructorBodyInspection : IntentionBasedInspection( RemoveEmptySecondaryConstructorBodyIntention::class ), CleanupLocalInspectionTool { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitSuperQualifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitSuperQualifierIntention.kt index 8f9d3e9213e..0b9aa9c93d4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitSuperQualifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitSuperQualifierIntention.kt @@ -34,11 +34,12 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.ErrorUtils +@Suppress("DEPRECATION") class RemoveExplicitSuperQualifierInspection : IntentionBasedInspection( - RemoveExplicitSuperQualifierIntention::class + RemoveExplicitSuperQualifierIntention::class ), CleanupLocalInspectionTool { override fun problemHighlightType(element: KtSuperExpression): ProblemHighlightType = - ProblemHighlightType.LIKE_UNUSED_SYMBOL + ProblemHighlightType.LIKE_UNUSED_SYMBOL } class RemoveExplicitSuperQualifierIntention : SelfTargetingRangeIntention(KtSuperExpression::class.java, "Remove explicit supertype qualification") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt index 3c792d72694..ad5b5f46543 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArgumentsIntention.kt @@ -42,9 +42,10 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +@Suppress("DEPRECATION") class RemoveExplicitTypeArgumentsInspection : IntentionBasedInspection(RemoveExplicitTypeArgumentsIntention::class) { override fun problemHighlightType(element: KtTypeArgumentList): ProblemHighlightType = - ProblemHighlightType.LIKE_UNUSED_SYMBOL + ProblemHighlightType.LIKE_UNUSED_SYMBOL } class RemoveExplicitTypeArgumentsIntention : SelfTargetingOffsetIndependentIntention(KtTypeArgumentList::class.java, "Remove explicit type arguments") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveForLoopIndicesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveForLoopIndicesIntention.kt index 065b693ab31..f833d1de1fd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveForLoopIndicesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveForLoopIndicesIntention.kt @@ -29,9 +29,10 @@ import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe +@Suppress("DEPRECATION") class RemoveForLoopIndicesInspection : IntentionBasedInspection( - RemoveForLoopIndicesIntention::class, - "Index is not used in the loop body" + RemoveForLoopIndicesIntention::class, + "Index is not used in the loop body" ) { override fun problemHighlightType(element: KtForExpression): ProblemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt index e97293c6397..d7d033c106f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.isFlexible +@Suppress("DEPRECATION") class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection( RemoveRedundantCallsOfConversionMethodsIntention::class ) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeCheckWithIsNotEmptyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeCheckWithIsNotEmptyIntention.kt index 0f0e40edd53..7269a4cb223 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeCheckWithIsNotEmptyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeCheckWithIsNotEmptyIntention.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtBinaryExpression import org.jetbrains.kotlin.psi.KtExpression -class ReplaceSizeCheckWithIsNotEmptyInspection : IntentionBasedInspection(ReplaceSizeCheckWithIsNotEmptyIntention::class) +@Suppress("DEPRECATION") +class ReplaceSizeCheckWithIsNotEmptyInspection : + IntentionBasedInspection(ReplaceSizeCheckWithIsNotEmptyIntention::class) class ReplaceSizeCheckWithIsNotEmptyIntention : ReplaceSizeCheckIntention("Replace size check with 'isNotEmpty'") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeZeroCheckWithIsEmptyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeZeroCheckWithIsEmptyIntention.kt index bdbbf03e219..63becb8723f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeZeroCheckWithIsEmptyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceSizeZeroCheckWithIsEmptyIntention.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtBinaryExpression import org.jetbrains.kotlin.psi.KtExpression -class ReplaceSizeZeroCheckWithIsEmptyInspection : IntentionBasedInspection(ReplaceSizeZeroCheckWithIsEmptyIntention::class) +@Suppress("DEPRECATION") +class ReplaceSizeZeroCheckWithIsEmptyInspection : + IntentionBasedInspection(ReplaceSizeZeroCheckWithIsEmptyIntention::class) class ReplaceSizeZeroCheckWithIsEmptyIntention : ReplaceSizeCheckIntention("Replace size zero check with 'isEmpty'") { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt index 223f26eea16..e33ea93b7b0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyBooleanWithConstantsIntention.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode.PARTIAL import org.jetbrains.kotlin.types.isFlexible +@Suppress("DEPRECATION") class SimplifyBooleanWithConstantsInspection : IntentionBasedInspection(SimplifyBooleanWithConstantsIntention::class) class SimplifyBooleanWithConstantsIntention : diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index 655d3531abe..2e7fc5d2bc4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -58,6 +58,7 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.isUnit import javax.swing.JComponent +@Suppress("DEPRECATION") class UsePropertyAccessSyntaxInspection : IntentionBasedInspection(UsePropertyAccessSyntaxIntention::class), CleanupLocalInspectionTool { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/UseWithIndexIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/UseWithIndexIntention.kt index b1a9c9e91a4..d20e0b295b3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/UseWithIndexIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/UseWithIndexIntention.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern +@Suppress("DEPRECATION") class UseWithIndexInspection : IntentionBasedInspection(UseWithIndexIntention::class) class UseWithIndexIntention : SelfTargetingRangeIntention( diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt index 3e8434b2610..24a5caf62f0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt @@ -105,10 +105,13 @@ object IntroduceIndexMatcher : TransformationMatcher { } private fun isAccessedAfter(variableDescriptor: VariableDescriptor, instruction: Instruction, loop: KtForExpression): Boolean { - return !traverseFollowingInstructions(instruction) { instruction -> + return !traverseFollowingInstructions(instruction) { when { - !loop.isAncestor(instruction.blockScope.block, strict = true) -> TraverseInstructionResult.SKIP // we are outside the loop or going to the next iteration - instruction.isReadOfVariable(variableDescriptor) -> TraverseInstructionResult.HALT + !loop.isAncestor( + it.blockScope.block, + strict = true + ) -> TraverseInstructionResult.SKIP // we are outside the loop or going to the next iteration + it.isReadOfVariable(variableDescriptor) -> TraverseInstructionResult.HALT else -> TraverseInstructionResult.CONTINUE } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/InitializePropertyQuickFixFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/InitializePropertyQuickFixFactory.kt index 0c75cffe9db..db8b864aee7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/InitializePropertyQuickFixFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/InitializePropertyQuickFixFactory.kt @@ -175,7 +175,6 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() { val descriptor = descriptorsToProcess.next() val constructorPointer = descriptor.source.getPsi()?.createSmartPointer() val config = configureChangeSignature(propertyDescriptor) - val changeSignature = { } object : CompositeRefactoringRunner(project, "refactoring.changeSignature") { override fun runRefactoring() { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameModToRemFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameModToRemFix.kt index 7def3f0cc43..84760780dba 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameModToRemFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameModToRemFix.kt @@ -44,7 +44,7 @@ class RenameModToRemFix(element: KtNamedFunction, val newName: Name) : KotlinQui if (diagnostic.factory != Errors.DEPRECATED_BINARY_MOD && diagnostic.factory != Errors.FORBIDDEN_BINARY_MOD) return null val operatorMod = diagnostic.psiElement.getNonStrictParentOfType() ?: return null - val newName = REM_TO_MOD_OPERATION_NAMES.inverse()[operatorMod.nameAsName] ?: return null + val newName = operatorMod.nameAsName?.let { REM_TO_MOD_OPERATION_NAMES.inverse()[it] } ?: return null return RenameModToRemFix(operatorMod, newName) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt index a3477ab1f4e..c260d8e3a2b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/migration/MigrateExternalExtensionFix.kt @@ -272,7 +272,7 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration) } } if ((e as? KtNamedDeclaration)?.modifierList?.annotationEntries?.any { it.isJsNativeAnnotation() } == true) { - return MigrateExternalExtensionFix(e as KtNamedDeclaration) + return MigrateExternalExtensionFix(e) } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt index d30a234ed7e..ecd4d9173da 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt @@ -234,7 +234,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor { val functionPsi = functionUsageInfo.element ?: return for (reference in findReferences(functionPsi)) { - val element = reference.element ?: continue + val element = reference.element when { reference is KtInvokeFunctionReference || reference is KtArrayAccessReference -> { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt index 2fb61d2cb50..9f4efdcbcf2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/changeSignatureUtils.kt @@ -111,9 +111,9 @@ fun suggestReceiverNames(project: Project, descriptor: CallableDescriptor): List val callable = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) as? KtCallableDeclaration ?: return emptyList() val bodyScope = (callable as? KtFunction)?.bodyExpression?.let { it.getResolutionScope(it.analyze(), it.getResolutionFacade()) } val paramNames = descriptor.valueParameters.map { it.name.asString() } - val validator = bodyScope?.let { bodyScope -> + val validator = bodyScope?.let { scope -> CollectingNameValidator(paramNames) { - bodyScope.findVariable(Name.identifier(it), NoLookupLocation.FROM_IDE) == null + scope.findVariable(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } } ?: CollectingNameValidator(paramNames) val receiverType = descriptor.extensionReceiverParameter?.type ?: return emptyList() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt index 2307caa7070..88ca12b8761 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt @@ -119,7 +119,7 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand val referenceExpressions = mutableListOf() val conflictUsages = MultiMap.create() for (ref in references) { - val refElement = ref.element ?: continue + val refElement = ref.element if (refElement !is KtElement) { conflictUsages.putValue(refElement, "Non-Kotlin usage: ${refElement.text}") continue diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt index 9206cec4e5c..98564204603 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt @@ -57,17 +57,17 @@ class KotlinExtractInterfaceDialog( } extractableMemberInfos.forEach { it.isToAbstract = true } return object : MemberInfoModelBase( - originalClass, - extractableMemberInfos, - getInterfaceContainmentVerifier { selectedMembers } + originalClass, + extractableMemberInfos, + getInterfaceContainmentVerifier { selectedMembers } ) { - override fun isMemberEnabled(memberInfo: KotlinMemberInfo): Boolean { - if (!super.isMemberEnabled(memberInfo)) return false + override fun isMemberEnabled(member: KotlinMemberInfo): Boolean { + if (!super.isMemberEnabled(member)) return false - val member = memberInfo.member - return !(member.hasModifier(KtTokens.INLINE_KEYWORD) || - member.hasModifier(KtTokens.EXTERNAL_KEYWORD) || - member.hasModifier(KtTokens.LATEINIT_KEYWORD)) + val declaration = member.member + return !(declaration.hasModifier(KtTokens.INLINE_KEYWORD) || + declaration.hasModifier(KtTokens.EXTERNAL_KEYWORD) || + declaration.hasModifier(KtTokens.LATEINIT_KEYWORD)) } override fun isAbstractEnabled(memberInfo: KotlinMemberInfo): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt index a06ee2ce5a3..695683f6950 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt @@ -278,7 +278,7 @@ open class KotlinIntroduceParameterHandler( ?: Collections.emptyList() val occurrencesToReplace = if (expression is KtProperty) { - ReferencesSearch.search(expression).mapNotNullTo(SmartList(expression.toRange())) { it.element?.toRange() } + ReferencesSearch.search(expression).mapNotNullTo(SmartList(expression.toRange())) { it.element.toRange() } } else { expression.toRange() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index 3afa3105db5..a01f62d63fb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -530,8 +530,8 @@ fun createJavaMethod(template: PsiMethod, targetClass: PsiClass): PsiMethod { method.modifierList.setModifierProperty(PsiModifier.FINAL, false) } - copyTypeParameters(template, method) { method, typeParameterList -> - method.addAfter(typeParameterList, method.modifierList) + copyTypeParameters(template, method) { psiMethod, typeParameterList -> + psiMethod.addAfter(typeParameterList, psiMethod.modifierList) } val targetParamList = method.parameterList @@ -597,8 +597,8 @@ fun createJavaClass(klass: KtClass, targetClass: PsiClass?, forcePlainClass: Boo javaClass.modifierList!!.setModifierProperty(PsiModifier.ABSTRACT, false) } - copyTypeParameters(template, javaClass) { klass, typeParameterList -> - klass.addAfter(typeParameterList, klass.nameIdentifier) + copyTypeParameters(template, javaClass) { clazz, typeParameterList -> + clazz.addAfter(typeParameterList, clazz.nameIdentifier) } // Turning interface to class diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt index 3abcd30326c..2d44f402602 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/changePackage/ChangePackageIntention.kt @@ -73,7 +73,6 @@ class ChangePackageIntention: SelfTargetingOffsetIndependentIntention LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext) } + val targetContainer = dataContext?.let { context -> LangDataKeys.TARGET_PSI_ELEMENT.getData(context) } return canMove(elementsToMove, targetContainer, true) && doMoveWithCheck(project, elementsToMove, targetContainer, null, editor) } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt index 00bbd800d43..87fa76d2fa9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt @@ -508,7 +508,7 @@ class MoveConflictChecker( for (memberToCheck in membersToCheck) { for (reference in ReferencesSearch.search(memberToCheck)) { - val element = reference.element ?: continue + val element = reference.element val usageModule = ModuleUtilCore.findModuleForPsiElement(element) ?: continue if (usageModule != targetModule && targetModule !in usageModule.implementedModules && !isToBeMoved(element)) { val container = element.getUsageContext() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt index 7b14ece498a..d9feb5a0931 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/JavaToKotlinPreconversionPullUpHelper.kt @@ -68,7 +68,7 @@ class JavaToKotlinPreconversionPullUpHelper( private fun collectFieldReferencesToEncapsulate(member: PsiField) { val helper = EncapsulateFieldHelper.getHelper(member.language) ?: return - val fieldName = member.name!! + val fieldName = member.name val getterName = JvmAbi.getterName(fieldName) val setterName = JvmAbi.setterName(fieldName) val getter = helper.generateMethodPrototype(member, getterName, true) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt index 217f8eeeef7..ad76f0ca88a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPsiProcessor.kt @@ -103,8 +103,8 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() { } override fun getElementToSearchInStringsAndComments(element: PsiElement): PsiElement? { - val unwrapped = element?.unwrapped ?: return null - if ((unwrapped is KtDeclaration) && KtPsiUtil.isLocal(unwrapped as KtDeclaration)) return null + val unwrapped = element.unwrapped ?: return null + if ((unwrapped is KtDeclaration) && KtPsiUtil.isLocal(unwrapped)) return null return element } @@ -185,7 +185,7 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() { } } else { - ref.element?.getStrictParentOfType()?.let { importDirective -> + ref.element.getStrictParentOfType()?.let { importDirective -> val fqName = importDirective.importedFqName!! val newFqName = fqName.parent().child(Name.identifier(newName)) val importList = importDirective.parent as KtImportList diff --git a/idea/src/org/jetbrains/kotlin/idea/roots/projectRootUtils.kt b/idea/src/org/jetbrains/kotlin/idea/roots/projectRootUtils.kt index d38c6040f2c..8f7db34f64f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/roots/projectRootUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/roots/projectRootUtils.kt @@ -30,7 +30,7 @@ fun JpsModuleSourceRoot.getMigratedSourceRootTypeWithProperties(): Pair = when (currentRootType) { - JavaSourceRootType.SOURCE -> SourceKotlinRootType + JavaSourceRootType.SOURCE -> SourceKotlinRootType as JpsModuleSourceRootType JavaSourceRootType.TEST_SOURCE -> TestSourceKotlinRootType JavaResourceRootType.RESOURCE -> ResourceKotlinRootType JavaResourceRootType.TEST_RESOURCE -> TestResourceKotlinRootType diff --git a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinDefinitionsSearcher.kt b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinDefinitionsSearcher.kt index 909ee95b1ce..e7be954f52c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinDefinitionsSearcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinDefinitionsSearcher.kt @@ -43,7 +43,7 @@ import java.util.* class KotlinDefinitionsSearcher : QueryExecutor { override fun execute(queryParameters: DefinitionsScopedSearch.SearchParameters, consumer: Processor): Boolean { - val consumer = skipDelegatedMethodsConsumer(consumer) + val processor = skipDelegatedMethodsConsumer(consumer) val element = queryParameters.element val scope = queryParameters.scope @@ -51,35 +51,35 @@ class KotlinDefinitionsSearcher : QueryExecutor { val isExpectEnum = runReadAction { element.isEnum() && element.isExpectDeclaration() } if (isExpectEnum) { - processActualDeclarations(element, consumer) + processActualDeclarations(element, processor) } else { - processClassImplementations(element, consumer) && processActualDeclarations(element, consumer) + processClassImplementations(element, processor) && processActualDeclarations(element, processor) } } is KtObjectDeclaration -> { - processActualDeclarations(element, consumer) + processActualDeclarations(element, processor) } is KtLightClass -> { val useScope = runReadAction { element.useScope } if (useScope is LocalSearchScope) - processLightClassLocalImplementations(element, useScope, consumer) + processLightClassLocalImplementations(element, useScope, processor) else true } is KtNamedFunction, is KtSecondaryConstructor -> { - processFunctionImplementations(element as KtFunction, scope, consumer) && processActualDeclarations(element, consumer) + processFunctionImplementations(element as KtFunction, scope, processor) && processActualDeclarations(element, processor) } is KtProperty -> { - processPropertyImplementations(element, scope, consumer) && processActualDeclarations(element, consumer) + processPropertyImplementations(element, scope, processor) && processActualDeclarations(element, processor) } is KtParameter -> { if (isFieldParameter(element)) { - processPropertyImplementations(element, scope, consumer) && processActualDeclarations(element, consumer) + processPropertyImplementations(element, scope, processor) && processActualDeclarations(element, processor) } else { true } diff --git a/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt b/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt index b7edbd225d8..e95c5842fda 100644 --- a/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/testIntegration/KotlinCreateTestIntention.kt @@ -163,7 +163,7 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention("Convert class '${generatedClass.name}' to Kotlin", this) { runWriteAction { generatedClass.methods.forEach { it.throwsList.referenceElements.forEach { referenceElement -> referenceElement.delete() } } } @@ -181,6 +181,7 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention existingClass.addDeclaration(declaration) } } generatedClass.delete() } + NavigationUtil.activateFileWithPsiElement(existingClass) } else { with(PsiDocumentManager.getInstance(project)) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt index a1b89a3591a..95d72ad07a6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt @@ -432,7 +432,7 @@ class IdeaModuleInfoTest : ModuleTestCase() { get() = LibraryInfo(project!!, this) private fun module(name: String, hasProductionRoot: Boolean = true, hasTestRoot: Boolean = true): Module { - return createModuleFromTestData(createTempDirectory()!!.absolutePath, name, StdModuleTypes.JAVA, false)!!.apply { + return createModuleFromTestData(createTempDirectory().absolutePath, name, StdModuleTypes.JAVA, false).apply { if (hasProductionRoot) PsiTestUtil.addSourceContentToRoots(this, dir(), false) if (hasTestRoot) diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt index a203f916082..60e356116a9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/MultiModuleHighlightingTest.kt @@ -196,12 +196,12 @@ open class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() { fun testSamWithReceiverExtension() { val module1 = module("m1").setupKotlinFacet { settings.compilerArguments!!.pluginOptions = - arrayOf("plugin:${PLUGIN_ID}:${ANNOTATION_OPTION.name}=anno.A") + arrayOf("plugin:$PLUGIN_ID:${ANNOTATION_OPTION.optionName}=anno.A") } val module2 = module("m2").setupKotlinFacet { settings.compilerArguments!!.pluginOptions = - arrayOf("plugin:${PLUGIN_ID}:${ANNOTATION_OPTION.name}=anno.B") + arrayOf("plugin:$PLUGIN_ID:${ANNOTATION_OPTION.optionName}=anno.B") } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractAsyncStackTraceTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractAsyncStackTraceTest.kt index e88c8e50879..73c2eba55a3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractAsyncStackTraceTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractAsyncStackTraceTest.kt @@ -94,7 +94,7 @@ abstract class AbstractAsyncStackTraceTest : KotlinDebuggerTestBase() { @Suppress("UNCHECKED_CAST") val variablesField = item.javaClass.declaredFields.first { !Modifier.isStatic(it.modifiers) && it.type == List::class.java } - val variables = variablesField.getSafe(item) as? List + @Suppress("UNCHECKED_CAST") val variables = variablesField.getSafe(item) as? List if (variables != null) { for (variable in variables) { val descriptor = variable.descriptor diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/dexLikeBytecodePatch.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/dexLikeBytecodePatch.kt index 8349de65ac0..de781c76dcd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/dexLikeBytecodePatch.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/dexLikeBytecodePatch.kt @@ -14,8 +14,8 @@ val DEX_BEFORE_PATCH_EXTENSION = "before_dex" fun String.needDexPatch() = split('.').any { it.endsWith("Dex") } fun patchDexTests(dir: File) { - dir.listFiles({ file -> file.isDirectory && file.name.needDexPatch() }).forEach { dir -> - dir.listFiles { testOutputFile -> testOutputFile.extension == "class" }.forEach(::applyDexLikePatch) + dir.listFiles { file -> file.isDirectory && file.name.needDexPatch() }.forEach { + it.listFiles { testOutputFile -> testOutputFile.extension == "class" }.forEach(::applyDexLikePatch) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateFromLibrarySourcesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateFromLibrarySourcesTest.kt index 36a82d2aeaf..82f6566322f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateFromLibrarySourcesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateFromLibrarySourcesTest.kt @@ -10,8 +10,8 @@ import com.intellij.psi.PsiElement import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.idea.caches.lightClasses.KtLightClassForDecompiledDeclaration -import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner @@ -36,10 +36,12 @@ class NavigateFromLibrarySourcesTest: AbstractNavigateFromLibrarySourcesTest() { fun testLightClassForLibrarySource() { val navigationElement = navigationElementForReferenceInLibrarySource("usage.kt", "Foo") assertTrue(navigationElement is KtClassOrObject, "Foo should navigate to JetClassOrObject") - val lightClass = (navigationElement as KtClassOrObject).toLightClass() - assertTrue(lightClass is KtLightClassForDecompiledDeclaration, - "Light classes for decompiled declaration should be provided for library source") - assertEquals("Foo", lightClass!!.name) + val lightClass = navigationElement.toLightClass() + assertTrue( + lightClass is KtLightClassForDecompiledDeclaration, + "Light classes for decompiled declaration should be provided for library source" + ) + assertEquals("Foo", lightClass.name) } private fun checkNavigationFromLibrarySource(referenceText: String, targetFqName: String) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigationWithMultipleLibrariesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigationWithMultipleLibrariesTest.kt index 95c42c35218..94f061b4232 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigationWithMultipleLibrariesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigationWithMultipleLibrariesTest.kt @@ -128,7 +128,7 @@ class NavigationToSingleJarInMultipleLibrariesTest : AbstractNavigationWithMulti abstract class AbstractNavigationWithMultipleLibrariesTest : ModuleTestCase() { abstract val testDataPath: String - protected fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!! + protected fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true) protected fun checkReferencesInModule(module: Module, libraryName: String, expectedFileName: String) { checkAnnotatedCode(findSourceFile(module), File(testDataPath + expectedFileName)) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerConsistencyTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerConsistencyTest.kt index 71d0f967f39..2a002fe6c93 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerConsistencyTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerConsistencyTest.kt @@ -66,7 +66,7 @@ class BuiltInDecompilerConsistencyTest : KotlinLightCodeInsightFixtureTestCase() val fileContent = FileContentImpl.createByFile(classFile) if (IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(fileContent.file) == null) continue val fileStub = classFileDecompiler.stubBuilder.buildFileStub(fileContent) ?: continue - val classStub = fileStub.findChildStubByType(KtClassElementType.getStubType(false)) as? KotlinClassStub ?: continue + val classStub = fileStub.findChildStubByType(KtClassElementType.getStubType(false)) ?: continue val classFqName = classStub.getFqName()!! val builtInClassStub = builtInFileStub.childrenStubs.firstOrNull { it is KotlinClassStub && it.getFqName() == classFqName diff --git a/idea/tests/org/jetbrains/kotlin/idea/index/AbstractKotlinTypeAliasByExpansionShortNameIndexTest.kt b/idea/tests/org/jetbrains/kotlin/idea/index/AbstractKotlinTypeAliasByExpansionShortNameIndexTest.kt index f9f86bed3af..5e1b934714e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/index/AbstractKotlinTypeAliasByExpansionShortNameIndexTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/index/AbstractKotlinTypeAliasByExpansionShortNameIndexTest.kt @@ -28,6 +28,7 @@ abstract class AbstractKotlinTypeAliasByExpansionShortNameIndexTest : KotlinLigh } override fun tearDown() { + @Suppress("UNCHECKED_CAST") (this::scope as KMutableProperty0).set(null) super.tearDown() } diff --git a/idea/tests/org/jetbrains/kotlin/idea/jvm/KotlinJvmDeclarationSearcherTest.kt b/idea/tests/org/jetbrains/kotlin/idea/jvm/KotlinJvmDeclarationSearcherTest.kt index d84f523b08d..aa9777c909e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/jvm/KotlinJvmDeclarationSearcherTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/jvm/KotlinJvmDeclarationSearcherTest.kt @@ -149,12 +149,13 @@ private class JvmDeclared(val textToContain: String, vararg jvmClasses: KClass assertMatches(elements: Collection, vararg conditions: (T) -> Boolean) { - val matchResult = matchElementsToConditions(elements, conditions.toList()) - when (matchResult) { + when (val matchResult = matchElementsToConditions(elements, conditions.toList())) { is MatchResult.UnmatchedCondition -> throw AssertionError("no one matches the ${matchResult.condition}, elements = ${elements.joinToString { it.toString() }}") is MatchResult.UnmatchedElements -> throw AssertionError("elements ${matchResult.elements.joinToString { it.toString() }} wasn't matched by any condition") + is MatchResult.Matched -> { + } } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoWithMultipleLibrariesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoWithMultipleLibrariesTest.kt index 6bec1036ea7..cd0b6233833 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoWithMultipleLibrariesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoWithMultipleLibrariesTest.kt @@ -61,5 +61,5 @@ class GotoWithMultipleLibrariesTest : AbstractMultiModuleTest() { } } - private fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!! + private fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt index ca331838048..5f4574e82e6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt @@ -45,7 +45,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() { val prefix = FileUtil.getNameWithoutExtension(PathUtil.getFileName(fileName)) val mainFile = File(FileUtil.toSystemDependentName(fileName)) mainFile.parentFile - .listFiles { dir, name -> name.startsWith("$prefix.") && name != mainFile.name } + .listFiles { _, name -> name.startsWith("$prefix.") && name != mainFile.name } .forEach { myFixture.configureByFile(FileUtil.toSystemIndependentName(it.path)) } myFixture.configureByFile(fileName) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AddRequireModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AddRequireModuleTest.kt index 529a12ee217..d87d6eb0050 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AddRequireModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AddRequireModuleTest.kt @@ -13,7 +13,7 @@ import org.junit.runner.RunWith @RunWith(JUnit3WithIdeaConfigurationRunner::class) class KotlinAddRequiredModuleTest : KotlinLightJava9ModulesCodeInsightFixtureTestCase() { - private val messageM2 = QuickFixBundle.message("module.info.add.requires.name", "M_TWO")!! + private val messageM2 = QuickFixBundle.message("module.info.add.requires.name", "M_TWO") override fun setUp() { super.setUp() @@ -72,7 +72,7 @@ class KotlinAddRequiredModuleTest : KotlinLightJava9ModulesCodeInsightFixtureTes MAIN) myFixture.configureFromExistingVirtualFile(editedFile) - findActionAndExecute(QuickFixBundle.message("module.info.add.requires.name", "java.logging")!!) + findActionAndExecute(QuickFixBundle.message("module.info.add.requires.name", "java.logging")) assertNoErrors() checkModuleInfo( diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt index 1f0bd1bbc46..815d725b25f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTest.kt @@ -30,8 +30,8 @@ interface QuickFixTest { val inspectionFile = findInspectionFile(File(beforeFileName).parentFile) if (inspectionFile != null) { val className = FileUtil.loadFile(inspectionFile).trim { it <= ' ' } - val inspectionClass = Class.forName(className) as Class - return InspectionTestUtil.instantiateTools(listOf>(inspectionClass)) + @Suppress("UNCHECKED_CAST") val inspectionClass = Class.forName(className) as Class + return InspectionTestUtil.instantiateTools(listOf(inspectionClass)) } return emptyList() diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt index b432106286e..5523ba0c96f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt @@ -48,7 +48,7 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() { fun module(name: String, jdk: TestJdkKind = TestJdkKind.MOCK_JDK, hasTestRoot: Boolean = false): Module { val srcDir = testDataPath + "${getTestName(true)}/$name" - val moduleWithSrcRootSet = createModuleFromTestData(srcDir, name, StdModuleTypes.JAVA, true)!! + val moduleWithSrcRootSet = createModuleFromTestData(srcDir, name, StdModuleTypes.JAVA, true) if (hasTestRoot) { addRoot( moduleWithSrcRootSet, diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt index 585d29cc582..1c801df81c3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt @@ -68,7 +68,7 @@ class DebugTextByStubTest : LightCodeInsightFixtureTestCase() { fun clazz(text: String, expectedText: String? = null) { val (file, tree) = createFileAndStubTree(text) val clazz = tree.findChildStubByType(KtStubElementTypes.CLASS)!! - val psiFromStub = KtClass(clazz as KotlinClassStub) + val psiFromStub = KtClass(clazz) val classByPsi = file.findChildByClass(KtClass::class.java) val toCheckAgainst = "STUB: " + (expectedText ?: classByPsi!!.text) Assert.assertEquals(toCheckAgainst, psiFromStub.getDebugText()) @@ -80,7 +80,7 @@ class DebugTextByStubTest : LightCodeInsightFixtureTestCase() { fun obj(text: String, expectedText: String? = null) { val (file, tree) = createFileAndStubTree(text) val obj = tree.findChildStubByType(KtStubElementTypes.OBJECT_DECLARATION)!! - val psiFromStub = KtObjectDeclaration(obj as KotlinObjectStub) + val psiFromStub = KtObjectDeclaration(obj) val objectByPsi = file.findChildByClass(KtObjectDeclaration::class.java) val toCheckAgainst = "STUB: " + (expectedText ?: objectByPsi!!.text) Assert.assertEquals(toCheckAgainst, psiFromStub.getDebugText()) @@ -89,7 +89,7 @@ class DebugTextByStubTest : LightCodeInsightFixtureTestCase() { fun property(text: String, expectedText: String? = null) { val (file, tree) = createFileAndStubTree(text) val property = tree.findChildStubByType(KtStubElementTypes.PROPERTY)!! - val psiFromStub = KtProperty(property as KotlinPropertyStub) + val psiFromStub = KtProperty(property) val propertyByPsi = file.findChildByClass(KtProperty::class.java) val toCheckAgainst = "STUB: " + (expectedText ?: propertyByPsi!!.text) Assert.assertEquals(toCheckAgainst, psiFromStub.getDebugText()) diff --git a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt index edc04113a14..4d257146067 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt @@ -189,7 +189,7 @@ class AnnotationConverter(private val converter: Converter) { val returnType = method.returnType if (returnType is PsiArrayType && value !is PsiArrayInitializerMemberValue) { return converter.deferredElement { codeConverter -> - val convertedType = converter.typeConverter.convertType(returnType) as ArrayType + converter.typeConverter.convertType(returnType) as ArrayType val convertAttributeValue = convertAttributeValue(value, returnType.componentType, false, false) createArrayLiteralExpression(codeConverter, convertAttributeValue.toList()) } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt index febaac2b6b5..ef2fa5f6d80 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ExpressionConverter.kt @@ -37,7 +37,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType -import java.lang.AssertionError import java.math.BigInteger interface ExpressionConverter { @@ -399,13 +398,15 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { } is KtFunction -> if (isTopLevel) { result = if (origin.isExtensionDeclaration()) { - val qualifier = codeConverter.convertExpression(arguments.firstOrNull(), shouldParenthesize = true) - MethodCallExpression.build(qualifier, - origin.name!!, - convertArguments(expression, isExtension = true), - typeArguments, - isNullable, - dot) + val receiver = codeConverter.convertExpression(arguments.firstOrNull(), shouldParenthesize = true) + MethodCallExpression.build( + receiver, + origin.name!!, + convertArguments(expression, isExtension = true), + typeArguments, + isNullable, + dot + ) } else { MethodCallExpression.build(null, @@ -420,13 +421,15 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter { val resolvedQualifier = (methodExpr.qualifier as? PsiReferenceExpression)?.resolve() if (isFacadeClassFromLibrary(resolvedQualifier)) { result = if (target.isKotlinExtensionFunction()) { - val qualifier = codeConverter.convertExpression(arguments.firstOrNull(), shouldParenthesize = true) - MethodCallExpression.build(qualifier, - methodExpr.referenceName!!, - convertArguments(expression, isExtension = true), - typeArguments, - isNullable, - dot) + val receiver = codeConverter.convertExpression(arguments.firstOrNull(), shouldParenthesize = true) + MethodCallExpression.build( + receiver, + methodExpr.referenceName!!, + convertArguments(expression, isExtension = true), + typeArguments, + isNullable, + dot + ) } else { MethodCallExpression.build(null, diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/jsRenderers.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/jsRenderers.kt index b49bad20a36..a5ccf2401ac 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/jsRenderers.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/jsRenderers.kt @@ -22,8 +22,8 @@ import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticParameterRenderer import org.jetbrains.kotlin.diagnostics.rendering.RenderingContext object RenderFirstLineOfElementText : DiagnosticParameterRenderer { - override fun render(element: PsiElement, context: RenderingContext): String { - val text = element.text + override fun render(obj: PsiElement, renderingContext: RenderingContext): String { + val text = obj.text val index = text.indexOf('\n') return if (index == -1) text else text.substring(0, index) + "..." } @@ -32,10 +32,10 @@ object RenderFirstLineOfElementText : DiagnosticParameterRenderer { abstract class JsCallDataRenderer : DiagnosticParameterRenderer { protected abstract fun format(data: JsCallDataWithCode): String - override fun render(data: JsCallData, context: RenderingContext): String = - when (data) { - is JsCallDataWithCode -> format(data) - else -> data.message + override fun render(obj: JsCallData, renderingContext: RenderingContext): String = + when (obj) { + is JsCallDataWithCode -> format(obj) + else -> obj.message } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt index 09c405c52e8..be37b0fe008 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/interop/ScriptEngineV8.kt @@ -39,7 +39,7 @@ class ScriptEngineV8 : ScriptEngine { private fun getGlobalPropertyNames(): List { val v8Array = eval("Object.getOwnPropertyNames(this)") - val javaArray = V8ObjectUtils.toList(v8Array) as List + @Suppress("UNCHECKED_CAST") val javaArray = V8ObjectUtils.toList(v8Array) as List v8Array.release() return javaArray } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt index 091b728d747..642ddb00d9b 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt @@ -46,7 +46,7 @@ import java.util.* object ArrayFIF : CompositeFIF() { @JvmField - val GET_INTRINSIC = intrinsify { callInfo, arguments, context -> + val GET_INTRINSIC = intrinsify { callInfo, arguments, _ -> assert(arguments.size == 1) { "Array get expression must have one argument." } val (indexExpression) = arguments JsArrayAccess(callInfo.dispatchReceiver, indexExpression) diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt index 4aa18179593..0dba5e1954e 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallArgumentTranslator.kt @@ -246,7 +246,7 @@ class CallArgumentTranslator private constructor( val concatExpression = concatArgumentsIfNeeded(concatArguments, varargElementType, false) concatExpression } else { - val arg = ArrayFIF.unsignedPrimitiveToSigned(varargElementType)?.let {type -> + val arg = ArrayFIF.unsignedPrimitiveToSigned(varargElementType)?.let { _ -> JsInvocation(JsNameRef("unbox", list[0])) } ?: list[0] JsAstUtils.invokeMethod(arg, "slice") diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt index 4240a599dbb..e310de44b88 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallableReferenceTranslator.kt @@ -154,8 +154,15 @@ object CallableReferenceTranslator { } } - val getter = translateForPropertyAccessor(call, expression, descriptor, context, receiver, false) { context, call, _, receiverParam -> - CallTranslator.translateGet(context, call, receiverParam) + val getter = translateForPropertyAccessor( + call, + expression, + descriptor, + context, + receiver, + false + ) { translationContext, resolvedCall, _, receiverParam -> + CallTranslator.translateGet(translationContext, resolvedCall, receiverParam) } val setter = if (isSetterVisible(descriptor, context)) { diff --git a/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt b/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt index 25ff7ac81a1..b34d7858c40 100644 --- a/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt +++ b/libraries/scripting/jvm/src/kotlin/script/experimental/jvm/util/jvmClasspathUtil.kt @@ -229,7 +229,7 @@ object KotlinJars { })) { throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.classpath property to proper location") } - return classpath!! + return classpath } fun getLib(propertyName: String, jarName: String, markerClass: KClass<*>, classLoader: ClassLoader? = null): File? = diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/NewJ2kPostProcessings.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/NewJ2kPostProcessings.kt index c15fe7ffede..61f25f37411 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/NewJ2kPostProcessings.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/NewJ2kPostProcessings.kt @@ -133,7 +133,7 @@ object NewJ2KPostProcessingRegistrar { RemoveRedundantVisibilityModifierProcessing(), RemoveRedundantModalityModifierProcessing(), RemoveRedundantConstructorKeywordProcessing(), - registerDiagnosticBasedProcessing(Errors.REDUNDANT_OPEN_IN_INTERFACE) { element: KtDeclaration, diagnostic -> + registerDiagnosticBasedProcessing(Errors.REDUNDANT_OPEN_IN_INTERFACE) { element: KtDeclaration, _ -> element.removeModifier(KtTokens.OPEN_KEYWORD) }, object : NewJ2kPostProcessing { @@ -220,7 +220,7 @@ object NewJ2KPostProcessingRegistrar { registerGeneralInspectionBasedProcessing(LiftReturnOrAssignmentInspection()), registerGeneralInspectionBasedProcessing(MayBeConstantInspection()), registerIntentionBasedProcessing(RemoveEmptyPrimaryConstructorIntention()), - registerDiagnosticBasedProcessing(Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) { element: KtDotQualifiedExpression, diagnostic -> + registerDiagnosticBasedProcessing(Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) { element: KtDotQualifiedExpression, _ -> val parent = element.parent as? KtImportDirective ?: return@registerDiagnosticBasedProcessing parent.delete() }, @@ -239,7 +239,8 @@ object NewJ2KPostProcessingRegistrar { registerDiagnosticBasedProcessingWithFixFactory(MissingIteratorExclExclFixFactory, Errors.ITERATOR_ON_NULLABLE), registerDiagnosticBasedProcessingWithFixFactory(SmartCastImpossibleExclExclFixFactory, Errors.SMARTCAST_IMPOSSIBLE), registerDiagnosticBasedProcessing(Errors.TYPE_MISMATCH) { element: PsiElement, diagnostic -> - val diagnosticWithParameters = diagnostic as? DiagnosticWithParameters2 + @Suppress("UNCHECKED_CAST") val diagnosticWithParameters = + diagnostic as? DiagnosticWithParameters2 ?: return@registerDiagnosticBasedProcessing val expectedType = diagnosticWithParameters.a val realType = diagnosticWithParameters.b @@ -348,7 +349,7 @@ object NewJ2KPostProcessingRegistrar { } - private inline fun registerGeneralInspectionBasedProcessing( + private fun registerGeneralInspectionBasedProcessing( inspection: TInspection, acceptInformationLevel: Boolean = false ) = (object : NewJ2kPostProcessing { @@ -373,8 +374,8 @@ object NewJ2KPostProcessingRegistrar { @Suppress("NOT_YET_SUPPORTED_IN_INLINE") fun applyIntention() { - val action = this.action - when (action) { + @Suppress("UNCHECKED_CAST") + when (val action = this.action) { is SelfTargetingIntention<*> -> applySelfTargetingIntention(action as SelfTargetingIntention) is QuickFixActionBase<*> -> applyQuickFixActionBase(action) } @@ -444,7 +445,7 @@ object NewJ2KPostProcessingRegistrar { } } - private inline fun registerDiagnosticBasedProcessingWithFixFactory( + private fun registerDiagnosticBasedProcessingWithFixFactory( fixFactory: KotlinIntentionActionsFactory, vararg diagnosticFactory: DiagnosticFactory<*> ): NewJ2kPostProcessing = registerDiagnosticBasedProcessing(*diagnosticFactory) { element: PsiElement, diagnostic: Diagnostic -> @@ -453,7 +454,6 @@ object NewJ2KPostProcessingRegistrar { } - private inline fun registerDiagnosticBasedProcessing( vararg diagnosticFactory: DiagnosticFactory<*>, crossinline fix: (TElement, Diagnostic) -> Unit diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/ConstraintBuilder.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/ConstraintBuilder.kt index 4f10fc1d1fb..17516fa943b 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/ConstraintBuilder.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/ConstraintBuilder.kt @@ -14,32 +14,32 @@ internal class ConstraintBuilder(val boundTypeStorage: BoundTypeStorage) { internal fun getConstraints(): List = constraints - inline fun KtExpression.addSubtypeNullabilityConstraint(typeVariable: TypeVariable, cameFrom: ConstraintCameFrom) { + fun KtExpression.addSubtypeNullabilityConstraint(typeVariable: TypeVariable, cameFrom: ConstraintCameFrom) { addSubtypeNullabilityConstraint(TypeVariableBoundType(typeVariable), cameFrom) } - inline fun KtExpression.addEqualsNullabilityConstraint(nullability: Nullability, cameFrom: ConstraintCameFrom) { + fun KtExpression.addEqualsNullabilityConstraint(nullability: Nullability, cameFrom: ConstraintCameFrom) { val boundType = boundTypeStorage.boundTypeFor(this).safeAs() ?.withForcedNullability(getForcedNullability()) ?: return constraints += EqualConstraint(boundType.bound, LiteralBound(nullability), cameFrom) } - inline fun TypeVariable.addEqualsNullabilityConstraint(other: BoundType, cameFrom: ConstraintCameFrom) { + fun TypeVariable.addEqualsNullabilityConstraint(other: BoundType, cameFrom: ConstraintCameFrom) { TypeVariableBoundType(this).isTheSameType(other, cameFrom) } - inline fun KtExpression.addSubtypeNullabilityConstraint(upperTypeExpression: KtExpression, cameFrom: ConstraintCameFrom) { + fun KtExpression.addSubtypeNullabilityConstraint(upperTypeExpression: KtExpression, cameFrom: ConstraintCameFrom) { boundTypeStorage.boundTypeFor(this).subtypeOf(boundTypeStorage.boundTypeFor(upperTypeExpression), cameFrom) } - inline fun KtExpression.addSubtypeNullabilityConstraint(upperBoundType: BoundType, cameFrom: ConstraintCameFrom) { + fun KtExpression.addSubtypeNullabilityConstraint(upperBoundType: BoundType, cameFrom: ConstraintCameFrom) { boundTypeStorage.boundTypeFor(this) .withForcedNullability(getForcedNullability()) .subtypeOf(upperBoundType, cameFrom) } - inline fun TypeVariable.subtypeOf(other: BoundType, cameFrom: ConstraintCameFrom) { + fun TypeVariable.subtypeOf(other: BoundType, cameFrom: ConstraintCameFrom) { TypeVariableBoundType(this).subtypeOf(other, cameFrom) } diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/solver.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/solver.kt index a39bedca43a..dc5229a3429 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/solver.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/solver.kt @@ -30,13 +30,13 @@ internal class Solver( } fun solveConstraints(constraints: List) { - val constraints = constraints.toMutableList() + val mutableConstraints = constraints.toMutableList() var currentStep = ConstraintCameFrom.values().first() var i = 0 do { var somethingChanged = false - with(constraints) { + with(mutableConstraints) { printDebugInfo(i) somethingChanged = handleConstraintsWithNullableLowerBound(currentStep) || somethingChanged somethingChanged = handleConstraintsWithNotNullUpperBound(currentStep) || somethingChanged @@ -53,7 +53,7 @@ internal class Solver( } } if (!somethingChanged) { - val typeVariable = constraints.getTypeVariableAsEqualsOrUpperBound() + val typeVariable = mutableConstraints.getTypeVariableAsEqualsOrUpperBound() if (typeVariable != null) { typeVariable.setNullabilityIfNotFixed(Nullability.NOT_NULL) somethingChanged = true diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/utils.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/utils.kt index a30f384b96d..0be9d801552 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/utils.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/nullabilityAnalysis/utils.kt @@ -21,15 +21,15 @@ import org.jetbrains.kotlin.resolve.jvm.checkers.mustNotBeNull import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.util.javaslang.getOrNull -internal inline fun KtExpression.deepestReceiver(): KtExpression = +internal fun KtExpression.deepestReceiver(): KtExpression = generateSequence(this) { if (it is KtQualifiedExpression) it.receiverExpression else null }.last() -internal inline fun KtExpression.isNullable(): Boolean = +internal fun KtExpression.isNullable(): Boolean = getType(analyze())?.isNullable() != false -internal inline fun KtExpression.getForcedNullability(): Nullability? { +internal fun KtExpression.getForcedNullability(): Nullability? { val bindingContext = analyze() val type = this.getType(bindingContext) ?: return null if (!type.isNullable()) return Nullability.NOT_NULL diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/ImportStorage.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/ImportStorage.kt index c82f96e74ac..0f7d03dbd25 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/ImportStorage.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/ImportStorage.kt @@ -25,8 +25,6 @@ class ImportStorage { return true } - inline fun isImportNeeded(fqName: String): Boolean = - isImportNeeded(FqName(fqName)) - + fun isImportNeeded(fqName: String): Boolean = isImportNeeded(FqName(fqName)) } } \ No newline at end of file diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/JKElementInfoStorage.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/JKElementInfoStorage.kt index a981fc7277d..bdcba1dcb94 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/JKElementInfoStorage.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/JKElementInfoStorage.kt @@ -19,7 +19,7 @@ data class FunctionInfo(val originalDescriptor: FunctionDescriptor, val superFun object UnknownNullability : JKElementInfo inline class JKElementInfoLabel(val label: String) { - inline fun render(): String = "/*@@$label@@*/" + fun render(): String = "/*@@$label@@*/" companion object { val LABEL_REGEX = """/\*@@(\w+)@@\*/""".toRegex() diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/JKSymbolProvider.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/JKSymbolProvider.kt index 6ca9323a1a2..611731d280b 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/JKSymbolProvider.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/JKSymbolProvider.kt @@ -84,6 +84,7 @@ class JKSymbolProvider { } fun transferSymbol(to: JKDeclaration, from: JKDeclaration) = symbolsByJK[from]?.also { + @Suppress("UNCHECKED_CAST") it as JKUniverseSymbol it.target = to symbolsByJK[to] = it diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt index a9d8b433d06..6278ba01f08 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt @@ -400,7 +400,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { printer.printWithNoIndent(" fun ") ktFunction.typeParameterList.accept(this) - elementInfoStorage.getOrCreateInfoForElement(ktFunction)?.also { + elementInfoStorage.getOrCreateInfoForElement(ktFunction).let { printer.printWithNoIndent(it.render()) } ktFunction.name.accept(this) @@ -656,7 +656,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { private fun renderType(type: JKType, owner: JKTreeElement?) { if (type is JKNoTypeImpl) return - elementInfoStorage.getOrCreateInfoForElement(type)?.also { + elementInfoStorage.getOrCreateInfoForElement(type).let { printer.print(it.render()) } when (type) { @@ -941,6 +941,8 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { JKClassLiteralExpression.LiteralType.KOTLIN_CLASS -> printer.printWithNoIndent("class") JKClassLiteralExpression.LiteralType.JAVA_CLASS -> printer.printWithNoIndent("class.java") JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS -> printer.printWithNoIndent("class.javaPrimitiveType") + JKClassLiteralExpression.LiteralType.JAVA_VOID_TYPE -> { + } } } } @@ -973,14 +975,14 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { } } -private inline fun List.headTail(): Pair?> { +private fun List.headTail(): Pair?> { val head = this.firstOrNull() val tail = if (size <= 1) null else subList(1, size) return head to tail } -private inline fun JKDelegationConstructorCall.isCallOfConstructorOf(type: JKType): Boolean { +private fun JKDelegationConstructorCall.isCallOfConstructorOf(type: JKType): Boolean { return when (type) { is JKClassType -> { val symbol = type.classReference as? JKClassSymbol ?: return false diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/TreeCopy.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/TreeCopy.kt index e92fdab1834..d9f57bc4f34 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/TreeCopy.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/TreeCopy.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.nj2k.tree.JKElement import org.jetbrains.kotlin.nj2k.tree.impl.JKElementBase import org.jetbrains.kotlin.nj2k.tree.withNonCodeElementsFrom +@Suppress("UNCHECKED_CAST") fun T.copyTree(): T = when (this) { is JKElementBase -> diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/BlockToRunConversion.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/BlockToRunConversion.kt index 609dd186c3e..a85a8d3efe9 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/BlockToRunConversion.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/BlockToRunConversion.kt @@ -16,8 +16,7 @@ class BlockToRunConversion(private val context: NewJ2kConverterContext) : Recurs if (element.parent !is JKBlock) return recurse(element) val parentDeclaration = element.parentOfType() ?: return recurse(element) - val psiContext = parentDeclaration.psi ?: return recurse(element) - + if (parentDeclaration.psi == null) return recurse(element) element.invalidate() val lambda = JKLambdaExpressionImpl( diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/CompositeConversion.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/CompositeConversion.kt index 5d31fc01eef..a124066aa2f 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/CompositeConversion.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/CompositeConversion.kt @@ -54,9 +54,11 @@ internal inline fun batchPipe(crossinline configure: PipelineConversionBuilder context.symbolProvider.provideDirectSymbol(target.containingClass()!!) as JKClassSymbol this is JKUniverseFieldSymbol && target is JKEnumConstant -> - context.symbolProvider.provideUniverseSymbol(target.parentOfType()!!) as JKClassSymbol + context.symbolProvider.provideUniverseSymbol(target.parentOfType()!!) else -> null } } \ No newline at end of file diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/ForConversion.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/ForConversion.kt index f259d0073d3..483c1b10b6d 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/ForConversion.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/ForConversion.kt @@ -185,7 +185,7 @@ class ForConversion(private val context: NewJ2kConverterContext) : RecursiveAppl convertBound(bound, if (inclusiveComparison) 0 else -1), JKKtSingleValueOperatorToken(KtTokens.RANGE), context.symbolProvider - )!! + ) } } @@ -203,7 +203,7 @@ class ForConversion(private val context: NewJ2kConverterContext) : RecursiveAppl JKKtLiteralExpressionImpl(abs(correction).toString(), JKLiteralExpression.LiteralType.INT), JKKtSingleValueOperatorToken(sign), context.symbolProvider - )!! + ) } private fun indicesIterationRange( @@ -265,7 +265,7 @@ class ForConversion(private val context: NewJ2kConverterContext) : RecursiveAppl } private fun toIndicesCall(javaSizeCall: JKQualifiedExpression): JKQualifiedExpression? { - val psiContext = javaSizeCall.psi ?: return null + if (javaSizeCall.psi == null) return null val selector = JKFieldAccessExpressionImpl( context.symbolProvider.provideByFqName( "kotlin/collections/indices", diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/RecursiveApplicableConversionBase.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/RecursiveApplicableConversionBase.kt index 82b386e439f..31c740d8cb5 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/RecursiveApplicableConversionBase.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/RecursiveApplicableConversionBase.kt @@ -23,7 +23,5 @@ abstract class RecursiveApplicableConversionBase : MatchBasedConversion() { abstract fun applyToElement(element: JKTreeElement): JKTreeElement - inline fun recurse(element: T): T { - return applyRecursive(element, ::applyToElement) - } + fun recurse(element: T): T = applyRecursive(element, ::applyToElement) } \ No newline at end of file diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/TypeMappingConversion.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/TypeMappingConversion.kt index 2e757a0da0e..694c06a2e19 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/TypeMappingConversion.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/conversions/TypeMappingConversion.kt @@ -122,7 +122,6 @@ class TypeMappingConversion(val context: NewJ2kConverterContext) : RecursiveAppl val newFqName = typeElement?.let { kotlinCollectionClassName(it) } ?: kotlinStandardType() ?: fqName - ?: return this return context.symbolProvider.provideByFqName(newFqName) } diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/expressions.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/expressions.kt index 6d9ca0dce34..99ceff35ff9 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/expressions.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/expressions.kt @@ -327,7 +327,7 @@ fun stringLiteral(content: String, symbolProvider: JKSymbolProvider): JKExpressi val newlineSeparator = if (i == lines.size - 1) "" else "\\n" JKKtLiteralExpressionImpl("\"$line$newlineSeparator\"", JKLiteralExpression.LiteralType.STRING) }.reduce { acc: JKExpression, literalExpression: JKKtLiteralExpression -> - kotlinBinaryExpression(acc, literalExpression, JKKtSingleValueOperatorToken(KtTokens.PLUS), symbolProvider)!! + kotlinBinaryExpression(acc, literalExpression, JKKtSingleValueOperatorToken(KtTokens.PLUS), symbolProvider) } } @@ -576,8 +576,7 @@ fun JKExpression.asLiteralTextWithPrefix(): String? = else -> null } -inline fun JKClass.primaryConstructor(): JKKtPrimaryConstructor? = - classBody.declarations.firstIsInstanceOrNull() +fun JKClass.primaryConstructor(): JKKtPrimaryConstructor? = classBody.declarations.firstIsInstanceOrNull() fun List.toArgumentList(): JKArgumentList = JKArgumentListImpl(map { JKArgumentImpl(it) }) @@ -597,11 +596,11 @@ fun JKAnnotation.isVarargsArgument(index: Int): Boolean { fun JKExpression.asStatement(): JKExpressionStatement = JKExpressionStatementImpl(this) -inline fun T.nullIfStubExpression(): T? = +fun T.nullIfStubExpression(): T? = if (this is JKStubExpression) null else this -inline fun JKExpression.qualified(qualifier: JKExpression?) = +fun JKExpression.qualified(qualifier: JKExpression?) = if (qualifier != null && qualifier !is JKStubExpression) { JKQualifiedExpressionImpl(qualifier, JKJavaQualifierImpl.DOT, this) } else this \ No newline at end of file diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/base.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/base.kt index 0b4a5eb86bf..0f35aa1391e 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/base.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/base.kt @@ -16,10 +16,12 @@ import kotlin.reflect.KProperty private class JKChild(val value: Int) : ReadWriteProperty { override operator fun getValue(thisRef: JKBranchElementBase, property: KProperty<*>): T { + @Suppress("UNCHECKED_CAST") return thisRef.children[value] as T } override operator fun setValue(thisRef: JKBranchElementBase, property: KProperty<*>, value: T) { + @Suppress("UNCHECKED_CAST") (thisRef.children[this.value] as T).detach(thisRef) thisRef.children[this.value] = value value.attach(thisRef) @@ -28,10 +30,12 @@ private class JKChild(val value: Int) : ReadWriteProperty(val value: Int) : ReadWriteProperty> { override operator fun getValue(thisRef: JKBranchElementBase, property: KProperty<*>): List { + @Suppress("UNCHECKED_CAST") return thisRef.children[value] as List } override operator fun setValue(thisRef: JKBranchElementBase, property: KProperty<*>, value: List) { + @Suppress("UNCHECKED_CAST") (thisRef.children[this.value] as List).forEach { it.detach(thisRef) } thisRef.children[this.value] = value value.forEach { it.attach(thisRef) } @@ -98,6 +102,7 @@ abstract class JKBranchElementBase : JKElementBase(), JKBranchElement { protected inline fun forEachChild(block: (JKTreeElement) -> Unit) { children.forEach { + @Suppress("UNCHECKED_CAST") if (it is JKTreeElement) block(it) else @@ -120,6 +125,7 @@ abstract class JKBranchElementBase : JKElementBase(), JKBranchElement { final override var children: MutableList = mutableListOf() private set + @Suppress("UNCHECKED_CAST") override fun copy(): JKTreeElement { val cloned = super.copy() as JKBranchElementBase val deepClonedChildren = diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/jk.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/jk.kt index f47da2d6c67..5614e8b6437 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/jk.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/jk.kt @@ -217,8 +217,7 @@ class JKStarProjectionTypeImpl : JKStarProjectionType fun JKType.fqName(): String = when (this) { is JKClassType -> { - val target = classReference?.target - when (target) { + when (val target = classReference.target) { is KtClass -> target.fqName?.asString() ?: throw RuntimeException("FqName can not be calculated") is PsiClass -> target.qualifiedName ?: throw RuntimeException("FqName can not be calculated") else -> TODO(target.toString()) @@ -473,8 +472,7 @@ class PsiOwnerImpl(override var psi: PsiElement? = null) : PsiOwner val JKElement.psi: PsiElement? get() = (this as? PsiOwner)?.psi -fun JKElement.psi(): Elem? = - (this as? PsiOwner)?.psi as? Elem +inline fun JKElement.psi(): Elem? = (this as? PsiOwner)?.psi as? Elem class JKTypeParameterListImpl(typeParameters: List = emptyList()) : JKTypeParameterList, JKBranchElementBase() { override var typeParameters by children(typeParameters) diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/symbols.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/symbols.kt index 4c74d61f74c..a0b930e30e1 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/symbols.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/impl/symbols.kt @@ -178,6 +178,7 @@ class JKMultiverseMethodSymbol(override val target: PsiMethod, private val symbo class JKMultiverseFunctionSymbol(override val target: KtFunction, private val symbolProvider: JKSymbolProvider) : JKMethodSymbol { override val receiverType: JKType? get() = target.receiverTypeReference?.toJK(symbolProvider) + @Suppress("UNCHECKED_CAST") override val parameterTypes: List? get() = target.valueParameters.map { parameter -> val type = parameter.typeReference?.toJK(symbolProvider) diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/markers.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/markers.kt index 57c5502b565..5a221e306fe 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/markers.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/markers.kt @@ -171,6 +171,7 @@ fun applyRecursive( val child = iter.next() if (child is List<*>) { + @Suppress("UNCHECKED_CAST") iter.set(applyRecursiveToList(element, child as List, iter, data, func)) } else if (child is JKTreeElement) { val newChild = func(child, data) diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt index d1653b7fb92..2870a85ed4d 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt @@ -25,7 +25,7 @@ interface JKNonCodeElementsListOwner { var rightNonCodeElements: List } -inline fun JKNonCodeElementsListOwner.takeNonCodeElementsFrom(other: JKNonCodeElementsListOwner) { +fun JKNonCodeElementsListOwner.takeNonCodeElementsFrom(other: JKNonCodeElementsListOwner) { leftNonCodeElements = other.leftNonCodeElements rightNonCodeElements = other.rightNonCodeElements } @@ -43,7 +43,7 @@ fun JKTreeElement.commentsFromInside(): List { inline fun T.withNonCodeElementsFrom(other: JKNonCodeElementsListOwner): T = also { it.takeNonCodeElementsFrom(other) } -inline fun JKNonCodeElementsListOwner.clearNonCodeElements() { +fun JKNonCodeElementsListOwner.clearNonCodeElements() { leftNonCodeElements = emptyList() rightNonCodeElements = emptyList() } diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/types.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/types.kt index 77ed6d114b3..14294d977d7 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/types.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/types.kt @@ -226,6 +226,7 @@ inline fun T.updateNullability(newNullability: Nullability) else -> TODO(this::class.toString()) } as T +@Suppress("UNCHECKED_CAST") fun T.updateNullabilityRecursively(newNullability: Nullability): T = applyRecursive { when (it) { diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt index 54863a0de3d..2c8a3bc28f7 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableResolveExtension.kt @@ -18,7 +18,8 @@ package org.jetbrains.kotlin.android.parcel import kotlinx.android.parcel.Parceler import kotlinx.android.parcel.Parcelize -import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.* +import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.DESCRIBE_CONTENTS +import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.WRITE_TO_PARCEL import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations @@ -82,33 +83,35 @@ open class ParcelableResolveExtension : SyntheticResolveExtension { override fun getSyntheticCompanionObjectNameIfNeeded(thisDescriptor: ClassDescriptor) = null override fun generateSyntheticMethods( - clazz: ClassDescriptor, + thisDescriptor: ClassDescriptor, name: Name, bindingContext: BindingContext, fromSupertypes: List, result: MutableCollection ) { fun isExperimental(): Boolean { - val sourceElement = (clazz.source as? PsiSourceElement)?.psi as? KtElement ?: return false + val sourceElement = (thisDescriptor.source as? PsiSourceElement)?.psi as? KtElement ?: return false return isExperimental(sourceElement) } if (name.asString() == DESCRIBE_CONTENTS.methodName - && clazz.isParcelize - && isExperimental() - && result.none { it.isDescribeContents() } - && fromSupertypes.none { it.isDescribeContents() } + && thisDescriptor.isParcelize + && isExperimental() + && result.none { it.isDescribeContents() } + && fromSupertypes.none { it.isDescribeContents() } ) { - result += createMethod(clazz, DESCRIBE_CONTENTS, Modality.OPEN, clazz.builtIns.intType) + result += createMethod(thisDescriptor, DESCRIBE_CONTENTS, Modality.OPEN, thisDescriptor.builtIns.intType) } else if (name.asString() == WRITE_TO_PARCEL.methodName - && clazz.isParcelize - && isExperimental() - && result.none { it.isWriteToParcel() } + && thisDescriptor.isParcelize + && isExperimental() + && result.none { it.isWriteToParcel() } ) { - val builtIns = clazz.builtIns - val parcelClassType = resolveParcelClassType(clazz.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type") - result += createMethod(clazz, WRITE_TO_PARCEL, Modality.OPEN, - builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType) + val builtIns = thisDescriptor.builtIns + val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type") + result += createMethod( + thisDescriptor, WRITE_TO_PARCEL, Modality.OPEN, + builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType + ) } } diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/serializers/ParcelSerializers.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/serializers/ParcelSerializers.kt index 7a39c5b3c74..9ca7060a2cb 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/serializers/ParcelSerializers.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/serializers/ParcelSerializers.kt @@ -816,12 +816,12 @@ private fun writeValueNullAware(v: InstructionAdapter, block: () -> Unit) { v.goTo(labelReturn) - labelNull@ v.visitLabel(labelNull) + v.visitLabel(labelNull) v.pop() v.aconst(0) v.invokevirtual(PARCEL_TYPE.internalName, "writeInt", "(I)V", false) - labelReturn@ v.visitLabel(labelReturn) + v.visitLabel(labelReturn) } internal class Method(val name: String, val signature: T) { diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/AndroidExtensionsReferenceSearchExecutor.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/AndroidExtensionsReferenceSearchExecutor.kt index 4adb66fd699..bb256a28a0f 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/AndroidExtensionsReferenceSearchExecutor.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/AndroidExtensionsReferenceSearchExecutor.kt @@ -37,6 +37,7 @@ class AndroidExtensionsReferenceSearchExecutor : QueryExecutorBase) { val elementToSearch = queryParameters.elementToSearch as? XmlAttributeValue ?: return val scopeElements = (queryParameters.effectiveSearchScope as? LocalSearchScope)?.scope ?: return + @Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") // BUNCH: 182 val referenceName = elementToSearch.value?.substringAfterLast("/") ?: return scopeElements.filterIsInstance().forEach { diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidSimpleNameReferenceExtension.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidSimpleNameReferenceExtension.kt index 41bf4a44b45..851e00e8b03 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidSimpleNameReferenceExtension.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidSimpleNameReferenceExtension.kt @@ -33,7 +33,7 @@ class AndroidSimpleNameReferenceExtension : SimpleNameReferenceExtension { element is XmlFile && reference.isReferenceToXmlFile(element) private fun isLayoutPackageIdentifier(reference: KtSimpleNameReference): Boolean { - val probablyVariant = reference.element?.parent as? KtDotQualifiedExpression ?: return false + val probablyVariant = reference.element.parent as? KtDotQualifiedExpression ?: return false val probablyKAS = probablyVariant.receiverExpression as? KtDotQualifiedExpression ?: return false return probablyKAS.receiverExpression.text == AndroidConst.SYNTHETIC_PACKAGE } @@ -51,6 +51,7 @@ class AndroidSimpleNameReferenceExtension : SimpleNameReferenceExtension { return null } + @Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") // BUNCH: 182 private fun isIdDeclaration(declaration: XmlAttributeValue) = declaration.value?.startsWith("@+id/") ?: false private fun KtSimpleNameReference.isReferenceToXmlFile(xmlFile: XmlFile): Boolean { diff --git a/plugins/android-extensions/android-extensions-idea/tests/org/jetbrains/kotlin/android/AbstractAndroidFindUsagesTest.kt b/plugins/android-extensions/android-extensions-idea/tests/org/jetbrains/kotlin/android/AbstractAndroidFindUsagesTest.kt index 7a784467853..0823eb848cb 100644 --- a/plugins/android-extensions/android-extensions-idea/tests/org/jetbrains/kotlin/android/AbstractAndroidFindUsagesTest.kt +++ b/plugins/android-extensions/android-extensions-idea/tests/org/jetbrains/kotlin/android/AbstractAndroidFindUsagesTest.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.android abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() { + @Suppress("UNREACHABLE_CODE") fun doTest(path: String) { return // TODO: investigate and fix this test copyResourceDirectoryForTest(path) diff --git a/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiAnalysisHandlerExtension.kt b/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiAnalysisHandlerExtension.kt index 1c9c5764416..daecba31d53 100644 --- a/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiAnalysisHandlerExtension.kt +++ b/plugins/jvm-abi-gen/src/org/jetbrains/kotlin/jvm/abi/JvmAbiAnalysisHandlerExtension.kt @@ -108,7 +108,7 @@ class JvmAbiAnalysisHandlerExtension( val visitor = InnerClassesCollectingVisitor() output.accept(visitor) - val outputInternalName = visitor.ownInternalName!! + val outputInternalName = visitor.ownInternalName internalNameToFile[outputInternalName] = output.file innerClasses[outputInternalName] = visitor.innerClasses } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt index a1e1d4ff9a4..63dbcd7021f 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt @@ -112,7 +112,7 @@ private class TypeTreeVisitor(val elementUtils: Elements, val trees: Trees, val val newVisibility = if (node.sym.getKind() == ElementKind.FIELD) { val flags = node.modifiers.getFlags() - node.sym.constValue?.let { constValue -> + node.sym.constValue?.let { _ -> constantTreeVisitor.scan(trees.getPath(compilationUnit, node.init), null) } if (flags.contains(Modifier.PRIVATE)) Visibility.NON_ABI else Visibility.ABI diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt index 59b8e834e9d..c85008e47eb 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt @@ -475,7 +475,7 @@ interface IrBuilderExtension { compilerContext.externalSymbols.referenceClass(module.getClassFromInternalSerializationPackage(SpecialBuiltins.nullableSerializer)) if (serializerClassOriginal == null) { if (genericIndex == null) return null - val thiz = enclosingGenerator.irClass.thisReceiver!! + val prop = enclosingGenerator.localSerializersFieldsDescriptors[genericIndex] return irGetField(irGet(dispatchReceiverParameter), compilerContext.localSymbolTable.referenceField(prop).owner) } diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt index 97aa5539bf5..5ed7712dcc2 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt @@ -176,7 +176,6 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext: serializerTower(this@SerializerIrGenerator, irFun.dispatchReceiverParameter!!, it)) { "Property ${it.name} must have a serializer" } } - val kSer = serializableDescriptor.module.getClassFromSerializationPackage(KSERIALIZER_NAME.identifier) val kSerType = ((irFun.returnType as IrSimpleType).arguments.first() as IrTypeProjection).type val array = createArrayOfExpression(kSerType, allSerializers) +irReturn(array) diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/resolve/KSerializerDescriptorResolver.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/resolve/KSerializerDescriptorResolver.kt index 0022261ad95..e9890e93f32 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/resolve/KSerializerDescriptorResolver.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/resolve/KSerializerDescriptorResolver.kt @@ -350,14 +350,12 @@ object KSerializerDescriptorResolver { ) val serializerClass = classDescriptor.getClassFromSerializationPackage(SerialEntityNames.KSERIALIZER_CLASS) assert(serializableDescriptor.declaredTypeParameters.size == typeParameters.size) - val args = serializableDescriptor.declaredTypeParameters.mapIndexed { index, param -> - - val pType = - KotlinTypeFactory.simpleNotNullType( - Annotations.EMPTY, - serializerClass, - listOf(TypeProjectionImpl(typeParameters[index].defaultType)) - ) + val args = List(serializableDescriptor.declaredTypeParameters.size) { index -> + val pType = KotlinTypeFactory.simpleNotNullType( + Annotations.EMPTY, + serializerClass, + listOf(TypeProjectionImpl(typeParameters[index].defaultType)) + ) ValueParameterDescriptorImpl( constrDesc, null, index, Annotations.EMPTY, Name.identifier("$typeArgPrefix$index"), pType, diff --git a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinition.kt b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinition.kt index 68d46149335..1cb1ebf7070 100644 --- a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinition.kt +++ b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinition.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.psi.KtScript import kotlin.reflect.KClass import kotlin.reflect.KType import kotlin.script.experimental.dependencies.DependenciesResolver -import kotlin.script.experimental.location.ScriptExpectedLocation import kotlin.script.templates.standard.ScriptTemplateWithArgs open class KotlinScriptDefinition(open val template: KClass) : UserDataHolderBase() { @@ -48,8 +47,12 @@ open class KotlinScriptDefinition(open val template: KClass) : UserData @Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon") open val additionalCompilerArguments: Iterable? = null - open val scriptExpectedLocations: List = - listOf(ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly) + @Suppress("DEPRECATION") + open val scriptExpectedLocations: List = + listOf( + kotlin.script.experimental.location.ScriptExpectedLocation.SourcesOnly, + kotlin.script.experimental.location.ScriptExpectedLocation.TestsOnly + ) open val implicitReceivers: List get() = emptyList() diff --git a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinitionAdapterFromNewAPI.kt b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinitionAdapterFromNewAPI.kt index fbb8c3bb241..ad6d72c9145 100644 --- a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinitionAdapterFromNewAPI.kt +++ b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/definitions/KotlinScriptDefinitionAdapterFromNewAPI.kt @@ -57,7 +57,10 @@ abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinit override val acceptedAnnotations: List> by lazy(LazyThreadSafetyMode.PUBLICATION) { scriptCompilationConfiguration[ScriptCompilationConfiguration.refineConfigurationOnAnnotations]?.annotations .orEmpty() - .map { getScriptingClass(it) as KClass } + .map { + @Suppress("UNCHECKED_CAST") + getScriptingClass(it) as KClass + } } override val implicitReceivers: List by lazy(LazyThreadSafetyMode.PUBLICATION) { @@ -75,9 +78,10 @@ abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinit get() = scriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions] .orEmpty() + @Suppress("DEPRECATION") override val scriptExpectedLocations: List get() = scriptCompilationConfiguration[ScriptCompilationConfiguration.ide.acceptedLocations]?.map { - when(it) { + when (it) { ScriptAcceptedLocation.Sources -> ScriptExpectedLocation.SourcesOnly ScriptAcceptedLocation.Tests -> ScriptExpectedLocation.TestsOnly ScriptAcceptedLocation.Libraries -> ScriptExpectedLocation.Libraries diff --git a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/resolve/ScriptContentLoader.kt b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/resolve/ScriptContentLoader.kt index 47008f2074e..70c62bdccaf 100644 --- a/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/resolve/ScriptContentLoader.kt +++ b/plugins/scripting/scripting-compiler-impl/src/org/jetbrains/kotlin/scripting/resolve/ScriptContentLoader.kt @@ -37,6 +37,7 @@ class ScriptContentLoader(private val project: Project) { scriptDefinition.acceptedAnnotations.find { ann -> psiAnn.typeName.let { it == ann.simpleName || it == ann.qualifiedName } }?.let { + @Suppress("UNCHECKED_CAST") constructAnnotation( psiAnn, classLoader.loadClass(it.qualifiedName).kotlin as KClass, diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt index 464fcce1157..f474533049e 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -202,7 +202,10 @@ internal object KotlinConverter { expectedTypes: Array> ): UElement? { fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? { - return { ctor(element as P, givenParent) } + return { + @Suppress("UNCHECKED_CAST") + ctor(element as P, givenParent) + } } return with (expectedTypes) { when (element) { @@ -306,7 +309,10 @@ internal object KotlinConverter { requiredType: Array> ): UExpression? { fun

build(ctor: (P, UElement?) -> UExpression): () -> UExpression? { - return { ctor(expression as P, givenParent) } + return { + @Suppress("UNCHECKED_CAST") + ctor(expression as P, givenParent) + } } return with (requiredType) { when (expression) { @@ -448,13 +454,20 @@ internal object KotlinConverter { givenParent: UElement?, expectedTypes: Array> ): UElement? { - fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) } + fun

build(ctor: (P, UElement?) -> UElement): () -> UElement? = { + @Suppress("UNCHECKED_CAST") + ctor(element as P, givenParent) + } - fun

buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = - { ctor(element as P, ktElement, givenParent) } + fun

buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = { + @Suppress("UNCHECKED_CAST") + ctor(element as P, ktElement, givenParent) + } - fun

buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = - { ctor(element as P, ktElement, givenParent) } + fun

buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = { + @Suppress("UNCHECKED_CAST") + ctor(element as P, ktElement, givenParent) + } val original = element.originalElement return with(expectedTypes) { @@ -631,6 +644,7 @@ internal object KotlinConverter { val file = createAnalyzableFile("dummy.kt", text, context) val declarations = file.declarations assert(declarations.size == 1) { "${declarations.size} declarations in $text" } + @Suppress("UNCHECKED_CAST") return declarations.first() as TDeclaration } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt index fe7e40dc45e..9f21c28d36e 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUSimpleReferenceExpression.kt @@ -102,17 +102,15 @@ open class KotlinUSimpleReferenceExpression( null } - if (resolvedCall != null) { - if (access.isRead) { - val getDescriptor = resultingDescriptor.getMethod - KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor) - } + if (access.isRead) { + val getDescriptor = resultingDescriptor.getMethod + KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor) + } - if (access.isWrite && setterValue != null) { - val setDescriptor = resultingDescriptor.setMethod - if (setDescriptor != null) { - KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor) - } + if (access.isWrite && setterValue != null) { + val setDescriptor = resultingDescriptor.setMethod + if (setDescriptor != null) { + KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor) } } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt index 535d277531b..606a409f92a 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt @@ -1,6 +1,7 @@ package org.jetbrains.uast.kotlin.expressions import com.intellij.psi.PsiElement +import com.intellij.psi.PsiExpression import com.intellij.psi.PsiType import com.intellij.psi.PsiVariable import org.jetbrains.kotlin.psi.KtFunction @@ -11,9 +12,9 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable internal class KotlinLocalFunctionUVariable( - val function: KtFunction, - override val psi: PsiVariable, - givenParent: UElement? + val function: KtFunction, + override val psi: PsiVariable, + givenParent: UElement? ) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by psi { override val javaPsi = psi @@ -25,6 +26,13 @@ internal class KotlinLocalFunctionUVariable( override val typeReference: UTypeReferenceExpression? = null override val uastAnchor: UElement? = null override val annotations: List = emptyList() + override fun getOriginalElement(): PsiElement { + return psi.originalElement + } + + override fun getInitializer(): PsiExpression? { + return psi.initializer + } }