@@ -33,6 +33,7 @@ import com.intellij.psi.PsiMethod
33
33
import com.intellij.psi.codeStyle.CodeStyleManager
34
34
import com.intellij.psi.codeStyle.JavaCodeStyleManager
35
35
import com.intellij.psi.search.GlobalSearchScopesCore
36
+ import com.intellij.psi.util.childrenOfType
36
37
import com.intellij.refactoring.util.classMembers.MemberInfo
37
38
import com.intellij.testIntegration.TestIntegrationUtils
38
39
import com.intellij.util.IncorrectOperationException
@@ -50,7 +51,6 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
50
51
import org.jetbrains.kotlin.psi.psiUtil.endOffset
51
52
import org.jetbrains.kotlin.psi.psiUtil.startOffset
52
53
import org.jetbrains.kotlin.scripting.resolve.classId
53
- import org.jetbrains.plugins.groovy.lang.psi.util.childrenOfType
54
54
import org.utbot.common.HTML_LINE_SEPARATOR
55
55
import org.utbot.common.PathUtil.toHtmlLinkTag
56
56
import org.utbot.common.allNestedClasses
@@ -161,11 +161,12 @@ object CodeGenerationController {
161
161
162
162
run (EDT_LATER ) {
163
163
waitForCountDown(latch, timeout = 100 , timeUnit = TimeUnit .MILLISECONDS ) {
164
+ val mockFrameworkUsed = utilClassListener.mockFrameworkUsed
164
165
val utilClassKind = utilClassListener.requiredUtilClassKind
165
166
? : return @waitForCountDown // no util class needed
166
167
167
168
val existingUtilClass = model.codegenLanguage.getUtilClassOrNull(model.project, model.testModule)
168
- if (shouldCreateOrUpdateUtilClass(existingUtilClass, utilClassListener )) {
169
+ if (shouldCreateOrUpdateUtilClass(existingUtilClass, mockFrameworkUsed, utilClassKind )) {
169
170
createOrUpdateUtilClass(
170
171
testDirectory = baseTestDirectory,
171
172
utilClassKind = utilClassKind,
@@ -203,13 +204,12 @@ object CodeGenerationController {
203
204
}
204
205
}
205
206
206
- private fun shouldCreateOrUpdateUtilClass (existingUtilClass : PsiFile ? , utilClassListener : UtilClassListener ): Boolean {
207
- val existingUtilClassVersion = existingUtilClass?.utilClassVersionOrNull
208
- // TODO: here should be the current version of UTBot
209
- val newUtilClassVersion = " 1.0-SNAPSHOT"
210
- val versionIsUpdated = existingUtilClassVersion != newUtilClassVersion
211
-
212
- val mockFrameworkNotUsed = ! utilClassListener.mockFrameworkUsed
207
+ private fun shouldCreateOrUpdateUtilClass (
208
+ existingUtilClass : PsiFile ? ,
209
+ mockFrameworkUsed : Boolean ,
210
+ requiredUtilClassKind : UtilClassKind
211
+ ): Boolean {
212
+ val mockFrameworkNotUsed = ! mockFrameworkUsed
213
213
214
214
val utilClassExists = existingUtilClass != null
215
215
@@ -218,6 +218,10 @@ object CodeGenerationController {
218
218
return true
219
219
}
220
220
221
+ val existingUtilClassVersion = existingUtilClass?.utilClassVersionOrNull
222
+ val newUtilClassVersion = requiredUtilClassKind.utilClassVersion
223
+ val versionIsUpdated = existingUtilClassVersion != newUtilClassVersion
224
+
221
225
if (versionIsUpdated) {
222
226
// If an existing util class is out of date,
223
227
// then we must overwrite it with a newer version.
@@ -353,17 +357,11 @@ object CodeGenerationController {
353
357
354
358
utilClass.childrenOfType<PsiComment >()
355
359
.map { comment -> comment.text }
356
- .firstOrNull { text -> UTBOT_VERSION_PREFIX in text }
357
- ?.substringAfterLast(UTBOT_VERSION_PREFIX )
360
+ .firstOrNull { text -> UtilClassKind . UTIL_CLASS_VERSION_COMMENT_PREFIX in text }
361
+ ?.substringAfterLast(UtilClassKind . UTIL_CLASS_VERSION_COMMENT_PREFIX )
358
362
?.trim()
359
363
}
360
364
361
- /* *
362
- * Util class must have a comment that specifies the version of UTBot it was generated with.
363
- * This prefix is the start of this comment. The version of UTBot goes after it in the comment.
364
- */
365
- private const val UTBOT_VERSION_PREFIX = " UTBot version:"
366
-
367
365
/* *
368
366
* @param srcClass class under test
369
367
* @return name of the package of a given [srcClass].
0 commit comments