@@ -1,13 +1,14 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* 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: | |||
* PARC initial implementation | |||
* 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: | |||
* PARC initial implementation | |||
* Alexandre Vasseur support for @AJ style | |||
* ******************************************************************/ | |||
package org.aspectj.ajdt.internal.core.builder; | |||
@@ -39,6 +40,7 @@ import org.aspectj.weaver.patterns.TypePattern; | |||
import org.aspectj.weaver.patterns.TypePatternList; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation; | |||
/** | |||
* @author Mik Kersten | |||
@@ -218,9 +220,31 @@ public class AsmElementFormatter { | |||
node.setKind(IProgramElement.Kind.CONSTRUCTOR); | |||
} else { | |||
node.setKind(IProgramElement.Kind.METHOD); | |||
} | |||
String label = new String(methodDeclaration.selector); | |||
node.setName(label); | |||
//TODO AV - could speed up if we could dig only for @Aspect declaring types (or aspect if mixed style allowed) | |||
//??? how to : node.getParent().getKind().equals(IProgramElement.Kind.ASPECT)) { | |||
if (true && methodDeclaration.annotations != null) { | |||
for (int i = 0; i < methodDeclaration.annotations.length; i++) { | |||
//Note: AV: implicit single advice type support here (should be enforced somewhere as well (APT etc)) | |||
Annotation annotation = methodDeclaration.annotations[i]; | |||
String annotationSig = new String(annotation.type.getTypeBindingPublic(methodDeclaration.scope).signature()); | |||
if ("Lorg/aspectj/lang/annotation/Pointcut;".equals(annotationSig)) { | |||
node.setKind(IProgramElement.Kind.POINTCUT); | |||
break; | |||
} else if ("Lorg/aspectj/lang/annotation/Before;".equals(annotationSig) | |||
|| "Lorg/aspectj/lang/annotation/After;".equals(annotationSig) | |||
|| "Lorg/aspectj/lang/annotation/AfterReturning;".equals(annotationSig) | |||
|| "Lorg/aspectj/lang/annotation/AfterThrowing;".equals(annotationSig) | |||
|| "Lorg/aspectj/lang/annotation/Around;".equals(annotationSig)) { | |||
node.setKind(IProgramElement.Kind.ADVICE); | |||
//TODO AV - all are considered anonymous - is that ok? | |||
node.setDetails(POINTCUT_ANONYMOUS); | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
node.setName(new String(methodDeclaration.selector)); | |||
setParameters(methodDeclaration, node); | |||
} | |||
} |
@@ -1,14 +1,15 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* 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: | |||
* PARC initial implementation | |||
* Mik Kersten revisions, added additional relationships | |||
* 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: | |||
* PARC initial implementation | |||
* Mik Kersten revisions, added additional relationships | |||
* Alexandre Vasseur support for @AJ style | |||
* ******************************************************************/ | |||
@@ -211,6 +212,17 @@ public class AsmHierarchyBuilder extends ASTVisitor { | |||
else if (typeDeclaration.kind() == IGenericType.ENUM_DECL) kind = IProgramElement.Kind.ENUM; | |||
else if (typeDeclaration.kind() == IGenericType.ANNOTATION_TYPE_DECL) kind = IProgramElement.Kind.ANNOTATION; | |||
//@AJ support | |||
if (typeDeclaration.annotations != null) { | |||
for (int i = 0; i < typeDeclaration.annotations.length; i++) { | |||
Annotation annotation = typeDeclaration.annotations[i]; | |||
if (Arrays.equals(annotation.type.getTypeBindingPublic(scope).signature(), | |||
"Lorg/aspectj/lang/annotation/Aspect;".toCharArray())) { | |||
kind = IProgramElement.Kind.ASPECT; | |||
} | |||
} | |||
} | |||
IProgramElement peNode = new ProgramElement( | |||
name, | |||
kind, | |||
@@ -239,6 +251,17 @@ public class AsmHierarchyBuilder extends ASTVisitor { | |||
else if (memberTypeDeclaration.kind() == IGenericType.ENUM_DECL) kind = IProgramElement.Kind.ENUM; | |||
else if (memberTypeDeclaration.kind() == IGenericType.ANNOTATION_TYPE_DECL) kind = IProgramElement.Kind.ANNOTATION; | |||
//@AJ support | |||
if (memberTypeDeclaration.annotations != null) { | |||
for (int i = 0; i < memberTypeDeclaration.annotations.length; i++) { | |||
Annotation annotation = memberTypeDeclaration.annotations[i]; | |||
if (Arrays.equals(annotation.type.getTypeBindingPublic(scope).signature(), | |||
"Lorg/aspectj/lang/annotation/Aspect;".toCharArray())) { | |||
kind = IProgramElement.Kind.ASPECT; | |||
} | |||
} | |||
} | |||
IProgramElement peNode = new ProgramElement( | |||
name, | |||
kind, | |||
@@ -277,6 +300,18 @@ public class AsmHierarchyBuilder extends ASTVisitor { | |||
else if (memberTypeDeclaration.kind() == IGenericType.ENUM_DECL) kind = IProgramElement.Kind.ENUM; | |||
else if (memberTypeDeclaration.kind() == IGenericType.ANNOTATION_TYPE_DECL) kind = IProgramElement.Kind.ANNOTATION; | |||
//@AJ support | |||
if (memberTypeDeclaration.annotations != null) { | |||
for (int i = 0; i < memberTypeDeclaration.annotations.length; i++) { | |||
Annotation annotation = memberTypeDeclaration.annotations[i]; | |||
if (Arrays.equals(annotation.type.getTypeBindingPublic(scope).signature(), | |||
"Lorg/aspectj/lang/annotation/Aspect;".toCharArray())) { | |||
kind = IProgramElement.Kind.ASPECT; | |||
break; | |||
} | |||
} | |||
} | |||
IProgramElement peNode = new ProgramElement( | |||
fullName, | |||
kind, |
@@ -50,8 +50,19 @@ public class EclipseSourceContext implements ISourceContext { | |||
return new EclipseSourceLocation(result, position.getStart(), position.getEnd()); | |||
} | |||
public ISourceLocation makeSourceLocation(int line) { | |||
return new SourceLocation(getSourceFile(), line); | |||
public ISourceLocation makeSourceLocation(int line) { | |||
SourceLocation sl = new SourceLocation(getSourceFile(), line); | |||
// compute the offset | |||
//TODO AV - should we do it lazily? | |||
int[] offsets = result.lineSeparatorPositions; | |||
int likelyOffset = 0; | |||
if (line > 0 && line < offsets.length) { | |||
//1st char of given line is next char after previous end of line | |||
likelyOffset = offsets[line-1]; | |||
} | |||
sl.setOffset(likelyOffset); | |||
return sl; | |||
} | |||
} |
@@ -21,7 +21,7 @@ | |||
<!-- use META-INF/aop.xml style --> | |||
<classpath path="ataspectj/pathentry"/> | |||
<jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/> | |||
<!--<jvmarg line="${jdwp}"/>--> | |||
<!-- <jvmarg line="${jdwp}"/>--> | |||
</java> | |||
</target> | |||
@@ -19,6 +19,9 @@ import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import junit.framework.TestCase; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
/** | |||
* Test various advice and JoinPoint + binding, without pc ref | |||
* | |||
@@ -129,4 +132,20 @@ public class SingletonAspectBindingsTest extends TestCase { | |||
} | |||
} | |||
// public void testHe() throws Throwable { | |||
// //Allow to look inn file based on advises/advised-by offset numbers | |||
// File f = new File("../tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj"); | |||
// FileReader r = new FileReader(f); | |||
// int i = 0; | |||
// for (i = 0; i < 2800; i++) { | |||
// r.read(); | |||
// } | |||
// for (;i < 2900; i++) { | |||
// if (i == 2817) System.out.print("X"); | |||
// System.out.print((char)r.read()); | |||
// } | |||
// System.out.print("|DONE"); | |||
// r.close(); | |||
// } | |||
} |
@@ -0,0 +1,150 @@ | |||
/******************************************************************************* | |||
* 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: | |||
* initial implementation Alexandre Vasseur | |||
*******************************************************************************/ | |||
package ataspectj; | |||
import org.aspectj.lang.annotation.Before; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.aspectj.lang.annotation.After; | |||
import org.aspectj.lang.annotation.Around; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import junit.framework.TestCase; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
/** | |||
* Test various advice and JoinPoint + binding, without pc ref | |||
* | |||
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> | |||
*/ | |||
public class SingletonAspectBindingsTest2 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(SingletonAspectBindingsTest2.class); | |||
} | |||
public void hello() { | |||
log("hello"); | |||
} | |||
public void hello(String s) { | |||
log("hello-"); | |||
log(s); | |||
} | |||
public void testExecutionWithThisBinding() { | |||
s_log = new StringBuffer(); | |||
SingletonAspectBindingsTest2 me = new SingletonAspectBindingsTest2(); | |||
me.hello(); | |||
// see here advice precedence as in source code order | |||
//TODO check around relative order | |||
// see fix in BcelWeaver sorting shadowMungerList | |||
//assertEquals("around2_ around_ before hello after _around _around2 ", s_log.toString()); | |||
assertEquals("around_ around2_ before hello _around2 _around after ", s_log.toString()); | |||
} | |||
public void testExecutionWithArgBinding() { | |||
s_log = new StringBuffer(); | |||
SingletonAspectBindingsTest2 me = new SingletonAspectBindingsTest2(); | |||
me.hello("x"); | |||
assertEquals("before- x hello- x ", s_log.toString()); | |||
} | |||
//@Aspect | |||
static aspect TestAspect { | |||
static int s = 0; | |||
static { | |||
s++; | |||
} | |||
public TestAspect() { | |||
// assert clinit has run when singleton aspectOf reaches that | |||
assertTrue(s>0); | |||
} | |||
//public static TestAspect aspectOf() {return null;} | |||
void around() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) { | |||
//public void aaround(ProceedingJoinPoint jp) { | |||
log("around_"); | |||
try { | |||
proceed(); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
log("_around"); | |||
} | |||
void around(Object t) : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) && this(t) { | |||
//public void around2(ProceedingJoinPoint jp, Object t) { | |||
log("around2_"); | |||
assertEquals(SingletonAspectBindingsTest2.class.getName(), t.getClass().getName()); | |||
try { | |||
proceed(t); | |||
} catch (Throwable throwable) { | |||
throwable.printStackTrace(); | |||
} | |||
log("_around2"); | |||
} | |||
before() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) { | |||
//public void before(JoinPoint.StaticPart sjp) { | |||
log("before"); | |||
assertEquals("hello", thisJoinPointStaticPart.getSignature().getName()); | |||
} | |||
after() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) { | |||
//public void after(JoinPoint.StaticPart sjp) { | |||
log("after"); | |||
assertEquals("execution(public void ataspectj.SingletonAspectBindingsTest2.hello())", thisJoinPointStaticPart.toLongString()); | |||
} | |||
//TODO see String alias, see before advice name clash - all that works | |||
// 1/ String is in java.lang.* - see SimpleScope.javalangPrefix array | |||
// 2/ the advice is register thru its Bcel Method mirror | |||
before(String s) : execution(* ataspectj.SingletonAspectBindingsTest2.hello(String)) && args(s) { | |||
//public void before(String s, JoinPoint.StaticPart sjp) { | |||
log("before-"); | |||
log(s); | |||
assertEquals("hello", thisJoinPointStaticPart.getSignature().getName()); | |||
} | |||
} | |||
// public void testHe() throws Throwable { | |||
// File f = new File("../tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj"); | |||
// FileReader r = new FileReader(f); | |||
// int i = 0; | |||
// for (i = 0; i < 3950; i++) { | |||
// r.read(); | |||
// } | |||
// for (;i < 4000; i++) { | |||
// if (i == 3983) System.out.print("X"); | |||
// System.out.print((char)r.read()); | |||
// } | |||
// System.out.print("|DONE"); | |||
// r.close(); | |||
// } | |||
} |
@@ -27,9 +27,6 @@ import org.aspectj.systemtest.xlint.XLintTests; | |||
/** | |||
* @author colyer | |||
* | |||
* TODO To change the template for this generated type comment go to | |||
* Window - Preferences - Java - Code Style - Code Templates | |||
*/ | |||
public class AllTests { | |||
@@ -54,6 +51,7 @@ public class AllTests { | |||
suite.addTest(SUIDTests.suite()); | |||
suite.addTest(XLintTests.suite()); | |||
//$JUnit-END$ | |||
return suite; | |||
} | |||
} |
@@ -40,7 +40,13 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase { | |||
} | |||
public void testSingletonAspectBindings() { | |||
//Note AV: uncomment setReporting to get it in modules/tests folder | |||
//org.aspectj.asm.AsmManager.setReporting("debug.txt",true,true,true,true); | |||
runTest("singletonAspectBindings"); | |||
// same stuff with AJ | |||
//org.aspectj.asm.AsmManager.setReporting("debug-aj.txt",true,true,true,true); | |||
runTest("singletonAspectBindings2"); | |||
} | |||
public void testCflowTest() { |
@@ -3,11 +3,11 @@ | |||
<ajc-test dir="java5/ataspectj" title="SimpleBefore"> | |||
<compile files="SimpleBefore.java" options="-1.5 -showWeaveInfo -XnoInline"> | |||
<message kind="weave" text="(SimpleBefore.java:23) advised by before advice from 'SimpleBefore$X' (SimpleBefore.java:1)"/> | |||
<message kind="weave" text="(SimpleBefore.java:23) advised by before advice from 'SimpleBefore$X' (SimpleBefore.java:33)"/> | |||
</compile> | |||
<run class="SimpleBefore"/> | |||
<compile files="SimpleBefore.java" options="-1.5 -showWeaveInfo -XnoInline -Xdev:NoAtAspectJProcessing"> | |||
<message kind="weave" text="(SimpleBefore.java:23) advised by before advice from 'SimpleBefore$X' (SimpleBefore.java:1)"/> | |||
<message kind="weave" text="(SimpleBefore.java:23) advised by before advice from 'SimpleBefore$X' (SimpleBefore.java:33)"/> | |||
</compile> | |||
<run class="SimpleBefore"/> | |||
</ajc-test> | |||
@@ -24,12 +24,17 @@ | |||
</ajc-test> | |||
<ajc-test dir="java5/ataspectj" title="singletonAspectBindings"> | |||
<compile files="ataspectj/SingletonAspectBindingsTest.java,ataspectj/TestHelper.java" options="-1.5 -XnoInline"/> | |||
<compile files="ataspectj/SingletonAspectBindingsTest.java,ataspectj/TestHelper.java" options="-1.5 -emacssym -XnoInline"/> | |||
<run class="ataspectj.SingletonAspectBindingsTest"/> | |||
<compile files="ataspectj/SingletonAspectBindingsTest.java,ataspectj/TestHelper.java" options="-1.5 -XnoInline -Xdev:NoAtAspectJProcessing"/> | |||
<compile files="ataspectj/SingletonAspectBindingsTest.java,ataspectj/TestHelper.java" options="-1.5 -emacssym -XnoInline -Xdev:NoAtAspectJProcessing"/> | |||
<run class="ataspectj.SingletonAspectBindingsTest"/> | |||
</ajc-test> | |||
<ajc-test dir="java5/ataspectj" title="singletonAspectBindings2"> | |||
<compile files="ataspectj/SingletonAspectBindingsTest2.aj,ataspectj/TestHelper.java" options="-1.5 -emacssym -XnoInline"/> | |||
<run class="ataspectj.SingletonAspectBindingsTest2"/> | |||
</ajc-test> | |||
<ajc-test dir="java5/ataspectj" title="CflowTest"> | |||
<compile files="ataspectj/CflowTest.java,ataspectj/TestHelper.java" options="-1.5"/> | |||
<run class="ataspectj.CflowTest"/> |
@@ -1,6 +1,6 @@ | |||
<?xml version="1.0"?> | |||
<!-- see ../build/*.html for explanation --> | |||
<project name="weaver" default="test" basedir="."> | |||
<import file="${basedir}/../build/build.xml"/> | |||
<import file="${basedir}/../build/build.xml"/> | |||
</project> | |||
@@ -32,6 +32,7 @@ import org.aspectj.bridge.IMessage; | |||
import org.aspectj.bridge.IMessageHandler; | |||
import org.aspectj.bridge.ISourceLocation; | |||
import org.aspectj.bridge.Message; | |||
import org.aspectj.bridge.SourceLocation; | |||
import org.aspectj.weaver.Advice; | |||
import org.aspectj.weaver.AdviceKind; | |||
import org.aspectj.weaver.AjAttribute; | |||
@@ -121,10 +122,12 @@ public class AtAjAttributes { | |||
private String[] m_argumentNamesLazy = null; | |||
final Method method; | |||
final BcelMethod bMethod; | |||
public AjAttributeMethodStruct(Method method, ResolvedTypeX type, ISourceContext sourceContext, IMessageHandler messageHandler) { | |||
public AjAttributeMethodStruct(Method method, BcelMethod bMethod, ResolvedTypeX type, ISourceContext sourceContext, IMessageHandler messageHandler) { | |||
super(type, sourceContext, messageHandler); | |||
this.method = method; | |||
this.bMethod = bMethod; | |||
} | |||
public String[] getArgumentNames() { | |||
@@ -230,7 +233,7 @@ public class AtAjAttributes { | |||
Method method = javaClass.getMethods()[i]; | |||
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); | |||
AjAttributeMethodStruct mstruct = new AjAttributeMethodStruct(method, null, type, context, msgHandler);//FIXME AVASM | |||
Attribute[] mattributes = method.getAttributes(); | |||
for (int j = 0; j < mattributes.length; j++) { | |||
@@ -290,10 +293,10 @@ public class AtAjAttributes { | |||
* @param msgHandler | |||
* @return list of AjAttributes | |||
*/ | |||
public static List readAj5MethodAttributes(Method method, ResolvedTypeX type, ResolvedPointcutDefinition preResolvedPointcut, ISourceContext context, IMessageHandler msgHandler) { | |||
public static List readAj5MethodAttributes(Method method, BcelMethod bMethod, 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); | |||
AjAttributeMethodStruct struct = new AjAttributeMethodStruct(method, bMethod, type, context, msgHandler); | |||
Attribute[] attributes = method.getAttributes(); | |||
// we remember if we found one @AJ annotation for minimal semantic error reporting | |||
@@ -427,7 +430,7 @@ public class AtAjAttributes { | |||
// could not parse it, ignore the aspect | |||
return false; | |||
} else { | |||
perClause.setLocation(struct.context, -1, -1); | |||
perClause.setLocation(struct.context, struct.context.getOffset(), struct.context.getOffset()+1);//FIXME AVASM | |||
struct.ajAttributes.add(new AjAttribute.Aspect(perClause)); | |||
return true; | |||
} | |||
@@ -549,13 +552,14 @@ public class AtAjAttributes { | |||
} | |||
setIgnoreUnboundBindingNames(pc, bindings); | |||
ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber()); | |||
struct.ajAttributes.add( | |||
new AjAttribute.AdviceAttribute( | |||
AdviceKind.Before, | |||
pc, | |||
extraArgument, | |||
-1, | |||
-1, | |||
sl.getOffset(), | |||
sl.getOffset()+1,//FIXME AVASM | |||
struct.context | |||
) | |||
); | |||
@@ -603,13 +607,14 @@ public class AtAjAttributes { | |||
} | |||
setIgnoreUnboundBindingNames(pc, bindings); | |||
ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber()); | |||
struct.ajAttributes.add( | |||
new AjAttribute.AdviceAttribute( | |||
AdviceKind.After, | |||
pc, | |||
extraArgument, | |||
-1, | |||
-1, | |||
sl.getOffset(), | |||
sl.getOffset()+1,//FIXME AVASM | |||
struct.context | |||
) | |||
); | |||
@@ -687,13 +692,14 @@ public class AtAjAttributes { | |||
} | |||
setIgnoreUnboundBindingNames(pc, bindings); | |||
ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber()); | |||
struct.ajAttributes.add( | |||
new AjAttribute.AdviceAttribute( | |||
AdviceKind.AfterReturning, | |||
pc, | |||
extraArgument, | |||
-1, | |||
-1, | |||
sl.getOffset(), | |||
sl.getOffset()+1,//FIXME AVASM | |||
struct.context | |||
) | |||
); | |||
@@ -770,13 +776,14 @@ public class AtAjAttributes { | |||
} | |||
setIgnoreUnboundBindingNames(pc, bindings); | |||
ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber()); | |||
struct.ajAttributes.add( | |||
new AjAttribute.AdviceAttribute( | |||
AdviceKind.AfterThrowing, | |||
pc, | |||
extraArgument, | |||
-1, | |||
-1, | |||
sl.getOffset(), | |||
sl.getOffset()+1,//FIXME AVASM | |||
struct.context | |||
) | |||
); | |||
@@ -823,13 +830,14 @@ public class AtAjAttributes { | |||
} | |||
setIgnoreUnboundBindingNames(pc, bindings); | |||
ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber()); | |||
struct.ajAttributes.add( | |||
new AjAttribute.AdviceAttribute( | |||
AdviceKind.Around, | |||
pc, | |||
extraArgument, | |||
-1, | |||
-1, | |||
sl.getOffset(), | |||
sl.getOffset()+1,//FIXME AVASM | |||
struct.context | |||
) | |||
); | |||
@@ -885,7 +893,7 @@ public class AtAjAttributes { | |||
Pointcut pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct, true); | |||
if (pc == null) return;//parse error | |||
// do not resolve binding now but lazily | |||
pc.setLocation(struct.context, -1, -1); | |||
pc.setLocation(struct.context, -1, -1);//FIXME AVASM !! bMethod is null here.. | |||
struct.ajAttributes.add( | |||
new AjAttribute.PointcutDeclarationAttribute( | |||
new LazyResolvedPointcutDefinition( | |||
@@ -1342,21 +1350,21 @@ public class AtAjAttributes { | |||
* Parse the given pointcut, return null on failure and issue an error | |||
* | |||
* @param pointcutString | |||
* @param location | |||
* @param struct | |||
* @param allowIf | |||
* @return | |||
*/ | |||
private static Pointcut parsePointcut(String pointcutString, AjAttributeStruct location, boolean allowIf) { | |||
private static Pointcut parsePointcut(String pointcutString, AjAttributeStruct struct, boolean allowIf) { | |||
try { | |||
Pointcut pointcut = new PatternParser(pointcutString, location.context).parsePointcut(); | |||
Pointcut pointcut = new PatternParser(pointcutString, struct.context).parsePointcut(); | |||
if (!allowIf && pointcutString.indexOf("if()") >= 0 && hasIf(pointcut)) { | |||
reportError("if() pointcut is not allowed at this pointcut location '" + pointcutString +"'", location); | |||
reportError("if() pointcut is not allowed at this pointcut location '" + pointcutString +"'", struct); | |||
return null; | |||
} | |||
pointcut.setLocation(location.context, -1, -1);//FIXME -1,-1 is not good enough | |||
pointcut.setLocation(struct.context, -1, -1);//FIXME -1,-1 is not good enough | |||
return pointcut; | |||
} catch (ParserException e) { | |||
reportError("Invalid pointcut '" + pointcutString + "': " + e.toString(), location); | |||
reportError("Invalid pointcut '" + pointcutString + "': " + e.toString(), struct); | |||
return null; | |||
} | |||
} |
@@ -100,7 +100,7 @@ final class BcelMethod extends ResolvedMember { | |||
associatedShadowMunger = null; | |||
List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world.getMessageHandler()); | |||
processAttributes(world, as); | |||
as = AtAjAttributes.readAj5MethodAttributes(method, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler()); | |||
as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler()); | |||
processAttributes(world,as); | |||
} | |||
@@ -87,7 +87,17 @@ public class BcelSourceContext implements ISourceContext { | |||
} | |||
public ISourceLocation makeSourceLocation(int line) { | |||
return new SourceLocation(getSourceFile(), line); | |||
if (line < 0) line = 0; | |||
SourceLocation sl = new SourceLocation(getSourceFile(), line); | |||
if (lineBreaks != null) { | |||
int likelyOffset = 0; | |||
if (line > 0 && line < lineBreaks.length) { | |||
//1st char of given line is next char after previous end of line | |||
likelyOffset = lineBreaks[line-1] + 1; | |||
} | |||
sl.setOffset(likelyOffset); | |||
} | |||
return sl; | |||
} | |||
public void addAttributeInfo(SourceContextAttribute sourceContextAttribute) { |
@@ -68,14 +68,16 @@ public class PerFromSuper extends PerClause { | |||
inAspect.getWorld().getMessageHandler().handleMessage( | |||
MessageUtil.error(WeaverMessages.format(WeaverMessages.MISSING_PER_CLAUSE,inAspect.getSuperclass()), getSourceLocation()) | |||
); | |||
} | |||
if (p.getKind() != kind) { | |||
inAspect.getWorld().getMessageHandler().handleMessage( | |||
MessageUtil.error(WeaverMessages.format(WeaverMessages.WRONG_PER_CLAUSE,kind,p.getKind()), | |||
getSourceLocation()) | |||
); | |||
} | |||
return p.concretize(inAspect); | |||
return new PerSingleton().concretize(inAspect);// AV: fallback on something else NPE in AJDT | |||
} else { | |||
if (p.getKind() != kind) { | |||
inAspect.getWorld().getMessageHandler().handleMessage( | |||
MessageUtil.error(WeaverMessages.format(WeaverMessages.WRONG_PER_CLAUSE,kind,p.getKind()), | |||
getSourceLocation()) | |||
); | |||
} | |||
return p.concretize(inAspect); | |||
} | |||
} | |||
@@ -200,7 +200,8 @@ public class WeavingAdaptor { | |||
||*/ name.startsWith("org.aspectj.") | |||
|| name.startsWith("java.") | |||
|| name.startsWith("javax.")) | |||
|| name.startsWith("$Proxy"));//JDK proxies | |||
|| name.startsWith("$Proxy")//JDK proxies | |||
|| name.startsWith("sun.reflect."));//JDK reflect | |||
} | |||
/** |