@@ -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.appendHtmlLine
@@ -153,11 +153,12 @@ object CodeGenerationController {
153
153
154
154
run (EDT_LATER ) {
155
155
waitForCountDown(latch, timeout = 100 , timeUnit = TimeUnit .MILLISECONDS ) {
156
+ val mockFrameworkUsed = utilClassListener.mockFrameworkUsed
156
157
val utilClassKind = utilClassListener.requiredUtilClassKind
157
158
? : return @waitForCountDown // no util class needed
158
159
159
160
val existingUtilClass = model.codegenLanguage.getUtilClassOrNull(model.project, model.testModule)
160
- if (shouldCreateOrUpdateUtilClass(existingUtilClass, utilClassListener )) {
161
+ if (shouldCreateOrUpdateUtilClass(existingUtilClass, mockFrameworkUsed, utilClassKind )) {
161
162
createOrUpdateUtilClass(
162
163
testDirectory = baseTestDirectory,
163
164
utilClassKind = utilClassKind,
@@ -195,13 +196,12 @@ object CodeGenerationController {
195
196
}
196
197
}
197
198
198
- private fun shouldCreateOrUpdateUtilClass (existingUtilClass : PsiFile ? , utilClassListener : UtilClassListener ): Boolean {
199
- val existingUtilClassVersion = existingUtilClass?.utilClassVersionOrNull
200
- // TODO: here should be the current version of UTBot
201
- val newUtilClassVersion = " 1.0-SNAPSHOT"
202
- val versionIsUpdated = existingUtilClassVersion != newUtilClassVersion
203
-
204
- val mockFrameworkNotUsed = ! utilClassListener.mockFrameworkUsed
199
+ private fun shouldCreateOrUpdateUtilClass (
200
+ existingUtilClass : PsiFile ? ,
201
+ mockFrameworkUsed : Boolean ,
202
+ requiredUtilClassKind : UtilClassKind
203
+ ): Boolean {
204
+ val mockFrameworkNotUsed = ! mockFrameworkUsed
205
205
206
206
val utilClassExists = existingUtilClass != null
207
207
@@ -210,6 +210,10 @@ object CodeGenerationController {
210
210
return true
211
211
}
212
212
213
+ val existingUtilClassVersion = existingUtilClass?.utilClassVersionOrNull
214
+ val newUtilClassVersion = requiredUtilClassKind.utilClassVersion
215
+ val versionIsUpdated = existingUtilClassVersion != newUtilClassVersion
216
+
213
217
if (versionIsUpdated) {
214
218
// If an existing util class is out of date,
215
219
// then we must overwrite it with a newer version.
@@ -345,17 +349,11 @@ object CodeGenerationController {
345
349
346
350
utilClass.childrenOfType<PsiComment >()
347
351
.map { comment -> comment.text }
348
- .firstOrNull { text -> UTBOT_VERSION_PREFIX in text }
349
- ?.substringAfterLast(UTBOT_VERSION_PREFIX )
352
+ .firstOrNull { text -> UtilClassKind . UTIL_CLASS_VERSION_COMMENT_PREFIX in text }
353
+ ?.substringAfterLast(UtilClassKind . UTIL_CLASS_VERSION_COMMENT_PREFIX )
350
354
?.trim()
351
355
}
352
356
353
- /* *
354
- * Util class must have a comment that specifies the version of UTBot it was generated with.
355
- * This prefix is the start of this comment. The version of UTBot goes after it in the comment.
356
- */
357
- private const val UTBOT_VERSION_PREFIX = " UTBot version:"
358
-
359
357
/* *
360
358
* @param srcClass class under test
361
359
* @return name of the package of a given [srcClass].
0 commit comments