| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html> |
| <head> |
| <title> |
| Creating an aspect |
| </title> |
| <link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css"> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| </head> |
| <body> |
| <h1> Creating an aspect </h1> |
| <p> In this section you will create a new aspect and add a pointcut and |
| some advice. </p> |
| <ol> |
| <li> In the Package Explorer view, select the helloworld package. From the package's |
| context menu, select <strong>New > Aspect</strong>. </li> |
| <li> Make sure that <em>Hello World</em> appears in the <strong>Source Folder</strong> |
| field and that <em>helloworld</em> appears in the <strong>Package</strong> |
| field. In the <strong>Name</strong> field, type <em>World</em>. |
| <p> <img src="../images/newaspect.png" alt="New aspect wizard"> |
| </p> |
| </li> |
| <li> Click <strong>Finish</strong> to create the new aspect. |
| </li> |
| <li> The new file is opened in the editor. It contains the new aspect, |
| the constructor and comments. |
| <li> Change the body of the aspect to the following: |
| <p><code><br> |
| public aspect World { <br><br> |
| |
| pointcut greeting() : execution(* Hello.sayHello(..)); <br><br> |
| |
| after() returning() : greeting() { <br> |
| System.out.println(" World!"); <br> |
| } <br><br> |
| |
| } <br> |
| </code></p> |
| </li> |
| <li> Save the file. </li> |
| </ol> |
| |
| <p> |
| <img src="../images/ngrelc.gif" width=159 height=27 alt="Related concepts" border="0"> |
| </p> |
| <p> |
| <a href="../concepts/editor.htm">AspectJ editor</a> </p> |
| <p> <img src="../images/ngrelt.gif" width=159 height=27 alt="Related tasks" border="0"> |
| </p> |
| <p> |
| <a href="../tasks/ajelements.htm">Creating AspectJ elements</a> |
| </p> |
| |
| </body> |
| </html> |
| |