diff options
author | Andy Clement <aclement@gopivotal.com> | 2014-09-30 11:08:50 -0700 |
---|---|---|
committer | Andy Clement <aclement@gopivotal.com> | 2014-09-30 11:08:50 -0700 |
commit | 102173fc11fc6648ed8f2283d3c5ad535e412c73 (patch) | |
tree | 41f4d30666dcbaf76353d34e7f94d6e92c10da73 /tests | |
parent | e26c781374ac7afeaf8859baf4fc55d7dfb7b3a7 (diff) | |
download | aspectj-102173fc11fc6648ed8f2283d3c5ad535e412c73.tar.gz aspectj-102173fc11fc6648ed8f2283d3c5ad535e412c73.zip |
445395: invokedynamic in around advice
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bugs183/445395/Code.java | 15 | ||||
-rwxr-xr-x | tests/bugs183/445395/ControlFlow.java | 75 | ||||
-rwxr-xr-x | tests/bugs183/445395/ControlFlowCommand.java | 7 | ||||
-rwxr-xr-x | tests/bugs183/445395/ControlFlowDriver.java | 75 | ||||
-rwxr-xr-x | tests/bugs183/445395/ForReplacer.java | 44 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java | 8 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc183/ajc183.xml | 17 |
7 files changed, 241 insertions, 0 deletions
diff --git a/tests/bugs183/445395/Code.java b/tests/bugs183/445395/Code.java new file mode 100644 index 000000000..647bc0401 --- /dev/null +++ b/tests/bugs183/445395/Code.java @@ -0,0 +1,15 @@ +import java.util.*; + +public class Code { + public void m() { } + public static void main(String []argv) { + new Code().m(); + } +} + +aspect X { + void around(): execution(* m(..)) { + Arrays.asList(4, 5, 6).forEach((i) -> { System.out.println(i);}); + } +} + diff --git a/tests/bugs183/445395/ControlFlow.java b/tests/bugs183/445395/ControlFlow.java new file mode 100755 index 000000000..3be5325f5 --- /dev/null +++ b/tests/bugs183/445395/ControlFlow.java @@ -0,0 +1,75 @@ +//package org.acmsl.pocs.lambdafor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class ControlFlow +{ + public <C extends Collection<I>, I, R> Collection<R> forloop( final C items, final Function<I, R> lambda) + { + return functionalForLoop(items, lambda); + } + + public <C extends Collection<I>, I, R> Collection<R> functionalForLoop( final C items, final Function<I, R> lambda) + { + return items.stream().map(lambda::apply).collect(Collectors.toList()); + } + + + public Collection iterativeForloop( final Collection items, final Function lambda) + { + final List<Object> result = new ArrayList<>(); + + for (final Object item: items) + { + result.add(lambda.<Object>apply(item)); + } + + return result; + } + + public <C extends Collection<I>, I, R> Collection<R> externallyDrivenForloop( + final ControlFlowDriver driver, final C items, final Function<I, R> lambda) + { + final List<R> result = new ArrayList<>(items.size()); + + final List<I> list = new ArrayList<>(items); + + int position = -1; + + while (true) + { + ControlFlowCommand command = driver.waitForCommand(); + + switch (command) + { + case NEXT: + position++; + break; + case PREVIOUS: + position++; + break; + case RELOAD: + break; + default: + break; + } + + if (position < 0) + { + position = 0; + } + else if (position > list.size() - 1) + { + break; + } + + result.set(position, lambda.apply(list.get(position))); + } + + return result; + } +} diff --git a/tests/bugs183/445395/ControlFlowCommand.java b/tests/bugs183/445395/ControlFlowCommand.java new file mode 100755 index 000000000..55c80d6cd --- /dev/null +++ b/tests/bugs183/445395/ControlFlowCommand.java @@ -0,0 +1,7 @@ +//package org.acmsl.pocs.lambdafor; + +public enum ControlFlowCommand { + NEXT, + PREVIOUS, + RELOAD; +} diff --git a/tests/bugs183/445395/ControlFlowDriver.java b/tests/bugs183/445395/ControlFlowDriver.java new file mode 100755 index 000000000..318362c79 --- /dev/null +++ b/tests/bugs183/445395/ControlFlowDriver.java @@ -0,0 +1,75 @@ +//package org.acmsl.pocs.lambdafor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; + +public class ControlFlowDriver { + + private static boolean m__bUsed = false; + + public ControlFlowDriver() { + } + + protected static void immutableSetUsed(final boolean used) { + m__bUsed = used; + } + + protected static void setUsed(final boolean used) { + immutableSetUsed(used); + } + + public static boolean isUsed() { + return m__bUsed; + } + + public <C extends Collection<I>, I, R> Collection<R> forloop(final C items, + final Function<I, R> lambda) { + setUsed(true); + + final List<R> result = new ArrayList<R>(items.size()); + + final List<I> list = new ArrayList<I>(items); + + int position = -1; + + while (true) { + ControlFlowCommand command = waitForCommand(); + + switch (command) { + case NEXT: + position++; + break; + case PREVIOUS: + position++; + break; + case RELOAD: + break; + default: + break; + } + + if (position < 0) { + position = 0; + } else if (position > list.size() - 1) { + break; + } + + result.set(position, lambda.apply(list.get(position))); + } + + return result; + } + + protected ControlFlowCommand waitForCommand() { + try { + Thread.sleep(1000); + } catch (final InterruptedException interruptedException) { + // whatever + } + + return ControlFlowCommand.NEXT; + } + +} diff --git a/tests/bugs183/445395/ForReplacer.java b/tests/bugs183/445395/ForReplacer.java new file mode 100755 index 000000000..25b7ca22a --- /dev/null +++ b/tests/bugs183/445395/ForReplacer.java @@ -0,0 +1,44 @@ +//package org.acmsl.pocs.lambdafor; + +import java.util.Arrays; + +public aspect ForReplacer +{ + /** + * Intercepting for loop constructs. + */ + pointcut forLoopPointcut(): +// execution(* Sample.sampleCode(..)); // -> error + execution(* forloop(..)); +// && args(Collect, ..); + + /** + * Replacing the loop construct. + */ + Object around() : forLoopPointcut() + { +// return proceed(); +// Collection<Integer> result = new ArrayList<>(); +// result.addAll(new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;})); +// return result; + return new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;}); + } + + /** + * Intercepting for loop constructs. + * + pointcut forLoopPointcut(ControlFlow loop): + call(* ControlFlow.forloop(..)) + && target(loop); +// && args(items, ..); + + /** + * Replacing the loop construct. + * + Collection around(ControlFlow loop) : forLoopPointcut(loop) + { + return loop.externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;}); +// return new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;}); + } + */ +} diff --git a/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java index 3c0257115..ed7c74aee 100644 --- a/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java @@ -21,6 +21,14 @@ import org.aspectj.testing.XMLBasedAjcTestCase; */ public class Ajc183Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + public void testConstantPool_445395_0() { + runTest("constant pool 0"); + } + + public void testConstantPool_445395() { + runTest("constant pool"); + } + public void testAbstractAspectNPE_444398() { runTest("abstract aspect npe"); } diff --git a/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml index 35bdca396..b08be60a9 100644 --- a/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml +++ b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml @@ -2,6 +2,23 @@ <suite> + <ajc-test dir="bugs183/445395" title="constant pool 0"> + <compile options="-1.8" files="Code.java"> + </compile> + <run class="Code"> + <stdout> + <line text="4"/> + <line text="5"/> + <line text="6"/> + </stdout> + </run> + </ajc-test> + + <ajc-test dir="bugs183/445395" title="constant pool"> + <compile options="-1.8" files="ControlFlow.java ForReplacer.java ControlFlowCommand.java ControlFlowDriver.java"> + </compile> + </ajc-test> + <ajc-test dir="bugs183/444398" title="abstract aspect npe"> <compile options="-1.8" files="Bottom.java Middle.java Top.java"> </compile> |