Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.

Slides:



Advertisements
Similar presentations
AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Advertisements

Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
An Overview of AspectJ Sabine Hauert. Today's Deserts  Whipped introduction served with its three berries syrup  Chocolate history soufflé  Design.
20-May-15 Aspect-Oriented Programming Dave Matuszek University of Pennsylvania.
Java.sun.com/javaone/sf | 2004 JavaOne SM Conference | Session BUS JavaOne 2004 What is AOP? Gregor Kiczales AspectMentor.com and University of.
Aspect-Oriented Programming Gregor Kiczales University of British Columbia © Copyright 2004, Gregor Kiczales. All rights reserved.
Advice Weaving in AspectJ Alex Gontmakher. Outline Possible implementation approaches Quick JVM primer AJC implementation Performance Evaluation.
359C 10/1/05 Eric Wohlstadter Introductions –Name –Degree objective/Year –Research Area (or interests) Syllabus Aspect-Oriented Programming –AspectJ –AspectC.
1 Aspect Oriented Programming Programming Languages Seminar Presenter: Barış Aktemur University of Illinois 18 Feb Mostly taken from Bedir Tekinerdogan’s.
Aspect-Oriented Software Development (AOSD) Tutorial #5 Categories of Aspects – contd.; LTL properties formalization; Assume – guarantee specifications.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
Aspect-Oriented Software Development (AOSD) Tutorial #4 Categories of Aspects.
Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP.
Aspect-Oriented Software Development (AOSD) Tutorial #4 Categories of Aspects.
Aspect-Oriented Software Development (AOSD) Tutorial #8 Composition Filters.
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Regression Test Selection for AspectJ Software Guoqing Xu and Atanas.
26-Jun-15 Aspect-Oriented Programming. 2 Programming paradigms Procedural programming Executing a set of commands in a given sequence Fortran, C, Cobol,
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University A Framework for Source-Code- Level Interprocedural Dataflow Analysis.
Session 15 Modeling Traceability of Concerns in Architectural Views Mark Stobbe October 29,
Aspect-Oriented Programming with AspectJ™ AspectJ.org Xerox PARC Erik Hilsdale Gregor Kiczales with Bill Griswold, Jim Hugunin, Wes Isberg, Mik Kersten.
Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
An Introduction to AOP Original slides developed by Julie Waterhouse and Mik Kersten for OOPSLA 2004 AspectJ Tutorial ( kerstens.org/mik/publications/aspectj-
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Session 2: AspectJ Mark Stobbe September 13,
1 An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture Naoyasu Ubayashi (Kyushu Institute of Technology) February 12, 2008.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
Kiczales and Mezini - FOAL AOP and Modular Reasoning [ICSE05] Start with first-principles definition of modularity and modular reasoning –localization,
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
1 CSC 221: Computer Programming I Fall 2004 Lists, data access, and searching  ArrayList class  ArrayList methods: add, get, size, remove  example:
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Virtual Support for Dynamic Join Points C. Bockisch, M. Haupt, M. Mezini, K. Ostermann Presented by Itai Sharon
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
AOP and observer pattern. Design pattern General reusable solution to a commonly occurring problem in software design Not a finished design that can be.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Extending the Field Access Pointcuts of AspectJ to Arrays ICS 2006 – Taipei, December 2006 Kung Chen and Chin-Hung Chien* National Chengchi University.
Review Creating Objects Pepper many references from rial/java/objects/object.html
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
A first language for Aspect-Oriented Programming
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Constructors; Encapsulation reading: self-checks: #13-18,
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
Classes and Objects Introduced
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Agenda Warmup AP Exam Review: Litvin A2
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Topic 28 classes and objects, part 2
CSE 115 September 29 – October 3, 2008.
Topic 29 classes and objects, part 3
CSE 115 September 29 – October 3, 2008.
Building Java Programs
Special instance methods: toString
Building Java Programs
Building Java Programs
Aspect Oriented Programming
Topic 29 classes and objects, part 3
Building Java Programs
Topic 29 classes and objects, part 3
Presentation transcript:

Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics

Aspect-Oriented Software Development (236608) 2 Today: Getting started with AspectJ Advice types Pointcuts –Primitive pointcuts –Pointcuts composition Examples English – AspectJ phrase book (selected entries)

Aspect-Oriented Software Development (236608) 3 Example Class: Point class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void MoveTo(Point p) {setX(p.x); setY(p.y); } public int getX() { return x; } public int getY() { return y; } }

Aspect-Oriented Software Development (236608) 4 English – AspectJ Phrase Book (1) pointcut getters(): target(Point) && (call(int getX()) || call(int getY())); Pointcut: all the calls to the “getters” of Point A short way to say the same: pointcut getters(): target(Point) && (call(get*(..))); Is this the same? pointcut getters2(Point pt): target(pt) && (call(get*(..))); The same join-points; different parameters exposed

Aspect-Oriented Software Development (236608) 5 English – AspectJ Phrase Book (2) What does this mean? pointcut questionPointcut(Point p1, Point p2): (target(p1) && call(void getX(int))) || (target(p2) && call(void getY(int))); Answer: empty pointcut (and compilation error)! (p1 is only bound when calling getX, and p2 is only bound when calling getY, but the pointcut picks out all of these join points and tries to bind both p1 and p2.)

Aspect-Oriented Software Development (236608) 6 Task 1: Positive Quarter Check Task1: After each change in our points, check whether they are in the positive quarter of the space “Positive quarter” means … ? When is the aspect called? (pointcut) - at every coordinate change What should the aspect do? (advice) - after each change, check the values of x and y of the point 0 ≤ x, y

Aspect-Oriented Software Development (236608) 7 Task 1 – contd.: Pointcut = ? call to public void setX(int x) call to public void setY(int y) call to public Point(int x, int y) In words: every coordinate change Where in the code? In AspectJ: (call(void set*(..))); (call(Point.new(..)));

Aspect-Oriented Software Development (236608) 8 Task 1 – contd.: Pointcut = ? pointcut movePoint(Point pt, int newArg): target(pt) && (call(void set*(newArg)))); pointcut createPoint(int x, int y): args(x,y) && (call(Point.new(int,int)))); Parameters? Pointcut as a whole, in AspectJ:

Aspect-Oriented Software Development (236608) 9 Task 1 – contd.: Advice = ? Advice type: after / after returning / after throwing Advice parameters: (Point pt, int newArg) ? (int x, int y) ? Both! => Need 2 pieces of advice!

Aspect-Oriented Software Development (236608) 10 Task 1: Advice = ? (In AspectJ) after(Point pt, int newArg) returning(): movePoint(pt, newArg) { if( newArg < 0) System.out.println( “…” ); } after(int x, int y) returning(): createPoint(x, y) { if( x < 0 || y < 0) System.out.println( “…” ); }

Aspect-Oriented Software Development (236608) 11 Task 2: Positive Quarter Alert Task2: Alert the user before each change that will result in points out of the positive quarter of the space Pointcut = ? The same as before!

Aspect-Oriented Software Development (236608) 12 Task 2 – contd. Advice = ? The only change: “after”  “before” before(Point pt, int newArg) : movePoint(pt, newArg) { if( newArg < 0) System.out.println( “…” ); } before(int x, int y) : createPoint(x, y) { if( x < 0 || y < 0) System.out.println( “…” ); }

Aspect-Oriented Software Development (236608) 13 Task 3: Enforce Positive Quarter Task3: Make sure that all our points are in the positive quarter of the space Pointcut = ? The same as before!

Aspect-Oriented Software Development (236608) 14 Task 3 – contd. Advice = ? Advice type: “around” void around(Point pt, int newArg): movePoint(pt, newArg) { if( newArg >= 0) proceed(pt, newArg); else System.out.println( “…” ); } Point around(int x, int y) : createPoint(x, y) { if( x < 0) { x=0; System.out.println( “…” );} if( y < 0) { y=0; System.out.println( “…” );} proceed(x,y); }

Aspect-Oriented Software Development (236608) 15 Call vs. Execute – contd. call(void m()) && withincode(void m()) = ? –directly recursive calls execution(void m()) && withincode(void m()) = ? –the same as execution(void m()) Enclosing code at a call join-point = ? –That of the call site. Enclosing code at an execution join point = ? –The method itself (as the program is already executing the method)

Aspect-Oriented Software Development (236608) 16 Execution vs. Withincode withincode(void m()) : –Matches all the join-points in the body of the function m() –Evaluated statically (by examining the code of m()) execution(void m()) : –Matches the beginning of the execution of the function m() for “before” advice, and the end of the execution of m() – for “after” advice –Evaluated dynamically, when the system is running –“Beginning of execution of m()” = the moment the execution enters m(); “End of the execution of m()” = the moment before the execution leaves m() –Does not match join-points inside the body of the function, except for the two points mentioned above (and does not match join-points in functions called by m()…)

Aspect-Oriented Software Development (236608) 17 More details… For more details please see the AspectJ Programming Guide, at: progguide/index.html To be continued at the next tutorial…