Minor: Move DumpService-related functions to dumbUtils.kt

This commit is contained in:
Alexey Sedunov
2015-10-22 21:10:43 +03:00
committed by Alexey Sedunov
parent 8d3296e08d
commit b6c01c0f94
4 changed files with 37 additions and 14 deletions
@@ -25,11 +25,6 @@ public fun runReadAction<T>(action: () -> T): T {
return ApplicationManager.getApplication().runReadAction<T>(action)
}
public fun <T> Project.runReadActionInSmartMode(action: () -> T): T {
if (ApplicationManager.getApplication().isReadAccessAllowed) return action()
return DumbService.getInstance(this).runReadActionInSmartMode<T>(action)
}
public fun runWriteAction<T>(action: () -> T): T {
return ApplicationManager.getApplication().runWriteAction<T>(action)
}
@@ -47,11 +42,4 @@ public fun <T> Project.executeCommand(name: String, groupId: Any? = null, comman
CommandProcessor.getInstance().executeCommand(this, { result = command() }, name, groupId)
@Suppress("USELESS_CAST")
return result as T
}
public fun <T> Project.runWithAlternativeResolveEnabled(action: () -> T): T {
var result: T = null as T
DumbService.getInstance(this).withAlternativeResolveEnabled { result = action() }
@Suppress("USELESS_CAST")
return result as T
}
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.util
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
public fun <T> Project.runReadActionInSmartMode(action: () -> T): T {
if (ApplicationManager.getApplication().isReadAccessAllowed) return action()
return DumbService.getInstance(this).runReadActionInSmartMode<T>(action)
}
public fun <T> Project.runWithAlternativeResolveEnabled(action: () -> T): T {
var result: T = null as T
DumbService.getInstance(this).withAlternativeResolveEnabled { result = action() }
@Suppress("USELESS_CAST")
return result as T
}
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.readWriteAccess
import org.jetbrains.kotlin.idea.search.restrictToKotlinSources
import org.jetbrains.kotlin.idea.util.application.runReadActionInSmartMode
import org.jetbrains.kotlin.idea.util.runReadActionInSmartMode
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName
import org.jetbrains.kotlin.name.Name
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.idea.core.refactoring.j2k
import org.jetbrains.kotlin.idea.core.refactoring.toPsiDirectory
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.util.application.executeCommand
import org.jetbrains.kotlin.idea.util.application.runWithAlternativeResolveEnabled
import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
@@ -133,6 +133,8 @@ class KotlinCreateTestIntention : JetSelfTargetingRangeIntention<KtClassOrObject
}
} as? PsiClass ?: return
val generatedFile = generatedClass.containingFile as? PsiJavaFile ?: return
if (generatedClass.language == JavaLanguage.INSTANCE) {