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.

Definition.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Alexandre Vasseur initial implementation
  11. *******************************************************************************/
  12. package org.aspectj.weaver.loadtime.definition;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * A POJO that contains raw strings from the XML (sort of XMLBean for our simple LTW DTD)
  19. *
  20. * @author Alexandre Vasseur (alex AT gnilux DOT com)
  21. */
  22. public class Definition {
  23. private final StringBuffer weaverOptions;
  24. private final List<String> dumpPatterns;
  25. private boolean dumpBefore;
  26. private boolean perClassloaderDumpDir;
  27. private final List<String> includePatterns;
  28. private final List<String> excludePatterns;
  29. private final List<String> aspectClassNames;
  30. private final List<String> aspectExcludePatterns;
  31. private final List<String> aspectIncludePatterns;
  32. private final List<Definition.ConcreteAspect> concreteAspects;
  33. /**
  34. * When aspects are defined, they can specify a scope type pattern and then will only apply to types matching that pattern.
  35. */
  36. private final Map<String, String> scopedAspects;
  37. /**
  38. * Some aspects (from aspect libraries) will describe a type that must be around for them to function properly
  39. */
  40. private final Map<String, String> requiredTypesForAspects;
  41. public Definition() {
  42. weaverOptions = new StringBuffer();
  43. dumpBefore = false;
  44. perClassloaderDumpDir = false;
  45. dumpPatterns = new ArrayList<>();
  46. includePatterns = new ArrayList<>();
  47. excludePatterns = new ArrayList<>();
  48. aspectClassNames = new ArrayList<>();
  49. aspectExcludePatterns = new ArrayList<>();
  50. aspectIncludePatterns = new ArrayList<>();
  51. concreteAspects = new ArrayList<>();
  52. scopedAspects = new HashMap<>();
  53. requiredTypesForAspects = new HashMap<>();
  54. }
  55. public String getWeaverOptions() {
  56. return weaverOptions.toString();
  57. }
  58. public List<String> getDumpPatterns() {
  59. return dumpPatterns;
  60. }
  61. public void setDumpBefore(boolean b) {
  62. dumpBefore = b;
  63. }
  64. public boolean shouldDumpBefore() {
  65. return dumpBefore;
  66. }
  67. public void setCreateDumpDirPerClassloader(boolean b) {
  68. perClassloaderDumpDir = b;
  69. }
  70. public boolean createDumpDirPerClassloader() {
  71. return perClassloaderDumpDir;
  72. }
  73. public List<String> getIncludePatterns() {
  74. return includePatterns;
  75. }
  76. public List<String> getExcludePatterns() {
  77. return excludePatterns;
  78. }
  79. public List<String> getAspectClassNames() {
  80. return aspectClassNames;
  81. }
  82. public List<String> getAspectExcludePatterns() {
  83. return aspectExcludePatterns;
  84. }
  85. public List<String> getAspectIncludePatterns() {
  86. return aspectIncludePatterns;
  87. }
  88. public List<Definition.ConcreteAspect> getConcreteAspects() {
  89. return concreteAspects;
  90. }
  91. public static class ConcreteAspect {
  92. public final String name;
  93. public final String extend;
  94. public final String precedence;
  95. public final List<Definition.Pointcut> pointcuts;
  96. public final List<Definition.DeclareAnnotation> declareAnnotations;
  97. public final List<Definition.PointcutAndAdvice> pointcutsAndAdvice;
  98. public final String perclause;
  99. public List<Definition.DeclareErrorOrWarning> deows;
  100. public ConcreteAspect(String name, String extend) {
  101. this(name, extend, null, null);
  102. }
  103. public ConcreteAspect(String name, String extend, String precedence, String perclause) {
  104. this.name = name;
  105. // make sure extend set to null if ""
  106. if (extend == null || extend.length() == 0) {
  107. this.extend = null;
  108. if (precedence == null || precedence.length() == 0) {
  109. // if (pointcutsAndAdvice.size() == 0) {
  110. // throw new RuntimeException("Not allowed");
  111. // }
  112. }
  113. } else {
  114. this.extend = extend;
  115. }
  116. this.precedence = precedence;
  117. this.pointcuts = new ArrayList<>();
  118. this.declareAnnotations = new ArrayList<>();
  119. this.pointcutsAndAdvice = new ArrayList<>();
  120. this.deows = new ArrayList<>();
  121. this.perclause = perclause;
  122. }
  123. }
  124. public static class Pointcut {
  125. public final String name;
  126. public final String expression;
  127. public Pointcut(String name, String expression) {
  128. this.name = name;
  129. this.expression = expression;
  130. }
  131. }
  132. public enum AdviceKind {
  133. Before, After, AfterReturning, AfterThrowing, Around;
  134. }
  135. public enum DeclareAnnotationKind {
  136. Method, Field, Type;
  137. }
  138. public static class DeclareAnnotation {
  139. public final DeclareAnnotationKind declareAnnotationKind;
  140. public final String pattern;
  141. public final String annotation;
  142. public DeclareAnnotation(DeclareAnnotationKind kind, String pattern, String annotation) {
  143. this.declareAnnotationKind = kind;
  144. this.pattern = pattern;
  145. this.annotation = annotation;
  146. }
  147. }
  148. public static class PointcutAndAdvice {
  149. public final AdviceKind adviceKind;
  150. public final String pointcut;
  151. public final String adviceClass; // com.foo.Bar
  152. public final String adviceMethod; // foo(java.lang.String,org.aspectj.lang.JoinPoint)
  153. public PointcutAndAdvice(AdviceKind adviceKind, String pointcut, String adviceClass, String adviceMethod) {
  154. this.adviceKind = adviceKind;
  155. this.pointcut = pointcut;
  156. this.adviceClass = adviceClass;
  157. this.adviceMethod = adviceMethod;
  158. }
  159. }
  160. public static class DeclareErrorOrWarning {
  161. public final boolean isError;
  162. public final String pointcut;
  163. public final String message;
  164. public DeclareErrorOrWarning(boolean isError, String pointcut, String message) {
  165. this.isError = isError;
  166. this.pointcut = pointcut;
  167. this.message = message;
  168. }
  169. }
  170. public void appendWeaverOptions(String option) {
  171. weaverOptions.append(option.trim()).append(' ');
  172. }
  173. public void addScopedAspect(String name, String scopePattern) {
  174. scopedAspects.put(name, scopePattern);
  175. }
  176. public String getScopeForAspect(String name) {
  177. return scopedAspects.get(name);
  178. }
  179. public void setAspectRequires(String name, String requiredType) {
  180. requiredTypesForAspects.put(name, requiredType);
  181. }
  182. public String getAspectRequires(String name) {
  183. return requiredTypesForAspects.get(name);
  184. }
  185. }