You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PinpointingMessageHandler.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.bridge.context;
  13. import java.io.PrintWriter;
  14. import java.io.StringWriter;
  15. import java.util.List;
  16. import org.aspectj.bridge.AbortException;
  17. import org.aspectj.bridge.IMessage;
  18. import org.aspectj.bridge.IMessageHandler;
  19. import org.aspectj.bridge.ISourceLocation;
  20. import org.aspectj.bridge.IMessage.Kind;
  21. /**
  22. * @author colyer
  23. * Facade for an IMessageHandler
  24. * Extends message with details of exactly what the compiler / weaver was doing at the
  25. * time. Use the -Xdev:Pinpoint option to turn this facility on.
  26. */
  27. public class PinpointingMessageHandler implements IMessageHandler {
  28. private IMessageHandler delegate;
  29. public PinpointingMessageHandler(IMessageHandler delegate) {
  30. this.delegate = delegate;
  31. }
  32. /* (non-Javadoc)
  33. * @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage)
  34. */
  35. public boolean handleMessage(IMessage message) throws AbortException {
  36. if (!isIgnoring(message.getKind())) {
  37. MessageIssued ex = new MessageIssued();
  38. ex.fillInStackTrace();
  39. StringWriter sw = new StringWriter();
  40. ex.printStackTrace(new PrintWriter(sw));
  41. StringBuilder sb = new StringBuilder();
  42. sb.append(CompilationAndWeavingContext.getCurrentContext());
  43. sb.append(sw.toString());
  44. IMessage pinpointedMessage = new PinpointedMessage(message,sb.toString());
  45. return delegate.handleMessage(pinpointedMessage);
  46. } else {
  47. return delegate.handleMessage(message);
  48. }
  49. }
  50. /* (non-Javadoc)
  51. * @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind)
  52. */
  53. public boolean isIgnoring(Kind kind) {
  54. return delegate.isIgnoring(kind);
  55. }
  56. /* (non-Javadoc)
  57. * @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind)
  58. */
  59. public void dontIgnore(Kind kind) {
  60. delegate.dontIgnore(kind);
  61. }
  62. /* (non-Javadoc)
  63. * @see org.aspectj.bridge.IMessageHandler#ignore(org.aspectj.bridge.IMessage.Kind)
  64. */
  65. public void ignore(Kind kind) {
  66. delegate.ignore(kind);
  67. }
  68. private static class PinpointedMessage implements IMessage {
  69. private IMessage delegate;
  70. private String message;
  71. public PinpointedMessage(IMessage delegate, String pinpoint) {
  72. this.delegate = delegate;
  73. this.message = delegate.getMessage() + "\n" + pinpoint;
  74. }
  75. public String getMessage() { return this.message; }
  76. public Kind getKind() { return delegate.getKind();}
  77. public boolean isError() { return delegate.isError(); }
  78. public boolean isWarning() { return delegate.isWarning();}
  79. public boolean isDebug() { return delegate.isDebug();}
  80. public boolean isUsage() { return delegate.isUsage();}
  81. public boolean isInfo() { return delegate.isInfo();}
  82. public boolean isAbort() { return delegate.isAbort();}
  83. public boolean isTaskTag() { return delegate.isTaskTag();}
  84. public boolean isFailed() { return delegate.isFailed();}
  85. public boolean getDeclared() { return delegate.getDeclared(); }
  86. public int getID() { return delegate.getID();}
  87. public int getSourceStart() { return delegate.getSourceStart();}
  88. public int getSourceEnd() { return delegate.getSourceEnd();}
  89. public Throwable getThrown() { return delegate.getThrown();}
  90. public ISourceLocation getSourceLocation() { return delegate.getSourceLocation();}
  91. public String getDetails() { return delegate.getDetails();}
  92. public List<ISourceLocation> getExtraSourceLocations() { return delegate.getExtraSourceLocations();}
  93. }
  94. private static class MessageIssued extends RuntimeException {
  95. private static final long serialVersionUID = 1L;
  96. public String getMessage() {
  97. return "message issued...";
  98. }
  99. }
  100. }