diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2021-04-10 19:19:39 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2021-04-10 19:19:39 +0700 |
commit | 92edca3ea7a482d59a9086b1cb61413ed8604b67 (patch) | |
tree | d709ab2fd24a563cf626fb5ff354a0972a1dc6a9 /docs/progGuideDB | |
parent | 79c272eb9c158a976b7b3313c50759dd87b1b5fd (diff) | |
download | aspectj-92edca3ea7a482d59a9086b1cb61413ed8604b67.tar.gz aspectj-92edca3ea7a482d59a9086b1cb61413ed8604b67.zip |
Remove indentation from <programlisting> blocks in docs
Many dozens (hundreds?) of documentation code blocks were indented to
match the surrounding XML or just arbitrarily. The thing is: Inside
<programlisting> tags, similar to <pre> tags, line feeds and leading
whitespace are being preserved, which looked very awkward in the HTML
documentation. While a few files were mostly correct in this respect,
which shows that it was meant to be like that, many others were not.
This was tedious, stupid work to fix, but it had to be done.
Please note that the documentation was in no way updated content-wise.
This is also overdue, but not my focus here.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'docs/progGuideDB')
-rw-r--r-- | docs/progGuideDB/examples.xml | 403 | ||||
-rw-r--r-- | docs/progGuideDB/implementation.xml | 92 | ||||
-rw-r--r-- | docs/progGuideDB/language.xml | 274 | ||||
-rw-r--r-- | docs/progGuideDB/semantics.xml | 743 |
4 files changed, 757 insertions, 755 deletions
diff --git a/docs/progGuideDB/examples.xml b/docs/progGuideDB/examples.xml index e3f109e98..f0ce3808e 100644 --- a/docs/progGuideDB/examples.xml +++ b/docs/progGuideDB/examples.xml @@ -541,14 +541,14 @@ public aspect ComparablePoint { </para> <para> - The method <literal>Object.hashCode</literal> returns an + The method <literal>Object.hashCode</literal> returns an integer, suitable for use as a hash table key. It is not required - that two objects which are not equal (according to the + that two objects which are not equal (according to the <literal>equals</literal> method) return different integer results from <literal>hashCode</literal> but it can - improve performance when the integer is used as a key into a - data structure. However, any two objects which are equal - must return the same integer value from a call to + improve performance when the integer is used as a key into a + data structure. However, any two objects which are equal + must return the same integer value from a call to <literal>hashCode</literal>. Since the default implementation of <literal>Object.equals</literal> returns <literal>true</literal> only when two objects are identical, we need to redefine both @@ -851,7 +851,7 @@ aspect TraceMyClasses { </para> <programlisting><![CDATA[ - ajc -argfile tracing/tracev1.lst +ajc -argfile tracing/tracev1.lst ]]></programlisting> <para> @@ -969,7 +969,7 @@ public aspect TraceMyClasses extends Trace { </para> <programlisting><![CDATA[ - ajc -argfile tracing/tracev2.lst +ajc -argfile tracing/tracev2.lst ]]></programlisting> <para> @@ -1099,7 +1099,7 @@ abstract aspect Trace { </para> <para> - This example examines an aspect that makes Point objects into + This example examines an aspect that makes Point objects into Java beans with bound properties. </para> @@ -1190,10 +1190,10 @@ class Point { <literal>Point</literal>'s "beanness". The first thing it does is privately declare that each <literal>Point</literal> has a <literal>support</literal> field that holds reference to an - instance of <classname>PropertyChangeSupport</classname>. + instance of <classname>PropertyChangeSupport</classname>. <programlisting><![CDATA[ - private PropertyChangeSupport Point.support = new PropertyChangeSupport(this); +private PropertyChangeSupport Point.support = new PropertyChangeSupport(this); ]]></programlisting> The property change support object must be constructed with a @@ -1210,24 +1210,24 @@ class Point { which delegate the work to the property change support object: <programlisting><![CDATA[ - public void Point.addPropertyChangeListener(PropertyChangeListener listener){ - support.addPropertyChangeListener(listener); - } - public void Point.addPropertyChangeListener(String propertyName, - PropertyChangeListener listener){ +public void Point.addPropertyChangeListener(PropertyChangeListener listener){ + support.addPropertyChangeListener(listener); +} +public void Point.addPropertyChangeListener(String propertyName, + PropertyChangeListener listener){ - support.addPropertyChangeListener(propertyName, listener); - } - public void Point.removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - support.removePropertyChangeListener(propertyName, listener); - } - public void Point.removePropertyChangeListener(PropertyChangeListener listener) { - support.removePropertyChangeListener(listener); - } - public void Point.hasListeners(String propertyName) { - support.hasListeners(propertyName); - } + support.addPropertyChangeListener(propertyName, listener); +} +public void Point.removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + support.removePropertyChangeListener(propertyName, listener); +} +public void Point.removePropertyChangeListener(PropertyChangeListener listener) { + support.removePropertyChangeListener(listener); +} +public void Point.hasListeners(String propertyName) { + support.hasListeners(propertyName); +} ]]></programlisting> </para> @@ -1237,7 +1237,7 @@ class Point { <classname>Serializable</classname> interface: <programlisting><![CDATA[ - declare parents: Point implements Serializable; +declare parents: Point implements Serializable; ]]></programlisting> Implementing this interface in Java does not require any methods to @@ -1254,7 +1254,7 @@ class Point { <literal>Y</literal> properties, calls the original <literal>set</literal> method and then fires the appropriate property change event according to which set method was - called. + called. </para> <programlisting><![CDATA[ @@ -1323,33 +1323,33 @@ aspect BoundPoint { </para> <programlisting><![CDATA[ - class Demo implements PropertyChangeListener { +class Demo implements PropertyChangeListener { - static final String fileName = "test.tmp"; + static final String fileName = "test.tmp"; - public void propertyChange(PropertyChangeEvent e){ - System.out.println("Property " + e.getPropertyName() + " changed from " + - e.getOldValue() + " to " + e.getNewValue() ); - } - - public static void main(String[] args){ - Point p1 = new Point(); - p1.addPropertyChangeListener(new Demo()); - System.out.println("p1 =" + p1); - p1.setRectangular(5,2); - System.out.println("p1 =" + p1); - p1.setX( 6 ); - p1.setY( 3 ); - System.out.println("p1 =" + p1); - p1.offset(6,4); - System.out.println("p1 =" + p1); - save(p1, fileName); - Point p2 = (Point) restore(fileName); - System.out.println("Had: " + p1); - System.out.println("Got: " + p2); - } - ... + public void propertyChange(PropertyChangeEvent e){ + System.out.println("Property " + e.getPropertyName() + " changed from " + + e.getOldValue() + " to " + e.getNewValue() ); } + + public static void main(String[] args){ + Point p1 = new Point(); + p1.addPropertyChangeListener(new Demo()); + System.out.println("p1 =" + p1); + p1.setRectangular(5,2); + System.out.println("p1 =" + p1); + p1.setX( 6 ); + p1.setY( 3 ); + System.out.println("p1 =" + p1); + p1.offset(6,4); + System.out.println("p1 =" + p1); + save(p1, fileName); + Point p2 = (Point) restore(fileName); + System.out.println("Had: " + p1); + System.out.println("Got: " + p2); + } + ... +} ]]></programlisting> </sect3> @@ -1381,7 +1381,7 @@ java bean.Demo <para> This demo illustrates how the Subject/Observer design pattern can be - coded with aspects. + coded with aspects. </para> <para> @@ -1419,26 +1419,26 @@ java bean.Demo </para> <programlisting><![CDATA[ - interface Subject { - void addObserver(Observer obs); - void removeObserver(Observer obs); - Vector getObservers(); - Object getData(); - } +interface Subject { + void addObserver(Observer obs); + void removeObserver(Observer obs); + Vector getObservers(); + Object getData(); +} ]]></programlisting> - <para> + <para> The <classname>Observer</classname> interface is just as simple, with methods to set and get <classname>Subject</classname> objects, and a method to call when the subject gets updated. </para> <programlisting><![CDATA[ - interface Observer { - void setSubject(Subject s); - Subject getSubject(); - void update(); - } +interface Observer { + void setSubject(Subject s); + Subject getSubject(); + void update(); +} ]]></programlisting> <para> @@ -1449,32 +1449,32 @@ java bean.Demo </para> <programlisting><![CDATA[ - abstract aspect SubjectObserverProtocol { +abstract aspect SubjectObserverProtocol { - abstract pointcut stateChanges(Subject s); + abstract pointcut stateChanges(Subject s); - after(Subject s): stateChanges(s) { - for (int i = 0; i < s.getObservers().size(); i++) { - ((Observer)s.getObservers().elementAt(i)).update(); - } - } + after(Subject s): stateChanges(s) { + for (int i = 0; i < s.getObservers().size(); i++) { + ((Observer)s.getObservers().elementAt(i)).update(); + } + } - private Vector Subject.observers = new Vector(); - public void Subject.addObserver(Observer obs) { - observers.addElement(obs); - obs.setSubject(this); - } - public void Subject.removeObserver(Observer obs) { - observers.removeElement(obs); - obs.setSubject(null); - } - public Vector Subject.getObservers() { return observers; } + private Vector Subject.observers = new Vector(); + public void Subject.addObserver(Observer obs) { + observers.addElement(obs); + obs.setSubject(this); + } + public void Subject.removeObserver(Observer obs) { + observers.removeElement(obs); + obs.setSubject(null); + } + public Vector Subject.getObservers() { return observers; } - private Subject Observer.subject = null; - public void Observer.setSubject(Subject s) { subject = s; } - public Subject Observer.getSubject() { return subject; } + private Subject Observer.subject = null; + public void Observer.setSubject(Subject s) { subject = s; } + public Subject Observer.getSubject() { return subject; } - } +} ]]></programlisting> <para> @@ -1482,7 +1482,7 @@ java bean.Demo pointcut that extending aspects can override. It defines advice that should run after the join points of the pointcut. And it declares an inter-type field and two inter-type methods so that - each <literal>Observer</literal> can hold onto its <literal>Subject</literal>. + each <literal>Observer</literal> can hold onto its <literal>Subject</literal>. </para> </sect3> @@ -1497,28 +1497,28 @@ java bean.Demo </para> <programlisting><![CDATA[ - class Button extends java.awt.Button { - - static final Color defaultBackgroundColor = Color.gray; - static final Color defaultForegroundColor = Color.black; - static final String defaultText = "cycle color"; - - Button(Display display) { - super(); - setLabel(defaultText); - setBackground(defaultBackgroundColor); - setForeground(defaultForegroundColor); - addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Button.this.click(); - } - }); - display.addToFrame(this); - } +class Button extends java.awt.Button { + + static final Color defaultBackgroundColor = Color.gray; + static final Color defaultForegroundColor = Color.black; + static final String defaultText = "cycle color"; + + Button(Display display) { + super(); + setLabel(defaultText); + setBackground(defaultBackgroundColor); + setForeground(defaultForegroundColor); + addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Button.this.click(); + } + }); + display.addToFrame(this); + } - public void click() {} + public void click() {} - } +} ]]></programlisting> <para> @@ -1531,24 +1531,24 @@ java bean.Demo </para> <programlisting><![CDATA[ - class ColorLabel extends Label { +class ColorLabel extends Label { - ColorLabel(Display display) { - super(); - display.addToFrame(this); - } + ColorLabel(Display display) { + super(); + display.addToFrame(this); + } - final static Color[] colors = {Color.red, Color.blue, - Color.green, Color.magenta}; - private int colorIndex = 0; - private int cycleCount = 0; - void colorCycle() { - cycleCount++; - colorIndex = (colorIndex + 1) % colors.length; - setBackground(colors[colorIndex]); - setText("" + cycleCount); - } - } + final static Color[] colors = {Color.red, Color.blue, + Color.green, Color.magenta}; + private int colorIndex = 0; + private int cycleCount = 0; + void colorCycle() { + cycleCount++; + colorIndex = (colorIndex + 1) % colors.length; + setBackground(colors[colorIndex]); + setText("" + cycleCount); + } +} ]]></programlisting> <para> @@ -1577,7 +1577,8 @@ aspect SubjectObserverProtocolImpl extends SubjectObserverProtocol { target(s) && call(void Button.click()); -}]]></programlisting> +} +]]></programlisting> <para> It does this by assuring that <classname>Button</classname> and @@ -1594,7 +1595,7 @@ aspect SubjectObserverProtocolImpl extends SubjectObserverProtocol { <sect3> <title>Compiling and Running</title> - <para> + <para> <classname>Demo</classname> is the top class that starts this demo. It instantiates a two buttons and three observers and links them together as subjects and observers. So to run the demo, go to @@ -1602,8 +1603,8 @@ aspect SubjectObserverProtocolImpl extends SubjectObserverProtocol { </para> <programlisting><![CDATA[ - ajc -argfile observer/files.lst - java observer.Demo +ajc -argfile observer/files.lst +java observer.Demo ]]></programlisting> </sect3> @@ -1803,43 +1804,43 @@ public class Customer { </para> <programlisting><![CDATA[ - abstract class Connection { +abstract class Connection { - public static final int PENDING = 0; - public static final int COMPLETE = 1; - public static final int DROPPED = 2; + public static final int PENDING = 0; + public static final int COMPLETE = 1; + public static final int DROPPED = 2; - Customer caller, receiver; - private int state = PENDING; + Customer caller, receiver; + private int state = PENDING; - Connection(Customer a, Customer b) { - this.caller = a; - this.receiver = b; - } + Connection(Customer a, Customer b) { + this.caller = a; + this.receiver = b; + } - public int getState(){ - return state; - } + public int getState(){ + return state; + } - public Customer getCaller() { return caller; } + public Customer getCaller() { return caller; } - public Customer getReceiver() { return receiver; } + public Customer getReceiver() { return receiver; } - void complete() { - state = COMPLETE; - System.out.println("connection completed"); - } + void complete() { + state = COMPLETE; + System.out.println("connection completed"); + } - void drop() { - state = DROPPED; - System.out.println("connection dropped"); - } + void drop() { + state = DROPPED; + System.out.println("connection dropped"); + } - public boolean connects(Customer c){ - return (caller == c || receiver == c); - } + public boolean connects(Customer c){ + return (caller == c || receiver == c); + } - } +} ]]></programlisting> </sect3> @@ -1854,23 +1855,23 @@ public class Customer { </para> <programlisting><![CDATA[ - class Local extends Connection { - Local(Customer a, Customer b) { - super(a, b); - System.out.println("[new local connection from " + - a + " to " + b + "]"); - } - } +class Local extends Connection { + Local(Customer a, Customer b) { + super(a, b); + System.out.println("[new local connection from " + + a + " to " + b + "]"); + } +} ]]></programlisting> <programlisting><![CDATA[ - class LongDistance extends Connection { - LongDistance(Customer a, Customer b) { - super(a, b); - System.out.println("[new long distance connection from " + - a + " to " + b + "]"); - } - } +class LongDistance extends Connection { + LongDistance(Customer a, Customer b) { + super(a, b); + System.out.println("[new long distance connection from " + + a + " to " + b + "]"); + } +} ]]></programlisting> </sect3> @@ -1913,22 +1914,22 @@ java telecom.BasicSimulation </para> <programlisting><![CDATA[ - class Timer { - long startTime, stopTime; +class Timer { + long startTime, stopTime; - public void start() { - startTime = System.currentTimeMillis(); - stopTime = startTime; - } + public void start() { + startTime = System.currentTimeMillis(); + stopTime = startTime; + } - public void stop() { - stopTime = System.currentTimeMillis(); - } + public void stop() { + stopTime = System.currentTimeMillis(); + } - public long getTime() { - return stopTime - startTime; - } - } + public long getTime() { + return stopTime - startTime; + } +} ]]></programlisting> </sect4> @@ -1963,14 +1964,14 @@ public aspect TimerLog { <para> The <classname>Timing</classname> aspect is declares an - inter-type field <literal>totalConnectTime</literal> for + inter-type field <literal>totalConnectTime</literal> for <classname>Customer</classname> to store the accumulated connection time per <classname>Customer</classname>. It also declares that - each <classname>Connection</classname> object has a timer. + each <classname>Connection</classname> object has a timer. <programlisting><![CDATA[ - public long Customer.totalConnectTime = 0; - private Timer Connection.timer = new Timer(); +public long Customer.totalConnectTime = 0; +private Timer Connection.timer = new Timer(); ]]></programlisting> Two pieces of after advice ensure that the timer is started when @@ -2029,7 +2030,7 @@ public aspect Timing { runs after <classname>Timing</classname>'s advice on the same join point. Finally, it declares inter-type methods and fields for <classname>Customer</classname> to handle the - <literal>totalCharge</literal>. + <literal>totalCharge</literal>. </para> <programlisting><![CDATA[ @@ -2097,10 +2098,10 @@ public aspect Billing { </para> <programlisting><![CDATA[ - protected void report(Customer c){ - Timing t = Timing.aspectOf(); - System.out.println(c + " spent " + t.getTotalConnectTime(c)); - } +protected void report(Customer c){ + Timing t = Timing.aspectOf(); + System.out.println(c + " spent " + t.getTotalConnectTime(c)); +} ]]></programlisting> </sect3> @@ -2115,8 +2116,8 @@ public aspect Billing { </para> <programlisting><![CDATA[ - ajc -argfile telecom/timing.lst - java telecom.TimingSimulation +ajc -argfile telecom/timing.lst +java telecom.TimingSimulation ]]></programlisting> <para> @@ -2125,8 +2126,8 @@ public aspect Billing { </para> <programlisting><![CDATA[ - ajc -argfile telecom/billing.lst - java telecom.BillingSimulation +ajc -argfile telecom/billing.lst +java telecom.BillingSimulation ]]></programlisting> </sect3> @@ -2199,8 +2200,8 @@ public aspect Billing { </para> <programlisting><![CDATA[ - public static void traceEntry(String str); - public static void traceExit(String str); +public static void traceEntry(String str); +public static void traceExit(String str); ]]></programlisting> <para> @@ -2210,7 +2211,7 @@ public aspect Billing { </para> <programlisting><![CDATA[ - Trace.traceEntry("Square.distance in " + toString()); +Trace.traceEntry("Square.distance in " + toString()); ]]></programlisting> <para> @@ -2219,8 +2220,8 @@ public aspect Billing { </para> <programlisting><![CDATA[ - public static void traceEntry(String str, Object obj); - public static void traceExit(String str, Object obj); +public static void traceEntry(String str, Object obj); +public static void traceExit(String str, Object obj); ]]></programlisting> <para> @@ -2230,7 +2231,7 @@ public aspect Billing { </para> <programlisting><![CDATA[ - Trace.traceEntry("Square.distance", this); +Trace.traceEntry("Square.distance", this); ]]></programlisting> <para> diff --git a/docs/progGuideDB/implementation.xml b/docs/progGuideDB/implementation.xml index 52da14d9c..e1fa05f2b 100644 --- a/docs/progGuideDB/implementation.xml +++ b/docs/progGuideDB/implementation.xml @@ -5,7 +5,7 @@ <sect1> <title>Compiler Notes</title> - <para> + <para> The initial implementations of AspectJ have all been compiler-based implementations. Certain elements of AspectJ's semantics are difficult to implement without making modifications @@ -25,7 +25,7 @@ </para> <programlisting><![CDATA[ - before(): get(int Point.x) { System.out.println("got x"); } +before(): get(int Point.x) { System.out.println("got x"); } ]]></programlisting> <para> @@ -36,7 +36,7 @@ compiled, whether changes were made later, etc. </para> - <para> + <para> But AspectJ implementations are permitted to deviate from this in a well-defined way -- they are permitted to advise only accesses in <emphasis>code the implementation controls</emphasis>. Each @@ -67,11 +67,11 @@ can be advised only if ajc controls the bytecode for the method or constructor body in question. The end of an exception handler is underdetermined in bytecode, - so ajc will not implement after or around advice on handler join + so ajc will not implement after or around advice on handler join points. - Similarly, ajc cannot implement around advice on initialization - or preinitialization join points. - In cases where ajc cannot implement advice, it will emit a + Similarly, ajc cannot implement around advice on initialization + or preinitialization join points. + In cases where ajc cannot implement advice, it will emit a compile-time error noting this as a compiler limitation. </para> @@ -100,35 +100,35 @@ </para> <para> When declaring members on interfaces, the implementation must - control both the interface and the top-level implementors of + control both the interface and the top-level implementors of that interface (the classes that implement the interface but do not have a superclass that implements the interface). You may weave these separately, but be aware that you will get runtime exceptions if you run the affected top-level classes - without the interface as produced by the same ajc implementation. - Any intertype declaration of an abstract method on an interface - must be specified as public, you will get a compile time error - message indicating this is a compiler limitation if you do not + without the interface as produced by the same ajc implementation. + Any intertype declaration of an abstract method on an interface + must be specified as public, you will get a compile time error + message indicating this is a compiler limitation if you do not specify public. A non-abstract method declared on an interface can use any access modifier except protected. Note that this is - different to normal Java rules where all members declared in + different to normal Java rules where all members declared in an interface are implicitly public. - Finally, note that one cannot define static fields or methods + Finally, note that one cannot define static fields or methods on interfaces. </para> <para> - When declaring methods on target types, only methods declared - public are recognizable in the bytecode, so methods must be - declared public to be overridden in any subtype or to be called + When declaring methods on target types, only methods declared + public are recognizable in the bytecode, so methods must be + declared public to be overridden in any subtype or to be called from code in a later compile using the target type as a library. </para> - + <para> Other AspectJ implementations, indeed, future versions of ajc, may define <emphasis>code the implementation controls</emphasis> more liberally or restrictively, so long as they comport with the Java language. For example, the <literal>call</literal> pointcut does - not pick out reflective calls to a method implemented in + not pick out reflective calls to a method implemented in <literal>java.lang.reflect.Method.invoke(Object, Object[])</literal>. Some suggest that the call "happens" and the call pointcut should pick it out, but the AspectJ language shouldn't anticipate what happens @@ -172,12 +172,12 @@ </para> <programlisting><![CDATA[ - class Test { - void main(String[] args) { - System.out.println(Test.class); // calls Class.forName - System.out.println(args[0] + args[1]); // calls StringBuffer.append - } - } +class Test { + void main(String[] args) { + System.out.println(Test.class); // calls Class.forName + System.out.println(args[0] + args[1]); // calls StringBuffer.append + } +} ]]></programlisting> <para>In short, the join point model of the current AspectJ @@ -217,7 +217,7 @@ </para> <programlisting><![CDATA[ - cflow(call(void foo()) || handler(java.io.IOException)) +cflow(call(void foo()) || handler(java.io.IOException)) ]]></programlisting> <para> will capture all join points in the control flow of a call to @@ -236,9 +236,9 @@ </para> <programlisting><![CDATA[ - before(): handler(java.io.IOException) && cflow(void parse()) { - System.out.println("about to handle an exception while parsing"); - } +before(): handler(java.io.IOException) && cflow(void parse()) { + System.out.println("about to handle an exception while parsing"); +} ]]></programlisting> <para> @@ -258,16 +258,16 @@ </para> <programlisting><![CDATA[ - class C { - double d = Math.sqrt(2); - } +class C { + double d = Math.sqrt(2); +} ]]></programlisting> <para> are considered part of constructors by the time AspectJ gets ahold of bytecode. That is, the assignment of d to the square root of two happens <emphasis>inside</emphasis> the default constructor of - C. + C. </para> <para> @@ -280,15 +280,15 @@ </para> <programlisting><![CDATA[ - aspect A { - C.new(Object o) {} // implicitly calls super() +aspect A { + C.new(Object o) {} // implicitly calls super() - public static void main(String[] args) { - System.out.println((new C() ).d); // prints 1.414... - System.out.println((new C(null)).d); // prints 0.0 - } + public static void main(String[] args) { + System.out.println((new C() ).d); // prints 1.414... + System.out.println((new C(null)).d); // prints 0.0 +} ]]></programlisting> - + <para> It is the job of an inter-type constructor to do all the required initialization, or to delegate to a <literal>this</literal> @@ -302,8 +302,8 @@ <para>Writing aspects in annotation-style is subject to the same bytecode limitations since the binary aspects take the same form and are woven in the same way. However, the implementation - differences (e.g., the mechanism for implementing around advice) - may be apparent at runtime. See the documentation on annotation-style + differences (e.g., the mechanism for implementing around advice) + may be apparent at runtime. See the documentation on annotation-style for more information. </para> </sect1> @@ -311,7 +311,7 @@ <title>Summary of implementation requirements</title> <para> This summarizes the requirements of our implementation of AspectJ. - For more details, see the relevant sections of this guide. + For more details, see the relevant sections of this guide. </para> <itemizedlist spacing="compact"> <listitem> @@ -343,7 +343,7 @@ <para>Implementation Caveats</para> <itemizedlist spacing="compact"> <listitem> - <para>The initialization and preinitialization join points + <para>The initialization and preinitialization join points do not support around advice</para> </listitem> <listitem> @@ -355,7 +355,7 @@ </itemizedlist> </listitem> <listitem> - <para>Declaring members on an interface in an aspect affects only + <para>Declaring members on an interface in an aspect affects only the topmost implementing classes the implementation controls.</para> </listitem> <listitem> @@ -363,7 +363,7 @@ </listitem> <listitem> <para> - Runtime <literal>ClassCastException</literal> may result + Runtime <literal>ClassCastException</literal> may result from supplying a supertype of the actual type as an argument to proceed(..) in around advice.</para> </listitem> diff --git a/docs/progGuideDB/language.xml b/docs/progGuideDB/language.xml index c666c106a..48b0fa62d 100644 --- a/docs/progGuideDB/language.xml +++ b/docs/progGuideDB/language.xml @@ -623,10 +623,10 @@ interface MyInterface { ... } </para> <programlisting> - P --------------------- +P --------------------- + \ + \ cflow of P \ - \ cflow of P - \ </programlisting> @@ -639,16 +639,16 @@ interface MyInterface { ... } </para> <programlisting> - P --------------------- + P --------------------- + \ + \ cflow of P \ - \ cflow of P + \ \ - \ - \ - Q -------------\------- +Q -------------\------- + \ \ + \ cflow of Q \ cflow(P) && cflow(Q) \ \ - \ cflow of Q \ cflow(P) && cflow(Q) - \ \ </programlisting> <para> @@ -666,10 +666,10 @@ interface MyInterface { ... } </para> <programlisting> - P && Q ------------------- - \ - \ cflow of (P && Q) - \ +P && Q ------------------- + \ + \ cflow of (P && Q) + \ </programlisting> <para> @@ -715,7 +715,7 @@ aspect A { <para> The <literal>!within(<replaceable>A</replaceable>)</literal> - pointcut above is required to avoid the <literal>printPC</literal> + pointcut above is required to avoid the <literal>printPC</literal> pointcut applying to the <literal>System.out.println</literal> call in the advice body. If this was not present a recursive call would result as the pointcut would apply to its own advice. @@ -734,9 +734,9 @@ aspect A { </para> <programlisting><![CDATA[ - pointcut setter(): target(Point) && - (call(void setX(int)) || - call(void setY(int))); +pointcut setter(): target(Point) && + (call(void setX(int)) || + call(void setY(int))); ]]></programlisting> <para> @@ -751,9 +751,9 @@ aspect A { </para> <programlisting><![CDATA[ - pointcut setter(Point p): target(p) && - (call(void setX(int)) || - call(void setY(int))); +pointcut setter(Point p): target(p) && + (call(void setX(int)) || + call(void setY(int))); ]]></programlisting> <para> @@ -774,9 +774,9 @@ aspect A { </para> <programlisting><![CDATA[ - pointcut testEquality(Point p): target(Point) && - args(p) && - call(boolean equals(Object)); +pointcut testEquality(Point p): target(Point) && + args(p) && + call(boolean equals(Object)); ]]></programlisting> <para> @@ -796,9 +796,9 @@ aspect A { </para> <programlisting><![CDATA[ - pointcut testEquality(Point p1, Point p2): target(p1) && - args(p2) && - call(boolean equals(Object)); +pointcut testEquality(Point p1, Point p2): target(p1) && + args(p2) && + call(boolean equals(Object)); ]]></programlisting> <para> @@ -828,9 +828,9 @@ pointcut setter(Point p, int newval): target(p) && following pointcut definition will result in a compilation error: <programlisting><![CDATA[ - pointcut badPointcut(Point p1, Point p2): - (target(p1) && call(void setX(int))) || - (target(p2) && call(void setY(int))); +pointcut badPointcut(Point p1, Point p2): + (target(p1) && call(void setX(int))) || + (target(p2) && call(void setY(int))); ]]></programlisting> because <literal>p1</literal> is only bound when calling @@ -856,38 +856,38 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - class Handle { - Partner partner = new Partner(); +class Handle { + Partner partner = new Partner(); - public void foo() { partner.foo(); } - public void bar(int x) { partner.bar(x); } + public void foo() { partner.foo(); } + public void bar(int x) { partner.bar(x); } - public static void main(String[] args) { - Handle h1 = new Handle(); - h1.foo(); - h1.bar(2); - } + public static void main(String[] args) { + Handle h1 = new Handle(); + h1.foo(); + h1.bar(2); } +} - class Partner { - boolean isAlive() { return true; } - void foo() { System.out.println("foo"); } - void bar(int x) { System.out.println("bar " + x); } - } +class Partner { + boolean isAlive() { return true; } + void foo() { System.out.println("foo"); } + void bar(int x) { System.out.println("bar " + x); } +} - aspect HandleLiveness { - before(Handle handle): target(handle) && call(public * *(..)) { - if ( handle.partner == null || !handle.partner.isAlive() ) { - throw new DeadPartnerException(); - } +aspect HandleLiveness { + before(Handle handle): target(handle) && call(public * *(..)) { + if ( handle.partner == null || !handle.partner.isAlive() ) { + throw new DeadPartnerException(); } } +} - class DeadPartnerException extends RuntimeException {} +class DeadPartnerException extends RuntimeException {} ]]></programlisting> </sect2> - + <sect2 id="pointcut-best-practice" xreflabel="pointcut-best-practice"> <title>Writing good pointcuts</title> @@ -919,15 +919,15 @@ pointcut setter(Point p, int newval): target(p) && </listitem> </itemizedlist> <para> - A well written pointcut should + A well written pointcut should try and include at least the first two types (kinded and scoping), whilst the contextual designators may be included if wishing to - match based on join point context, or bind that context for use in the advice. Supplying either just a kinded designator or - just a contextual designator will work but could affect weaving performance (time and memory used) - due to all the extra processing and analysis. - Scoping designators are very fast to match, they can very quickly dismiss groups of join points that should not be further + match based on join point context, or bind that context for use in the advice. Supplying either just a kinded designator or + just a contextual designator will work but could affect weaving performance (time and memory used) + due to all the extra processing and analysis. + Scoping designators are very fast to match, they can very quickly dismiss groups of join points that should not be further processed - that is why a good pointcut should always include one if possible. </para> - + </sect2> </sect1> @@ -945,14 +945,14 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - pointcut setter(Point p1, int newval): target(p1) && args(newval) - (call(void setX(int) || - call(void setY(int))); +pointcut setter(Point p1, int newval): target(p1) && args(newval) + (call(void setX(int) || + call(void setY(int))); - before(Point p1, int newval): setter(p1, newval) { - System.out.println("About to set something in " + p1 + - " to the new value " + newval); - } +before(Point p1, int newval): setter(p1, newval) { + System.out.println("About to set something in " + p1 + + " to the new value " + newval); +} ]]></programlisting> <para> @@ -961,12 +961,12 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - before(Point p1, int newval): target(p1) && args(newval) - (call(void setX(int)) || - call(void setY(int))) { - System.out.println("About to set something in " + p1 + - " to the new value " + newval); - } +before(Point p1, int newval): target(p1) && args(newval) + (call(void setX(int)) || + call(void setY(int))) { + System.out.println("About to set something in " + p1 + + " to the new value " + newval); +} ]]></programlisting> <para> @@ -979,9 +979,9 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - before(Point p, int x): target(p) && args(x) && call(void setX(int)) { - if (!p.assertX(x)) return; - } +before(Point p, int x): target(p) && args(x) && call(void setX(int)) { + if (!p.assertX(x)) return; +} ]]></programlisting> <para> @@ -991,9 +991,9 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - after(Point p, int x): target(p) && args(x) && call(void setX(int)) { - if (!p.assertX(x)) throw new PostConditionViolation(); - } +after(Point p, int x): target(p) && args(x) && call(void setX(int)) { + if (!p.assertX(x)) throw new PostConditionViolation(); +} ]]></programlisting> <para> @@ -1004,9 +1004,9 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - after(Point p) returning(int x): target(p) && call(int getX()) { - System.out.println("Returning int value " + x + " for p = " + p); - } +after(Point p) returning(int x): target(p) && call(int getX()) { + System.out.println("Returning int value " + x + " for p = " + p); +} ]]></programlisting> <para> @@ -1018,9 +1018,9 @@ pointcut setter(Point p, int newval): target(p) && </para> <programlisting><![CDATA[ - after() throwing(Exception e): target(Point) && call(void setX(int)) { - System.out.println(e); - } +after() throwing(Exception e): target(Point) && call(void setX(int)) { + System.out.println(e); +} ]]></programlisting> <para> @@ -1059,7 +1059,7 @@ void around(Point p, int x): target(p) initialized to <literal>false</literal>: <programlisting><![CDATA[ - private boolean Server.disabled = false; +private boolean Server.disabled = false; ]]></programlisting> It is declared <literal>private</literal>, which means that it is @@ -1077,7 +1077,7 @@ void around(Point p, int x): target(p) arguments that returns whatever <literal>this.x</literal> is: <programlisting><![CDATA[ - public int Point.getX() { return this.x; } +public int Point.getX() { return this.x; } ]]></programlisting> Inside the body, <literal>this</literal> is the @@ -1092,7 +1092,7 @@ void around(Point p, int x): target(p) <literal>Point</literal>: <programlisting><![CDATA[ - public Point.new(int x, int y) { this.x = x; this.y = y; } +public Point.new(int x, int y) { this.x = x; this.y = y; } ]]></programlisting> </para> @@ -1103,7 +1103,7 @@ void around(Point p, int x): target(p) to zero: <programlisting><![CDATA[ - public int Point.x = 0; +public int Point.x = 0; ]]></programlisting> Because this is publically declared, it is an error if @@ -1117,7 +1117,7 @@ void around(Point p, int x): target(p) <literal>Comparable</literal> interface: <programlisting><![CDATA[ - declare parents: Point implements Comparable; +declare parents: Point implements Comparable; ]]></programlisting> Of course, this will be an error unless <literal>Point</literal> @@ -1129,7 +1129,7 @@ void around(Point p, int x): target(p) <literal>GeometricObject</literal> class. <programlisting><![CDATA[ - declare parents: Point extends GeometricObject; +declare parents: Point extends GeometricObject; ]]></programlisting> </para> @@ -1138,8 +1138,8 @@ void around(Point p, int x): target(p) following declarations <programlisting><![CDATA[ - public String Point.name; - public void Point.setName(String name) { this.name = name; } +public String Point.name; +public void Point.setName(String name) { this.name = name; } ]]></programlisting> publicly declare that Point has both a String field @@ -1155,13 +1155,13 @@ void around(Point p, int x): target(p) interface: <programlisting><![CDATA[ - aspect A { - private interface HasName {} - declare parents: (Point || Line || Square) implements HasName; +aspect A { + private interface HasName {} + declare parents: (Point || Line || Square) implements HasName; - private String HasName.name; - public String HasName.getName() { return name; } - } + private String HasName.name; + public String HasName.getName() { return name; } +} ]]></programlisting> This declares a marker interface <literal>HasName</literal>, and also declares that any @@ -1193,7 +1193,7 @@ void around(Point p, int x): target(p) aspect makes a private inter-type declaration of a field <programlisting><![CDATA[ - private int Foo.x; +private int Foo.x; ]]></programlisting> Then code in the aspect can refer to <literal>Foo</literal>'s @@ -1230,38 +1230,38 @@ void around(Point p, int x): target(p) </para> <programlisting><![CDATA[ - class Point { - int x, y; +class Point { + int x, y; - public void setX(int x) { this.x = x; } - public void setY(int y) { this.y = y; } + public void setX(int x) { this.x = x; } + public void setY(int y) { this.y = y; } - public static void main(String[] args) { - Point p = new Point(); - p.setX(3); p.setY(333); - } - } + public static void main(String[] args) { + Point p = new Point(); + p.setX(3); p.setY(333); + } +} - aspect PointAssertions { - - private boolean Point.assertX(int x) { - return (x <= 100 && x >= 0); - } - private boolean Point.assertY(int y) { - return (y <= 100 && y >= 0); - } - - before(Point p, int x): target(p) && args(x) && call(void setX(int)) { - if (!p.assertX(x)) { - System.out.println("Illegal value for x"); return; - } - } - before(Point p, int y): target(p) && args(y) && call(void setY(int)) { - if (!p.assertY(y)) { - System.out.println("Illegal value for y"); return; - } - } - } +aspect PointAssertions { + + private boolean Point.assertX(int x) { + return (x <= 100 && x >= 0); + } + private boolean Point.assertY(int y) { + return (y <= 100 && y >= 0); + } + + before(Point p, int x): target(p) && args(x) && call(void setX(int)) { + if (!p.assertX(x)) { + System.out.println("Illegal value for x"); return; + } + } + before(Point p, int y): target(p) && args(y) && call(void setY(int)) { + if (!p.assertY(y)) { + System.out.println("Illegal value for y"); return; + } + } +} ]]></programlisting> </sect2> @@ -1290,11 +1290,11 @@ void around(Point p, int x): target(p) </para> <programlisting><![CDATA[ - aspect TraceNonStaticMethods { - before(Point p): target(p) && call(* *(..)) { - System.out.println("Entering " + thisJoinPoint + " in " + p); - } - } +aspect TraceNonStaticMethods { + before(Point p): target(p) && call(* *(..)) { + System.out.println("Entering " + thisJoinPoint + " in " + p); + } +} ]]></programlisting> <para> @@ -1304,7 +1304,7 @@ void around(Point p, int x): target(p) arguments of the join point: <programlisting><![CDATA[ - thisJoinPoint.getArgs() +thisJoinPoint.getArgs() ]]></programlisting> In addition, it holds an object consisting of all the static @@ -1312,7 +1312,7 @@ void around(Point p, int x): target(p) and static signature: <programlisting><![CDATA[ - thisJoinPoint.getStaticPart() +thisJoinPoint.getStaticPart() ]]></programlisting> If you only need the static information about the join point, you may @@ -1327,11 +1327,11 @@ void around(Point p, int x): target(p) </para> <programlisting><![CDATA[ - thisJoinPointStaticPart == thisJoinPoint.getStaticPart() +thisJoinPointStaticPart == thisJoinPoint.getStaticPart() - thisJoinPoint.getKind() == thisJoinPointStaticPart.getKind() - thisJoinPoint.getSignature() == thisJoinPointStaticPart.getSignature() - thisJoinPoint.getSourceLocation() == thisJoinPointStaticPart.getSourceLocation() +thisJoinPoint.getKind() == thisJoinPointStaticPart.getKind() +thisJoinPoint.getSignature() == thisJoinPointStaticPart.getSignature() +thisJoinPoint.getSourceLocation() == thisJoinPointStaticPart.getSourceLocation() ]]></programlisting> <para> diff --git a/docs/progGuideDB/semantics.xml b/docs/progGuideDB/semantics.xml index 23d1fb2d6..6bba37818 100644 --- a/docs/progGuideDB/semantics.xml +++ b/docs/progGuideDB/semantics.xml @@ -204,7 +204,7 @@ <literal>this</literal> expression would pick out at the join point. The target object is where control or attention is transferred to by the join point. The arguments are those - values passed for that transfer of control or attention. + values passed for that transfer of control or attention. </para> <informaltable frame="1"> @@ -216,7 +216,7 @@ <entry><emphasis role="bold">Target Object</emphasis></entry> <entry><emphasis role="bold">Arguments</emphasis></entry> </row> - </thead> + </thead> <tbody> <row> <entry>Method Call</entry> @@ -296,7 +296,7 @@ </para> <para>** There is no target object for join points associated - with static methods or fields. + with static methods or fields. </para> </sect1> @@ -485,9 +485,9 @@ <listitem> Picks out each join point where the arguments are instances of the appropriate type (or type of the identifier if using that form). A - <literal>null</literal> argument is matched iff the static type of the + <literal>null</literal> argument is matched iff the static type of the argument (declared parameter type or field type) is the same as, or a subtype of, - the specified args type. + the specified args type. </listitem> </varlistentry> @@ -556,8 +556,8 @@ </para> <programlisting> - pointcut publicIntCall(int i): - call(public * *(int)) <![CDATA[&&]]> args(i); +pointcut publicIntCall(int i): + call(public * *(int)) <![CDATA[&&]]> args(i); </programlisting> <para> @@ -568,15 +568,15 @@ </para> <programlisting> - class C { - pointcut publicCall(int i): - call(public * *(int)) <![CDATA[&&]]> args(i); - } +class C { + pointcut publicCall(int i): + call(public * *(int)) <![CDATA[&&]]> args(i); +} - class D { - pointcut myPublicCall(int i): - C.publicCall(i) <![CDATA[&&]]> within(SomeType); - } +class D { + pointcut myPublicCall(int i): + C.publicCall(i) <![CDATA[&&]]> within(SomeType); +} </programlisting> <para> @@ -586,9 +586,9 @@ </para> <programlisting> - abstract aspect A { - abstract pointcut publicCall(int i); - } +abstract aspect A { + abstract pointcut publicCall(int i); +} </programlisting> <para> @@ -597,9 +597,9 @@ </para> <programlisting> - aspect B extends A { - pointcut publicCall(int i): call(public Foo.m(int)) <![CDATA[&&]]> args(i); - } +aspect B extends A { + pointcut publicCall(int i): call(public Foo.m(int)) <![CDATA[&&]]> args(i); +} </programlisting> <para> @@ -622,9 +622,9 @@ </para> <programlisting> - aspect B percflow(publicCall()) { - pointcut publicCall(): call(public Foo.m(int)); - } +aspect B percflow(publicCall()) { + pointcut publicCall(): call(public Foo.m(int)); +} </programlisting> </sect2> @@ -653,7 +653,7 @@ </para> <programlisting> - pointcut intArg(int i): args(i); +pointcut intArg(int i): args(i); </programlisting> <para> @@ -662,7 +662,7 @@ <literal>char</literal>; anything assignable to an <literal>int</literal>) is being passed as an argument. Second, though, it makes the value of that argument - available to the enclosing advice or pointcut. + available to the enclosing advice or pointcut. </para> <para> @@ -670,8 +670,8 @@ </para> <programlisting> - pointcut publicCall(int x): call(public *.*(int)) <![CDATA[&&]]> intArg(x); - pointcut intArg(int i): args(i); +pointcut publicCall(int x): call(public *.*(int)) <![CDATA[&&]]> intArg(x); +pointcut intArg(int i): args(i); </programlisting> <para> @@ -686,7 +686,7 @@ </para> <programlisting> - pointcut publicCall(): call(public *.*(..)) <![CDATA[&&]]> args(Object); +pointcut publicCall(): call(public *.*(..)) <![CDATA[&&]]> args(Object); </programlisting> <para> @@ -696,7 +696,7 @@ </para> <programlisting> - pointcut publicCall(Object o): call(public *.*(..)) <![CDATA[&&]]> args(o); +pointcut publicCall(Object o): call(public *.*(..)) <![CDATA[&&]]> args(o); </programlisting> <para> @@ -712,23 +712,23 @@ </para> <programlisting> - public class InstanceOf { +public class InstanceOf { - public static void main(String[] args) { - doInt(5); - } - - static void doInt(int i) { } + public static void main(String[] args) { + doInt(5); } - aspect IntToLong { - pointcut el(long l) : - execution(* doInt(..)) <![CDATA[&&]]> args(l); + static void doInt(int i) { } +} - before(Object o) : el(o) { - System.out.println(o.getClass()); - } +aspect IntToLong { + pointcut el(long l) : + execution(* doInt(..)) <![CDATA[&&]]> args(l); + + before(Object o) : el(o) { + System.out.println(o.getClass()); } +} </programlisting> <para> @@ -775,13 +775,13 @@ </para> <programlisting><![CDATA[ - aspect GuardedX { - static final int MAX_CHANGE = 100; - before(int newval): set(static int T.x) && args(newval) { - if (Math.abs(newval - T.x) > MAX_CHANGE) - throw new RuntimeException(); - } - } +aspect GuardedX { + static final int MAX_CHANGE = 100; + before(int newval): set(static int T.x) && args(newval) { + if (Math.abs(newval - T.x) > MAX_CHANGE) + throw new RuntimeException(); + } +} ]]></programlisting> </sect3> @@ -838,11 +838,11 @@ </para> <programlisting> - aspect NormalizeFooException { - before(FooException e): handler(FooException) <![CDATA[&&]]> args(e) { - e.normalize(); - } - } +aspect NormalizeFooException { + before(FooException e): handler(FooException) <![CDATA[&&]]> args(e) { + e.normalize(); + } +} </programlisting> </sect3> @@ -865,13 +865,13 @@ </para> <programlisting> - aspect TraceStuff { - pointcut myAdvice(): adviceexecution() <![CDATA[&&]]> within(TraceStuff); +aspect TraceStuff { + pointcut myAdvice(): adviceexecution() <![CDATA[&&]]> within(TraceStuff); - before(): call(* *(..)) <![CDATA[&&]]> !cflow(myAdvice) { - // do something - } - } + before(): call(* *(..)) <![CDATA[&&]]> !cflow(myAdvice) { + // do something + } +} </programlisting> </sect3> @@ -926,7 +926,7 @@ </para> <programlisting> - args(int, .., String) +args(int, .., String) </programlisting> <para> @@ -978,7 +978,7 @@ <literal>cflowbelow</literal> pointcuts may expose context state through enclosed <literal>this</literal>, <literal>target</literal>, and <literal>args</literal> - pointcuts. + pointcuts. </para> <para> @@ -1006,7 +1006,7 @@ class Test { aspect A { pointcut entry(int i): call(int fact(int)) <![CDATA[&&]]> args(i); pointcut writing(): call(void println(String)) <![CDATA[&&]]> ! within(A); - + before(int i): writing() <![CDATA[&&]]> cflow(entry(i)) { System.err.println("Current arg is " + i); } @@ -1079,14 +1079,14 @@ aspect A { </para> <programlisting> - if(thisJoinPoint.getKind().equals("call")) +if(thisJoinPoint.getKind().equals("call")) </programlisting> <para> - Note that the order of evaluation for pointcut expression - components at a join point is undefined. Writing <literal>if</literal> - pointcuts that have side-effects is considered bad style and may also - lead to potentially confusing or even changing behavior with regard + Note that the order of evaluation for pointcut expression + components at a join point is undefined. Writing <literal>if</literal> + pointcuts that have side-effects is considered bad style and may also + lead to potentially confusing or even changing behavior with regard to when or if the test code will run. </para> </sect3> @@ -1207,9 +1207,9 @@ aspect A { <programlisting> - class C { - public final void foo() throws ArrayOutOfBoundsException { ... } - } +class C { + public final void foo() throws ArrayOutOfBoundsException { ... } +} </programlisting> <para> @@ -1219,7 +1219,7 @@ aspect A { <programlisting> - call(public final void C.foo() throws ArrayOutOfBoundsException) +call(public final void C.foo() throws ArrayOutOfBoundsException) </programlisting> <para> @@ -1227,7 +1227,7 @@ aspect A { </para> <programlisting> - call(public final void *.*() throws ArrayOutOfBoundsException) +call(public final void *.*() throws ArrayOutOfBoundsException) </programlisting> @@ -1245,16 +1245,16 @@ aspect A { </para> <programlisting> - call(public final void *() throws ArrayOutOfBoundsException) +call(public final void *() throws ArrayOutOfBoundsException) </programlisting> <para> - The wildcard <literal>..</literal> indicates zero or more + The wildcard <literal>..</literal> indicates zero or more parameters, so </para> <programlisting> - execution(void m(..)) +execution(void m(..)) </programlisting> <para> @@ -1263,7 +1263,7 @@ aspect A { </para> <programlisting> - execution(void m(.., int)) +execution(void m(.., int)) </programlisting> <para> @@ -1280,7 +1280,7 @@ aspect A { </para> <programlisting> - withincode(!public void foo()) +withincode(!public void foo()) </programlisting> <para> @@ -1289,7 +1289,7 @@ aspect A { </para> <programlisting> - withincode(void foo()) +withincode(void foo()) </programlisting> <para> @@ -1303,7 +1303,7 @@ aspect A { </para> <programlisting> - call(int *()) +call(int *()) </programlisting> <para> @@ -1312,7 +1312,7 @@ aspect A { </para> <programlisting> - call(int get*()) +call(int get*()) </programlisting> <para> @@ -1328,7 +1328,7 @@ aspect A { </para> <programlisting> - execution(private C.new() throws ArithmeticException) +execution(private C.new() throws ArithmeticException) </programlisting> <sect3> @@ -1341,23 +1341,23 @@ aspect A { </para> <para> - When matching for pointcuts <literal>withincode</literal>, + When matching for pointcuts <literal>withincode</literal>, <literal>get</literal>, and <literal>set</literal>, the declaring type is the class that contains the declaration. </para> <para> - When matching method-call join points, the + When matching method-call join points, the declaring type is the static type used to access the method. - A common mistake is to specify a declaring type for the - <literal>call</literal> pointcut that is a subtype of the + A common mistake is to specify a declaring type for the + <literal>call</literal> pointcut that is a subtype of the originally-declaring type. For example, given the class </para> <programlisting> - class Service implements Runnable { - public void run() { ... } - } +class Service implements Runnable { + public void run() { ... } +} </programlisting> <para> @@ -1365,7 +1365,7 @@ aspect A { </para> <programlisting> - call(void Service.run()) +call(void Service.run()) </programlisting> <para> @@ -1373,49 +1373,49 @@ aspect A { </para> <programlisting> - ((Runnable) new Service()).run(); +((Runnable) new Service()).run(); </programlisting> <para> Specifying the originally-declaring type is correct, but would pick out any such call (here, calls to the <literal>run()</literal> - method of any Runnable). + method of any Runnable). In this situation, consider instead picking out the target type: </para> <programlisting> - call(void run()) && target(Service) +call(void run()) && target(Service) </programlisting> <para> - When matching method-execution join points, - if the execution pointcut method signature specifies a declaring type, - the pointcut will only match methods declared in that type, or methods + When matching method-execution join points, + if the execution pointcut method signature specifies a declaring type, + the pointcut will only match methods declared in that type, or methods that override methods declared in or inherited by that type. So the pointcut </para> <programlisting> - execution(public void Middle.*()) +execution(public void Middle.*()) </programlisting> <para> picks out all method executions for public methods returning void - and having no arguments that are either declared in, or inherited by, - Middle, even if those methods are overridden in a subclass of Middle. + and having no arguments that are either declared in, or inherited by, + Middle, even if those methods are overridden in a subclass of Middle. So the pointcut would pick out the method-execution join point for Sub.m() in this code: </para> <programlisting> - class Super { - protected void m() { ... } - } - class Middle extends Super { - } - class Sub extends Middle { - public void m() { ... } - } +class Super { + protected void m() { ... } +} +class Middle extends Super { +} +class Sub extends Middle { + public void m() { ... } +} </programlisting> </sect3> @@ -1430,15 +1430,15 @@ aspect A { </para> <programlisting> - pointcut throwsMathlike(): - // each call to a method with a throws clause containing at least - // one exception exception with "Math" in its name. - call(* *(..) throws *..*Math*); +pointcut throwsMathlike(): + // each call to a method with a throws clause containing at least + // one exception exception with "Math" in its name. + call(* *(..) throws *..*Math*); - pointcut doesNotThrowMathlike(): - // each call to a method with a throws clause containing no - // exceptions with "Math" in its name. - call(* *(..) throws !*..*Math*); +pointcut doesNotThrowMathlike(): + // each call to a method with a throws clause containing no + // exceptions with "Math" in its name. + call(* *(..) throws !*..*Math*); </programlisting> <para> @@ -1550,7 +1550,7 @@ aspect A { <literal>java.util.HashMap</literal> unless the aspect were in <literal>java.util</literal> or the type had been imported. - </listitem> + </listitem> </itemizedlist> <para> @@ -1569,7 +1569,7 @@ aspect A { </para> <programlisting> - call(void foo(*)) +call(void foo(*)) </programlisting> <para> @@ -1585,7 +1585,7 @@ aspect A { </para> <programlisting> - handler(java.util.*Map) +handler(java.util.*Map) </programlisting> <para> @@ -1594,7 +1594,7 @@ aspect A { </para> <programlisting> - handler(java.util.*) +handler(java.util.*) </programlisting> <para> @@ -1611,11 +1611,11 @@ aspect A { </para> <programlisting> - within(com.xerox..*) +within(com.xerox..*) </programlisting> <para> - picks out all join points where the code is in any + picks out all join points where the code is in any declaration of a type whose name begins with "<literal>com.xerox.</literal>". </para> @@ -1638,7 +1638,7 @@ aspect A { </para> <programlisting> - call(Foo.new()) +call(Foo.new()) </programlisting> <para> @@ -1647,7 +1647,7 @@ aspect A { </para> <programlisting> - call(Foo+.new()) +call(Foo+.new()) </programlisting> <para> @@ -1656,7 +1656,7 @@ aspect A { </para> <programlisting> - call(*Handler+.new()) +call(*Handler+.new()) </programlisting> <para> @@ -1689,7 +1689,7 @@ aspect A { </para> <programlisting> - staticinitialization(Foo || Bar) +staticinitialization(Foo || Bar) </programlisting> <para> @@ -1698,7 +1698,7 @@ aspect A { </para> <programlisting> - call((Foo+ <![CDATA[&&]]> ! Foo).new(..)) +call((Foo+ <![CDATA[&&]]> ! Foo).new(..)) </programlisting> <para> @@ -1716,24 +1716,24 @@ aspect A { </para> <programlisting> -MethodPattern = - [ModifiersPattern] TypePattern - [TypePattern . ] IdPattern (TypePattern | ".." , ... ) +MethodPattern = + [ModifiersPattern] TypePattern + [TypePattern . ] IdPattern (TypePattern | ".." , ... ) [ throws ThrowsPattern ] -ConstructorPattern = - [ModifiersPattern ] - [TypePattern . ] new (TypePattern | ".." , ...) +ConstructorPattern = + [ModifiersPattern ] + [TypePattern . ] new (TypePattern | ".." , ...) [ throws ThrowsPattern ] -FieldPattern = +FieldPattern = [ModifiersPattern] TypePattern [TypePattern . ] IdPattern -ThrowsPattern = +ThrowsPattern = [ ! ] TypePattern , ... -TypePattern = +TypePattern = IdPattern [ + ] [ [] ... ] | ! TypePattern | TypePattern <![CDATA[&&]]> TypePattern | TypePattern || TypePattern - | ( TypePattern ) + | ( TypePattern ) IdPattern = Sequence of characters, possibly with special * and .. wildcards ModifiersPattern = @@ -1785,7 +1785,7 @@ ModifiersPattern = <para> and where <replaceable>Formal</replaceable> refers to a variable binding like those used for method parameters, - of the form + of the form <literal><replaceable>Type</replaceable></literal> <literal><replaceable>Variable-Name</replaceable></literal>, and <replaceable>Formals</replaceable> refers to a comma-delimited @@ -1816,18 +1816,18 @@ ModifiersPattern = </para> <programlisting> - aspect A { - pointcut publicCall(): call(public Object *(..)); - after() returning (Object o): publicCall() { - System.out.println("Returned normally with " + o); - } - after() throwing (Exception e): publicCall() { - System.out.println("Threw an exception: " + e); - } - after(): publicCall(){ - System.out.println("Returned or threw an Exception"); - } - } +aspect A { + pointcut publicCall(): call(public Object *(..)); + after() returning (Object o): publicCall() { + System.out.println("Returned normally with " + o); + } + after() throwing (Exception e): publicCall() { + System.out.println("Threw an exception: " + e); + } + after(): publicCall(){ + System.out.println("Returned or threw an Exception"); + } +} </programlisting> <para> @@ -1836,9 +1836,9 @@ ModifiersPattern = </para> <programlisting> - after() returning: call(public Object *(..)) { - System.out.println("Returned normally"); - } +after() returning: call(public Object *(..)) { + System.out.println("Returned normally"); +} </programlisting> <para> @@ -1888,11 +1888,11 @@ ModifiersPattern = </para> <programlisting> - aspect A { - int around(): call(int C.foo()) { - return 3; - } - } +aspect A { + int around(): call(int C.foo()) { + return 3; + } +} </programlisting> <para> @@ -1901,7 +1901,7 @@ ModifiersPattern = </para> <programlisting> - proceed( ... ) +proceed( ... ) </programlisting> <para> @@ -1913,12 +1913,12 @@ ModifiersPattern = <programlisting> - aspect A { - int around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) { - int newi = proceed(i*2) - return newi/2; - } - } +aspect A { + int around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) { + int newi = proceed(i*2) + return newi/2; + } +} </programlisting> <para> @@ -1931,38 +1931,38 @@ ModifiersPattern = </para> <programlisting> - aspect A { - Object around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) { - Integer newi = (Integer) proceed(i*2) - return new Integer(newi.intValue() / 2); - } - } +aspect A { + Object around(int i): call(int C.foo(Object, int)) <![CDATA[&&]]> args(i) { + Integer newi = (Integer) proceed(i*2) + return new Integer(newi.intValue() / 2); + } +} </programlisting> - + <para> - Any occurence of <literal>proceed(..)</literal> within the body of around + Any occurence of <literal>proceed(..)</literal> within the body of around advice is treated as the special proceed form (even if the - aspect defines a method named <literal>proceed</literal>), unless a + aspect defines a method named <literal>proceed</literal>), unless a target other than the aspect instance is specified as the recipient of the call. - For example, in the following program the first + For example, in the following program the first call to proceed will be treated as a method call to the <literal>ICanProceed</literal> instance, whereas the second call to proceed is treated as the special proceed form. </para> <programlisting> - aspect A { - Object around(ICanProceed canProceed) : execution(* *(..)) <![CDATA[&&]]> this(canProceed) { - canProceed.proceed(); // a method call - return proceed(canProceed); // the special proceed form - } - - private Object proceed(ICanProceed canProceed) { - // this method cannot be called from inside the body of around advice in - // the aspect - } - } +aspect A { + Object around(ICanProceed canProceed) : execution(* *(..)) <![CDATA[&&]]> this(canProceed) { + canProceed.proceed(); // a method call + return proceed(canProceed); // the special proceed form + } + + private Object proceed(ICanProceed canProceed) { + // this method cannot be called from inside the body of around advice in + // the aspect + } +} </programlisting> <para> @@ -1973,11 +1973,11 @@ ModifiersPattern = </para> <programlisting> - aspect A { - after() returning (int i): call(int C.foo()) { - i = i * 2; - } - } +aspect A { + after() returning (int i): call(int C.foo()) { + i = i * 2; + } +} </programlisting> <para> @@ -1990,47 +1990,47 @@ ModifiersPattern = With <literal>proceed(..)</literal> it is possible to change the values used by less-precedent advice and the underlying join point by supplying different values for the variables. For example, this aspect replaces - the string bound to <literal>s</literal> in the named pointcut + the string bound to <literal>s</literal> in the named pointcut <literal>privateData</literal>: </para> <programlisting> - aspect A { - Object around(String s): MyPointcuts.privateData(s) { - return proceed("private data"); - } +aspect A { + Object around(String s): MyPointcuts.privateData(s) { + return proceed("private data"); } +} </programlisting> <para> - If you replace an argument to <literal>proceed(..)</literal>, you can cause + If you replace an argument to <literal>proceed(..)</literal>, you can cause a <literal>ClassCastException</literal> at runtime when the argument - refers to a supertype of the actual type and you do not supply a + refers to a supertype of the actual type and you do not supply a reference of the actual type. In the following aspect, the - around advice replaces the declared target <literal>List</literal> + around advice replaces the declared target <literal>List</literal> with an <literal>ArrayList</literal>. This is valid code at - compile-time since the types match. + compile-time since the types match. </para> <programlisting> - import java.util.*; +import java.util.*; - aspect A { - Object around(List list): call(* List+.*()) <![CDATA[&&]]> target(list) { - return proceed(new ArrayList()); - } +aspect A { + Object around(List list): call(* List+.*()) <![CDATA[&&]]> target(list) { + return proceed(new ArrayList()); } +} </programlisting> <para> But imagine a simple program where the actual target is <literal>LinkedList</literal>. In this case, the advice would cause a - <literal>ClassCastException</literal> at runtime, and + <literal>ClassCastException</literal> at runtime, and <literal>peek()</literal> is not declared in <literal>ArrayList</literal>. </para> <programlisting> - public class Test { - public static void main(String[] args) { - new LinkedList().peek(); - } +public class Test { + public static void main(String[] args) { + new LinkedList().peek(); } +} </programlisting> <para> The <literal>ClassCastException</literal> can occur even in situations @@ -2038,17 +2038,17 @@ ModifiersPattern = call <literal>size()</literal>, declared in <literal>List</literal>: </para> <programlisting> - public class Test { - public static void main(String[] args) { - new LinkedList().size(); - } +public class Test { + public static void main(String[] args) { + new LinkedList().size(); } +} </programlisting> <para> There will still be a <literal>ClassCastException</literal> because it is impossible to prove that there won't be a runtime binary-compatible change in the hierarchy of <literal>LinkedList</literal> or some - other advice on the join point that requires a + other advice on the join point that requires a <literal>LinkedList</literal>. </para> @@ -2077,22 +2077,22 @@ ModifiersPattern = </para> <programlisting> - import java.io.FileNotFoundException; +import java.io.FileNotFoundException; - class C { - int i; +class C { + int i; - int getI() { return i; } - } + int getI() { return i; } +} - aspect A { - before(): get(int C.i) { - throw new FileNotFoundException(); - } - before() throws FileNotFoundException: get(int C.i) { - throw new FileNotFoundException(); - } - } +aspect A { + before(): get(int C.i) { + throw new FileNotFoundException(); + } + before() throws FileNotFoundException: get(int C.i) { + throw new FileNotFoundException(); + } +} </programlisting> <para> @@ -2124,7 +2124,7 @@ ModifiersPattern = <varlistentry> <term>field get and set</term> <listitem> - no checked exceptions can be thrown from these join points. + no checked exceptions can be thrown from these join points. </listitem> </varlistentry> @@ -2138,7 +2138,7 @@ ModifiersPattern = <varlistentry> <term>static initializer execution</term> <listitem> - no checked exceptions can be thrown from these join points. + no checked exceptions can be thrown from these join points. </listitem> </varlistentry> @@ -2146,14 +2146,14 @@ ModifiersPattern = <term>pre-initialization and initialization</term> <listitem> any exception that is in the throws clause of - <emphasis>all</emphasis> constructors of the initialized class. + <emphasis>all</emphasis> constructors of the initialized class. </listitem> </varlistentry> <varlistentry> <term>advice execution</term> <listitem> - any exception that is in the throws clause of the advice. + any exception that is in the throws clause of the advice. </listitem> </varlistentry> @@ -2218,11 +2218,11 @@ ModifiersPattern = <para>These rules can lead to circularity, such as</para> <programlisting> - aspect A { - before(): execution(void main(String[] args)) {} - after(): execution(void main(String[] args)) {} - before(): execution(void main(String[] args)) {} - } +aspect A { + before(): execution(void main(String[] args)) {} + after(): execution(void main(String[] args)) {} + before(): execution(void main(String[] args)) {} +} </programlisting> <para>such circularities will result in errors signalled by the compiler. </para> @@ -2268,7 +2268,7 @@ ModifiersPattern = <para> Three special variables are visible within bodies of advice - and within <literal>if()</literal> pointcut expressions: + and within <literal>if()</literal> pointcut expressions: <literal>thisJoinPoint</literal>, <literal>thisJoinPointStaticPart</literal>, and <literal>thisEnclosingJoinPointStaticPart</literal>. Each is bound to @@ -2280,7 +2280,7 @@ ModifiersPattern = <programlisting> - pointcut publicCall(): call(public * *(..)); +pointcut publicCall(): call(public * *(..)); </programlisting> @@ -2372,17 +2372,17 @@ ModifiersPattern = </para> <programlisting> - interface Iface {} +interface Iface {} - aspect A { - private void Iface.m() { - System.err.println("I'm a private method on an interface"); - } - void worksOnI(Iface iface) { - // calling a private method on an interface - iface.m(); - } - } +aspect A { + private void Iface.m() { + System.err.println("I'm a private method on an interface"); + } + void worksOnI(Iface iface) { + // calling a private method on an interface + iface.m(); + } +} </programlisting> <para> @@ -2499,7 +2499,7 @@ ModifiersPattern = is illegal because it would say that a public interface has a constraint that only non-public implementors must fulfill. This would not be compatible with Java's type - system. + system. </para> </sect2> @@ -2514,13 +2514,13 @@ ModifiersPattern = </para> <programlisting> - aspect A { - private Registry otherPackage.onType.r; - public void otherPackage.onType.register(Registry r) { - r.register(this); - this.r = r; - } - } +aspect A { + private Registry otherPackage.onType.r; + public void otherPackage.onType.register(Registry r) { + r.register(this); + this.r = r; + } +} </programlisting> <para> @@ -2546,7 +2546,7 @@ ModifiersPattern = </para> <programlisting> - this.r = r +this.r = r </programlisting> <para> @@ -2614,10 +2614,10 @@ ModifiersPattern = </para> <programlisting> - aspect A { - declare parents: SomeClass implements Runnable; - public void SomeClass.run() { ... } - } +aspect A { + declare parents: SomeClass implements Runnable; + public void SomeClass.run() { ... } +} </programlisting> </sect2> @@ -2647,13 +2647,13 @@ ModifiersPattern = </para> <programlisting> - Object M O - \ / \ / - C N Q - \ / / - D P - \ / - E + Object M O + \ / \ / + C N Q + \ / / + D P + \ / + E </programlisting> <para> @@ -2661,7 +2661,7 @@ ModifiersPattern = </para> <programlisting> - Object M C O N D Q P E +Object M C O N D Q P E </programlisting> </sect2> @@ -2703,9 +2703,9 @@ ModifiersPattern = <para>For example, the aspect</para> <programlisting> - aspect A { - declare soft: Exception: execution(void main(String[] args)); - } +aspect A { + declare soft: Exception: execution(void main(String[] args)); +} </programlisting> <para>Would, at the execution join point, catch any @@ -2716,14 +2716,14 @@ ModifiersPattern = <para>This is similar to what the following advice would do</para> <programlisting> - aspect A { - void around() execution(void main(String[] args)) { - try { proceed(); } - catch (Exception e) { - throw new org.aspectj.lang.SoftException(e); - } - } +aspect A { + void around() execution(void main(String[] args)) { + try { proceed(); } + catch (Exception e) { + throw new org.aspectj.lang.SoftException(e); } + } +} </programlisting> <para>except, in addition to wrapping the exception, it also affects @@ -2735,15 +2735,15 @@ ModifiersPattern = extending concrete aspect:</para> <programlisting> - abstract aspect A { - abstract pointcut softeningPC(); +abstract aspect A { + abstract pointcut softeningPC(); - before() : softeningPC() { - Class.forName("FooClass"); // error: uncaught ClassNotFoundException - } - - declare soft : ClassNotFoundException : call(* Class.*(..)); + before() : softeningPC() { + Class.forName("FooClass"); // error: uncaught ClassNotFoundException } + + declare soft : ClassNotFoundException : call(* Class.*(..)); +} </programlisting> </sect2> @@ -2777,7 +2777,7 @@ ModifiersPattern = expressed by:</para> <programlisting> - declare precedence: *..*Security*, Logging+, *; +declare precedence: *..*Security*, Logging+, *; </programlisting> <para> @@ -2791,22 +2791,22 @@ ModifiersPattern = </para> <programlisting> - aspect Ordering { - declare precedence: CountEntry, DisallowNulls; - } - aspect DisallowNulls { - pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..); - before(Type obj): allTypeMethods(obj) { - if (obj == null) throw new RuntimeException(); - } - } - aspect CountEntry { - pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..); - static int count = 0; - before(): allTypeMethods(Type) { - count++; - } - } +aspect Ordering { + declare precedence: CountEntry, DisallowNulls; +} +aspect DisallowNulls { + pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..); + before(Type obj): allTypeMethods(obj) { + if (obj == null) throw new RuntimeException(); + } +} +aspect CountEntry { + pointcut allTypeMethods(Type obj): call(* *(..)) <![CDATA[&&]]> args(obj, ..); + static int count = 0; + before(): allTypeMethods(Type) { + count++; + } +} </programlisting> <sect3> @@ -2818,7 +2818,7 @@ ModifiersPattern = </para> <programlisting> - declare precedence: A, B, A ; // error +declare precedence: A, B, A ; // error </programlisting> <para> @@ -2828,8 +2828,8 @@ ModifiersPattern = </para> <programlisting> - declare precedence: B, A; - declare precedence: A, B; +declare precedence: B, A; +declare precedence: A, B; </programlisting> <para> @@ -2848,31 +2848,31 @@ ModifiersPattern = </para> <programlisting> - abstract aspect Logging { - abstract pointcut logged(); +abstract aspect Logging { + abstract pointcut logged(); - before(): logged() { - System.err.println("thisJoinPoint: " + thisJoinPoint); - } - } + before(): logged() { + System.err.println("thisJoinPoint: " + thisJoinPoint); + } +} - abstract aspect MyProfiling { - abstract pointcut profiled(); - - Object around(): profiled() { - long beforeTime = System.currentTimeMillis(); - try { - return proceed(); - } finally { - long afterTime = System.currentTimeMillis(); - addToProfile(thisJoinPointStaticPart, - afterTime - beforeTime); - } - } - abstract void addToProfile( - org.aspectj.JoinPoint.StaticPart jp, - long elapsed); - } +abstract aspect MyProfiling { + abstract pointcut profiled(); + + Object around(): profiled() { + long beforeTime = System.currentTimeMillis(); + try { + return proceed(); + } finally { + long afterTime = System.currentTimeMillis(); + addToProfile(thisJoinPointStaticPart, + afterTime - beforeTime); + } + } + abstract void addToProfile( + org.aspectj.JoinPoint.StaticPart jp, + long elapsed); +} </programlisting> <para> @@ -2883,7 +2883,7 @@ ModifiersPattern = </para> <programlisting> - declare precedence: Logging, Profiling; +declare precedence: Logging, Profiling; </programlisting> <para> @@ -2891,8 +2891,8 @@ ModifiersPattern = </para> <programlisting> - declare precedence: MyLogging, MyProfiling; - declare precedence: Logging+, Profiling+; +declare precedence: MyLogging, MyProfiling; +declare precedence: Logging+, Profiling+; </programlisting> <para> @@ -2932,7 +2932,7 @@ ModifiersPattern = <para> An aspect is a crosscutting type defined by the <literal>aspect</literal> - declaration. + declaration. </para> <sect2 id="aspect-declaration" xreflabel="aspect-declaration"> @@ -2955,7 +2955,7 @@ ModifiersPattern = declarations that can can cut across other types (including those defined by other aspect declarations). </para> - </sect3> + </sect3> <sect3> <title>Aspects are not directly instantiated</title> @@ -2966,19 +2966,19 @@ ModifiersPattern = constructor taking no arguments and throwing no checked exceptions. </para> - </sect3> + </sect3> <sect3> <title>Nested aspects must be <literal>static</literal></title> - <para> + <para> Aspects may be defined either at the package level, or as a static nested aspect -- that is, a static member of a class, interface, or aspect. If it is not at the package level, the aspect <emphasis>must</emphasis> be defined with the static keyword. Local and anonymous aspects are not allowed. </para> - </sect3> + </sect3> </sect2> <sect2 id="aspect-extension" xreflabel="aspect-extension"> @@ -3041,7 +3041,7 @@ ModifiersPattern = The criteria used to determine how an aspect is instantiated is inherited from its parent aspect. If the aspect has no parent aspect, then by default the aspect is a singleton aspect. - How an aspect is instantiated controls the form of the + How an aspect is instantiated controls the form of the <literal>aspectOf(..)</literal> method defined on the concrete aspect class. </para> @@ -3103,7 +3103,7 @@ ModifiersPattern = target object of the join points picked out by <replaceable>Pointcut</replaceable>. The advice defined in A will run only at a join point where the - target object has been associated with an instance of + target object has been associated with an instance of A. </para> @@ -3156,20 +3156,20 @@ ModifiersPattern = </para> <programlisting> - public class Client - { - public static void main(String[] args) { - Client c = new Client(); - } - } +public class Client +{ + public static void main(String[] args) { + Client c = new Client(); + } +} - aspect Watchcall { - pointcut myConstructor(): execution(new(..)); +aspect Watchcall { + pointcut myConstructor(): execution(new(..)); - before(): myConstructor() { - System.err.println("Entering Constructor"); - } - } + before(): myConstructor() { + System.err.println("Entering Constructor"); + } +} </programlisting> <para> @@ -3214,16 +3214,16 @@ ModifiersPattern = </para> <programlisting> - class C { - private int i = 0; - void incI(int x) { i = i+x; } - } - privileged aspect A { - static final int MAX = 1000; - before(int x, C c): call(void C.incI(int)) <![CDATA[&&]]> target(c) <![CDATA[&&]]> args(x) { - if (c.i+x > MAX) throw new RuntimeException(); - } - } +class C { + private int i = 0; + void incI(int x) { i = i+x; } +} +privileged aspect A { + static final int MAX = 1000; + before(int x, C c): call(void C.incI(int)) <![CDATA[&&]]> target(c) <![CDATA[&&]]> args(x) { + if (c.i+x > MAX) throw new RuntimeException(); + } +} </programlisting> <para> @@ -3238,16 +3238,17 @@ ModifiersPattern = </para> <programlisting> - class C { - private int i = 0; - void foo() { } - } - privileged aspect A { - private int C.i = 999; - before(C c): call(void C.foo()) target(c) { - System.out.println(c.i); - } - } +class C { + private int i = 0; + void foo() { } +} + +privileged aspect A { + private int C.i = 999; + before(C c): call(void C.foo()) target(c) { + System.out.println(c.i); + } +} </programlisting> <para> |