11package org.utbot.intellij.plugin.process
22
33import com.intellij.ide.plugins.cl.PluginClassLoader
4+ import com.intellij.openapi.application.runReadAction
45import com.intellij.openapi.project.DumbService
56import com.intellij.openapi.project.Project
7+ import com.intellij.openapi.util.Computable
68import com.intellij.psi.PsiMethod
79import com.intellij.psi.impl.file.impl.JavaFileManager
810import com.intellij.psi.search.GlobalSearchScope
@@ -30,8 +32,7 @@ import org.utbot.instrumentation.util.KryoHelper
3032import org.utbot.intellij.plugin.UtbotBundle
3133import org.utbot.intellij.plugin.models.GenerateTestsModel
3234import org.utbot.intellij.plugin.ui.TestReportUrlOpeningListener
33- import org.utbot.intellij.plugin.util.assertIsNonDispatchThread
34- import org.utbot.intellij.plugin.util.assertIsReadAccessAllowed
35+ import org.utbot.intellij.plugin.util.assertReadAccessNotAllowed
3536import org.utbot.intellij.plugin.util.methodDescription
3637import org.utbot.rd.*
3738import org.utbot.rd.exceptions.InstantProcessDeathException
@@ -164,7 +165,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
164165 private val sourceFindingStrategies = ConcurrentHashMap <Long , SourceFindingStrategy >()
165166
166167 fun setupUtContext (classpathForUrlsClassloader : List <String >) {
167- engineModel.setupUtContext.start(lifetime, SetupContextParams (classpathForUrlsClassloader))
168+ assertReadAccessNotAllowed()
169+ engineModel.setupUtContext.startBlocking(SetupContextParams (classpathForUrlsClassloader))
168170 }
169171
170172 private fun computeSourceFileByClass (params : ComputeSourceFileByClassArguments ): String =
@@ -185,6 +187,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
185187 jdkInfo : JdkInfo ,
186188 isCancelled : (Unit ) -> Boolean
187189 ) {
190+ assertReadAccessNotAllowed()
191+
188192 engineModel.isCancelled.set(handler = isCancelled)
189193 instrumenterAdapterModel.computeSourceFileByClass.set(handler = this ::computeSourceFileByClass)
190194
@@ -194,19 +198,18 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
194198 dependencyPaths,
195199 JdkInfo (jdkInfo.path.pathString, jdkInfo.version)
196200 )
197- engineModel.createTestGenerator.start(lifetime, params)
201+ engineModel.createTestGenerator.startBlocking( params)
198202 }
199203
200204 fun obtainClassId (canonicalName : String ): ClassId {
201- assertIsNonDispatchThread ()
205+ assertReadAccessNotAllowed ()
202206 return kryoHelper.readObject(engineModel.obtainClassId.startBlocking(canonicalName))
203207 }
204208
205209 fun findMethodsInClassMatchingSelected (clazzId : ClassId , srcMethods : List <MemberInfo >): List <ExecutableId > {
206- assertIsNonDispatchThread()
207- assertIsReadAccessAllowed()
210+ assertReadAccessNotAllowed()
208211
209- val srcDescriptions = srcMethods.map { it.methodDescription() }
212+ val srcDescriptions = runReadAction { srcMethods.map { it.methodDescription() } }
210213 val rdDescriptions = srcDescriptions.map { MethodDescription (it.name, it.containingClass, it.parameterTypes) }
211214 val binaryClassId = kryoHelper.writeObject(clazzId)
212215 val arguments = FindMethodsInClassMatchingSelectedArguments (binaryClassId, rdDescriptions)
@@ -216,10 +219,13 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
216219 }
217220
218221 fun findMethodParamNames (classId : ClassId , methods : List <MemberInfo >): Map <ExecutableId , List <String >> {
219- assertIsNonDispatchThread()
220- assertIsReadAccessAllowed()
222+ assertReadAccessNotAllowed()
221223
222- val bySignature = methods.associate { it.methodDescription() to it.paramNames() }
224+ val bySignature = executeWithTimeoutSuspended {
225+ DumbService .getInstance(project).runReadActionInSmartMode(Computable {
226+ methods.associate { it.methodDescription() to it.paramNames() }
227+ })
228+ }
223229 val arguments = FindMethodParamNamesArguments (
224230 kryoHelper.writeObject(classId),
225231 kryoHelper.writeObject(bySignature)
@@ -254,7 +260,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
254260 fuzzingValue : Double ,
255261 searchDirectory : String
256262 ): RdTestGenerationResult {
257- assertIsNonDispatchThread ()
263+ assertReadAccessNotAllowed ()
258264 val params = GenerateParams (
259265 mockInstalled,
260266 staticsMockingIsConfigured,
@@ -291,7 +297,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
291297 enableTestsTimeout : Boolean ,
292298 testClassPackageName : String
293299 ): Pair <String , UtilClassKind ?> {
294- assertIsNonDispatchThread ()
300+ assertReadAccessNotAllowed ()
295301 val params = RenderParams (
296302 testSetsId,
297303 kryoHelper.writeObject(classUnderTest),
@@ -353,7 +359,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
353359 generatedTestsCode : String ,
354360 sourceFindingStrategy : SourceFindingStrategy
355361 ): String {
356- assertIsNonDispatchThread ()
362+ assertReadAccessNotAllowed ()
357363
358364 val params = WriteSarifReportArguments (testSetsId, reportFilePath.pathString, generatedTestsCode)
359365
@@ -362,7 +368,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
362368 }
363369
364370 fun generateTestsReport (model : GenerateTestsModel , eventLogMessage : String? ): Triple <String , String ?, Boolean > {
365- assertIsNonDispatchThread ()
371+ assertReadAccessNotAllowed ()
366372
367373 val forceMockWarning = UtbotBundle .takeIf (
368374 " test.report.force.mock.warning" ,
@@ -411,10 +417,12 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
411417
412418 fun <T > executeWithTimeoutSuspended (block : () -> T ): T {
413419 try {
420+ assertReadAccessNotAllowed()
414421 protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(true )
415422 return block()
416423 }
417424 finally {
425+ assertReadAccessNotAllowed()
418426 protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(false )
419427 }
420428 }
0 commit comments