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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(
  34. String message,
  35. String affectedTypeName, String aspectName,
  36. ISourceLocation affectedTypeLocation, ISourceLocation aspectLocation
  37. ) {
  38. super(message, null, IMessage.WEAVEINFO, affectedTypeLocation, null, new ISourceLocation[] { aspectLocation });
  39. this.affectedTypeName = affectedTypeName;
  40. this.aspectName = aspectName;
  41. }
  42. /**
  43. * Static helper method for constructing weaving messages.
  44. *
  45. * @param kind what kind of message (e.g. declare parents)
  46. * @param inserts inserts for the message (inserts are marked %n in the message)
  47. * @return new weaving message
  48. */
  49. public static WeaveMessage constructWeavingMessage(WeaveMessageKind kind, String[] inserts) {
  50. StringBuilder str = new StringBuilder(kind.getMessage());
  51. int pos = -1;
  52. while ((pos = new String(str).indexOf("%")) != -1) {
  53. int n = Character.getNumericValue(str.charAt(pos + 1));
  54. str.replace(pos, pos + 2, inserts[n - 1]);
  55. }
  56. return new WeaveMessage(str.toString(), null, null, null, null);
  57. }
  58. /**
  59. * Static helper method for constructing weaving messages.
  60. *
  61. * @param kind what kind of message (e.g. declare parents)
  62. * @param inserts inserts for the message (inserts are marked %n in the message)
  63. * @param affectedTypeName the type which is being advised/declaredUpon
  64. * @param aspectName the aspect that defined the advice or declares
  65. * @param affectedTypeLocation the source location of the advised/declaredUpon type
  66. * @param aspectLocation the source location of the declaring/defining advice/declare
  67. * @return new weaving message
  68. */
  69. public static WeaveMessage constructWeavingMessage(
  70. WeaveMessageKind kind, String[] inserts,
  71. String affectedTypeName, String aspectName,
  72. ISourceLocation affectedTypeLocation, ISourceLocation aspectLocation
  73. ) {
  74. StringBuilder str = new StringBuilder(kind.getMessage());
  75. int pos = -1;
  76. while ((pos = new String(str).indexOf("%")) != -1) {
  77. int n = Character.getNumericValue(str.charAt(pos + 1));
  78. str.replace(pos, pos + 2, inserts[n - 1]);
  79. }
  80. return new WeaveMessage(str.toString(), affectedTypeName, aspectName, affectedTypeLocation, aspectLocation);
  81. }
  82. /**
  83. * @return Returns the aspectname.
  84. */
  85. public String getAspectName() {
  86. return aspectName;
  87. }
  88. /**
  89. * @return Returns the affectedtypename.
  90. */
  91. public String getAffectedTypeName() {
  92. return affectedTypeName;
  93. }
  94. public static class WeaveMessageKind {
  95. // private int id;
  96. private String message;
  97. public WeaveMessageKind(int id, String message) {
  98. // this.id = id;
  99. this.message = message;
  100. }
  101. public String getMessage() {
  102. return message;
  103. }
  104. }
  105. }