summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-02-17 12:58:24 +0000
committeracolyer <acolyer>2005-02-17 12:58:24 +0000
commitb4574b90b2db6cdae830e702825d86957447c3b9 (patch)
treed93001dbf1804933f64350dbd52bc1ced5402e7c /weaver
parentdb5e1868bb553bad01441e70db166ac4429de2f2 (diff)
downloadaspectj-b4574b90b2db6cdae830e702825d86957447c3b9.tar.gz
aspectj-b4574b90b2db6cdae830e702825d86957447c3b9.zip
support for annotations on ITDs, and declare annotation
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/CrosscuttingMembers.java3
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/Declare.java3
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/DeclareAnnotation.java143
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PatternParser.java48
4 files changed, 196 insertions, 1 deletions
diff --git a/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java b/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java
index 0685ef0be..e02b8a214 100644
--- a/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java
+++ b/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java
@@ -19,6 +19,7 @@ import java.util.Iterator;
import java.util.List;
import org.aspectj.weaver.patterns.Declare;
+import org.aspectj.weaver.patterns.DeclareAnnotation;
import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
import org.aspectj.weaver.patterns.DeclareParents;
import org.aspectj.weaver.patterns.DeclarePrecedence;
@@ -114,6 +115,8 @@ public class CrosscuttingMembers {
m.pointcut = concretePointcut;
declareSofts.add(new DeclareSoft(d.getException(), concretePointcut));
addConcreteShadowMunger(m);
+ } else if (declare instanceof DeclareAnnotation) {
+ System.err.println("Need to implement CrosscuttingMembers.addDeclare for annotations");
} else {
throw new RuntimeException("unimplemented");
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/Declare.java b/weaver/src/org/aspectj/weaver/patterns/Declare.java
index c03394316..d5ffff9a1 100644
--- a/weaver/src/org/aspectj/weaver/patterns/Declare.java
+++ b/weaver/src/org/aspectj/weaver/patterns/Declare.java
@@ -23,6 +23,7 @@ public abstract class Declare extends PatternNode {
public static final byte PARENTS = 2;
public static final byte SOFT = 3;
public static final byte DOMINATES = 4;
+ public static final byte ANNOTATION = 5;
public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
byte kind = s.readByte();
@@ -35,6 +36,8 @@ public abstract class Declare extends PatternNode {
return DeclareParents.read(s, context);
case SOFT:
return DeclareSoft.read(s, context);
+ case ANNOTATION:
+ return DeclareAnnotation.read(s,context);
default:
throw new RuntimeException("unimplemented");
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/DeclareAnnotation.java b/weaver/src/org/aspectj/weaver/patterns/DeclareAnnotation.java
new file mode 100644
index 000000000..003ce2a31
--- /dev/null
+++ b/weaver/src/org/aspectj/weaver/patterns/DeclareAnnotation.java
@@ -0,0 +1,143 @@
+/* *******************************************************************
+ * Copyright (c) 2005 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer initial implementation
+ * ******************************************************************/
+package org.aspectj.weaver.patterns;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.weaver.ISourceContext;
+import org.aspectj.weaver.VersionedDataInputStream;
+
+public class DeclareAnnotation extends Declare {
+
+ private String kind;
+ private TypePattern typePattern;
+ private SignaturePattern sigPattern;
+ private String annotationMethod = "unknown";
+ private String annotationString = "@<annotation>";
+
+ public DeclareAnnotation(String kind, TypePattern typePattern) {
+ this.typePattern = typePattern;
+ this.kind = kind;
+ }
+
+ public DeclareAnnotation(String kind, SignaturePattern sigPattern) {
+ this.sigPattern = sigPattern;
+ this.kind = kind;
+ }
+
+ public String toString() {
+ StringBuffer ret = new StringBuffer();
+ ret.append("declare @");
+ ret.append(kind);
+ ret.append(" : ");
+ ret.append(typePattern != null ? typePattern.toString() : sigPattern.toString());
+ ret.append(" : ");
+ ret.append(annotationString);
+ return ret.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.weaver.patterns.Declare#resolve(org.aspectj.weaver.patterns.IScope)
+ */
+ public void resolve(IScope scope) {
+ if (typePattern != null) typePattern.resolve(scope.getWorld());
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.weaver.patterns.Declare#isAdviceLike()
+ */
+ public boolean isAdviceLike() {
+ return false;
+ }
+
+ public void setAnnotationString(String as) {
+ this.annotationString = as;
+ }
+
+ public void setAnnotationMethod(String methName){
+ this.annotationMethod = methName;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof DeclareAnnotation)) return false;
+ DeclareAnnotation other = (DeclareAnnotation) obj;
+ if (!this.kind.equals(other.kind)) return false;
+ if (!this.annotationString.equals(other.annotationString)) return false;
+ if (!this.annotationMethod.equals(other.annotationMethod)) return false;
+ if (this.typePattern != null) {
+ if (!typePattern.equals(other.typePattern)) return false;
+ }
+ if (this.sigPattern != null) {
+ if (!sigPattern.equals(other.sigPattern)) return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ int result = 19;
+ result = 37*result + kind.hashCode();
+ result = 37*result + annotationString.hashCode();
+ result = 37*result + annotationMethod.hashCode();
+ if (typePattern != null) result = 37*result + typePattern.hashCode();
+ if (sigPattern != null) result = 37*result + sigPattern.hashCode();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream)
+ */
+ public void write(DataOutputStream s) throws IOException {
+ s.writeByte(Declare.ANNOTATION);
+ s.writeUTF(kind);
+ s.writeUTF(annotationString);
+ s.writeUTF(annotationMethod);
+ if (typePattern != null) typePattern.write(s);
+ if (sigPattern != null) sigPattern.write(s);
+ writeLocation(s);
+ }
+
+ /**
+ * @param s
+ * @param context
+ * @return
+ * @throws IOException
+ */
+ public static Declare read(VersionedDataInputStream s,
+ ISourceContext context) throws IOException {
+ DeclareAnnotation ret = null;
+ String kind = s.readUTF();
+ String annotationString = s.readUTF();
+ String annotationMethod = s.readUTF();
+ TypePattern tp = null;
+ SignaturePattern sp = null;
+ if (kind.equals("type")) {
+ tp = TypePattern.read(s,context);
+ ret = new DeclareAnnotation(kind,tp);
+ } else {
+ sp = SignaturePattern.read(s,context);
+ ret = new DeclareAnnotation(kind,sp);
+ }
+ ret.setAnnotationString(annotationString);
+ ret.setAnnotationMethod(annotationMethod);
+ ret.readLocation(context,s);
+ return ret;
+ }
+}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
index 575bcc7e1..80322fabe 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
@@ -101,7 +101,6 @@ public class PatternParser {
String kind = parseIdentifier();
eat(":");
Declare ret;
- //XXX beta add soft, dominates
if (kind.equals("error")) {
ret = parseErrorOrWarning(true);
} else if (kind.equals("warning")) {
@@ -122,6 +121,53 @@ public class PatternParser {
ret.setLocation(sourceContext, startPos, endPos);
return ret;
}
+
+ public Declare parseDeclareAnnotation() {
+ int startPos = tokenSource.peek().getStart();
+
+ eatIdentifier("declare");
+ eat("@");
+ String kind = parseIdentifier();
+ eat(":");
+ Declare ret;
+ if (kind.equals("type")) {
+ ret = parseDeclareAtType();
+ } else if (kind.equals("method")) {
+ ret = parseDeclareAtMethod(true);
+ } else if (kind.equals("field")) {
+ ret = parseDeclareAtField();
+ } else if (kind.equals("constructor")) {
+ ret = parseDeclareAtMethod(false);
+ } else {
+ throw new ParserException("expected one of type, method, field, constructor",
+ tokenSource.peek(-1));
+ }
+ eat(";");
+ int endPos = tokenSource.peek(-1).getEnd();
+ ret.setLocation(sourceContext, startPos, endPos);
+ return ret;
+
+ }
+
+ public DeclareAnnotation parseDeclareAtType() {
+ return new DeclareAnnotation("type",parseTypePattern());
+ }
+
+ public DeclareAnnotation parseDeclareAtMethod(boolean isMethod) {
+ SignaturePattern sp = parseMethodOrConstructorSignaturePattern();
+ boolean isConstructorPattern = (sp.getKind() == Member.CONSTRUCTOR);
+ if (isMethod && isConstructorPattern) {
+ throw new ParserException("method signature pattern",tokenSource.peek(-1));
+ }
+ if (!isMethod && !isConstructorPattern) {
+ throw new ParserException("constructor signature pattern",tokenSource.peek(-1));
+ }
+ return new DeclareAnnotation("method",sp); // sp itself differentiates...
+ }
+
+ public DeclareAnnotation parseDeclareAtField() {
+ return new DeclareAnnotation("field",parseFieldSignaturePattern());
+ }
public DeclarePrecedence parseDominates() {
List l = new ArrayList();