From 8c53c2c5cf76b4e517ff779a85c4cbb543e68d27 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 23 Mar 2018 12:58:34 +0100 Subject: [PATCH] Cleanup (unifies "drop an error" actions) --- .../diagnostic/DropAnErrorAction.java | 37 --------------- .../DropAnErrorWithAttachmentsAction.java | 44 ------------------ .../DropAnOutOfMemoryErrorAction.java | 34 -------------- .../DropAnOutOfMetaspaceErrorAction.java | 29 ------------ .../intellij/diagnostic/dropErrorActions.kt | 45 +++++++++++++++++++ 5 files changed, 45 insertions(+), 144 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorAction.java delete mode 100644 platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorWithAttachmentsAction.java delete mode 100644 platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMemoryErrorAction.java delete mode 100644 platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMetaspaceErrorAction.java create mode 100644 platform/platform-impl/src/com/intellij/diagnostic/dropErrorActions.kt diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorAction.java b/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorAction.java deleted file mode 100644 index 7a63fe7a7360..000000000000 --- a/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2000-2009 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 com.intellij.diagnostic; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.DumbAwareAction; - -@SuppressWarnings({"HardCodedStringLiteral"}) -public class DropAnErrorAction extends DumbAwareAction { - public DropAnErrorAction() { - super ("Drop an error"); - } - - public void actionPerformed(AnActionEvent e) { - /* - Project p = (Project)e.getDataContext().getData(DataConstants.PROJECT); - final StatusBar bar = WindowManager.getInstance().getStatusBar(p); - bar.fireNotificationPopup(new JLabel("
Notifier

")); - */ - - Logger.getInstance("test").error("Test"); - } -} diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorWithAttachmentsAction.java b/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorWithAttachmentsAction.java deleted file mode 100644 index a2f54fc1ae24..000000000000 --- a/platform/platform-impl/src/com/intellij/diagnostic/DropAnErrorWithAttachmentsAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2011 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 com.intellij.diagnostic; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.diagnostic.Attachment; -import com.intellij.openapi.diagnostic.IdeaLoggingEvent; -import com.intellij.openapi.project.DumbAwareAction; - -import java.awt.event.InputEvent; - -@SuppressWarnings({"HardCodedStringLiteral"}) -public class DropAnErrorWithAttachmentsAction extends DumbAwareAction { - public DropAnErrorWithAttachmentsAction() { - super("Drop An Error With Attachments", "Hold down SHIFT for multiple attachments", null); - } - - public void actionPerformed(AnActionEvent e) { - final boolean multipleAttachments = (e.getModifiers() & InputEvent.SHIFT_MASK) != 0; - Attachment[] attachments; - if (multipleAttachments) { - attachments = new Attachment[]{new Attachment("first.txt", "first content"), new Attachment("second.txt", "second content")}; - } - else { - attachments = new Attachment[]{new Attachment("attachment.txt", "content")}; - } - IdeaLoggingEvent test = LogMessageEx.createEvent("test", "test details", attachments); - throw new LogEventException(test); - //Logger.getInstance("test (with attachments)").error(test); - } -} diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMemoryErrorAction.java b/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMemoryErrorAction.java deleted file mode 100644 index d2d83ac31261..000000000000 --- a/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMemoryErrorAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2000-2009 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 com.intellij.diagnostic; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.DumbAwareAction; - -@SuppressWarnings({"HardCodedStringLiteral"}) -public class DropAnOutOfMemoryErrorAction extends DumbAwareAction { - public DropAnOutOfMemoryErrorAction() { - super ("Drop an OutOfMemoryError"); - } - - public void actionPerformed(AnActionEvent e) { - Object[] array = new Object[Integer.MAX_VALUE]; - for (int i = 0; i < array.length; i++) { - array[i] = new Object[Integer.MAX_VALUE]; - } - throw new OutOfMemoryError(); - } -} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMetaspaceErrorAction.java b/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMetaspaceErrorAction.java deleted file mode 100644 index 99e092dfbfc4..000000000000 --- a/platform/platform-impl/src/com/intellij/diagnostic/DropAnOutOfMetaspaceErrorAction.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2000-2017 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 com.intellij.diagnostic; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.DumbAwareAction; - -public class DropAnOutOfMetaspaceErrorAction extends DumbAwareAction { - public DropAnOutOfMetaspaceErrorAction() { - super ("Drop an OutOfMemoryError in Metaspace"); - } - - public void actionPerformed(AnActionEvent e) { - throw new OutOfMemoryError("foo Metaspace foo"); - } -} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/diagnostic/dropErrorActions.kt b/platform/platform-impl/src/com/intellij/diagnostic/dropErrorActions.kt new file mode 100644 index 000000000000..597edbbd1284 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/diagnostic/dropErrorActions.kt @@ -0,0 +1,45 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.diagnostic + +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.diagnostic.Attachment +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.project.DumbAwareAction +import java.awt.event.InputEvent + +private const val TEST_LOGGER = "TEST.LOGGER" +private const val TEST_MESSAGE = "test exception; please ignore" + +class DropAnErrorAction : DumbAwareAction("Drop an error") { + override fun actionPerformed(e: AnActionEvent) { + Logger.getInstance(TEST_LOGGER).error(TEST_MESSAGE, Exception()) + } +} + +class DropAnErrorWithAttachmentsAction : DumbAwareAction("Drop An Error With Attachments", "Hold down SHIFT for multiple attachments", null) { + override fun actionPerformed(e: AnActionEvent) { + val attachments = if (e.modifiers and InputEvent.SHIFT_MASK != 0) { + arrayOf(Attachment("first.txt", "content"), Attachment("second.txt", "more content"), Attachment("third.txt", "even more content")) + } + else { + arrayOf(Attachment("attachment.txt", "content")) + } + Logger.getInstance(TEST_LOGGER).error(TEST_MESSAGE, Exception(), *attachments) + } +} + +class DropAnOutOfMemoryErrorAction : DumbAwareAction("Drop an OutOfMemoryError") { + override fun actionPerformed(e: AnActionEvent) { + val array = arrayOfNulls(Integer.MAX_VALUE) + for (i in array.indices) { + array[i] = arrayOfNulls(Integer.MAX_VALUE) + } + throw OutOfMemoryError() + } +} + +class DropAnOutOfMetaspaceErrorAction : DumbAwareAction("Drop an OutOfMemoryError in Metaspace") { + override fun actionPerformed(e: AnActionEvent) { + throw OutOfMemoryError("foo Metaspace foo") + } +} \ No newline at end of file