aboutsummaryrefslogtreecommitdiffstats
path: root/docs/sandbox/inoculated/src/RunTime.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/inoculated/src/RunTime.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/inoculated/src/RunTime.java')
-rw-r--r--docs/sandbox/inoculated/src/RunTime.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/docs/sandbox/inoculated/src/RunTime.java b/docs/sandbox/inoculated/src/RunTime.java
new file mode 100644
index 000000000..e3e93e9d0
--- /dev/null
+++ b/docs/sandbox/inoculated/src/RunTime.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1998-2002 PARC Inc. All rights reserved.
+ *
+ * Use and copying of this software and preparation of derivative works based
+ * upon this software are permitted. Any distribution of this software or
+ * derivative works must comply with all applicable United States export
+ * control laws.
+ *
+ * This software is made available AS IS, and PARC Inc. makes no
+ * warranty about the software, its performance or its conformity to any
+ * specification.
+ */
+
+import java.util.*;
+import java.awt.Point;
+
+import org.aspectj.lang.JoinPoint;
+
+public class RunTime {
+ public static void main(String[] a) {
+ AnotherPoint.create();
+ SubPoint.create();
+ }
+}
+
+/** @author Wes Isberg */
+aspect FactoryValidation {
+
+ // START-SAMPLE declares-inoculated-prohibitNonprivateConstructors Error to have accessible sub-Point constructors
+ /** We make it an error for any Point subclasses to have non-private constructors */
+ declare error : execution(!private Point+.new(..))
+ && !within(java*..*) :
+ "non-private Point subclass constructor";
+ // END-SAMPLE declares-inoculated-prohibitNonprivateConstructors
+
+ // article page 41 - runtime NPE
+ // START-SAMPLE testing-inoculated-runtimeErrorWhenNullReturnedFromFactory Throw Error when factory returns null
+ /** Throw Error if a factory method for creating a Point returns null */
+ after () returning (Point p) :
+ call(Point+ SubPoint+.create(..)) {
+ if (null == p) {
+ String err = "Null Point constructed when this ("
+ + thisJoinPoint.getThis()
+ + ") called target ("
+ + thisJoinPoint.getTarget()
+ + ") at join point ("
+ + thisJoinPoint.getSignature()
+ + ") from source location ("
+ + thisJoinPoint.getSourceLocation()
+ + ") with args ("
+ + Arrays.asList(thisJoinPoint.getArgs())
+ + ")";
+ throw new Error(err);
+ }
+ }
+ // END-SAMPLE testing-inoculated-runtimeErrorWhenNullReturnedFromFactory
+}
+
+class SubPoint extends Point {
+ public static SubPoint create() { return null; } // will cause Error
+ private SubPoint(){}
+}
+
+class AnotherPoint extends Point {
+ public static Point create() { return new Point(); }
+
+ // to see that default constructor is picked out by declare error
+ // comment out this constructor
+ private AnotherPoint(){}
+}
+
+