From d9f5bd013ba2a3d2c169d6cf8444747bdc692a86 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 17 Oct 2014 12:56:30 +0400 Subject: [PATCH] Clean up declarations of runReadAction() etc --- .../plugin/search/usagesSearch/usagesSearch.kt | 2 +- .../jetbrains/jet/plugin/util/ApplicationUtils.kt | 15 ++++++++------- .../jetbrains/jet/plugin/util/ProjectRootsUtil.kt | 2 +- .../debugger/evaluate/KotlinEvaluationBuilder.kt | 6 +++--- .../handlers/KotlinFindClassUsagesHandler.kt | 2 +- .../KotlinTypeParameterFindUsagesHandler.kt | 2 +- .../rename/RenameKotlinPropertyProcessor.kt | 2 +- .../plugin/debugger/AbstractKotlinSteppingTest.kt | 2 +- .../refactoring/move/AbstractJetMoveTest.kt | 2 +- .../jet/plugin/run/RunConfigurationTest.kt | 4 ++-- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/search/usagesSearch/usagesSearch.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/search/usagesSearch/usagesSearch.kt index a7b6abcb1bc..f9498711318 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/search/usagesSearch/usagesSearch.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/search/usagesSearch/usagesSearch.kt @@ -144,7 +144,7 @@ public class KotlinPsiSearchHelper(private val project: Project): PsiSearchHelpe FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, entries, scope, checker) { file -> !index.shouldBeFound(scope, file) || processor.process(file) } - }!! + } } public fun processFilesWithText(item: UsagesSearchRequestItem, consumer: Processor): Boolean { diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ApplicationUtils.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ApplicationUtils.kt index 3bc48edbffb..a226fde854b 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ApplicationUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ApplicationUtils.kt @@ -20,20 +20,21 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project import com.intellij.openapi.command.CommandProcessor -public fun runReadAction(action: () -> T?): T? { - return ApplicationManager.getApplication()?.runReadAction(action) +public fun runReadAction(action: () -> T): T { + return ApplicationManager.getApplication().runReadAction(action) } -public fun runWriteAction(action: () -> T?): T? { - return ApplicationManager.getApplication()?.runWriteAction(action) +public fun runWriteAction(action: () -> T): T { + return ApplicationManager.getApplication().runWriteAction(action) } public fun Project.executeWriteCommand(name: String, command: () -> Unit) { CommandProcessor.getInstance().executeCommand(this, { runWriteAction(command) }, name, null) } -public fun Project.executeWriteCommand(name: String, command: () -> T): T { - var result: T? = null +public fun Project.executeWriteCommand(name: String, command: () -> T): T { + var result: T = null as T CommandProcessor.getInstance().executeCommand(this, { result = runWriteAction(command) }, name, null) - return result!! + [suppress("USELESS_CAST")] + return result as T } \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ProjectRootsUtil.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ProjectRootsUtil.kt index 681fb850d2b..1b165e04831 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ProjectRootsUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/util/ProjectRootsUtil.kt @@ -50,7 +50,7 @@ public object ProjectRootsUtil { val project = element.getProject() return@runReadAction isInSources(project, virtualFile, includeLibrarySources, withLibraryClassesRoots) - }!! + } } platformStatic diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt index 854a7825a3e..6ab23427f3f 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -221,7 +221,7 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment, } } parameters - }!! + } } private fun EvaluationContextImpl.getArgumentsForEval4j(parameterNames: List, parameterTypes: Array): List { @@ -246,7 +246,7 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment, KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION) state.getFactory() - }!! + } } private fun exception(msg: String) = throw EvaluateExceptionUtil.createEvaluateException(msg) @@ -328,7 +328,7 @@ fun EvaluationContextImpl.findLocalVariable(name: String, asmType: Type?, checkT val thisDesc = value.asmType.getClassDescriptor(project) val expDesc = asmType.getClassDescriptor(project) - return thisDesc != null && expDesc != null && runReadAction { DescriptorUtils.isSubclass(thisDesc, expDesc) }!! + return thisDesc != null && expDesc != null && runReadAction { DescriptorUtils.isSubclass(thisDesc, expDesc) } } diff --git a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindClassUsagesHandler.kt b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindClassUsagesHandler.kt index 0053035b29a..4b9a53d7892 100644 --- a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindClassUsagesHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindClassUsagesHandler.kt @@ -81,7 +81,7 @@ public class KotlinFindClassUsagesHandler( val declarationUsages = kotlinOptions.toClassDeclarationsHelper().newRequest(target).search() (classUsages + declarationUsages).all { ref -> KotlinFindUsagesHandler.processUsage(processor, ref) } && processInheritors() - }!! + } } protected override fun isSearchForTextOccurencesAvailable(psiElement: PsiElement, isSingleFile: Boolean): Boolean { diff --git a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinTypeParameterFindUsagesHandler.kt b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinTypeParameterFindUsagesHandler.kt index f649b73f5e4..8ac81da530e 100644 --- a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinTypeParameterFindUsagesHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinTypeParameterFindUsagesHandler.kt @@ -47,7 +47,7 @@ public class KotlinTypeParameterFindUsagesHandler( val target = options.toSearchTarget(element as JetNamedDeclaration, true) val request = DefaultSearchHelper().newRequest(target) request.search().all { ref -> KotlinFindUsagesHandler.processUsage(processor, ref) } - }!! + } } public override fun getFindUsagesOptions(dataContext: DataContext?): FindUsagesOptions { diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinPropertyProcessor.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinPropertyProcessor.kt index 32383b0ec69..f1586fd602d 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinPropertyProcessor.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinPropertyProcessor.kt @@ -83,7 +83,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() { val jetProperty = element?.namedUnwrappedElement as? JetProperty if (jetProperty == null) throw IllegalStateException("Can't be for element $element there because of canProcessElement()") - val propertyMethods = runReadAction { LightClassUtil.getLightClassPropertyMethods(jetProperty) }!! + val propertyMethods = runReadAction { LightClassUtil.getLightClassPropertyMethods(jetProperty) } for (propertyMethod in propertyMethods) { addRenameElements(propertyMethod, jetProperty.getName(), newName, allRenames, scope) diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt index 78d78a5d546..37b183f626d 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt @@ -128,6 +128,6 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { else -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines()) } } - }!! + } } } diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt b/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt index e27e2f7b793..23da901ab01 100644 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/move/AbstractJetMoveTest.kt @@ -75,7 +75,7 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() { } offset - }!! + } } val config = JsonParser().parse(FileUtil.loadFile(File(path), true)) as JsonObject diff --git a/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt index 888f9b68de4..7baa48f0bf4 100644 --- a/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/run/RunConfigurationTest.kt @@ -62,7 +62,7 @@ class RunConfigurationTest: CodeInsightTestCase() { fun testDependencyModuleClasspath() { val dependencyModuleSrcDir = configureModule(moduleDirPath("module"), getTestProject().getBaseDir()!!).src - val moduleWithDependencyDir = runWriteAction { getTestProject().getBaseDir()!!.createChildDirectory(this, "moduleWithDependency") }!! + val moduleWithDependencyDir = runWriteAction { getTestProject().getBaseDir()!!.createChildDirectory(this, "moduleWithDependency") } val moduleWithDependency = createModule("moduleWithDependency") ModuleRootModificationUtil.setModuleSdk(moduleWithDependency, getTestProjectJdk()) @@ -109,7 +109,7 @@ class RunConfigurationTest: CodeInsightTestCase() { PsiTestUtil.setCompilerOutputPath(configModule, testOutDir.getUrl(), true) Pair(srcOutDir, testOutDir) - }!! + } PsiDocumentManager.getInstance(getTestProject()).commitAllDocuments()