aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-05-31 09:35:11 +0000
committeravasseur <avasseur>2005-05-31 09:35:11 +0000
commit883a12ba6407156d15fc5b53b8590e3a15b262f6 (patch)
tree1fc9fda57208a5a0b5fdb42d9ebf1d732c86440a
parentf14646f57a93e7ec865416048c4491d9943064e5 (diff)
downloadaspectj-883a12ba6407156d15fc5b53b8590e3a15b262f6.tar.gz
aspectj-883a12ba6407156d15fc5b53b8590e3a15b262f6.zip
@AJ aspect inheritance and static pc ref
-rw-r--r--tests/java5/ataspectj/ataspectj/AllLTWTests.java1
-rw-r--r--tests/java5/ataspectj/ataspectj/SingletonInheritanceTest.java84
-rw-r--r--tests/java5/ataspectj/ataspectj/pathentry/META-INF/aop.xml2
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java4
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml8
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java26
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java2
7 files changed, 124 insertions, 3 deletions
diff --git a/tests/java5/ataspectj/ataspectj/AllLTWTests.java b/tests/java5/ataspectj/ataspectj/AllLTWTests.java
index e015a0a8e..7ef68618e 100644
--- a/tests/java5/ataspectj/ataspectj/AllLTWTests.java
+++ b/tests/java5/ataspectj/ataspectj/AllLTWTests.java
@@ -34,6 +34,7 @@ public class AllLTWTests extends TestCase {
suite.addTestSuite(ataspectj.BindingTest.class);
suite.addTestSuite(ataspectj.PerClauseTest.class);
suite.addTestSuite(AroundInlineMungerTest.class);
+ suite.addTestSuite(SingletonInheritanceTest.class);
return suite;
}
diff --git a/tests/java5/ataspectj/ataspectj/SingletonInheritanceTest.java b/tests/java5/ataspectj/ataspectj/SingletonInheritanceTest.java
new file mode 100644
index 000000000..9393afaae
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/SingletonInheritanceTest.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.annotation.Before;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class SingletonInheritanceTest extends TestCase {
+
+ static StringBuffer s_log = new StringBuffer();
+
+ static void log(String s) {
+ s_log.append(s).append(" ");
+ }
+
+ public static void main(String[] args) {
+ TestHelper.runAndThrowOnFailure(suite());
+ }
+
+ public static junit.framework.Test suite() {
+ return new junit.framework.TestSuite(ataspectj.SingletonInheritanceTest.class);
+ }
+
+ public void hello() {
+ log("hello");
+ }
+
+ public void hello2() {
+ log("hello2");
+ }
+
+ public void testInheritance() {
+ s_log = new StringBuffer();
+ hello();
+ assertEquals("aop hello ", s_log.toString());
+ }
+
+ public void testStaticRef() {
+ s_log = new StringBuffer();
+ hello2();
+ assertEquals("aop2 hello2 ", s_log.toString());
+ }
+
+ @Aspect
+ static abstract class AbstractAspect {
+ @Pointcut("execution(* ataspectj.SingletonInheritanceTest.hello2())")
+ void pc2() {}
+ }
+
+ @Aspect
+ static abstract class ParentAspect {
+ @Pointcut("execution(* ataspectj.SingletonInheritanceTest.hello())")
+ void pc() {}
+ }
+
+ @Aspect
+ static class ChildAspect extends ParentAspect {
+ @Before("pc()")
+ public void abefore() {
+ log("aop");
+ }
+
+ @Before("ataspectj.SingletonInheritanceTest.AbstractAspect.pc2()")
+ public void abefore2() {
+ log("aop2");
+ }
+ }
+
+
+}
diff --git a/tests/java5/ataspectj/ataspectj/pathentry/META-INF/aop.xml b/tests/java5/ataspectj/ataspectj/pathentry/META-INF/aop.xml
index 365cd5d17..e2fa88d1b 100644
--- a/tests/java5/ataspectj/ataspectj/pathentry/META-INF/aop.xml
+++ b/tests/java5/ataspectj/ataspectj/pathentry/META-INF/aop.xml
@@ -22,5 +22,7 @@
<aspect name="ataspectj.PerClauseTestAspects.TestAspectPTW"/>
<aspect name="ataspectj.AroundInlineMungerTestAspects.Open"/>
+
+ <aspect name="ataspectj.SingletonInheritanceTest.ChildAspect"/>
</aspects>
</aspectj>
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java
index 6c936ef4f..27803227a 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java
+++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java
@@ -91,4 +91,8 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase {
public void testDeow() {
runTest("Deow");
}
+
+ public void testSingletonInheritance() {
+ runTest("singletonInheritance");
+ }
} \ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml
index 2a4024617..b3697fbb0 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml
+++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml
@@ -107,4 +107,12 @@
<message kind="error" line="29" text="call hi"/>
</compile>
</ajc-test>
+
+ <ajc-test dir="java5/ataspectj" title="singletonInheritance">
+ <compile files="ataspectj/SingletonInheritanceTest.java,ataspectj/TestHelper.java" options="-1.5 -XnoInline"/>
+ <run class="ataspectj.SingletonInheritanceTest"/>
+ <compile files="ataspectj/SingletonInheritanceTest.java,ataspectj/TestHelper.java" options="-1.5 -XnoInline -Xdev:NoAtAspectJProcessing"/>
+ <run class="ataspectj.SingletonInheritanceTest"/>
+ </ajc-test>
+
</suite> \ No newline at end of file
diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
index 154ec2748..595372848 100644
--- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
+++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
@@ -25,6 +25,8 @@ import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.Message;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.Advice;
import org.aspectj.weaver.AdviceKind;
import org.aspectj.weaver.AjAttribute;
@@ -34,6 +36,7 @@ import org.aspectj.weaver.NameMangler;
import org.aspectj.weaver.ResolvedPointcutDefinition;
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.TypeX;
+import org.aspectj.weaver.IHasPosition;
import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
import org.aspectj.weaver.patterns.DeclarePrecedence;
import org.aspectj.weaver.patterns.FormalBinding;
@@ -406,6 +409,13 @@ public class AtAjAttributes {
// could not parse it, ignore the aspect
return false;
} else {
+ // semantic check for inheritance (only one level up)
+ if (!"java.lang.Object".equals(struct.enclosingType.getSuperclass().getName())) {
+ if (!struct.enclosingType.getSuperclass().isAbstract() && struct.enclosingType.getSuperclass().isAspect()) {
+ reportError("cannot extend a concrete aspect", struct);
+ return false;
+ }
+ }
perClause.setLocation(struct.context, -1, -1);
struct.ajAttributes.add(new AjAttribute.Aspect(perClause));
return true;
@@ -510,6 +520,7 @@ public class AtAjAttributes {
}
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
@@ -563,6 +574,7 @@ public class AtAjAttributes {
}
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
@@ -641,6 +653,7 @@ public class AtAjAttributes {
}
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
@@ -723,6 +736,7 @@ public class AtAjAttributes {
}
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
@@ -780,6 +794,7 @@ public class AtAjAttributes {
}
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
@@ -840,6 +855,7 @@ public class AtAjAttributes {
try {
binding = new BindingScope(
struct.enclosingType,
+ struct.context,
extractBindings(struct)
);
} catch (UnreadableDebugInfoException e) {
@@ -893,6 +909,7 @@ public class AtAjAttributes {
FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct);
@@ -919,6 +936,7 @@ public class AtAjAttributes {
FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
IScope binding = new BindingScope(
struct.enclosingType,
+ struct.context,
bindings
);
Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct);
@@ -1176,15 +1194,21 @@ public class AtAjAttributes {
*/
public static class BindingScope extends SimpleScope {
private ResolvedTypeX m_enclosingType;
+ private ISourceContext m_sourceContext;
- public BindingScope(ResolvedTypeX type, FormalBinding[] bindings) {
+ public BindingScope(ResolvedTypeX type, ISourceContext sourceContext, FormalBinding[] bindings) {
super(type.getWorld(), bindings);
m_enclosingType = type;
+ m_sourceContext = sourceContext;
}
public ResolvedTypeX getEnclosingType() {
return m_enclosingType;
}
+
+ public ISourceLocation makeSourceLocation(IHasPosition location) {
+ return m_sourceContext.makeSourceLocation(location);
+ }
}
/**
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java b/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
index 8d313c4e7..ea748b953 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
@@ -77,8 +77,6 @@ public class BcelSourceContext implements ISourceContext {
public ISourceLocation makeSourceLocation(IHasPosition position) {
-
-
if (lineBreaks != null) {
int line = Arrays.binarySearch(lineBreaks, position.getStart());
if (line < 0) line = -line;