Skip to content

IllegalStateException is thrown in IDEA together with notification th… #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,15 +50,28 @@ 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))
}
}

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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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
}

/**
Expand Down