Presentation is loading. Please wait.

Presentation is loading. Please wait.

COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003.

Similar presentations


Presentation on theme: "COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003."— Presentation transcript:

1 COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003

2 Motivation  DemeterJ can automate the process of generating traversal methods from Traversal Strategy, but …

3 class Tree { //simplified version public void allLabels_Tree_trv(SummingVisitor __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels_Tree_trv(__v0, __v1); } public void allLabels2(SummingVisitor2 __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels2_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels2_Tree_trv(__v0, __v1); } public String toString() { return new String(“a Tree”); } class Label { //simplified version void allLabels_Tree_trv (SummingVisitor __v0, UniversalVisitor __v1) { allLabels_Tree_trv_bef(__v0, __v1); allLabels_Tree_trv_aft(__v0, __v1); } void allLabels2_Tree_trv(SummingVisitor2 __v0, UniversalVisitor __v1) { allLabels2_Tree_trv_bef(__v0, __v1); allLabels2_Tree_trv_aft(__v0, __v1); } public String toString() { return new String(“a Label”); }

4 Motivation  DemeterJ can automate the process of generating traversal methods from Traversal Strategy, but the traversal methods are scattered over the classes, but …  the traversal methods are scattered over the classes and are tangled with the functional methods, e.g., toString().  We want something like …

5 construct AllLabels { public void Tree. allLabels_Tree_trv(SummingVisitor __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels_Tree_trv(__v0, __v1); } public void Label. Label.allLabels_Tree_trv (SummingVisitor __v0, UniversalVisitor __v1) { allLabels_Tree_trv_bef(__v0, __v1); allLabels_Tree_trv_aft(__v0, __v1); } construct AllLabels2 { public void Tree. allLabels2(SummingVisitor2 __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels2_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels2_Tree_trv(__v0, __v1); } public void Label. allLabels2_Tree_trv(SummingVisitor2 __v0, UniversalVisitor __v1) { allLabels2_Tree_trv_bef(__v0, __v1); allLabels2_Tree_trv_aft(__v0, __v1); }

6 Motivation  DemeterJ can automate the process of generating traversal methods from Traversal Strategy, but the traversal methods are scattered over the classes, but …  the traversal methods are scattered over the classes and are tangled with the functional methods, e.g., toString().  We want something like …  In reality, this can be done by using AspectJ’s (http://www.aspectj.org) introduction facility.

7 aspect AllLabels { public void Tree. allLabels_Tree_trv(SummingVisitor __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels_Tree_trv(__v0, __v1); } public void Label. Label.allLabels_Tree_trv (SummingVisitor __v0, UniversalVisitor __v1) { allLabels_Tree_trv_bef(__v0, __v1); allLabels_Tree_trv_aft(__v0, __v1); } aspect AllLabels2 { public void Tree. allLabels2(SummingVisitor2 __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels2_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels2_Tree_trv(__v0, __v1); } public void Label. allLabels2_Tree_trv(SummingVisitor2 __v0, UniversalVisitor __v1) { allLabels2_Tree_trv_bef(__v0, __v1); allLabels2_Tree_trv_aft(__v0, __v1); } aspectj code class Tree { public String toString() { return new String(“a Tree”); } class Label { public String toString() { return new String(“a Label”); } base program Actual code and runnable classes. AspectJ compiler (ajc) weaving

8 Your job … regular java files: *.java AllLabels.java aspect AllLabels { public void Tree. allLabels_Tree_trv(SummingVisitor __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels_Tree_trv(__v0, __v1); } public void Label. Label.allLabels_Tree_trv (SummingVisitor __v0, UniversalVisitor __v1) { allLabels_Tree_trv_bef(__v0, __v1); allLabels_Tree_trv_aft(__v0, __v1); } AllLabels2.java aspect AllLabesl2 { public void Tree. allLabels2(SummingVisitor2 __v0, UniversalVisitor __v1) { if (left != null) { left.allLabels2_Tree_trv(__v0, __v1); } if (right != null) { right.allLabels2_Tree_trv(__v0, __v1); } public void Label. allLabels2_Tree_trv(SummingVisitor2 __v0, UniversalVisitor __v1) { allLabels2_Tree_trv_bef(__v0, __v1); allLabels2_Tree_trv_aft(__v0, __v1); } traversal specification: *.trv generate!

9 What is provided:  CreateClassGraph.java – a small fragment of AspectJ code, which intercepts call to function main and creates a ClassGraph object. Then, passes it to TraversalJ project implementation using the ClassGraphFactor/Listener interface.  AspectJTraversal.java – a regular java class that generates the traversal code in AspectJ given a Traversal or ClassGraph and a Strategy. Also, takes in traversal name for naming various components of the traversal.  available at http://www.ccs.neu.edu/home/lieber/com1205/w03/project/

10 What you need to do:

11 How do the components communicate: 1.declare ClassGraphListener interface, void ClassGraphEvent(String [] args,ClassGraph cg) 2.implement ClassGraphListener interface, e.g., MyListener,giving an implementation of void ClassGraphEvent(String [] args,ClassGraph cg) (most job done here) 3.define ClassGraphFactory factory class, public static ClassGraphListener getNew() { return new MyListener(); } //for example

12 Implementation of ClassGraphEvent(String[] args,ClassGraph cg)  parsing the command line: -d option to specify to which directory the aspectj code will be generated, e.g., -d trav get all the traversal files, e.g., a.trv  construct the traversal specification objects from the traversal files, from which you can compute Traversal objects by DJ or just get the ClassGraph object and the traversal strategy.  new AspectJTraversal(String tn, Traversal tg) or new AspectJTraversal(ClassGraph cg, String tn, String st) provided by AspectJTraversal.java; toString() returns String representation of the generated AspectJ code.

13 Traversal Files  A list of traversal strategy or traversal declarations  Simple form strategy declaration: declare strategy AtoB: “from A to B”;  Composed form strategy declaration: declare strategy AtoBviaTelephone: intersect(AtoB,”from * via Telephone to * ”); or declare strategy AtoCviaMail: intersect(“from A to C”, “from * via Mail to *”);  traversal declaration: declare traversal t1:AtoBviaTelephone; or declare traversal t2: intersect(AtoBviaTelephone, “from * bypassing -> *,tail,* to *”);  need to construct a class dictionary for traversals so that you can create objects from input files (in DemeterJ)

14 An example of traversal files File A.trv aspect MyTraversal { declare strategy st1: “ from * bypassing -> *,tail,* to * ” ); declare traversal t1 : intersect ( “ from CompoundFile to SimpleFile ”, st1); } A typo: in the example given by the project specification document, I wrote: declare strategy: skipTail: “ from * bypassing -> *,tail,* to * ” ; it should be: declare strategy skipTail: “ from * bypassing -> *,tail,* to * ” ;

15 Questions ….prj configuration, see project description document.


Download ppt "COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003."

Similar presentations


Ads by Google