An Aspect Refactoring Tool for the Observer Pattern

An Aspect Refactoring Tool for the Observer Pattern

An Aspect Refactoring Tool for The Observer Pattern A Thesis Submitted to the College of Graduate Studies and Research in Partial Fulfillment of the Requirements for the degree of MSc in the Department of Computer Science University of Saskatchewan Saskatoon By Fatima Alawami ©Fatima Alawami, May/2012. All rights reserved. Permission to Use In presenting this thesis in partial fulfilment of the requirements for a Postgraduate degree from the University of Saskatchewan, I agree that the Libraries of this University may make it freely available for inspection. I further agree that permission for copying of this thesis in any manner, in whole or in part, for scholarly purposes may be granted by the professor or professors who supervised my thesis work or, in their absence, by the Head of the Department or the Dean of the College in which my thesis work was done. It is understood that any copying or publication or use of this thesis or parts thereof for financial gain shall not be allowed without my written permission. It is also understood that due recognition shall be given to me and to the University of Saskatchewan in any scholarly use which may be made of any material in my thesis. Requests for permission to copy or to make other use of material in this thesis in whole or part should be addressed to: Head of the Department of Computer Science 176 Thorvaldson Building 110 Science Place University of Saskatchewan Saskatoon, Saskatchewan Canada S7N 5C9 i Abstract Current integrated development environments such as Eclipse provide strong support for object- oriented automatic refactorings; however, the same cannot be said about aspect-oriented refactor- ings. Refactoring of design patterns is one area where aspect refactoring automation remains to be explored in depth and few current tools are available to support it. To support aspect refactoring tools we present the AJRefactor plug-in, a semi-automatic refactoring tool for the observer pattern, a widely-used solution in the design of object-oriented programs. Aspect refactoring of the observer pattern allows aspects to capture pattern-specific code into a more modularized unit, and local- izes the code of participating classes. After applying AJRefactor on two Java projects JHotDraw and Prevayler, the results showed that AJRefactor was able to refactor 75% of the total observer instances found in both projects. Also, the refactoring enhanced the modularity and loosens the coupling of the pattern classes. Finally, the results showed a significant time savings and a small reduction in code size when refactoring with AJRefactor. ii Acknowledgements I would like to use this opportunity to give special thanks to several people who contributed to the completion of this work. • I am heartily thankful to my supervisor, Christopher Dutchyn , whose encouragement, guid- ance and support from the initial to the final level enabled me to develop a deep understanding of the subject of my thesis. I really appreciate your enlightening advice through the entire pe- riod of my master's studies. Working with my supervisor has improved my writing, thinking and learning skills. • I would like to sincerely thank the Ministry of High Education of Saudi Arabia for supporting this work financially. • I wish to avail myself of this opportunity, to express a sense of gratitude and love to my husband and my beloved parents for their continuous support. • Lastly, I offer my regards and blessings to all of those who supported me in any respect during the completion of my thesis. iii Contents Permission to Use i Abstract ii Acknowledgements iii Contents iv List of Tables vii List of Figures viii List of Abbreviations ix 1 Introduction 1 1.1 Thesis Statement . 2 1.2 Outline . 2 2 Background 3 2.1 AspectJ . 3 2.1.1 Pointcut and Join Points . 4 2.1.2 Advice . 8 2.1.3 Inter-type Declaration . 10 2.1.4 Aspect . 10 2.2 Observer Pattern . 10 2.3 Eclipse Platform . 11 2.3.1 Eclipse Plug-ins . 12 2.3.2 Java Refactoring Framework . 13 2.3.3 Java Source Manipulation . 14 2.4 Related Work . 18 2.4.1 Aspect Mining Tools . 20 2.4.2 Aspect Refactoring Tools . 23 2.5 Summary . 26 3 AJRefactor 28 3.1 AJRefactor Functionality . 28 3.1.1 Observer Pattern Following Pushing Technique . 28 3.2 AJRefactor GUI . 32 3.2.1 Observer Update . 34 3.3 AJRefactor Implementation . 35 3.3.1 Refactoring Action . 35 3.3.2 Refactoring Wizard . 35 3.3.3 Refactoring Class . 36 3.4 Refactoring Observer Pattern Starting with Subject . 38 3.4.1 Refactoring Action . 39 3.4.2 Refactoring Wizard . 40 3.4.3 Refactoring Class . 40 3.5 Refactoring Java API Observer Pattern Starting with Subject . 46 3.5.1 Refactoring Action . 46 3.5.2 Refactoring Wizard . 47 iv 3.5.3 Refactoring Class . 47 3.6 Refactoring Observer Pattern Starting with Observer . 49 3.6.1 Refactoring Action . 49 3.6.2 Refactoring Wizard . 49 3.6.3 Refactoring Class . 49 3.7 Refactoring Java API Observer Pattern Starting with Observer . 51 3.7.1 Refactoring Action . 51 3.7.2 Refactoring Wizard . 51 3.7.3 Refactoring Class . 52 3.8 Summary . 53 4 AJRefactor Design 54 4.1 Refactoring Observer Pattern Implemented with Pushing Technique . 54 4.1.1 Protocol Aspect . 58 4.1.2 Observer Update Instance Aspect . 59 4.1.3 Generating Pointcut and Advice . 61 4.1.4 Limitations . 65 4.2 Refactoring Update Calls . 66 4.2.1 MethodDecSubjectChange - multiInvocations . 68 4.2.2 IfExpSubjectChange - multiInvocations . 68 4.2.3 ThenStmntSubjectChange - multiInvocations . 68 4.2.4 Limitations . 69 4.3 Summary . 70 5 Results and Evaluation 72 5.1 Results by Instance Shape . 72 5.1.1 Observer Pattern Implemented with Pushing Technique . 73 5.1.2 Refactoring Update Calls . 73 5.2 LOC Assessment . 74 5.3 Modularity Assessment . 76 5.3.1 JHotDraw . 76 5.3.2 Prevayler . 78 5.4 Time Assessment . 79 5.4.1 Observer Pattern Implemented with Pushing Technique . 79 5.4.2 Refactoring Update Calls . 81 5.5 Reflection and Refactoring . 81 5.6 Refactoring and Program Correctness . 83 5.7 AspectJ Performance Overhead . 83 5.8 Multithreading and Refactoring . 84 5.9 Volatile Variables and Refactoring . 86 5.10 Java Annotations . 88 5.11 Summary . 90 6 Summary 91 6.1 Summary . 91 6.2 Contribution . 92 6.3 Future Work . 93 References 94 A Observer Pattern Instances 96 A.1 Observer Pattern Implemented with Pushing Technique . 96 A.2 Refactoring Update Calls . 96 B Dependency Structure Matrix 99 v B.1 DSM of Prevayler Before Refactoring . 99 B.2 DSM of Prevayler After Refactoring . 99 C AJRefactor Plugin Source Code 102 vi List of Tables 2.1 Mapping of exposed join points to pointcut construct . 6 2.2 Example pointcuts with Description . 9 2.3 Node Type of the Expression of Method Invocation . 18 4.1 Shape of the Method Changing Subject State by Observer Pattern . 71 5.1 Results of refactoring the observer pattern - The pushing technique . 74 5.2 Update Calls Refactoring Results . 74 5.3 JHotDraw and Prevayler Metrics . 76 vii List of Figures 2.1 Java Model Overview . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    112 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us