summaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2015-05-26 15:12:55 -0700
committerAndy Clement <aclement@pivotal.io>2015-06-08 08:35:23 -0700
commite1f6d1fc52d329b018ed11c08cab5011f267c3d0 (patch)
treef6e01041d784e766bc1a341c75701db454ea575e /tests/src/org/aspectj
parent066dc11d46731d5a60866dc1ded2dd3e3ef2fcd0 (diff)
downloadaspectj-e1f6d1fc52d329b018ed11c08cab5011f267c3d0.tar.gz
aspectj-e1f6d1fc52d329b018ed11c08cab5011f267c3d0.zip
allow reflection world to resolve generated types (e.g. lambdas)
1.8.6 release prep 1.8.6 pom updates Fix rogue chars in javadoc rebuilt with javadoc fixes
Diffstat (limited to 'tests/src/org/aspectj')
-rw-r--r--tests/src/org/aspectj/systemtest/ajc186/Ajc186Tests.java123
-rw-r--r--tests/src/org/aspectj/systemtest/ajc186/ajc186.xml5
2 files changed, 126 insertions, 2 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc186/Ajc186Tests.java b/tests/src/org/aspectj/systemtest/ajc186/Ajc186Tests.java
index aeb6c1621..1625f96d1 100644
--- a/tests/src/org/aspectj/systemtest/ajc186/Ajc186Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc186/Ajc186Tests.java
@@ -11,20 +11,139 @@
package org.aspectj.systemtest.ajc186;
import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
import junit.framework.Test;
import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.weaver.tools.ContextBasedMatcher;
+import org.aspectj.weaver.tools.DefaultMatchingContext;
+import org.aspectj.weaver.tools.FuzzyBoolean;
+import org.aspectj.weaver.tools.MatchingContext;
+import org.aspectj.weaver.tools.PointcutDesignatorHandler;
+import org.aspectj.weaver.tools.PointcutExpression;
+import org.aspectj.weaver.tools.PointcutParser;
/**
* @author Andy Clement
*/
public class Ajc186Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
+ private class FooDesignatorHandler implements PointcutDesignatorHandler {
+
+ private String askedToParse;
+ public boolean simulateDynamicTest = false;
+
+ public String getDesignatorName() {
+ return "foo";
+ }
+
+ public ContextBasedMatcher parse(String expression) {
+ this.askedToParse = expression;
+ return new FooPointcutExpression(expression, this.simulateDynamicTest);
+ }
+
+ public String getExpressionLastAskedToParse() {
+ return this.askedToParse;
+ }
+ }
+
+ private class FooPointcutExpression implements ContextBasedMatcher {
+
+ private final String beanNamePattern;
+ private final boolean simulateDynamicTest;
+
+ public FooPointcutExpression(String beanNamePattern,
+ boolean simulateDynamicTest) {
+ this.beanNamePattern = beanNamePattern;
+ this.simulateDynamicTest = simulateDynamicTest;
+ }
+
+ public boolean couldMatchJoinPointsInType(Class aClass) {
+ System.out.println("wubble?");
+ return true;
+ }
+
+ public boolean couldMatchJoinPointsInType(Class aClass,
+ MatchingContext context) {
+ System.out.println("wibble?");
+ if (this.beanNamePattern.equals(context.getBinding("beanName"))) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean mayNeedDynamicTest() {
+ return this.simulateDynamicTest;
+ }
+
+ public FuzzyBoolean matchesStatically(MatchingContext matchContext) {
+ System.out.println("wobble?");
+ if (this.simulateDynamicTest)
+ return FuzzyBoolean.MAYBE;
+ if (this.beanNamePattern
+ .equals(matchContext.getBinding("beanName"))) {
+ return FuzzyBoolean.YES;
+ } else {
+ return FuzzyBoolean.NO;
+ }
+ }
+
+ public boolean matchesDynamically(MatchingContext matchContext) {
+ System.out.println("wabble?");
+ return this.beanNamePattern.equals(matchContext
+ .getBinding("beanName"));
+ }
+ }
+
+ public void testLambdaBeans() throws Exception {
+ runTest("lambda beans");
+
+ // Load the 1.8 compiled code
+ URLClassLoader ucl = new URLClassLoader(new URL[] {ajc.getSandboxDirectory().toURI().toURL()},this.getClass().getClassLoader());
+ Class<?> applicationClass = Class.forName("Application",false,ucl);
+ assertNotNull(applicationClass);
+ Object instance = applicationClass.newInstance();
+ Method works = applicationClass.getDeclaredMethod("fromInnerClass");
+ works.setAccessible(true);
+ Runnable r = (Runnable) works.invoke(instance);
+ // r.getClass().getName() == Application$1
+
+ Method fails = applicationClass.getDeclaredMethod("fromLambdaExpression");
+ fails.setAccessible(true);
+ Runnable r2 = (Runnable) fails.invoke(instance);
+ // r2.getClass().getName() == Application$$Lambda$1/1652149987
+
+// JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), "Application");
+ PointcutParser parser = PointcutParser
+ .getPointcutParserSupportingAllPrimitivesAndUsingSpecifiedClassloaderForResolution(ucl);
+ FooDesignatorHandler beanHandler = new FooDesignatorHandler();
+ parser.registerPointcutDesignatorHandler(beanHandler);
+ PointcutExpression pc = parser.parsePointcutExpression("foo(myBean)");
+ DefaultMatchingContext context = new DefaultMatchingContext();
+ pc.setMatchingContext(context);
+
+ context.addContextBinding("beanName", "myBean");
+ assertTrue(pc.couldMatchJoinPointsInType(r.getClass()));
+
+ context.addContextBinding("beanName", "yourBean");
+ assertFalse(pc.couldMatchJoinPointsInType(r.getClass()));
+
+ context.addContextBinding("beanName", "myBean");
+ assertTrue(pc.couldMatchJoinPointsInType(r2.getClass()));
+
+ context.addContextBinding("beanName", "yourBean");
+ assertFalse(pc.couldMatchJoinPointsInType(r2.getClass()));
+ }
+
+
public void testMissingExtends() throws Exception {
runTest("missing extends on generic target");
}
-
+
public void testMissingMethod_462821() throws Exception {
runTest("missing method");
}
@@ -37,7 +156,7 @@ public class Ajc186Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
@Override
protected File getSpecFile() {
- return getClassResource("ajc186.xml");
+ return getClassResource("ajc186.xml");
}
}
diff --git a/tests/src/org/aspectj/systemtest/ajc186/ajc186.xml b/tests/src/org/aspectj/systemtest/ajc186/ajc186.xml
index 69d0e0c05..4f1394a95 100644
--- a/tests/src/org/aspectj/systemtest/ajc186/ajc186.xml
+++ b/tests/src/org/aspectj/systemtest/ajc186/ajc186.xml
@@ -2,6 +2,11 @@
<suite>
+<ajc-test dir="bugs186/lambdaBeans" title="lambda beans">
+<compile files="Foo.java Application.java" options="-1.8">
+</compile>
+</ajc-test>
+
<ajc-test dir="bugs186/462821" title="missing method">
<compile files="FooService.java AbstractLoggerAspect.java FooServiceLoggerAspect.java" options="-1.8">
</compile>