aboutsummaryrefslogtreecommitdiffstats
path: root/docs/dist
diff options
context:
space:
mode:
authorwisberg <wisberg>2004-01-15 02:52:01 +0000
committerwisberg <wisberg>2004-01-15 02:52:01 +0000
commit9122ff2963909f54608b43cdb454a1282cbd9e16 (patch)
treee66eb9dc1c8f3cc9f598488a1521db95c53c7ef7 /docs/dist
parent0071cb4d0f30fc95f335eb6df73ad09e92d662ed (diff)
downloadaspectj-9122ff2963909f54608b43cdb454a1282cbd9e16.tar.gz
aspectj-9122ff2963909f54608b43cdb454a1282cbd9e16.zip
Gregor's mailing list fixes to BoundPoint (two advice), plus (a) properties miscapitalized; (b) execution rather than call.
Could also skip proceed and event notification if input value not different, but that's a different example, eh?
Diffstat (limited to 'docs/dist')
-rw-r--r--docs/dist/doc/examples/bean/BoundPoint.java50
1 files changed, 23 insertions, 27 deletions
diff --git a/docs/dist/doc/examples/bean/BoundPoint.java b/docs/dist/doc/examples/bean/BoundPoint.java
index e5d9ab8c6..36c85819c 100644
--- a/docs/dist/doc/examples/bean/BoundPoint.java
+++ b/docs/dist/doc/examples/bean/BoundPoint.java
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 1998-2002 Xerox Corporation. All rights reserved.
+ * Copyright (c) 1998-2002 Xerox Corporation,
+ * 2004 Contributors. 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
@@ -16,28 +17,27 @@ package bean;
import java.beans.*;
import java.io.Serializable;
-/*
- * Add bound properties and serialization to point objects
+/**
+ * Add bound properties and serialization to Point objects
*/
-
aspect BoundPoint {
/*
- * privately introduce a field into Point to hold the property
+ * privately declare a field on Point to hold the property
* change support object. `this' is a reference to a Point object.
*/
private PropertyChangeSupport Point.support = new PropertyChangeSupport(this);
/*
- * Introduce the property change registration methods into Point.
- * also introduce implementation of the Serializable interface.
+ * Declare property change registration methods on Point,
+ * and introduce implementation of the Serializable interface.
*/
+
public void Point.addPropertyChangeListener(PropertyChangeListener listener){
support.addPropertyChangeListener(listener);
}
public void Point.addPropertyChangeListener(String propertyName,
PropertyChangeListener listener){
-
support.addPropertyChangeListener(propertyName, listener);
}
@@ -57,36 +57,32 @@ aspect BoundPoint {
declare parents: Point implements Serializable;
/**
- * Pointcut describing the set<property> methods on Point.
- * (uses a wildcard in the method name)
+ * Send property change event after X setter completes normally.
+ * Use around advice to keep the old value on the stack.
*/
- pointcut setter(Point p): call(void Point.set*(*)) && target(p);
+ void around(Point p): execution(void Point.setX(int)) && target(p) {
+ int oldValue = p.getX();
+ proceed(p);
+ firePropertyChange(p, "x", oldValue, p.getX());
+ }
/**
- * Advice to get the property change event fired when the
- * setters are called. It's around advice because you need
- * the old value of the property.
+ * Send property change event after Y setter completes normally.
+ * Use around advice to keep the old value on the stack.
*/
- void around(Point p): setter(p) {
- String propertyName =
- thisJoinPointStaticPart.getSignature().getName().substring("set".length());
- int oldX = p.getX();
- int oldY = p.getY();
- proceed(p);
- if (propertyName.equals("X")){
- firePropertyChange(p, propertyName, oldX, p.getX());
- } else {
- firePropertyChange(p, propertyName, oldY, p.getY());
- }
+ void around(Point p): execution(void Point.setY(int)) && target(p) {
+ int oldValue = p.getY();
+ proceed(p);
+ firePropertyChange(p, "y", oldValue, p.getY());
}
-
+
/*
* Utility to fire the property change event.
*/
void firePropertyChange(Point p,
String property,
double oldval,
- double newval) {
+ double newval) {
p.support.firePropertyChange(property,
new Double(oldval),
new Double(newval));