Cleanup (unifies "drop an error" actions)

This commit is contained in:
Roman Shevchenko
2018-03-23 12:58:34 +01:00
parent 5cfcf6bc53
commit 8c53c2c5cf
5 changed files with 45 additions and 144 deletions
@@ -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("<html><body><br><b> Notifier </b><br><br></body></html>"));
*/
Logger.getInstance("test").error("Test");
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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");
}
}
@@ -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<Any>(Integer.MAX_VALUE)
for (i in array.indices) {
array[i] = arrayOfNulls<Any>(Integer.MAX_VALUE)
}
throw OutOfMemoryError()
}
}
class DropAnOutOfMetaspaceErrorAction : DumbAwareAction("Drop an OutOfMemoryError in Metaspace") {
override fun actionPerformed(e: AnActionEvent) {
throw OutOfMemoryError("foo Metaspace foo")
}
}