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.

WeaveMessage.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation
  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. * Andy Clement IBM initial implementation 30-May-2004
  11. * ******************************************************************/
  12. package org.aspectj.bridge;
  13. public class WeaveMessage extends Message {
  14. // Kinds of weaving message we can produce
  15. public static WeaveMessageKind WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS = new WeaveMessageKind(1,
  16. "Extending interface set for type '%1' (%2) to include '%3' (%4)");
  17. public static WeaveMessageKind WEAVEMESSAGE_ITD = new WeaveMessageKind(2, "Type '%1' (%2) has intertyped %3 from '%4' (%5)");
  18. // %7 is information like "[with runtime test]"
  19. public static WeaveMessageKind WEAVEMESSAGE_ADVISES = new WeaveMessageKind(3,
  20. "Join point '%1' in Type '%2' (%3) advised by %4 advice from '%5' (%6)%7");
  21. public static WeaveMessageKind WEAVEMESSAGE_DECLAREPARENTSEXTENDS = new WeaveMessageKind(4,
  22. "Setting superclass of type '%1' (%2) to '%3' (%4)");
  23. public static WeaveMessageKind WEAVEMESSAGE_SOFTENS = new WeaveMessageKind(5,
  24. "Softening exceptions in type '%1' (%2) as defined by aspect '%3' (%4)");
  25. public static WeaveMessageKind WEAVEMESSAGE_ANNOTATES = new WeaveMessageKind(6,
  26. "'%1' (%2) is annotated with %3 %4 annotation from '%5' (%6)");
  27. public static WeaveMessageKind WEAVEMESSAGE_MIXIN = new WeaveMessageKind(7, "Mixing interface '%1' (%2) into type '%3' (%4)");
  28. public static WeaveMessageKind WEAVEMESSAGE_REMOVES_ANNOTATION = new WeaveMessageKind(6,
  29. "'%1' (%2) has had %3 %4 annotation removed by '%5' (%6)");
  30. private String affectedtypename;
  31. private String aspectname;
  32. // private ctor - use the static factory method
  33. private WeaveMessage(String message, String affectedtypename, String aspectname) {
  34. super(message, IMessage.WEAVEINFO, null, null);
  35. this.affectedtypename = affectedtypename;
  36. this.aspectname = aspectname;
  37. }
  38. /**
  39. * Static helper method for constructing weaving messages.
  40. *
  41. * @param kind what kind of message (e.g. declare parents)
  42. * @param inserts inserts for the message (inserts are marked %n in the message)
  43. * @return new weaving message
  44. */
  45. public static WeaveMessage constructWeavingMessage(WeaveMessageKind kind, String[] inserts) {
  46. StringBuilder str = new StringBuilder(kind.getMessage());
  47. int pos = -1;
  48. while ((pos = new String(str).indexOf("%")) != -1) {
  49. int n = Character.getNumericValue(str.charAt(pos + 1));
  50. str.replace(pos, pos + 2, inserts[n - 1]);
  51. }
  52. return new WeaveMessage(str.toString(), null, null);
  53. }
  54. /**
  55. * Static helper method for constructing weaving messages.
  56. *
  57. * @param kind what kind of message (e.g. declare parents)
  58. * @param inserts inserts for the message (inserts are marked %n in the message)
  59. * @param affectedtypename the type which is being advised/declaredUpon
  60. * @param aspectname the aspect that defined the advice or declares
  61. * @return new weaving message
  62. */
  63. public static WeaveMessage constructWeavingMessage(WeaveMessageKind kind, String[] inserts, String affectedtypename,
  64. String aspectname) {
  65. StringBuilder str = new StringBuilder(kind.getMessage());
  66. int pos = -1;
  67. while ((pos = new String(str).indexOf("%")) != -1) {
  68. int n = Character.getNumericValue(str.charAt(pos + 1));
  69. str.replace(pos, pos + 2, inserts[n - 1]);
  70. }
  71. return new WeaveMessage(str.toString(), affectedtypename, aspectname);
  72. }
  73. /**
  74. * @return Returns the aspectname.
  75. */
  76. public String getAspectname() {
  77. return aspectname;
  78. }
  79. /**
  80. * @return Returns the affectedtypename.
  81. */
  82. public String getAffectedtypename() {
  83. return affectedtypename;
  84. }
  85. public static class WeaveMessageKind {
  86. // private int id;
  87. private String message;
  88. public WeaveMessageKind(int id, String message) {
  89. // this.id = id;
  90. this.message = message;
  91. }
  92. public String getMessage() {
  93. return message;
  94. }
  95. }
  96. }