aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authorAndy Clement <andrew.clement@gmail.com>2012-04-02 14:15:08 -0700
committerAndy Clement <andrew.clement@gmail.com>2012-04-02 14:15:08 -0700
commit096b004fda4d21cca0e1ee4c776e5824715d0ecd (patch)
tree1b56bf3e3ba31d909df8822f9ef7093166916c19 /weaver
parentf85631fd2fb2e0f3213abb9c5a7cd86eec2c9ab5 (diff)
downloadaspectj-096b004fda4d21cca0e1ee4c776e5824715d0ecd.tar.gz
aspectj-096b004fda4d21cca0e1ee4c776e5824715d0ecd.zip
375881
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java4
-rw-r--r--weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java18
-rw-r--r--weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java27
3 files changed, 49 insertions, 0 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
index d8a9c0e0e..62ebac92c 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
@@ -1578,6 +1578,10 @@ public final class LazyClassGen {
annotations.add(new AnnotationGen(a, getConstantPool(), true));
}
}
+
+ public void addAttribute(AjAttribute attribute) {
+ myGen.addAttribute(Utility.bcelAttribute(attribute, getConstantPool()));
+ }
// this test is like asking:
// if
diff --git a/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java b/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
index 7f9ce729d..de780156e 100644
--- a/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
+++ b/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
@@ -112,6 +112,7 @@ public class Definition {
public final String extend;
public final String precedence;
public final List<Definition.Pointcut> pointcuts;
+ public final List<Definition.DeclareAnnotation> declareAnnotations;
public final List<Definition.PointcutAndAdvice> pointcutsAndAdvice;
public final String perclause;
public List<Definition.DeclareErrorOrWarning> deows;
@@ -135,6 +136,7 @@ public class Definition {
}
this.precedence = precedence;
this.pointcuts = new ArrayList<Definition.Pointcut>();
+ this.declareAnnotations = new ArrayList<Definition.DeclareAnnotation>();
this.pointcutsAndAdvice = new ArrayList<Definition.PointcutAndAdvice>();
this.deows = new ArrayList<Definition.DeclareErrorOrWarning>();
this.perclause = perclause;
@@ -154,6 +156,22 @@ public class Definition {
public enum AdviceKind {
Before, After, AfterReturning, AfterThrowing, Around;
}
+
+ public enum DeclareAnnotationKind {
+ Method, Field, Type;
+ }
+
+ public static class DeclareAnnotation {
+ public final DeclareAnnotationKind declareAnnotationKind;
+ public final String pattern;
+ public final String annotation;
+
+ public DeclareAnnotation(DeclareAnnotationKind kind, String pattern, String annotation) {
+ this.declareAnnotationKind = kind;
+ this.pattern = pattern;
+ this.annotation = annotation;
+ }
+ }
public static class PointcutAndAdvice {
public final AdviceKind adviceKind;
diff --git a/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java b/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
index 13968a696..7ff275fd7 100644
--- a/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
+++ b/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
@@ -22,6 +22,8 @@ import javax.xml.parsers.SAXParserFactory;
import org.aspectj.util.LangUtil;
import org.aspectj.weaver.loadtime.definition.Definition.AdviceKind;
+import org.aspectj.weaver.loadtime.definition.Definition.DeclareAnnotation;
+import org.aspectj.weaver.loadtime.definition.Definition.DeclareAnnotationKind;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -72,6 +74,7 @@ public class DocumentParser extends DefaultHandler {
private final static String AROUND_ELEMENT = "around";
private final static String WITHIN_ATTRIBUTE = "within";
private final static String EXPRESSION_ATTRIBUTE = "expression";
+ private final static String DECLARE_ANNOTATION_ELEMENT = "declare-annotation";
private final Definition definition;
@@ -226,6 +229,30 @@ public class DocumentParser extends DefaultHandler {
if (!isNull(name) && !isNull(expression)) {
activeConcreteAspectDefinition.pointcuts.add(new Definition.Pointcut(name, replaceXmlAnd(expression)));
}
+ } else if (DECLARE_ANNOTATION_ELEMENT.equals(qName) && activeConcreteAspectDefinition!=null) {
+ String methodSig = attributes.getValue("method");
+ String fieldSig = attributes.getValue("field");
+ String typePat = attributes.getValue("type");
+ String anno = attributes.getValue("annotation");
+ if (isNull(anno)) {
+ throw new SAXException("Badly formed <declare-annotation> element, 'annotation' value is missing");
+ }
+ if (isNull(methodSig) && isNull(fieldSig) && isNull(typePat)) {
+ throw new SAXException("Badly formed <declare-annotation> element, need one of 'method'/'field'/'type' specified");
+ }
+ if (!isNull(methodSig)) {
+ // declare @method
+ activeConcreteAspectDefinition.declareAnnotations.add(new Definition.DeclareAnnotation(DeclareAnnotationKind.Method,
+ methodSig, anno));
+ } else if (!isNull(fieldSig)) {
+ // declare @field
+ activeConcreteAspectDefinition.declareAnnotations.add(new Definition.DeclareAnnotation(DeclareAnnotationKind.Field,
+ fieldSig, anno));
+ } else if (!isNull(typePat)) {
+ // declare @type
+ activeConcreteAspectDefinition.declareAnnotations.add(new Definition.DeclareAnnotation(DeclareAnnotationKind.Type,
+ typePat, anno));
+ }
} else if (BEFORE_ELEMENT.equals(qName) && activeConcreteAspectDefinition != null) {
String pointcut = attributes.getValue(POINTCUT_ELEMENT);
String adviceClass = attributes.getValue("invokeClass");