1
1
package org.utbot.intellij.plugin.process
2
2
3
3
import com.intellij.ide.plugins.cl.PluginClassLoader
4
+ import com.intellij.openapi.application.runReadAction
4
5
import com.intellij.openapi.project.DumbService
5
6
import com.intellij.openapi.project.Project
7
+ import com.intellij.openapi.util.Computable
6
8
import com.intellij.psi.PsiMethod
7
9
import com.intellij.psi.impl.file.impl.JavaFileManager
8
10
import com.intellij.psi.search.GlobalSearchScope
@@ -30,8 +32,7 @@ import org.utbot.instrumentation.util.KryoHelper
30
32
import org.utbot.intellij.plugin.UtbotBundle
31
33
import org.utbot.intellij.plugin.models.GenerateTestsModel
32
34
import 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
35
36
import org.utbot.intellij.plugin.util.methodDescription
36
37
import org.utbot.rd.*
37
38
import org.utbot.rd.exceptions.InstantProcessDeathException
@@ -164,7 +165,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
164
165
private val sourceFindingStrategies = ConcurrentHashMap <Long , SourceFindingStrategy >()
165
166
166
167
fun setupUtContext (classpathForUrlsClassloader : List <String >) {
167
- engineModel.setupUtContext.start(lifetime, SetupContextParams (classpathForUrlsClassloader))
168
+ assertReadAccessNotAllowed()
169
+ engineModel.setupUtContext.startBlocking(SetupContextParams (classpathForUrlsClassloader))
168
170
}
169
171
170
172
private fun computeSourceFileByClass (params : ComputeSourceFileByClassArguments ): String =
@@ -185,6 +187,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
185
187
jdkInfo : JdkInfo ,
186
188
isCancelled : (Unit ) -> Boolean
187
189
) {
190
+ assertReadAccessNotAllowed()
191
+
188
192
engineModel.isCancelled.set(handler = isCancelled)
189
193
instrumenterAdapterModel.computeSourceFileByClass.set(handler = this ::computeSourceFileByClass)
190
194
@@ -194,19 +198,18 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
194
198
dependencyPaths,
195
199
JdkInfo (jdkInfo.path.pathString, jdkInfo.version)
196
200
)
197
- engineModel.createTestGenerator.start(lifetime, params)
201
+ engineModel.createTestGenerator.startBlocking( params)
198
202
}
199
203
200
204
fun obtainClassId (canonicalName : String ): ClassId {
201
- assertIsNonDispatchThread ()
205
+ assertReadAccessNotAllowed ()
202
206
return kryoHelper.readObject(engineModel.obtainClassId.startBlocking(canonicalName))
203
207
}
204
208
205
209
fun findMethodsInClassMatchingSelected (clazzId : ClassId , srcMethods : List <MemberInfo >): List <ExecutableId > {
206
- assertIsNonDispatchThread()
207
- assertIsReadAccessAllowed()
210
+ assertReadAccessNotAllowed()
208
211
209
- val srcDescriptions = srcMethods.map { it.methodDescription() }
212
+ val srcDescriptions = runReadAction { srcMethods.map { it.methodDescription() } }
210
213
val rdDescriptions = srcDescriptions.map { MethodDescription (it.name, it.containingClass, it.parameterTypes) }
211
214
val binaryClassId = kryoHelper.writeObject(clazzId)
212
215
val arguments = FindMethodsInClassMatchingSelectedArguments (binaryClassId, rdDescriptions)
@@ -216,10 +219,13 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
216
219
}
217
220
218
221
fun findMethodParamNames (classId : ClassId , methods : List <MemberInfo >): Map <ExecutableId , List <String >> {
219
- assertIsNonDispatchThread()
220
- assertIsReadAccessAllowed()
222
+ assertReadAccessNotAllowed()
221
223
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
+ }
223
229
val arguments = FindMethodParamNamesArguments (
224
230
kryoHelper.writeObject(classId),
225
231
kryoHelper.writeObject(bySignature)
@@ -254,7 +260,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
254
260
fuzzingValue : Double ,
255
261
searchDirectory : String
256
262
): RdTestGenerationResult {
257
- assertIsNonDispatchThread ()
263
+ assertReadAccessNotAllowed ()
258
264
val params = GenerateParams (
259
265
mockInstalled,
260
266
staticsMockingIsConfigured,
@@ -291,7 +297,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
291
297
enableTestsTimeout : Boolean ,
292
298
testClassPackageName : String
293
299
): Pair <String , UtilClassKind ?> {
294
- assertIsNonDispatchThread ()
300
+ assertReadAccessNotAllowed ()
295
301
val params = RenderParams (
296
302
testSetsId,
297
303
kryoHelper.writeObject(classUnderTest),
@@ -353,7 +359,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
353
359
generatedTestsCode : String ,
354
360
sourceFindingStrategy : SourceFindingStrategy
355
361
): String {
356
- assertIsNonDispatchThread ()
362
+ assertReadAccessNotAllowed ()
357
363
358
364
val params = WriteSarifReportArguments (testSetsId, reportFilePath.pathString, generatedTestsCode)
359
365
@@ -362,7 +368,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
362
368
}
363
369
364
370
fun generateTestsReport (model : GenerateTestsModel , eventLogMessage : String? ): Triple <String , String ?, Boolean > {
365
- assertIsNonDispatchThread ()
371
+ assertReadAccessNotAllowed ()
366
372
367
373
val forceMockWarning = UtbotBundle .takeIf (
368
374
" test.report.force.mock.warning" ,
@@ -411,10 +417,12 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
411
417
412
418
fun <T > executeWithTimeoutSuspended (block : () -> T ): T {
413
419
try {
420
+ assertReadAccessNotAllowed()
414
421
protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(true )
415
422
return block()
416
423
}
417
424
finally {
425
+ assertReadAccessNotAllowed()
418
426
protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(false )
419
427
}
420
428
}
0 commit comments