diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt index 8b8aa67b08..6def13fd9d 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt @@ -77,7 +77,7 @@ import org.utbot.intellij.plugin.models.packageName import org.utbot.intellij.plugin.process.EngineProcess import org.utbot.intellij.plugin.process.RdTestGenerationResult import org.utbot.intellij.plugin.sarif.SarifReportIdea -import org.utbot.intellij.plugin.ui.CommonErrorNotifier +import org.utbot.intellij.plugin.ui.CommonLoggingNotifier import org.utbot.intellij.plugin.ui.DetailsTestsReportNotifier import org.utbot.intellij.plugin.ui.SarifReportNotifier import org.utbot.intellij.plugin.ui.TestReportUrlOpeningListener @@ -760,9 +760,12 @@ object CodeGenerationController { val project = model.project val codeStyleManager = CodeStyleManager.getInstance(project) val file = smartPointer.containingFile?: return - - if (file.virtualFile.length > UtSettings.maxTestFileSize) { - CommonErrorNotifier.notify( + val fileLength = runReadAction { + FileDocumentManager.getInstance().getDocument(file.virtualFile)?.textLength + ?: file.virtualFile.length.toInt() + } + if (fileLength > UtSettings.maxTestFileSize && file.name != model.codegenLanguage.utilClassFileName) { + CommonLoggingNotifier().notify( "Size of ${file.virtualFile.presentableName} exceeds configured limit " + "(${FileUtil.byteCountToDisplaySize(UtSettings.maxTestFileSize.toLong())}), reformatting was skipped. " + "The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestFileSize' property", diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/Notifications.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/Notifications.kt index 87a9f36317..5891e48f8b 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/Notifications.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/Notifications.kt @@ -19,11 +19,14 @@ import com.intellij.ui.awt.RelativePoint import com.intellij.util.ui.JBFont import java.awt.Point import javax.swing.event.HyperlinkEvent +import mu.KotlinLogging abstract class Notifier { + protected val logger = KotlinLogging.logger {} + protected abstract val notificationType: NotificationType protected abstract val displayId: String - protected abstract fun content(project: Project?, module: Module?, info: String): String + protected open fun content(project: Project?, module: Module?, info: String): String = info open fun notify(info: String, project: Project? = null, module: Module? = null) { notificationGroup @@ -47,7 +50,7 @@ abstract class WarningNotifier : Notifier() { abstract class ErrorNotifier : Notifier() { final override val notificationType: NotificationType = NotificationType.ERROR - final override fun notify(info: String, project: Project?, module: Module?) { + override fun notify(info: String, project: Project?, module: Module?) { super.notify(info, project, module) error(content(project, module, info)) } @@ -55,7 +58,20 @@ abstract class ErrorNotifier : Notifier() { object CommonErrorNotifier : ErrorNotifier() { override val displayId: String = "UTBot plugin errors" - override fun content(project: Project?, module: Module?, info: String): String = info +} + +class CommonLoggingNotifier(val type :NotificationType = NotificationType.WARNING) : Notifier() { + override val displayId: String = "UTBot plugin errors" + override val notificationType = type + + override fun notify(info: String, project: Project?, module: Module?) { + super.notify(info, project, module) + when (notificationType) { + NotificationType.WARNING -> logger.warn(content(project, module, info)) + NotificationType.INFORMATION -> logger.info(content(project, module, info)) + else -> logger.error(content(project, module, info)) + } + } } object UnsupportedJdkNotifier : ErrorNotifier() { @@ -113,8 +129,6 @@ object SarifReportNotifier : EventLogNotifier() { override val titleText: String = "" // no title override val urlOpeningListener: NotificationListener = NotificationListener.UrlOpeningListener(false) - - override fun content(project: Project?, module: Module?, info: String): String = info } object TestsReportNotifier : InformationUrlNotifier() { @@ -123,8 +137,6 @@ object TestsReportNotifier : InformationUrlNotifier() { override val titleText: String = "UTBot: unit tests generated successfully" public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener - - override fun content(project: Project?, module: Module?, info: String): String = info } // TODO replace inheritance with decorators @@ -134,8 +146,6 @@ object WarningTestsReportNotifier : WarningUrlNotifier() { override val titleText: String = "UTBot: unit tests generated with warnings" public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener - - override fun content(project: Project?, module: Module?, info: String): String = info } object DetailsTestsReportNotifier : EventLogNotifier() { @@ -144,8 +154,6 @@ object DetailsTestsReportNotifier : EventLogNotifier() { override val titleText: String = "Test report details of the unit tests generation via UtBot" public override val urlOpeningListener: TestReportUrlOpeningListener = TestReportUrlOpeningListener - - override fun content(project: Project?, module: Module?, info: String): String = info } /**