html5-img
1 / 19

AspectJ Syntax Basics

AspectJ Syntax Basics. Identify Join Points. 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 }. 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 void Get() {

davin
Download Presentation

AspectJ Syntax Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AspectJ Syntax Basics

  2. Identify Join Points 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 void Get() { 14 return value; 15 } 16 }

  3. Pointcuts • Named pointcut AllCall(): call( * *(..)); • Anonymous before(): call( * *(..)) { … }

  4. Named Pointcut Syntax [access specifier] pointcut pointcut- name([args]): pointcut definition

  5. Why Named Pointcuts? • Pointcut Reuse • Separation of two specifications: • Where additional behavior is to be applied? • What is the additional behavior? • Late Binding of Design Decisions

  6. Pointcut Reuse & Separation public pointcut StringArg(String s): execution( * *(..)) && args(s); around(String s): StringArg(s) { /* Omit execution if null argument */ } around(String s): StringArg(s) { /* Omit execution if not valid XML */ }

  7. Late Binding abstract aspect Lock { pointcut CriticalSections(); before(): CriticalSections() { /* Acquire lock */ } after(): CriticalSections() { /* Release lock */ } }

  8. Late Binding … aspect BufferLock extends Lock { pointcut CriticalSections(): call(* * Buffer.Write(..)); }

  9. Poincut composition • pointcut1 && pointcut2 • pointcut1 || pointcut2 • ! pointcut

  10. Signatures • Type Signatures • Method Signatures • Field Signatures

  11. Example Type Signature javax..*Model+ Any sub-type of a given type Any number of characters including period Any number of characters excluding the period

  12. Exercise 1 • Write down the type signature to pick out only the sub-types of all the types in the javax package or its direct and indirect subpackages that have a name ending in Model.

  13. Example Method Signature * javax..*.add*Listener(EventListener+)

  14. Example Field Signature !public static * banking..*.*

  15. Cflow and Cflowbelow • Cflow (Pointcut) - Captures all join points in the control flow of the join points matched by the specified pointcut, including the join points themselves. • Cflowbelow(Pointcut) – Excludes the matching join points, matches everything below.

  16. cflow( execution Account.debit(..)) 1 void debit(int amount) { 2 if( this.getBalance() > amount) { 3 this.setBalance( this.getBalance() – amount); 4 } 5 int getBalance() { 6 return db.Query(name, “balance”); 7 } 8 int setBalance(int balance) { 9 db.Update(name, “balance”, balance); 10 }

  17. Lexical Pointcuts • within( type pattern ) • withincode( method or constructor pattern)

  18. Identify matches within(Bit) 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 void Get() { 14 return value; 15 } 16 }

  19. withincode(* * Bit.*et(..)) 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 bool Get() { 14 return value; 15 } 16 }

More Related