summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-04-25 16:07:25 +0000
committeracolyer <acolyer>2005-04-25 16:07:25 +0000
commit75c1c3ea4d4cc5308cf3ba4490d18b8536b08dd2 (patch)
treed06e4c67eae3c9879eebabc6854ecf40817181d4 /weaver
parent92fce1440c9017376efaf544802d8cef07546b03 (diff)
downloadaspectj-75c1c3ea4d4cc5308cf3ba4490d18b8536b08dd2.tar.gz
aspectj-75c1c3ea4d4cc5308cf3ba4490d18b8536b08dd2.zip
support in ajc for parsing and error reporting of @AspectJ style aspect definitions (aspect, pointcut, advice only at this point). Also include the AddAtAspectJAnnotationsVisitor support. Switch off using -Xdev:NoAtAspectJProcessing.
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/ISourceContext.java1
-rw-r--r--weaver/src/org/aspectj/weaver/ataspectj/Aj5Attributes.java71
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelMethod.java16
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java38
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java2
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/BasicTokenSource.java7
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PatternNode.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PatternParser.java6
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerCflow.java5
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerClause.java2
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerObject.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerSingleton.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java4
-rw-r--r--weaver/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java2
15 files changed, 124 insertions, 46 deletions
diff --git a/weaver/src/org/aspectj/weaver/ISourceContext.java b/weaver/src/org/aspectj/weaver/ISourceContext.java
index 16cb3c8bc..d0c91a27b 100644
--- a/weaver/src/org/aspectj/weaver/ISourceContext.java
+++ b/weaver/src/org/aspectj/weaver/ISourceContext.java
@@ -18,4 +18,5 @@ import org.aspectj.bridge.ISourceLocation;
public interface ISourceContext {
public ISourceLocation makeSourceLocation(IHasPosition position);
public ISourceLocation makeSourceLocation(int line);
+ public int getOffset();
}
diff --git a/weaver/src/org/aspectj/weaver/ataspectj/Aj5Attributes.java b/weaver/src/org/aspectj/weaver/ataspectj/Aj5Attributes.java
index f708b6f8f..2eb120ecd 100644
--- a/weaver/src/org/aspectj/weaver/ataspectj/Aj5Attributes.java
+++ b/weaver/src/org/aspectj/weaver/ataspectj/Aj5Attributes.java
@@ -27,7 +27,6 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.bridge.IMessageHandler;
-import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.Message;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -36,6 +35,7 @@ import org.aspectj.weaver.AdviceKind;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjcMemberMaker;
import org.aspectj.weaver.ISourceContext;
+import org.aspectj.weaver.NameMangler;
import org.aspectj.weaver.ResolvedPointcutDefinition;
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.TypeX;
@@ -142,14 +142,14 @@ public class Aj5Attributes {
* @param msgHandler
* @return list of AjAttributes
*/
- public static List readAj5ClassAttributes(JavaClass javaClass, ResolvedTypeX type, ISourceContext context,IMessageHandler msgHandler) {
+ public static List readAj5ClassAttributes(JavaClass javaClass, ResolvedTypeX type, ISourceContext context,IMessageHandler msgHandler, boolean isCodeStyleAspect) {
AjAttributeStruct struct = new AjAttributeStruct(type, context, msgHandler);
Attribute[] attributes = javaClass.getAttributes();
for (int i = 0; i < attributes.length; i++) {
Attribute attribute = attributes[i];
if (acceptAttribute(attribute)) {
RuntimeAnnotations rvs = (RuntimeAnnotations) attribute;
- handleAspectAnnotation(rvs, struct);
+ if (!isCodeStyleAspect) handleAspectAnnotation(rvs, struct);
handlePrecedenceAnnotation(rvs, struct);
}
}
@@ -161,6 +161,7 @@ public class Aj5Attributes {
//FIXME alex can that be too slow ?
for (int m = 0; m < javaClass.getMethods().length; m++) {
Method method = javaClass.getMethods()[m];
+ if (method.getName().startsWith(NameMangler.PREFIX)) continue; // already dealt with by ajc...
//FIXME alex optimize, this method struct will gets recreated for advice extraction
AjAttributeMethodStruct mstruct = new AjAttributeMethodStruct(method, type, context, msgHandler);
Attribute[] mattributes = method.getAttributes();
@@ -187,19 +188,21 @@ public class Aj5Attributes {
* @param msgHandler
* @return list of AjAttributes
*/
- public static List readAj5MethodAttributes(Method method, ResolvedTypeX type, ISourceContext context,IMessageHandler msgHandler) {
- AjAttributeMethodStruct struct = new AjAttributeMethodStruct(method, type, context, msgHandler);
+ public static List readAj5MethodAttributes(Method method, ResolvedTypeX type, ResolvedPointcutDefinition preResolvedPointcut, ISourceContext context,IMessageHandler msgHandler) {
+ if (method.getName().startsWith(NameMangler.PREFIX)) return Collections.EMPTY_LIST; // already dealt with by ajc...
+
+ AjAttributeMethodStruct struct = new AjAttributeMethodStruct(method, type, context, msgHandler);
Attribute[] attributes = method.getAttributes();
for (int i = 0; i < attributes.length; i++) {
Attribute attribute = attributes[i];
if (acceptAttribute(attribute)) {
RuntimeAnnotations rvs = (RuntimeAnnotations) attribute;
- handleBeforeAnnotation(rvs, struct);
- handleAfterAnnotation(rvs, struct);
- handleAfterReturningAnnotation(rvs, struct);
- handleAfterThrowingAnnotation(rvs, struct);
- handleAroundAnnotation(rvs, struct);
+ handleBeforeAnnotation(rvs, struct, preResolvedPointcut);
+ handleAfterAnnotation(rvs, struct, preResolvedPointcut);
+ handleAfterReturningAnnotation(rvs, struct, preResolvedPointcut);
+ handleAfterThrowingAnnotation(rvs, struct, preResolvedPointcut);
+ handleAroundAnnotation(rvs, struct, preResolvedPointcut);
}
}
return struct.ajAttributes;
@@ -215,6 +218,7 @@ public class Aj5Attributes {
* @return list of AjAttributes, always empty for now
*/
public static List readAj5FieldAttributes(Field field, ResolvedTypeX type, ISourceContext context,IMessageHandler msgHandler) {
+ if (field.getName().startsWith(NameMangler.PREFIX)) return Collections.EMPTY_LIST; // already dealt with by ajc...
return EMPTY_LIST;
}
@@ -271,7 +275,7 @@ public class Aj5Attributes {
} else if (perClause.startsWith(PerClause.KindAnnotationPrefix.PERTYPEWITHIN.getName())) {
pointcut = PerClause.KindAnnotationPrefix.PERTYPEWITHIN.extractPointcut(perClause);
return new PerTypeWithin(new PatternParser(pointcut).parseTypePattern());
- } else if (perClause.equalsIgnoreCase(PerClause.SINGLETON.getName())) {
+ } else if (perClause.equalsIgnoreCase(PerClause.SINGLETON.getName() + "()")) {
return new PerSingleton();
}
// could not parse the @AJ perclause
@@ -310,7 +314,7 @@ public class Aj5Attributes {
* @param runtimeAnnotations
* @param struct
*/
- private static void handleBeforeAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
+ private static void handleBeforeAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
Annotation before = getAnnotation(runtimeAnnotations, "org.aspectj.lang.annotation.Before");
if (before != null) {
ElementNameValuePair beforeAdvice = getAnnotationElement(before, "value");
@@ -325,7 +329,12 @@ public class Aj5Attributes {
// joinpoint, staticJoinpoint binding
int extraArgument = extractExtraArgument(struct.method);
- Pointcut pc = Pointcut.fromString(beforeAdvice.getValue().stringifyValue()).resolve(binding);
+ Pointcut pc = null;
+ if (preResolvedPointcut != null) {
+ pc = preResolvedPointcut.getPointcut();
+ } else {
+ pc = Pointcut.fromString(beforeAdvice.getValue().stringifyValue()).resolve(binding);
+ }
setIgnoreUnboundBindingNames(pc, bindings);
struct.ajAttributes.add(new AjAttribute.AdviceAttribute(
@@ -347,7 +356,7 @@ public class Aj5Attributes {
* @param runtimeAnnotations
* @param struct
*/
- private static void handleAfterAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
+ private static void handleAfterAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
Annotation after = getAnnotation(runtimeAnnotations, "org.aspectj.lang.annotation.After");
if (after != null) {
ElementNameValuePair afterAdvice = getAnnotationElement(after, "value");
@@ -362,7 +371,12 @@ public class Aj5Attributes {
// joinpoint, staticJoinpoint binding
int extraArgument = extractExtraArgument(struct.method);
- Pointcut pc = Pointcut.fromString(afterAdvice.getValue().stringifyValue()).resolve(binding);
+ Pointcut pc = null;
+ if (preResolvedPointcut != null) {
+ pc = preResolvedPointcut.getPointcut();
+ } else {
+ pc = Pointcut.fromString(afterAdvice.getValue().stringifyValue()).resolve(binding);
+ }
setIgnoreUnboundBindingNames(pc, bindings);
struct.ajAttributes.add(new AjAttribute.AdviceAttribute(
@@ -384,7 +398,7 @@ public class Aj5Attributes {
* @param runtimeAnnotations
* @param struct
*/
- private static void handleAfterReturningAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
+ private static void handleAfterReturningAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
Annotation after = getAnnotation(runtimeAnnotations, "org.aspectj.lang.annotation.AfterReturning");
if (after != null) {
ElementNameValuePair annValue = getAnnotationElement(after, "value");
@@ -427,7 +441,12 @@ public class Aj5Attributes {
extraArgument |= Advice.ExtraArgument;
}
- Pointcut pc = Pointcut.fromString(pointcut).resolve(binding);
+ Pointcut pc = null;
+ if (preResolvedPointcut != null) {
+ pc = preResolvedPointcut.getPointcut();
+ } else {
+ pc = Pointcut.fromString(pointcut).resolve(binding);
+ }
setIgnoreUnboundBindingNames(pc, bindings);
struct.ajAttributes.add(new AjAttribute.AdviceAttribute(
@@ -448,7 +467,7 @@ public class Aj5Attributes {
* @param runtimeAnnotations
* @param struct
*/
- private static void handleAfterThrowingAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
+ private static void handleAfterThrowingAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
Annotation after = getAnnotation(runtimeAnnotations, "org.aspectj.lang.annotation.AfterThrowing");
if (after != null) {
ElementNameValuePair annValue = getAnnotationElement(after, "value");
@@ -491,7 +510,12 @@ public class Aj5Attributes {
extraArgument |= Advice.ExtraArgument;
}
- Pointcut pc = Pointcut.fromString(pointcut).resolve(binding);
+ Pointcut pc = null;
+ if (preResolvedPointcut != null) {
+ pc = preResolvedPointcut.getPointcut();
+ } else {
+ pc = Pointcut.fromString(pointcut).resolve(binding);
+ }
setIgnoreUnboundBindingNames(pc, bindings);
struct.ajAttributes.add(new AjAttribute.AdviceAttribute(
@@ -512,7 +536,7 @@ public class Aj5Attributes {
* @param runtimeAnnotations
* @param struct
*/
- private static void handleAroundAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
+ private static void handleAroundAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
Annotation around = getAnnotation(runtimeAnnotations, "org.aspectj.lang.annotation.Around");
if (around != null) {
ElementNameValuePair aroundAdvice = getAnnotationElement(around, "value");
@@ -527,7 +551,12 @@ public class Aj5Attributes {
// joinpoint, staticJoinpoint binding
int extraArgument = extractExtraArgument(struct.method);
- Pointcut pc = Pointcut.fromString(aroundAdvice.getValue().stringifyValue()).resolve(binding);
+ Pointcut pc = null;
+ if (preResolvedPointcut != null) {
+ pc = preResolvedPointcut.getPointcut();
+ } else {
+ pc = Pointcut.fromString(aroundAdvice.getValue().stringifyValue()).resolve(binding);
+ }
setIgnoreUnboundBindingNames(pc, bindings);
struct.ajAttributes.add(new AjAttribute.AdviceAttribute(
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
index 7de8b3735..a8c629992 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
@@ -29,6 +29,7 @@ import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedPointcutDefinition;
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.ShadowMunger;
import org.aspectj.weaver.TypeX;
@@ -40,6 +41,7 @@ final class BcelMethod extends ResolvedMember {
private Method method;
private boolean isAjSynthetic;
private ShadowMunger associatedShadowMunger;
+ private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice
private ResolvedTypeX[] annotationTypes = null;
private AnnotationX[] annotations = null;
@@ -96,27 +98,33 @@ final class BcelMethod extends ResolvedMember {
}
private void unpackAjAttributes(World world) {
+ associatedShadowMunger = null;
List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world.getMessageHandler());
- as.addAll(Aj5Attributes.readAj5MethodAttributes(method, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler()));
+ processAttributes(world, as);
+ as = Aj5Attributes.readAj5MethodAttributes(method, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler());
+ processAttributes(world,as);
+ }
- //System.out.println("unpack: " + this + ", " + as);
+ private void processAttributes(World world, List as) {
for (Iterator iter = as.iterator(); iter.hasNext();) {
AjAttribute a = (AjAttribute) iter.next();
if (a instanceof AjAttribute.MethodDeclarationLineNumberAttribute) {
declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
} else if (a instanceof AjAttribute.AdviceAttribute) {
associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
- return;
+ // return;
} else if (a instanceof AjAttribute.AjSynthetic) {
isAjSynthetic = true;
} else if (a instanceof AjAttribute.EffectiveSignatureAttribute) {
//System.out.println("found effective: " + this);
effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a;
+ } else if (a instanceof AjAttribute.PointcutDeclarationAttribute) {
+ // this is an @AspectJ annotated advice method, with pointcut pre-resolved by ajc
+ preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify();
} else {
throw new BCException("weird method attribute " + a);
}
}
- associatedShadowMunger = null;
}
public boolean isAjSynthetic() {
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
index 46a7fe783..862b2a65b 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
@@ -66,6 +66,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
private boolean discoveredWhetherAnnotationStyle = false;
private boolean isAnnotationStyleAspect = false;// set upon construction
+ private boolean isCodeStyleAspect = false; // not redundant with field above!
public Collection getTypeMungers() {
@@ -185,7 +186,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
public boolean isAnnotationStyleAspect() {
if (!discoveredWhetherAnnotationStyle) {
discoveredWhetherAnnotationStyle = true;
- isAnnotationStyleAspect = hasAnnotation(Ajc5MemberMaker.ASPECT);
+ isAnnotationStyleAspect = !isCodeStyleAspect && hasAnnotation(Ajc5MemberMaker.ASPECT);
}
return isAnnotationStyleAspect;
}
@@ -196,13 +197,32 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
declares = new ArrayList();
// Pass in empty list that can store things for readAj5 to process
List l = BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass.getAttributes(), getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld().getMessageHandler());
- l.addAll(Aj5Attributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler()));
+ processAttributes(l,pointcuts,false);
+ l = Aj5Attributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler(),isCodeStyleAspect);
+ processAttributes(l,pointcuts,true);
+
+ this.pointcuts = (ResolvedPointcutDefinition[])
+ pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]);
+ // Test isn't quite right, leaving this out for now...
+// if (isAspect() && wvInfo.getMajorVersion() == WeaverVersionInfo.UNKNOWN.getMajorVersion()) {
+// throw new BCException("Unable to continue, this version of AspectJ cannot use aspects as input that were built "+
+// "with an AspectJ earlier than version 1.2.1. Please rebuild class: "+javaClass.getClassName());
+// }
+
+// this.typeMungers = (BcelTypeMunger[])
+// typeMungers.toArray(new BcelTypeMunger[typeMungers.size()]);
+// this.declares = (Declare[])
+// declares.toArray(new Declare[declares.size()]);
+ }
- for (Iterator iter = l.iterator(); iter.hasNext();) {
+
+ private void processAttributes(List attributeList, List pointcuts, boolean fromAnnotations) {
+ for (Iterator iter = attributeList.iterator(); iter.hasNext();) {
AjAttribute a = (AjAttribute) iter.next();
//System.err.println("unpacking: " + this + " and " + a);
if (a instanceof AjAttribute.Aspect) {
perClause = ((AjAttribute.Aspect)a).reify(this.getResolvedTypeX());
+ if (!fromAnnotations) isCodeStyleAspect = true;
} else if (a instanceof AjAttribute.PointcutDeclarationAttribute) {
pointcuts.add(((AjAttribute.PointcutDeclarationAttribute)a).reify());
} else if (a instanceof AjAttribute.WeaverState) {
@@ -223,18 +243,6 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
throw new BCException("bad attribute " + a);
}
}
- this.pointcuts = (ResolvedPointcutDefinition[])
- pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]);
- // Test isn't quite right, leaving this out for now...
-// if (isAspect() && wvInfo.getMajorVersion() == WeaverVersionInfo.UNKNOWN.getMajorVersion()) {
-// throw new BCException("Unable to continue, this version of AspectJ cannot use aspects as input that were built "+
-// "with an AspectJ earlier than version 1.2.1. Please rebuild class: "+javaClass.getClassName());
-// }
-
-// this.typeMungers = (BcelTypeMunger[])
-// typeMungers.toArray(new BcelTypeMunger[typeMungers.size()]);
-// this.declares = (Declare[])
-// declares.toArray(new Declare[declares.size()]);
}
public PerClause getPerClause() {
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java b/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
index 8f7f4065a..8d313c4e7 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
@@ -51,6 +51,8 @@ public class BcelSourceContext implements ISourceContext {
return new File(fileName);
}
+
+ public int getOffset() { return 0; }
/*
// AMC - a temporary "fudge" to give as much information as possible about the identity of the
diff --git a/weaver/src/org/aspectj/weaver/patterns/BasicTokenSource.java b/weaver/src/org/aspectj/weaver/patterns/BasicTokenSource.java
index c8c215a3d..dad3bccd4 100644
--- a/weaver/src/org/aspectj/weaver/patterns/BasicTokenSource.java
+++ b/weaver/src/org/aspectj/weaver/patterns/BasicTokenSource.java
@@ -80,7 +80,7 @@ public class BasicTokenSource implements ITokenSource {
//////////////////////////////////////////////////////
// Convenience, maybe just for testing
- static ITokenSource makeTokenSource(String input) {
+ static ITokenSource makeTokenSource(String input, ISourceContext context) {
char[] chars = input.toCharArray();
int i = 0;
@@ -136,7 +136,7 @@ public class BasicTokenSource implements ITokenSource {
//System.out.println(tokens);
- return new BasicTokenSource((IToken[])tokens.toArray(new IToken[tokens.size()]), null);
+ return new BasicTokenSource((IToken[])tokens.toArray(new IToken[tokens.size()]), context);
}
private static String makeString(char ch) {
@@ -153,5 +153,8 @@ public class BasicTokenSource implements ITokenSource {
public ISourceContext getSourceContext() {
return sourceContext;
}
+ public void setSourceContext(ISourceContext context) {
+ this.sourceContext = context;
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternNode.java b/weaver/src/org/aspectj/weaver/patterns/PatternNode.java
index c49b52923..0730538ca 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PatternNode.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PatternNode.java
@@ -31,11 +31,11 @@ public abstract class PatternNode implements IHasSourceLocation {
}
public int getStart() {
- return start;
+ return start + (sourceContext != null ? sourceContext.getOffset() : 0);
}
public int getEnd() {
- return end;
+ return end + (sourceContext != null ? sourceContext.getOffset() : 0);
}
public ISourceContext getSourceContext() {
diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
index ffd4446ca..ea0be3fe2 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java
@@ -1160,6 +1160,10 @@ public class PatternParser {
public PatternParser(String data) {
- this(BasicTokenSource.makeTokenSource(data));
+ this(BasicTokenSource.makeTokenSource(data,null));
+ }
+
+ public PatternParser(String data, ISourceContext context) {
+ this(BasicTokenSource.makeTokenSource(data,context));
}
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerCflow.java b/weaver/src/org/aspectj/weaver/patterns/PerCflow.java
index 97c06bc55..cded77643 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerCflow.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerCflow.java
@@ -126,4 +126,9 @@ public class PerCflow extends PerClause {
public String toString() {
return "percflow(" + inAspect + " on " + entry + ")";
}
+
+ public String toDeclarationString() {
+ if (isBelow) return "percflowbelow(" + entry + ")";
+ return "percflow(" + entry + ")";
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerClause.java b/weaver/src/org/aspectj/weaver/patterns/PerClause.java
index e8fbc834a..d410436b0 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerClause.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerClause.java
@@ -41,6 +41,8 @@ public abstract class PerClause extends Pointcut {
public abstract PerClause.Kind getKind();
+ public abstract String toDeclarationString();
+
public static class Kind extends TypeSafeEnum {
public Kind(String name, int key) { super(name, key); }
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java b/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java
index d7841008e..87d6b61db 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerFromSuper.java
@@ -97,6 +97,10 @@ public class PerFromSuper extends PerClause {
public String toString() {
return "perFromSuper(" + kind + ", " + inAspect + ")";
}
+
+ public String toDeclarationString() {
+ return "";
+ }
public PerClause.Kind getKind() {
return kind;
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerObject.java b/weaver/src/org/aspectj/weaver/patterns/PerObject.java
index b4283bc0e..79426942e 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerObject.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerObject.java
@@ -137,4 +137,8 @@ public class PerObject extends PerClause {
return "per" + (isThis ? "this" : "target") +
"(" + entry + ")";
}
+
+ public String toDeclarationString() {
+ return toString();
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java
index 169e83962..f98d07980 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java
@@ -126,5 +126,9 @@ public class PerSingleton extends PerClause {
public String toString() {
return "persingleton(" + inAspect + ")";
}
+
+ public String toDeclarationString() {
+ return "";
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java b/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java
index cdc7c3aa9..151e3f2d7 100644
--- a/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java
+++ b/weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java
@@ -169,6 +169,10 @@ public class PerTypeWithin extends PerClause {
return "pertypewithin("+typePattern+")";
}
+ public String toDeclarationString() {
+ return toString();
+ }
+
private FuzzyBoolean isWithinType(ResolvedTypeX type) {
while (type != null) {
if (typePattern.matchesStatically(type)) {
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java
index b43526586..cd646b122 100644
--- a/weaver/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/patterns/NamePatternParserTestCase.java
@@ -51,7 +51,7 @@ public class NamePatternParserTestCase extends TestCase {
private void checkMatch(String[] patterns) {
for (int i=0, len=patterns.length; i < len; i++) {
String pattern = patterns[i];
- ITokenSource tokenSource = BasicTokenSource.makeTokenSource(pattern);
+ ITokenSource tokenSource = BasicTokenSource.makeTokenSource(pattern,null);
NamePattern p1 = new PatternParser(tokenSource).parseNamePattern();
NamePattern p2 = new NamePattern(pattern);
assertEquals("pattern: " + pattern, p2, p1);