LoD in AspectJ Karl Lieberherr.

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.
ASTA Aspect Software Testing Assistant Juha Gustafsson, Juha Taina, Jukka Viljamaa University of Helsinki.
1 Shyness in Programming Karl Lieberherr Demeter Research Group Northeastern University Boston.
An Overview of AspectJ Sabine Hauert. Today's Deserts  Whipped introduction served with its three berries syrup  Chocolate history soufflé  Design.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
1 Why do we need XAspects Structure-shyness –Can build DSL objects using constructors and use AspectJ to implement meaning of DSL objects. Is inconvenient.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Visit at MIT: Daniel Jackson’s Lectures on Coupling Karl Lieberherr
Aspect-Oriented Programming: An Overview Brandon Wirick Feb
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Controlling the Complexity of Software Designs Karl Lieberherr College of Computer and Information Science Northeastern University.
Developing Adaptive J2ME Applications Using AspectJ Ayla Débora and Paulo Borba {add, Centro de Informática - UFPE.
Master’s Thesis Defense: Aspectual Concepts John J. Sung.
Change Impact Analysis for AspectJ Programs Sai Zhang, Zhongxian Gu, Yu Lin and Jianjun Zhao Shanghai Jiao Tong University.
Session 2: AspectJ Mark Stobbe September 13,
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect Oriented Programming Gülşah KARADUMAN.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Master’s Thesis Defense: Aspectual Concepts John J. Sung.
Virtual Support for Dynamic Join Points C. Bockisch, M. Haupt, M. Mezini, K. Ostermann Presented by Itai Sharon
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa.
Adaptive Software Kevin Cella Graduate Seminar 02/04/2005.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Slicing AspectJ Woven Code Luca Cavallaro Mattia Monga Antonio Castaldo D'Ursi Davide Balzarotti Politecnico di Milano.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Controlling the Complexity of Software Designs Karl Lieberherr College of Computer and Information Science Northeastern University.
Topics for exam in AOSD Basic concepts: tangling, scattering, joinpoint, advice, cross-cutting, weaving AspectJ: syntax, pointcut notations, around, proceed,
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Checking LoD in AspectJ Show the idea, not the details. How can we precisely express it in a programming language?
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Controlling the Complexity of Software Designs Karl Lieberherr College of Computer and Information Science Northeastern University.
Adaptive Aspect-Oriented Programming in AspectJ Karl J. Lieberherr Northeastern University.
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05.
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
UCI Feb 031 Adaptive Aspect-Oriented Programming in AspectJ Karl J. Lieberherr Northeastern University Joint work of Demeter Research Group.
SCoPE: an AspectJ Compiler for Supporting User-Defined Analysis-Based Pointcuts Tomoyuki Aotani Hidehiko Masuhara
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
AO Mechanisms in Demeter1 Discussion with Gregor Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what exists. An.
Unified Modeling Language (UML)
 Is a programming paradigm  Extends OOP  Enables modularization of cross cutting concerns.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
UCI Feb 031 Adaptive Aspect-Oriented Programming in AspectJ Karl J. Lieberherr Northeastern University Joint work of Demeter Research Group.
Software Engineering Lecture 7
Aspect-Oriented Generation of the API Documentation for AspectJ
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Discussion with Gregor Kiczales at UBC
Controlling the Complexity of Software Designs
Demeter Aspects Who We Are Aspectual Collaborations
Controlling the Complexity of Software Designs
Lecture 21: Crosscutting Aspect-Oriented Programming Background
Structuring Adaptive Applications using AspectJ and AOM
Analysis Aspects Deters and Cytron propose to use analysis aspects to get profiling information from running Java programs. We explore the design issues.
Better Separation of Crosscutting Concerns with Aspectual Components
AOSD and the Law of Demeter: Shyness in Programming
AspectAda Aspect-Oriented Programming for Ada95
For DARPA PI Meeting Dec. 2002
Aspect Oriented Software Design
Aspect Oriented Programming
Adaptive Programming in JAsCo
Presentation transcript:

LoD in AspectJ Karl Lieberherr

Checking LoD in AspectJ Show the idea, not the details. How can we precisely express it in a programming language?

An adaptive aspect: Law of Demeter Checker (Object Form) aspect Check { … after(): MethodCallSite{ // call (* *(..)); // check whether // thisJoinPoint.getTarget() // is a preferred supplier // object }

How can we capture all calls? pointcut MethodCallSite(): scope() && call(* *(..)); BUT: how to avoid checking calls in Java libraries?

Avoiding the Java libraries pointcut IgnoreCalls(): call(* java..*.*(..)); pointcut MethodCallSite(): scope() && call(* *(..)) && !IgnoreCalls();

AspectJ from PARC J DEMETER DHMHTRA AJ (Demeter AspectJ) EMETERJ

Observation Many AspectJ programs are adaptive (designed for a family of Java programs) Context: Java program or its execution tree (lexical joinpoints or dynamic join points) Features enabling adaptiveness: *, .. (wildcards) cflow, + (graph transitivity) this(s), target(s), args(a), call (…), … inheritance as wild card pc(Object s, Object t): this(s) && target(t) && call(… f …)

AspectJ crosscutting used in Law of Demeter checker Dynamic call graph cflow(…) target(Object) Connected join points Isolated join points

Aspects and lexical join points Going to the roots of the Northeastern branch of AOP: Law of Demeter. Closing the circle: Write an ultimately adaptive program in AspectJ: Works with all Java programs Checks the object-form of the Law of Demeter: “talk only to your friends”

Instrumentation of Java programs with Aspects Aspect framework Aspect Diagram Supplier ImmediatePartBin TargetBinStack ArgumentBin Checker LocallyConstructedBin uses pointcuts ReturnValueBin Requirements: Statistics GlobalPreferredBin Good Separation of Concerns in Law of Demeter Checker

Explanation The *bin* aspects collect potential preferred supplier objects that represent good coupling in the context of a method body. The Checker aspect checks each method call whether the receiver is a preferred supplier object. The Statistics aspect counts events generated by the Checker aspect.

AspectJ code In AOSD 2003 paper with David Lorenz and Pengcheng Wu AspectJ works well. Program uses most adaptive ingredients of AspectJ: *, cflow, this, target, etc.

package lawOfDemeter; public abstract class Any { public pointcut scope(): !within(lawOfDemeter..*) && !cflow(withincode(* lawOfDemeter..*(..))); public pointcut StaticInitialization(): scope() && staticinitialization(*); public pointcut MethodCallSite(): scope() && call(* *(..)); public pointcut ConstructorCall(): scope() && call(*.new (..)); public pointcut MethodExecution(): scope() && execution(* *(..)); public pointcut ConstructorExecution(): scope() && execution(*.new (..)); public pointcut Execution(): ConstructorExecution() || MethodExecution(); public pointcut MethodCall(Object thiz, Object target): MethodCallSite() && this(thiz) && target(target);

Class Any continued public pointcut SelfCall(Object thiz, Object target): MethodCall(thiz, target) && if(thiz == target); public pointcut StaticCall(): scope() && call(static * *(..)); public pointcut Set(Object value): scope() && set(* *.*) && args(value); public pointcut Initialization(): scope() && initialization(*.new(..)); }

package lawOfDemeter.objectform; import java.util.*; abstract class ObjectSupplier { protected boolean containsValue(Object supplier){ return targets.containsValue(supplier); } protected void add(Object key,Object value){ targets.put(key,value); protected void addValue(Object supplier) { add(supplier,supplier); protected void addAll(Object[] suppliers) { for(int i=0; i< suppliers.length; i++) addValue(suppliers[i]); private IdentityHashMap targets = new IdentityHashMap();

package lawOfDemeter.objectform; public aspect Pertarget extends ObjectSupplier pertarget(Any.Initialization()) { before(Object value): Any.Set(value) { add(fieldIdentity(thisJoinPointStaticPart), value); } public boolean contains(Object target) { return super.containsValue(target) || Percflow.aspectOf().containsValue(target); private String fieldIdentity(JoinPoint.StaticPart sp) { … } private static HashMap fieldNames = new HashMap();

package lawOfDemeter.objectform; aspect Check { private pointcut IgnoreCalls(): call(* java..*.*(..)); private pointcut IgnoreTargets(): get(static * java..*.*); after() returning(Object o):IgnoreTargets() { ignoredTargets.put(o,o); } after(Object thiz,Object target): Any.MethodCall(thiz, target) && !IgnoreCalls() { if (!ignoredTargets.containsKey(target) && !Pertarget.aspectOf(thiz).contains(target)) System.out.println( " !! LoD Object Violation !! " + thisJoinPointStaticPart/*[*/ + at(thisJoinPointStaticPart)/*]*/); private IdentityHashMap ignoredTargets = new IdentityHashMap();}

package lawOfDemeter.objectform; aspect Percflow extends ObjectSupplier percflow(Any.Execution() || Any.Initialization()){ before(): Any.Execution() { addValue(thisJoinPoint.getThis()); addAll(thisJoinPoint.getArgs()); } after() returning (Object result): Any.SelfCall(Object,Object) || Any.StaticCall() || Any.ConstructorCall() { addValue(result);

Conclusions Aspects and adaptiveness must work closely together to achieve best results. Crosscutting is closely linked to adaptiveness. AP is a specialization of AOP and AOP is a specialization of AP. It goes both ways. AspectJ is a really useful language but we are a little concerned about how difficult it was to debug the Law of Demeter checkers.