summaryrefslogtreecommitdiffstats
path: root/docs/sandbox/common/language/ControlFlow.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-08-06 02:08:40 +0000
committerwisberg <wisberg>2003-08-06 02:08:40 +0000
commita63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43 (patch)
treecd4e827c60136df7bf9850591b0c64baff549d20 /docs/sandbox/common/language/ControlFlow.java
parentb0d37c4b51a344bee94bb7f7cc1ecef1a233e3ab (diff)
downloadaspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.tar.gz
aspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.zip
initial checkin of the sandbox.
The basic structure and examples of each type are there, but I have more examples and the ones there are not altogether validated. I'll make a few more changes before emailing dev and users about usage, etc.
Diffstat (limited to 'docs/sandbox/common/language/ControlFlow.java')
-rw-r--r--docs/sandbox/common/language/ControlFlow.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/sandbox/common/language/ControlFlow.java b/docs/sandbox/common/language/ControlFlow.java
new file mode 100644
index 000000000..d832259db
--- /dev/null
+++ b/docs/sandbox/common/language/ControlFlow.java
@@ -0,0 +1,43 @@
+
+package language;
+
+public class ControlFlow {
+ public static void main(String[] argList) {
+ Fact.factorial(6);
+ }
+}
+
+class Fact {
+ static int factorial(int i) {
+ if (i < 0) {
+ throw new IllegalArgumentException("negative: " + i);
+ }
+ if (i > 100) {
+ throw new IllegalArgumentException("big: " + i);
+ }
+ return (i == 0 ? 1 : i * factorial(i-1));
+ }
+}
+
+/**
+ * Demonstrate recursive calls.
+ * @author Erik Hilsdale
+ */
+aspect LogFactorial {
+ // START-SAMPLE language-cflowRecursionBasic Pick out latest and original recursive call
+ /** call to factorial, with argument */
+ pointcut f(int i) : call(int Fact.factorial(int)) && args(i);
+
+ /** print most-recent recursive call */
+ before(int i, final int j) : f(i) && cflowbelow(f(j)) {
+ System.err.println(i + "-" + j);
+ }
+
+ /** print initial/topmost recursive call */
+ before(int i, final int j) : f(i)
+ && cflowbelow(cflow(f(j)) && !cflowbelow(f(int))) {
+ System.err.println(i + "@" + j);
+ }
+ // END-SAMPLE language-cflowRecursionBasic
+}
+