Skip to content

Commit b30cab4

Browse files
IllegalStateException is thrown in IDEA together with notification th… (#1311)
IllegalStateException is thrown in IDEA together with notification that file exceeds configured limit #1295
1 parent 4cae57e commit b30cab4

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import org.utbot.intellij.plugin.models.packageName
7777
import org.utbot.intellij.plugin.process.EngineProcess
7878
import org.utbot.intellij.plugin.process.RdTestGenerationResult
7979
import org.utbot.intellij.plugin.sarif.SarifReportIdea
80-
import org.utbot.intellij.plugin.ui.CommonErrorNotifier
80+
import org.utbot.intellij.plugin.ui.CommonLoggingNotifier
8181
import org.utbot.intellij.plugin.ui.DetailsTestsReportNotifier
8282
import org.utbot.intellij.plugin.ui.SarifReportNotifier
8383
import org.utbot.intellij.plugin.ui.TestReportUrlOpeningListener
@@ -760,9 +760,12 @@ object CodeGenerationController {
760760
val project = model.project
761761
val codeStyleManager = CodeStyleManager.getInstance(project)
762762
val file = smartPointer.containingFile?: return
763-
764-
if (file.virtualFile.length > UtSettings.maxTestFileSize) {
765-
CommonErrorNotifier.notify(
763+
val fileLength = runReadAction {
764+
FileDocumentManager.getInstance().getDocument(file.virtualFile)?.textLength
765+
?: file.virtualFile.length.toInt()
766+
}
767+
if (fileLength > UtSettings.maxTestFileSize && file.name != model.codegenLanguage.utilClassFileName) {
768+
CommonLoggingNotifier().notify(
766769
"Size of ${file.virtualFile.presentableName} exceeds configured limit " +
767770
"(${FileUtil.byteCountToDisplaySize(UtSettings.maxTestFileSize.toLong())}), reformatting was skipped. " +
768771
"The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestFileSize' property",

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/Notifications.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import com.intellij.ui.awt.RelativePoint
1919
import com.intellij.util.ui.JBFont
2020
import java.awt.Point
2121
import javax.swing.event.HyperlinkEvent
22+
import mu.KotlinLogging
2223

2324
abstract class Notifier {
25+
protected val logger = KotlinLogging.logger {}
26+
2427
protected abstract val notificationType: NotificationType
2528
protected abstract val displayId: String
26-
protected abstract fun content(project: Project?, module: Module?, info: String): String
29+
protected open fun content(project: Project?, module: Module?, info: String): String = info
2730

2831
open fun notify(info: String, project: Project? = null, module: Module? = null) {
2932
notificationGroup
@@ -47,15 +50,28 @@ abstract class WarningNotifier : Notifier() {
4750
abstract class ErrorNotifier : Notifier() {
4851
final override val notificationType: NotificationType = NotificationType.ERROR
4952

50-
final override fun notify(info: String, project: Project?, module: Module?) {
53+
override fun notify(info: String, project: Project?, module: Module?) {
5154
super.notify(info, project, module)
5255
error(content(project, module, info))
5356
}
5457
}
5558

5659
object CommonErrorNotifier : ErrorNotifier() {
5760
override val displayId: String = "UTBot plugin errors"
58-
override fun content(project: Project?, module: Module?, info: String): String = info
61+
}
62+
63+
class CommonLoggingNotifier(val type :NotificationType = NotificationType.WARNING) : Notifier() {
64+
override val displayId: String = "UTBot plugin errors"
65+
override val notificationType = type
66+
67+
override fun notify(info: String, project: Project?, module: Module?) {
68+
super.notify(info, project, module)
69+
when (notificationType) {
70+
NotificationType.WARNING -> logger.warn(content(project, module, info))
71+
NotificationType.INFORMATION -> logger.info(content(project, module, info))
72+
else -> logger.error(content(project, module, info))
73+
}
74+
}
5975
}
6076

6177
object UnsupportedJdkNotifier : ErrorNotifier() {
@@ -113,8 +129,6 @@ object SarifReportNotifier : EventLogNotifier() {
113129
override val titleText: String = "" // no title
114130

115131
override val urlOpeningListener: NotificationListener = NotificationListener.UrlOpeningListener(false)
116-
117-
override fun content(project: Project?, module: Module?, info: String): String = info
118132
}
119133

120134
object TestsReportNotifier : InformationUrlNotifier() {
@@ -123,8 +137,6 @@ object TestsReportNotifier : InformationUrlNotifier() {
123137
override val titleText: String = "UTBot: unit tests generated successfully"
124138

125139
public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener
126-
127-
override fun content(project: Project?, module: Module?, info: String): String = info
128140
}
129141

130142
// TODO replace inheritance with decorators
@@ -134,8 +146,6 @@ object WarningTestsReportNotifier : WarningUrlNotifier() {
134146
override val titleText: String = "UTBot: unit tests generated with warnings"
135147

136148
public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener
137-
138-
override fun content(project: Project?, module: Module?, info: String): String = info
139149
}
140150

141151
object DetailsTestsReportNotifier : EventLogNotifier() {
@@ -144,8 +154,6 @@ object DetailsTestsReportNotifier : EventLogNotifier() {
144154
override val titleText: String = "Test report details of the unit tests generation via UtBot"
145155

146156
public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener
147-
148-
override fun content(project: Project?, module: Module?, info: String): String = info
149157
}
150158

151159
/**

0 commit comments

Comments
 (0)