
ENHANCING A DESIGN BY CONTRACT TOOL USING INFERENCE RULES OF PROGRAMMING LOGIC A Project Presented to the faculty of the Department of Computer Science California State University, Sacramento Submitted in partial satisfaction of the requirements for the degree of MASTER OF SCIENCE in Computer Science by Nuha Aldausari FALL 2017 © 2017 Nuha Aldausari ALL RIGHTS RESERVED ii ENHANCING A DESIGN BY CONTRACT TOOL USING INFERENCE RULES OF PROGRAMMING LOGIC A Project by Nuha Aldausari Approved by: __________________________________, Committee Chair Dr. Cui Zhang __________________________________, Second Reader Dr. Jun Dai ____________________________ Date iii Student: Nuha Aldausari I certify that this student has met the requirements for format contained in the University format manual, and that this project is suitable for shelving in the Library and credit is to be awarded for the project. __________________________, Graduate Coordinator ___________________ Dr. Jinsong Ouyang Date Department of Computer Science iv Abstract of ENHANCING A DESIGN BY CONTACT TOOL USING INFERENCE RULES OF PROGRAMMING LOGIC by Nuha Aldausari Design by contract (DBC) is an effective methodology that dynamically checks whether a program meets its specifications which are also called design contracts. The contracts for object-oriented programs are defined in terms of preconditions and postconditions for methods as well as invariants for classes. However, if there is an error in a large piece of code that has a design contract, it is still tedious and difficult to spot the exact location of that error. To address this issue, a tool named Subcontractor has been developed. Subcontractor is implemented in Eclipse environment using libraries such as Java Development Tools (JDT), Plugin Development Environment (PDE), and JFace. The tool Subcontractor is built upon an open source DBC tool, OpenJML Runtime Assertion Checking (RAC), which is a tool that verifies specifications at runtime. Subcontractor enhances this DBC tool by automatically generating subcontracts for programs using inference rules of v program logic for if-statements and loop-statements. When the programs with the automatically generated and inserted subcontracts are verified using OpenJML Runtime Assertion Checking (RAC), identification of errors in the code can be facilitated. _______________________, Committee Chair Dr. Cui Zhang _______________________ Date vi Acknowledgements I cannot believe this moment, the moment of finishing my Master’s project, is finally here. It was a full year of learning experiences, struggles, and achievements. I would not have reached the finish line without the support I had from the great people who I was lucky to have around me. Fortunately, this support was always there when I needed it, and I am sincerely thankful for such motivation, supervision, and assistance. Foremost, I would like to thank my adviser, Dr. Cui Zhang, for her continuous care, patience, and enthusiasm. She provided me with valuable guidance during the journey of working in this project. She endeavored to keep me on the right path. To achieve the outcome of this Master’s project, her aspiring views and insightful comments were fundamental. I am very honored to work with her during this project. I would also like to acknowledge Dr. Jun Dai as the second reader of this Master’s project. His remarks were useful to abolish this project. I must express my gratitude to my amazing parents: Nasser Aldausari and Noura Alrobaqi for their continuous encouragements throughout not only this project, but also through my Master’s life. Even though they were far away, their supports and prayers were always with me when I needed them. Last but not the least, I must not to forget my beloved small family. My husband, Basel Qenam, was always the first support that I approach when I encounter a problem. This vii project would not have been possible to progress without him. I would like to thank my little one, Dana. She was born with the idea of this project. She was and is the source of happiness in this project and in my life. Her simile keeps me going to overcome my struggles. Thank you all. viii TABLE OF CONTENTS Page Acknowledgements ........................................................................................................... vii List of Tables ..................................................................................................................... xi List of Figures ................................................................................................................... xii Chapter 1. INTRODUCTION ...................................................................................................... 1 2. BACKGROUND AND RELATED WORK .............................................................. 4 2.1 Programming Logic ........................................................................................................ 4 2.2 DBC ................................................................................................................................ 5 2.3 DBC in Java .................................................................................................................... 8 2.3.1 COFOJA ......................................................................................................... 9 2.3.2 JML ............................................................................................................... 10 3. DESIGN AND IMPLEMENTATION ..................................................................... 13 3.1 External Components Related to the Tool Subcontractor ............................................ 13 3.1.1 Eclipse ........................................................................................................... 13 3.1.2 Plugin Development Environment (PDE) .................................................... 14 3.1.3 Java Development Tools (JDT) .................................................................... 15 3.1.4 JFace ............................................................................................................. 16 3.1.4.1 Viewers ................................................................................................. 16 3.1.4.2 Content Provider ................................................................................... 18 3.1.4.3 Label Provider ....................................................................................... 19 ix 3.1.4.4 ASTVisitor ............................................................................................ 20 3.1.4.5 ASTRewiter .......................................................................................... 23 3.1.4.6 Comment ............................................................................................... 23 3.2 Sequence Diagram for the Tool Subcontractor ............................................................ 24 3.3 Flow Chart for Contracts Unit in the Tool Subcontractor ............................................ 25 3.4 Class Diagram for the Tool Subcontractor ................................................................... 30 4. EXAMPLES USING THE TOOL SUBCONTRACTOR ........................................ 39 4.1 Loop-Statement Example and Valid Contracts ............................................................ 40 4.2 If-Statement Example and Invalid Contracts ............................................................... 43 5. CONCLUSION AND FUTURE ENHANCEMENTS ............................................. 49 Appendix A. Project Source Code .................................................................................... 52 References ......................................................................................................................... 85 x List of Tables Tables Page 1. Table 2.1 Client-supplier example of design by contract ............................................. 6 2. Table 3.1 List of the visitor classes in the tool Subcontractor .................................... 22 xi List of Figures Figures Page 3. Figure 1.1 State diagram of the programming code in the tool Subcontractor ............. 3 4. Figure 3.1 Subcontractor in Eclipse architecture ........................................................ 13 5. Figure 3.2 Converting from source code to TreeViewer in tab Generate (a) and tab Delete (b) in the tool Subcontractor .......................................................... 18 6. Figure 3.3 Sequence diagram of a JFace viewer in the tool Subcontractor ................ 19 7. Figure 3.4 Class diagram for the visitor pattern in the tool Subcontractor ................. 21 8. Figure 3.5 Sequence diagram of the tool Subcontractor ............................................. 25 9. Figure 3.6 Flow chart of the Contracts Unit in the tool Subcontracto ........................ 29 10. Figure 3.7 Class diagram for the package dialogbox in the tool Subcontractor ......... 33 11. Figure 3.8 Class diagram for package programminglogic in the tool Subcontractor . 37 12. Figure 4.1 Source code of the Factorial example with a precondition and a postcondition ........................................................................................... 41 13. Figure 4.2 Dialog box after writing the loop invariant and choosing loop statement 42 14. Figure 4.3 Source code after generating and inserting subcontracts .......................... 43 15. Figure 4.4 Source code of Account example with a precondition and postconditions 44 16. Figure 4.5 The output of OpenJML shows invalid postcondition
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages100 Page
-
File Size-