import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.WeaverStateInfo;
import org.aspectj.weaver.World;
+import org.aspectj.weaver.patterns.ParserException;
+import org.aspectj.weaver.patterns.PatternParser;
import org.aspectj.weaver.patterns.PerClause;
import org.aspectj.weaver.patterns.PerFromSuper;
import org.aspectj.weaver.patterns.PerSingleton;
+import org.aspectj.weaver.patterns.Pointcut;
/**
* Supports viewing eclipse TypeDeclarations/SourceTypeBindings as a ResolvedType
}
return false;
}
+
+ /** Returns "" if there is a problem */
+ private String getPointcutStringFromAnnotationStylePointcut(AbstractMethodDeclaration amd) {
+ Annotation[] ans = amd.annotations;
+ if (ans == null) return "";
+ for (int i = 0; i < ans.length; i++) {
+ if (ans[i].resolvedType == null) continue; // XXX happens if we do this very early from buildInterTypeandPerClause
+ // may prevent us from resolving references made in @Pointcuts to
+ // an @Pointcut in a code-style aspect
+ char[] sig = ans[i].resolvedType.signature();
+ if (CharOperation.equals(pointcutSig,sig)) {
+ if (ans[i].memberValuePairs().length==0) return ""; // empty pointcut expression
+ StringLiteral sLit = ((StringLiteral)(ans[i].memberValuePairs()[0].value));
+ return new String(sLit.source());
+ }
+ }
+ return "";
+ }
private boolean isAnnotationStylePointcut(Annotation[] annotations) {
if (annotations == null) return false;
private ResolvedPointcutDefinition makeResolvedPointcutDefinition(AbstractMethodDeclaration md) {
if (md.binding==null) return null; // there is another error that has caused this... pr138143
+
+ EclipseSourceContext eSourceContext = new EclipseSourceContext(md.compilationResult);
+ Pointcut pc = null;
+ if (!md.isAbstract()) {
+ String expression = getPointcutStringFromAnnotationStylePointcut(md);
+ try {
+ pc = new PatternParser(expression,eSourceContext).parsePointcut();
+ } catch (ParserException pe) { // error will be reported by other means...
+ pc = Pointcut.makeMatchesNothing(Pointcut.SYMBOLIC);
+ }
+ }
+
+
ResolvedPointcutDefinition resolvedPointcutDeclaration = new ResolvedPointcutDefinition(
factory.fromBinding(md.binding.declaringClass),
md.modifiers,
new String(md.selector),
factory.fromBindings(md.binding.parameters),
- null); //??? might want to use null
+ pc);
resolvedPointcutDeclaration.setPosition(md.sourceStart, md.sourceEnd);
- resolvedPointcutDeclaration.setSourceContext(new EclipseSourceContext(md.compilationResult));
+ resolvedPointcutDeclaration.setSourceContext(eSourceContext);
return resolvedPointcutDeclaration;
}
// public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); }
// public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");}
// public void testNoIllegalStateExceptionWithGenericInnerAspect_pr156058() { runTest("no IllegalStateException with generic inner aspect"); }
+ public void testAnnotationStylePointcutNPE_pr158412() { runTest("annotation style pointcut npe"); }
+ public void testAnnotationStylePointcutNPE_pr158412_2() { runTest("annotation style pointcut npe - 2"); }
public void testAnnotationsCallConstructors_pr158126() { runTest("annotations, call and constructors problem");}
public void testIllegalStateExceptionGenerics_pr153845() { runTest("IllegalStateException at GenericSignatureParser.java"); }
public void testNoIllegalStateExceptionFromAsmDelegate_pr153490_1() { runTest("no illegal state exception from AsmDelegate - 1");}
<compile files="Nothing.java" aspectpath="blob.jar" options="-1.5" outjar="bang.jar"/>
</ajc-test>
+ <ajc-test dir="bugs153/pr158412" title="annotation style pointcut npe">
+ <compile files="layering/Layering.aj,layering/SystemArchitektur.java" options="-1.5"/>
+ </ajc-test>
+
+ <ajc-test dir="bugs153/pr158412" title="annotation style pointcut npe - 2">
+ <compile files="layering/Layering.aj,layering/SystemArchitektur.java,dao/Foo.java" options="-1.5">
+ <message kind="warning" line="3" text="Whatever"/>
+ </compile>
+ </ajc-test>
+
<ajc-test dir="bugs153/pr158126" title="annotations, call and constructors problem">
<compile files="A.java,B.java,MyAnnotation.java,MyAspect.java" options="-1.5 -showWeaveInfo">
<message kind="weave" text="Join point 'constructor-call(void B.<init>())' in Type 'A' (A.java:5) advised by before advice from 'MyAspect' (MyAspect.java:3)"/>