aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java38
-rw-r--r--tests/bugs153/pr158412/dao/Foo.java4
-rw-r--r--tests/bugs153/pr158412/layering/Layering.aj8
-rw-r--r--tests/bugs153/pr158412/layering/SystemArchitektur.java14
-rw-r--r--tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java2
-rw-r--r--tests/src/org/aspectj/systemtest/ajc153/ajc153.xml10
6 files changed, 74 insertions, 2 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
index 179410bc4..f933fff98 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
@@ -67,9 +67,12 @@ import org.aspectj.weaver.TypeVariable;
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
@@ -150,6 +153,24 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
}
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;
@@ -237,15 +258,28 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
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;
}
diff --git a/tests/bugs153/pr158412/dao/Foo.java b/tests/bugs153/pr158412/dao/Foo.java
new file mode 100644
index 000000000..376414c31
--- /dev/null
+++ b/tests/bugs153/pr158412/dao/Foo.java
@@ -0,0 +1,4 @@
+package dao;
+
+public class Foo {
+}
diff --git a/tests/bugs153/pr158412/layering/Layering.aj b/tests/bugs153/pr158412/layering/Layering.aj
new file mode 100644
index 000000000..c78561ee0
--- /dev/null
+++ b/tests/bugs153/pr158412/layering/Layering.aj
@@ -0,0 +1,8 @@
+package layering;
+
+//import architektur.SystemArchitektur;
+
+public aspect Layering {
+ declare warning : (layering.SystemArchitektur.inDAOLayer() ) : "Whatever";
+
+}
diff --git a/tests/bugs153/pr158412/layering/SystemArchitektur.java b/tests/bugs153/pr158412/layering/SystemArchitektur.java
new file mode 100644
index 000000000..735b0ced9
--- /dev/null
+++ b/tests/bugs153/pr158412/layering/SystemArchitektur.java
@@ -0,0 +1,14 @@
+package layering;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+
+@Aspect
+public class SystemArchitektur {
+ @Pointcut("within(dao.*)")
+ public void inDAOLayer() {}
+
+}
+
+
diff --git a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
index 0c4e59e8d..3fdae3771 100644
--- a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
@@ -28,6 +28,8 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
// 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");}
diff --git a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
index 451bf3a80..455f181b1 100644
--- a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
+++ b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
@@ -8,6 +8,16 @@
<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.&lt;init&gt;())' in Type 'A' (A.java:5) advised by before advice from 'MyAspect' (MyAspect.java:3)"/>