@@ -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; | |||
} |
@@ -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"); | |||
} | |||
} | |||
} |
@@ -22,5 +22,7 @@ | |||
<aspect name="ataspectj.PerClauseTestAspects.TestAspectPTW"/> | |||
<aspect name="ataspectj.AroundInlineMungerTestAspects.Open"/> | |||
<aspect name="ataspectj.SingletonInheritanceTest.ChildAspect"/> | |||
</aspects> | |||
</aspectj> |
@@ -91,4 +91,8 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase { | |||
public void testDeow() { | |||
runTest("Deow"); | |||
} | |||
public void testSingletonInheritance() { | |||
runTest("singletonInheritance"); | |||
} | |||
} |
@@ -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> |
@@ -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); | |||
} | |||
} | |||
/** |
@@ -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; |