Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

BrowserMessageHandler.java 2.7KB

17 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
14 anos atrás
17 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version (bug 148190)
  10. *******************************************************************/
  11. package org.aspectj.tools.ajbrowser.ui;
  12. import java.io.PrintWriter;
  13. import java.io.StringWriter;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import org.aspectj.ajde.Ajde;
  17. import org.aspectj.ajde.IUIBuildMessageHandler;
  18. import org.aspectj.ajde.ui.swing.ErrorDialog;
  19. import org.aspectj.bridge.AbortException;
  20. import org.aspectj.bridge.IMessage;
  21. import org.aspectj.bridge.IMessage.Kind;
  22. /**
  23. * MessageHandler used by AjBrowser that displays ERROR messages with exceptions and ABORT messages in an error dialog. Other
  24. * messages are displayed by the MessageHandlerPanel. By default INFO and WEAVEINFO messages are ignored.
  25. */
  26. public class BrowserMessageHandler implements IUIBuildMessageHandler {
  27. private List<IMessage.Kind> ignoring;
  28. private List<IMessage> messages;
  29. public BrowserMessageHandler() {
  30. ignoring = new ArrayList<>();
  31. messages = new ArrayList<>();
  32. ignore(IMessage.INFO);
  33. ignore(IMessage.WEAVEINFO);
  34. }
  35. public boolean handleMessage(IMessage message) throws AbortException {
  36. Kind messageKind = message.getKind();
  37. if (isIgnoring(messageKind)) {
  38. return true;
  39. }
  40. if (messageKind.equals(IMessage.ABORT) || (message.getThrown() != null)) {
  41. String stack = getStackTraceAsString(message.getThrown());
  42. ErrorDialog errorDialog = new ErrorDialog(Ajde.getDefault().getRootFrame(), "AJDE Error", message.getThrown(),
  43. message.getMessage(), stack);
  44. errorDialog.setVisible(true);
  45. return true;
  46. }
  47. messages.add(message);
  48. return true;
  49. }
  50. public void dontIgnore(Kind kind) {
  51. if (null != kind) {
  52. ignoring.remove(kind);
  53. }
  54. }
  55. public boolean isIgnoring(Kind kind) {
  56. return ((null != kind) && (ignoring.contains(kind)));
  57. }
  58. public void ignore(Kind kind) {
  59. if ((null != kind) && (!ignoring.contains(kind))) {
  60. ignoring.add(kind);
  61. }
  62. }
  63. public List<IMessage> getMessages() {
  64. return messages;
  65. }
  66. private String getStackTraceAsString(Throwable t) {
  67. StringWriter stringWriter = new StringWriter();
  68. if (t != null) {
  69. t.printStackTrace(new PrintWriter(stringWriter));
  70. return stringWriter.getBuffer().toString();
  71. }
  72. return "<no stack trace available>";
  73. }
  74. public void reset() {
  75. messages.clear();
  76. }
  77. }