From e1f6d1fc52d329b018ed11c08cab5011f267c3d0 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Tue, 26 May 2015 15:12:55 -0700 Subject: 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 --- .../org/aspectj/systemtest/ajc186/Ajc186Tests.java | 123 ++++++++++++++++++++- tests/src/org/aspectj/systemtest/ajc186/ajc186.xml | 5 + 2 files changed, 126 insertions(+), 2 deletions(-) (limited to 'tests/src/org/aspectj') 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 @@ + + + + + -- cgit v1.2.3