From b458e187af75759964e61fd34ad6c0aad4b6518c Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 28 Feb 2019 18:32:35 +0300 Subject: [PATCH] Extract ITNReporter.submit() compatibility problem to separate file --- .idea/inspectionProfiles/idea_default.xml | 2 + .../kotlin/idea/reporter/ITNReporterCompat.kt | 33 ++++++++ .../idea/reporter/ITNReporterCompat.kt.as32 | 33 ++++++++ .../idea/reporter/ITNReporterCompat.kt.as33 | 33 ++++++++ .../idea/reporter/ITNReporterCompat.kt.as34 | 33 ++++++++ .../idea/reporter/KotlinReportSubmitter.kt | 45 ++++++---- .../reporter/KotlinReportSubmitter.kt.as32 | 82 ------------------- .../reporter/KotlinReportSubmitter.kt.as33 | 82 ------------------- .../reporter/KotlinReportSubmitter.kt.as34 | 82 ------------------- 9 files changed, 164 insertions(+), 261 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as32 create mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as33 create mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as34 delete mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as32 delete mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as33 delete mode 100644 idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as34 diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index d027fff050f..35cb410b445 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -121,6 +121,8 @@ + + diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt new file mode 100644 index 00000000000..06dfb32a015 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.reporter + +import com.intellij.diagnostic.ITNReporter +import com.intellij.openapi.diagnostic.IdeaLoggingEvent +import com.intellij.openapi.diagnostic.SubmittedReportInfo +import com.intellij.util.Consumer +import java.awt.Component + +abstract class ITNReporterCompat : ITNReporter() { + final override fun submit( + events: Array, + additionalInfo: String?, + parentComponent: Component, + consumer: Consumer + ): Boolean { + return submitCompat(events, additionalInfo, parentComponent, consumer) + } + + open fun submitCompat( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + @Suppress("IncompatibleAPI") + return super.submit(events, additionalInfo, parentComponent ?: error("Should never happen in Intellij Idea"), consumer) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as32 b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as32 new file mode 100644 index 00000000000..ac944c264b2 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as32 @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.reporter + +import com.intellij.diagnostic.ITNReporter +import com.intellij.openapi.diagnostic.IdeaLoggingEvent +import com.intellij.openapi.diagnostic.SubmittedReportInfo +import com.intellij.util.Consumer +import java.awt.Component + +abstract class ITNReporterCompat : ITNReporter() { + final override fun submit( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + return submitCompat(events, additionalInfo, parentComponent, consumer) + } + + open fun submitCompat( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + @Suppress("IncompatibleAPI") + return super.submit(events, additionalInfo, parentComponent, consumer) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as33 b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as33 new file mode 100644 index 00000000000..ac944c264b2 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as33 @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.reporter + +import com.intellij.diagnostic.ITNReporter +import com.intellij.openapi.diagnostic.IdeaLoggingEvent +import com.intellij.openapi.diagnostic.SubmittedReportInfo +import com.intellij.util.Consumer +import java.awt.Component + +abstract class ITNReporterCompat : ITNReporter() { + final override fun submit( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + return submitCompat(events, additionalInfo, parentComponent, consumer) + } + + open fun submitCompat( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + @Suppress("IncompatibleAPI") + return super.submit(events, additionalInfo, parentComponent, consumer) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as34 b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as34 new file mode 100644 index 00000000000..ac944c264b2 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/reporter/ITNReporterCompat.kt.as34 @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.reporter + +import com.intellij.diagnostic.ITNReporter +import com.intellij.openapi.diagnostic.IdeaLoggingEvent +import com.intellij.openapi.diagnostic.SubmittedReportInfo +import com.intellij.util.Consumer +import java.awt.Component + +abstract class ITNReporterCompat : ITNReporter() { + final override fun submit( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + return submitCompat(events, additionalInfo, parentComponent, consumer) + } + + open fun submitCompat( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { + @Suppress("IncompatibleAPI") + return super.submit(events, additionalInfo, parentComponent, consumer) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt b/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt index a7288dc56b3..bca48638891 100644 --- a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.idea.reporter -import com.intellij.diagnostic.ITNReporter import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.IdeaLoggingEvent import com.intellij.openapi.diagnostic.SubmittedReportInfo @@ -26,11 +25,12 @@ import org.jetbrains.kotlin.idea.KotlinPluginUpdater import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.PluginUpdateStatus import java.awt.Component +import javax.swing.Icon /** * We need to wrap ITNReporter for force showing or errors from kotlin plugin even from released version of IDEA. */ -class KotlinReportSubmitter : ITNReporter() { +class KotlinReportSubmitter : ITNReporterCompat() { private var hasUpdate = false private var hasLatestVersion = false @@ -39,16 +39,21 @@ class KotlinReportSubmitter : ITNReporter() { return notificationEnabled && (!hasUpdate || ApplicationManager.getApplication().isInternal) } - override fun submit(events: Array, additionalInfo: String?, parentComponent: Component, consumer: Consumer): Boolean { + override fun submitCompat( + events: Array, + additionalInfo: String?, + parentComponent: Component?, + consumer: Consumer + ): Boolean { if (hasUpdate) { if (ApplicationManager.getApplication().isInternal) { - return super.submit(events, additionalInfo, parentComponent, consumer) + return super.submitCompat(events, additionalInfo, parentComponent, consumer) } return true } if (hasLatestVersion) { - return super.submit(events, additionalInfo, parentComponent, consumer) + return super.submitCompat(events, additionalInfo, parentComponent, consumer) } KotlinPluginUpdater.getInstance().runUpdateCheck { status -> @@ -56,25 +61,35 @@ class KotlinReportSubmitter : ITNReporter() { hasUpdate = true if (ApplicationManager.getApplication().isInternal) { - super.submit(events, additionalInfo, parentComponent, consumer) + super.submitCompat(events, additionalInfo, parentComponent, consumer) } - val rc = Messages.showDialog(parentComponent, - "You're running Kotlin plugin version ${KotlinPluginUtil.getPluginVersion()}, " + - "while the latest version is ${status.pluginDescriptor.version}", - "Update Kotlin Plugin", - arrayOf("Update", "Ignore"), - 0, Messages.getInformationIcon()) + val rc = showDialog( + parentComponent, + "You're running Kotlin plugin version ${KotlinPluginUtil.getPluginVersion()}, " + + "while the latest version is ${status.pluginDescriptor.version}", + "Update Kotlin Plugin", + arrayOf("Update", "Ignore"), + 0, Messages.getInformationIcon() + ) + if (rc == 0) { KotlinPluginUpdater.getInstance().installPluginUpdate(status) } - } - else { + } else { hasLatestVersion = true - super.submit(events, additionalInfo, parentComponent, consumer) + super.submitCompat(events, additionalInfo, parentComponent, consumer) } false } return true } + + fun showDialog(parent: Component?, message: String, title: String, options: Array, defaultOptionIndex: Int, icon: Icon?): Int { + return if (parent != null) { + Messages.showDialog(parent, message, title, options, defaultOptionIndex, icon) + } else { + Messages.showDialog(message, title, options, defaultOptionIndex, icon) + } + } } diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as32 b/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as32 deleted file mode 100644 index 9572b8bca94..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as32 +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.reporter - -import com.intellij.diagnostic.ITNReporter -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.diagnostic.IdeaLoggingEvent -import com.intellij.openapi.diagnostic.SubmittedReportInfo -import com.intellij.openapi.ui.Messages -import com.intellij.util.Consumer -import org.jetbrains.kotlin.idea.KotlinPluginUpdater -import org.jetbrains.kotlin.idea.KotlinPluginUtil -import org.jetbrains.kotlin.idea.PluginUpdateStatus -import java.awt.Component - -/** - * We need to wrap ITNReporter for force showing or errors from kotlin plugin even from released version of IDEA. - */ -class KotlinReportSubmitter : ITNReporter() { - private var hasUpdate = false - private var hasLatestVersion = false - - override fun showErrorInRelease(event: IdeaLoggingEvent): Boolean { - val notificationEnabled = "disabled" != System.getProperty("kotlin.fatal.error.notification", "enabled") - return notificationEnabled && (!hasUpdate || ApplicationManager.getApplication().isInternal) - } - - override fun submit(events: Array, additionalInfo: String?, parentComponent: Component?, consumer: Consumer): Boolean { - if (hasUpdate) { - if (ApplicationManager.getApplication().isInternal) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - return true - } - - if (hasLatestVersion) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - - KotlinPluginUpdater.getInstance().runUpdateCheck { status -> - if (status is PluginUpdateStatus.Update) { - hasUpdate = true - if (parentComponent != null) { - - if (ApplicationManager.getApplication().isInternal) { - super.submit(events, additionalInfo, parentComponent, consumer) - } - - val rc = Messages.showDialog(parentComponent, - "You're running Kotlin plugin version ${KotlinPluginUtil.getPluginVersion()}, " + - "while the latest version is ${status.pluginDescriptor.version}", - "Update Kotlin Plugin", - arrayOf("Update", "Ignore"), - 0, Messages.getInformationIcon()) - if (rc == 0) { - KotlinPluginUpdater.getInstance().installPluginUpdate(status) - } - } - } - else { - hasLatestVersion = true - super.submit(events, additionalInfo, parentComponent, consumer) - } - false - } - return true - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as33 b/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as33 deleted file mode 100644 index 9572b8bca94..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as33 +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.reporter - -import com.intellij.diagnostic.ITNReporter -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.diagnostic.IdeaLoggingEvent -import com.intellij.openapi.diagnostic.SubmittedReportInfo -import com.intellij.openapi.ui.Messages -import com.intellij.util.Consumer -import org.jetbrains.kotlin.idea.KotlinPluginUpdater -import org.jetbrains.kotlin.idea.KotlinPluginUtil -import org.jetbrains.kotlin.idea.PluginUpdateStatus -import java.awt.Component - -/** - * We need to wrap ITNReporter for force showing or errors from kotlin plugin even from released version of IDEA. - */ -class KotlinReportSubmitter : ITNReporter() { - private var hasUpdate = false - private var hasLatestVersion = false - - override fun showErrorInRelease(event: IdeaLoggingEvent): Boolean { - val notificationEnabled = "disabled" != System.getProperty("kotlin.fatal.error.notification", "enabled") - return notificationEnabled && (!hasUpdate || ApplicationManager.getApplication().isInternal) - } - - override fun submit(events: Array, additionalInfo: String?, parentComponent: Component?, consumer: Consumer): Boolean { - if (hasUpdate) { - if (ApplicationManager.getApplication().isInternal) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - return true - } - - if (hasLatestVersion) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - - KotlinPluginUpdater.getInstance().runUpdateCheck { status -> - if (status is PluginUpdateStatus.Update) { - hasUpdate = true - if (parentComponent != null) { - - if (ApplicationManager.getApplication().isInternal) { - super.submit(events, additionalInfo, parentComponent, consumer) - } - - val rc = Messages.showDialog(parentComponent, - "You're running Kotlin plugin version ${KotlinPluginUtil.getPluginVersion()}, " + - "while the latest version is ${status.pluginDescriptor.version}", - "Update Kotlin Plugin", - arrayOf("Update", "Ignore"), - 0, Messages.getInformationIcon()) - if (rc == 0) { - KotlinPluginUpdater.getInstance().installPluginUpdate(status) - } - } - } - else { - hasLatestVersion = true - super.submit(events, additionalInfo, parentComponent, consumer) - } - false - } - return true - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as34 b/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as34 deleted file mode 100644 index 9572b8bca94..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/reporter/KotlinReportSubmitter.kt.as34 +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.reporter - -import com.intellij.diagnostic.ITNReporter -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.diagnostic.IdeaLoggingEvent -import com.intellij.openapi.diagnostic.SubmittedReportInfo -import com.intellij.openapi.ui.Messages -import com.intellij.util.Consumer -import org.jetbrains.kotlin.idea.KotlinPluginUpdater -import org.jetbrains.kotlin.idea.KotlinPluginUtil -import org.jetbrains.kotlin.idea.PluginUpdateStatus -import java.awt.Component - -/** - * We need to wrap ITNReporter for force showing or errors from kotlin plugin even from released version of IDEA. - */ -class KotlinReportSubmitter : ITNReporter() { - private var hasUpdate = false - private var hasLatestVersion = false - - override fun showErrorInRelease(event: IdeaLoggingEvent): Boolean { - val notificationEnabled = "disabled" != System.getProperty("kotlin.fatal.error.notification", "enabled") - return notificationEnabled && (!hasUpdate || ApplicationManager.getApplication().isInternal) - } - - override fun submit(events: Array, additionalInfo: String?, parentComponent: Component?, consumer: Consumer): Boolean { - if (hasUpdate) { - if (ApplicationManager.getApplication().isInternal) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - return true - } - - if (hasLatestVersion) { - return super.submit(events, additionalInfo, parentComponent, consumer) - } - - KotlinPluginUpdater.getInstance().runUpdateCheck { status -> - if (status is PluginUpdateStatus.Update) { - hasUpdate = true - if (parentComponent != null) { - - if (ApplicationManager.getApplication().isInternal) { - super.submit(events, additionalInfo, parentComponent, consumer) - } - - val rc = Messages.showDialog(parentComponent, - "You're running Kotlin plugin version ${KotlinPluginUtil.getPluginVersion()}, " + - "while the latest version is ${status.pluginDescriptor.version}", - "Update Kotlin Plugin", - arrayOf("Update", "Ignore"), - 0, Messages.getInformationIcon()) - if (rc == 0) { - KotlinPluginUpdater.getInstance().installPluginUpdate(status) - } - } - } - else { - hasLatestVersion = true - super.submit(events, additionalInfo, parentComponent, consumer) - } - false - } - return true - } -}