For John.

Slides:



Advertisements
Similar presentations
The Singleton Pattern II Recursive Linked Structures.
Advertisements

Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
1 Shyness in Programming Karl Lieberherr Demeter Research Group Northeastern University Boston.
Explaining DJ with AOP. DJ ClassGraph.traverse (this,whereToGo,whatToDo) Intertype declaration Advice.
Integration of Demeter and AspectJ (DAJ) John J. Sung.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Demeter Interfaces: AP without Surprises Prof. Karl Lieberherr and Therapon Skotiniotis, Jeffrey Palm.
Master’s Thesis Defense: Aspectual Concepts John J. Sung.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Expression evaluation E : S | C. S = int. C = Op E E. Op : A | M. A = “+”. M = “*”.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Take-Home Final COM 3205 Fall Stamp Coupling Def: data structure is passed as parameter, but called method operates on only some of the` individual.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
Master’s Thesis Defense: Aspectual Concepts John J. Sung.
John J. Sung TA Consulting. Motivation for TraversalJ KL Enterprises identified AOP Enter into the AOP market early Add value by adding traversals to.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
System Body Thing * * Definition Fig. UML1 def body Ident S D T B definitions things.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
System Body Thing * * Definition Fig. UML1 def body Ident S D T B definitions things.
1 Functional Visitor Ø Motivation Example Container checking -- Make sure each Container is not overloaded Weight Item + int total( ) w Container + int.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Demeter Interfaces: AP without Surprises Prof. Karl Lieberherr and Therapon Skotiniotis, Jeffrey Palm.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Translating Traversals to AspectJ. Outline Motivation Demeter Process for Traversals AspectJ Translation Process.
Static?. Static Not dynamic class Widget { static int s; int d; // dynamic // or instance // variable }
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Adaptive Aspect-Oriented Programming in AspectJ Karl J. Lieberherr Northeastern University.
DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Enum,Structure and Nullable Types Ashima Wadhwa. Enumerations, Enumerations, or enums, are used to group named constants similar to how they are used.
COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003.
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
The need for Programming Languages
CSC111 Quick Revision.
Crosscutting Capabilities for Java and AspectJ through DJ
Software Development Java Classes and Methods
Lecture 2: Data Types, Variables, Operators, and Expressions
IST311 / 602 Cleveland State University – Prof. Victor Matos
University of Central Florida COP 3330 Object Oriented Programming
Discussion with Gregor Kiczales at UBC
Computing Adjusted Quiz Total Score
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
The Boolean (logical) data type boolean
Building Java Programs
AP/DJ AP: a generic technology
Better Separation of Crosscutting Concerns with Aspectual Components
Simple Classes in Java CSCI 392 Classes – Part 1.
AOSD and the Law of Demeter: Shyness in Programming
Generics, Lambdas, Reflections
IST311 / 602 Cleveland State University – Prof. Victor Matos
Special instance methods: toString
Building Java Programs
Subtype Substitution Principle
CSS161: Fundamentals of Computing
Adaptive Programming in JAsCo
Midterm Winter 2002 Karl Lieberherr.
Presentation transcript:

For John

DAJ (temporary name for AspectJ with traversals) planned to be added to AspectJ provides an efficient implementation of traversals using the AP library we have also added traversals to Java but implementation is very slow (using reflection) AspectJ + traversals > Java + traversals because AspectJ > Java

Adding Demeter Traversals to AspectJ Because the AspectJ join point model is a generalization of Demeter’s join point model, we can use the AspectJ pointcuts to express the traversal pointcuts for visitors. declare ClassGraph declare TraversalGraph declare Behavior

Traversal(t) pointcut picks out all join points between the start and the end of the traversal that are needed for the traversal only, i.e. the node visits and the edge visits.

Traversal Syntax Example aspect MyTraversal { ClassGraph defaultCG = new ClassGraph(); ClassGraph cg1 = new ClassGraph(defaultCG, “from CompoundFile to * bypassing ->*,tail,*”); declare traversal t1: “from CompoundFile to SimpleFile”; declare traversal t2(cg1): “from CompoundFile to *”; }

Traversal Syntax Example aspect MyTraversal { declare visitors : VisitorInterface1; ClassGraph defaultCG = new ClassGraph(); ClassGraph cg1 = new ClassGraph(defaultCG, “from CompoundFile to * bypassing ->*,tail,*”); declare traversal t1(defaultCG): “from CompoundFile to SimpleFile”; declare traversal t2(cg1, VisitorInterface1): “from CompoundFile to *”; }

Generate pointcuts / advice interface VisitorInterface1 { void before(Object host); void after(B host); void after(C source, D target); void around(A host); void start(); void finish(); }

M1: Equation System used = from EquationSystem via -> *,rhs,* to Variable M1: Equation System EquationSystem equations Equation_List Ident * lhs Equation Variable Numerical rhs Simple args Expression Expression_List S T * op Add Compound D B

Motivation for edge advice before_rhs < before ! Motivation for edge advice for each used variable v print the largest expression that contains v class LargestVisitor { Expression exp; void before_rhs(Object s, Expression t){ exp = t; }; void before(Variable v) { System.out.println(exp, v) } from EquationSystem via -> *,rhs,* to Variable

Motivation for edge advice from EquationSystem to Variable around < before ! Motivation for edge advice class MarkVariableVisitor { boolean through_lhs; … void before(Variable v) { if (through_lhs) { … } else if (through_rhs) { … } }; void around_lhs(Subtraversal t){ through_lhs = true; t.proceed(); through_lhs = false; }; … } for each variable print whether it is used or defined

Self-Contained Example Java classes Traversal file Use traversal defined

Basket Example Basket f p Pencil Fruit Orange w c Weight Color int i s String

BasketMain.java class Weight{ class Basket { Weight(int _i) { i = _i;} int get_i() { return i; } } class Pencil {} class Color { Color(String _s) { s = _s;} String s; class Basket { Basket(Fruit _f, Pencil _p) { f = _f; p = _p; } Fruit f; Pencil p; } class Fruit { Fruit(Weight _w) { w = _w; } Weight w; class Orange extends Fruit { Orange(Color _c) { super(null); c=_c;} Orange(Color _c, Weight _w) { super(_w); c = _c;} Color c;

BasketMain.java class BasketMain { static public void main(String args[]) throws Exception { Basket b = new Basket( new Orange( new Color("orange"), new Weight(5)), new Pencil()); int totalWeight = b.totalWeight(); System.out.println("Total weight of basket = " + totalWeight); }}

Traversals Count the total weight within the basket Traversal Strategy: “From Basket to Weight” Visitor: Add up all the values within Weight

Basket Example Traversal Graph f p Pencil Fruit Orange w c Weight Color int i s String

Two versions define visitor using AspectJ pointcuts and advice Java visitor class complete with initialization, finalization and return value processing

BasketTraversal.trv // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare traversal t2(myClassGraph) : "from Basket to Weight"; declare TraversalGraph t2 : myClassGraph, "from Basket to Weight"; }

generated: BasketTraversal.java public aspect BasketTraversal { // traversal t2 : {source: Basket -> target: Weight} with { } public void Basket.t2(){ if (f != null) t2_crossing_f(); } public void Basket.t2_crossing_f() { f.t2();} public void Fruit.t2(){ if (w != null) t2_crossing_w(); public void Fruit.t2_crossing_w() { w.t2();} public void Weight.t2(){ public void Orange.t2(){ super.t2(); } pointcut pointcut_t2() : call(public void t2*()); before () : pointcut_t2 () { System.out.println(thisJoinPoint); } // BasketTraversal for testing traversal code

BasketMainCount.java // the aspect for counting the total weight of the basket aspect BasketMainCount { static int returnVal; int Basket.totalWeight() { returnVal = 0; t2(); return returnVal; } pointcut t2WeightPC(Weight weight) : call(* *t2*()) && target(weight); before(Weight weight) : t2WeightPC(weight) { returnVal += weight.get_i();

BasketTraversal.trv “visitor in Java” version // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare traversal Integer t2(myClassGraph, SumVis) : "from Basket to Weight"; }

BasketTraversal.trv !!!!!!!!!!!!!!! Better “visitor in Java” version // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare TraversalGraph tg : myClassGraph, “from A to B”; // tg() declare Behavior void b1 : tg, Vis; //b1() declare Behavior Integer summing : myCg, “from A to B”, Vis; //b2() declare traversal Integer t2(myClassGraph, SumVis) : "from Basket to Weight"; }

BasketMainCount.java // the aspect for counting the total weight of the basket aspect BasketMainCount { int Basket.totalWeight() { Integer retVal = summing(); return retVal.intValue(); } class SumVis { int retVal = 0; void before (Weight w) {retVal += weight.get_i();} Object returnVal() {return new Integer(retVal);}

Compilation Process Detail Traversal Files Stub Java Files AspectJ Compiler CreateClassGraph.java DAJ JVM AspectJ Files AspectJ Compiler Class Files Traversal Implementation and User Class Files Traversal Implementation Java Files