Eva van Emden, CWI Reverse Engineering Java Using ASF+SDF and Rigi A preliminary experience report.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Introduction to Rational Rose 2000 v6.5 Copyright © 1999 Rational Software, all rights reserved 1 Rational Rose 2000 Interaction Diagrams.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Copyright W. Howden1 Lecture 7: Functional and OO Design Descriptions.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Chapter 2 A Simple Compiler
Chapter 10 Classes Continued
CPSC Compiler Tutorial 3 Parser. Parsing The syntax of most programming languages can be specified by a Context-free Grammar (CGF) Parsing: Given.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
The Dr ü G Book: An Intro to Drupal The Dr ü G Book: An Intro to Drupal (Dr ü G: Drupal User ’ s Group - users, not developers) This is an introduction.
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 Architecture: Component and Deployment Diagrams Patrick Bailey Keith Vander Linden Calvin College.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Implementation Yaodong Bi. Introduction to Implementation Purposes of Implementation – Plan the system integrations required in each iteration – Distribute.
Implementation Considerations Yonglei Tao. Components of Coding Standards 2  File header  file location, version number, author, project, update history.
Files and Streams. Java I/O File I/O I/O streams provide data input/output solutions to the programs. A stream can represent many different kinds of sources.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Generation and Implementation. More on classes Types Implementation classes Interfaces Templates Associations –Dependencies –Compositions.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
LANGUAGE TRANSLATORS: WEEK 3 LECTURE: Grammar Theory Introduction to Parsing Parser - Generators TUTORIAL: Questions on grammar theory WEEKLY WORK: Read.
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Cross Language Clone Analysis Team 2 October 13, 2010.
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Advanced C# Types Tom Roeder CS fa. From last time out parameters difference is that the callee is required to assign it before returning not the.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Gordana Rakić, Zoran Budimac
Object-Oriented Programming Chapter Chapter
M1G Introduction to Programming 2 5. Completing the program.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
Concepts and Realization of a Diagram Editor Generator Based on Hypergraph Transformation Author: Mark Minas Presenter: Song Gu.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
310414IMPLEMENTATION1 IMPLEMENTATIONIMPLEMENTATION SOFTWARE ENGINEERING SOFTWARE ENGINEERING.
Java Classes Introduction. Contents Introduction Objects and Classes Using the Methods in a Java Class – References and Aliases Defining a Java Class.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
CSE 420 Lecture Program is lexically well-formed: ▫Identifiers have valid names. ▫Strings are properly terminated. ▫No stray characters. Program.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Software Testing.
Creating Your Own Classes
A Simple Syntax-Directed Translator
CS 3304 Comparative Languages
Programming Languages Translator
CS510 Compiler Lecture 4.
(Slides copied liberally from Ruth Anderson, Hal Perkins and others)
Hands-on Introduction to Visual Basic .NET
Packages and Interfaces
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Presentation transcript:

Eva van Emden, CWI Reverse Engineering Java Using ASF+SDF and Rigi A preliminary experience report

Eva van Emden, CWI Contents Introduction to Rigi and the Rsf format Java2RSF: Translating with an ASF+SDF specification Visualizing Java code smells in Rigi

Eva van Emden, CWI What is Rigi? Visual reverse engineering tool Rigi represents a program as a collection of nodes and arcs –Nodes represent features in the program, such as methods or classes –Arcs represent relationships between the nodes, such as “contain” or “call” Different views can be created by: –Filtering out certain node and arc types –Using the built-in layout algorithms –Writing scripts in the Rigi command language (RCL) Intro to Rigi and RSF

Eva van Emden, CWI Rigi Screenshot A subsystem hierarchy view for a C program Intro to Rigi and RSF

Eva van Emden, CWI Rigi standard format (RSF) Interchange format between parsing and processing Graph description language Simple text file Each line describes a node, arc, or attribute There are tools to translate between RSF and the GXL Graph Exchange Format Intro to Rigi and RSF

Eva van Emden, CWI RSF rsf-file: rsf-tuples: “/n” rsf-tuple: node-definition: “type” arc-definition: attribute-definition: node-spec: node-type: arc-type: attribute-type: attribute-value: Intro to Rigi and RSF

Eva van Emden, CWI Structured RSF Each node has a unique number The file must start with a root and there must be "level" arcs connecting the root node to every node in the top level of the graph Intro to Rigi and RSF

Eva van Emden, CWI Rigi Domains A collection of node, arc, and attribute types used to describe a particular language Specified by creating a new directory with the name of the domain in the Rigi domain directory and adding text files specifying valid node, arc, and attribute types Intro to Rigi and RSF

Eva van Emden, CWI The Rigi Java Domain Nodes: Package, Class, Interface, Method, Constructor, Variable etc. Arcs: contain, call, access, isSuper, implementedBy etc. Attributes: visibility, static, abstract etc. Intro to Rigi and RSF

Eva van Emden, CWI Java to RSF Translation SDF Java Specification RSF ASF Specification SDF Java2RSF ASF Compiler ParserJava2RSF Parse Table Java Sources SDF Parser Generator Java2RSF

Eva van Emden, CWI SDF Java Specification Java grammar taken from online grammar base Some modifications made before it parsed all input files successfully Java2RSF

Eva van Emden, CWI Java RSF Specification Describes RSF in the Java domain Makes use of standard ASF library components Refers to certain Java modules Java2RSF

Eva van Emden, CWI Specification of Full Translator Java2RSF

Eva van Emden, CWI Rewriting Recognize certain Java constructs and output corresponding RSF e.g. becomes public class Square { public Position xpos; } type Square Class type xpos Variable contain Square xpos Java2RSF

Eva van Emden, CWI Rewriting: Traversal Functions Function signature in SDF specification: methodinv(Block, RsfTuple*, Name, Name) -> RsfTuple* {traversal(accu, bottom-up)} methodinv(MethodInvocation, RsfTuple*, Name, Name) -> RsfTuple* {traversal(accu, bottom-up)} Java2RSF

Eva van Emden, CWI Rewriting: Traversal Functions (2) methodinv traversal function is called in ASF: [mb1] Methodbdy(_Block,_RsfTuple*,_MethodName,_ClassId) = _RsfTuple* methodinv(_Block,, _MethodName, _ClassId) Java2RSF

Eva van Emden, CWI Rewriting: Traversal Functions (3) [mi1] _Type=getType(_Identifier0), _MethodName2 = _Type._Identifier1 ====================================================== methodinv(_Identifier0._Identifier1(_ExpressionList*), _RsfTuple*,_MethodName1,_ClassId) = _RsfTuple* call _MethodName1 _MethodName2 Rewrite rule for a methodinv match: Java2RSF

Eva van Emden, CWI The Power of Traversal Functions Consider how many possibilities there are for a method invocation to appear in a statement: –s.draw(); –if (s.isBlue()){…}; –current = (Shape)list.getNext(); –java.lang.Math.max(s.getx(), s.gety()); Very tedious and error-prone to write rules to match all of these possibilities by hand Java2RSF

Eva van Emden, CWI Using Rigi to Provide Refactoring Support Test system of loc System is being refactored to improve maintainability Decided to display code smells to see if visualizing them could be useful What are code smells? –A code smell is a symptom that may indicate something wrong in the code (Beck and Fowler) –A clustering of a code smells visible in Rigi may indicate a class or package that needs to be refactored Visualizing Code Smells

Eva van Emden, CWI Visualization Options colour nodes according to degree of smell present (i.e. red smells, green does not), but this can’t be done in rigi Each instance of a smell appears as a node attached to the method or class Smells currently implemented: –Typecasts –Instanceof –Switch statements Visualizing Code Smells

Eva van Emden, CWI Smell Detection: ASF+SDF New smell detection module added to ASF+SDF specification SDF: smell(Block, RsfTuple*, Name, Name) -> RsfTuple* {traversal(accu,bottom-up)} smell(Expression, RsfTuple*, Name, Name) -> RsfTuple* {traversal(accu,bottom-up)} ASF: [s2] smell(_Expression instanceof _ReferenceType, _RsfTuple*,_MethodName, _ClassId) = _RsfTuple* type _NodeSpec Instanceof contain _MethodName _NodeSpec Visualizing Code Smells

Eva van Emden, CWI Smell Detection: RSF Now a problem shows up: if method “draw” in the Java code contains two instanceofs, we get the following RSF: type instanceof Instanceof contain draw instanceof Visualizing Code Smells

Eva van Emden, CWI Solution: Adding Structure to the RSF Standard RSF deletes all duplicate lines and therefore cannot have two nodes with the same name To allow multiple smell nodes to show I had to switch to producing partially structured RSF type instanceof Instanceof contain draw instanceof type 1!Root Unknown type 2!draw Method level 1!Root 2!draw type 3!instanceof Instanceof level 1!Root 3!instanceof type 4!instanceof Instanceof level 1!Root 4!instanceof contain 2!draw 3!instanceof contain 2!draw 4!instanceof Becomes Visualizing Code Smells

Eva van Emden, CWI Smell Detection: Adding Structure to the RSF Add a structuring module to the existing specification unstructured rsf structuring module structured rsf Structuring process: –Unique all the rsf tuples –Take all the node names and assign them unique node numbers –Replace all node names with the numbered version –Place a level tuple after each node definition Visualizing Code Smells

Eva van Emden, CWI Smell Detection: Rigi Display Add smell node types to the Java domain in Rigi Write a script in the Rigi command language to produce a meaningful view in Rigi Visualizing Code Smells

Eva van Emden, CWI Rigi View 1 All nodes except classes, methods, constructors and typecasts have been filtered out and a layout algorithm applied. Visualizing Code Smells

Eva van Emden, CWI Rigi View 2: Show Smell By Class methods collapsed into their classes All the casts inside a class are attached to that class… Visualizing Code Smells

Eva van Emden, CWI Rigi View 2: Show Smell By Class (2) …but a class node can be opened to show the members inside with their cast nodes attached Visualizing Code Smells

Eva van Emden, CWI Where to Go From Here? Continue to experiment with views Expand to displaying further code smells Find a way to make the specification more efficient –Small programs (several kloc) ok –Does not finish in reasonable time (at all) on our 60 kloc test system Finish making the specification correct and complete –Still some problems with getting types to show method calls properly Visualizing Code Smells

Eva van Emden, CWI