From e2f1a5c0926764f0a9291b32afc5a74aec213363 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 1 Feb 2016 14:16:04 +0300 Subject: [PATCH] Minor: refactoring --- .../UsePropertyAccessSyntaxIntention.kt | 3 ++- .../idea/versions/KotlinRuntimeLibraryUtil.kt | 27 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index 2e728436a8a..3a91f44e204 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DelegatingBindingTrace import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo +import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression import org.jetbrains.kotlin.resolve.calls.CallResolver import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker @@ -97,7 +98,7 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention val isSetUsage = callExpression.valueArguments.size == 1 - if (isSetUsage && bindingContext[BindingContext.USED_AS_EXPRESSION, qualifiedExpression] == true) { + if (isSetUsage && qualifiedExpression.isUsedAsExpression(bindingContext)) { // call to the setter used as expression can be converted in the only case when it's used as body expression for some declaration and its type is Unit val parent = qualifiedExpression.parent if (parent !is KtDeclarationWithBody || qualifiedExpression != parent.bodyExpression) return null diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt index ea526c7aac9..1803efb4421 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt @@ -67,11 +67,11 @@ fun updateLibraries( project: Project, libraries: Collection) { ApplicationManager.getApplication().invokeLater { - val kJvmConfigurator = getConfiguratorByName(KotlinJavaModuleConfigurator.NAME) as KotlinJavaModuleConfigurator? - assert(kJvmConfigurator != null) { "Configurator with given name doesn't exists: " + KotlinJavaModuleConfigurator.NAME } + val kJvmConfigurator = getConfiguratorByName(KotlinJavaModuleConfigurator.NAME) as KotlinJavaModuleConfigurator? ?: + error("Configurator with given name doesn't exists: " + KotlinJavaModuleConfigurator.NAME) - val kJsConfigurator = getConfiguratorByName(KotlinJsModuleConfigurator.NAME) as KotlinJsModuleConfigurator? - assert(kJsConfigurator != null) { "Configurator with given name doesn't exists: " + KotlinJsModuleConfigurator.NAME } + val kJsConfigurator = getConfiguratorByName(KotlinJsModuleConfigurator.NAME) as KotlinJsModuleConfigurator? ?: + error("Configurator with given name doesn't exists: " + KotlinJsModuleConfigurator.NAME) for (library in libraries) { if (LibraryPresentationProviderUtil.isDetected(JavaRuntimePresentationProvider.getInstance(), library)) { @@ -79,7 +79,7 @@ fun updateLibraries( updateJar(project, JavaRuntimePresentationProvider.getReflectJar(library), LibraryJarDescriptor.REFLECT_JAR) updateJar(project, JavaRuntimePresentationProvider.getTestJar(library), LibraryJarDescriptor.TEST_JAR) - if (kJvmConfigurator!!.changeOldSourcesPathIfNeeded(project, library)) { + if (kJvmConfigurator.changeOldSourcesPathIfNeeded(project, library)) { kJvmConfigurator.copySourcesToPathFromLibrary(project, library) } else { @@ -89,7 +89,7 @@ fun updateLibraries( else if (LibraryPresentationProviderUtil.isDetected(JSLibraryStdPresentationProvider.getInstance(), library)) { updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibJar(library), LibraryJarDescriptor.JS_STDLIB_JAR) - if (kJsConfigurator!!.changeOldSourcesPathIfNeeded(project, library)) { + if (kJsConfigurator.changeOldSourcesPathIfNeeded(project, library)) { kJsConfigurator.copySourcesToPathFromLibrary(project, library) } else { @@ -196,8 +196,8 @@ internal fun replaceFile(updatedFile: File, replacedJarFile: VirtualFile) { try { val replacedFile = getLocalFile(replacedJarFile) - val localPath = getLocalPath(replacedFile) - assert(localPath != null) { "Should be called for replacing valid root file: " + replacedJarFile } + val localPath = getLocalPath(replacedFile) ?: + error("Should be called for replacing valid root file: $replacedJarFile") val libraryJarPath = File(localPath) @@ -229,13 +229,12 @@ private fun getLibraryRootsWithAbiIncompatibleVersion( val fileIndex = ProjectFileIndex.SERVICE.getInstance(module.project) for (version in badVersions) { - val indexedFiles = FileBasedIndex.getInstance().getContainingFiles( - id, version, moduleWithAllDependentLibraries) - + val indexedFiles = FileBasedIndex.getInstance().getContainingFiles(id, version, moduleWithAllDependentLibraries) for (indexedFile in indexedFiles) { - val libraryRoot = fileIndex.getClassRootForFile(indexedFile) - assert(libraryRoot != null) { "Only library roots were requested, " + "and only class files should be indexed with KotlinAbiVersionIndex key. " + "File: " + indexedFile.path } - badRoots.add(getLocalFile(libraryRoot!!)) + val libraryRoot = fileIndex.getClassRootForFile(indexedFile) ?: + error("Only library roots were requested, and only class files should be indexed with KotlinAbiVersionIndex key. " + + "File: ${indexedFile.path}") + badRoots.add(getLocalFile(libraryRoot)) } }