code parser for object oriented software modularization

3 downloads 2626 Views 304KB Size Report
Keywords: code parser; metadata; modularization, token, regular expression. 1. ... frequently require text processing for features like word searches, email ...
Mr. Sunil L. Bangare et. al. / International Journal of Engineering Science and Technology Vol. 2 (12), 2010, 7262-7265

CODE PARSER FOR OBJECT ORIENTED SOFTWARE MODULARIZATION SUNIL L. BANGARE Department of Information Technology, Bharati Vidyapeeth University College of Engineering, Pune-43, Maharashtra, India

PROF. AKHIL R. KHARE Department of Information Technology, Bharati Vidyapeeth University College of Engineering, Pune-43, Maharashtra, India

PALLAVI S. BANGARE Department of Information Technology, STES’s Sinhgad Academy of Engineering, Pune-48, Maharashtra, India

Abstract: We proposed a System to measure the quality of modularization of object-oriented software system. Our work is proposed in three Parts as follows: MODULE 1: DEFINING METRICS FOR OBJECT ORIENTED SOFTWARE AND ALGORITHM MODULE 2: CODE PARSER MODULE 3: CODE ANALYZER In this paper we are concentrating on Module 2 of our work that is Code Parser for object oriented software modularization. Keywords: code parser; metadata; modularization, token, regular expression 1. Introduction Software development process is based on the modularized versions of the code. As we know in the object oriented code the modules are kept separate from each other especially when the original size of the software is large. It is useful for the manager and the team of developers to work on the separate modules. But at the same time the quality of code modularization is also need to be checked. In modular technique there are lots of concepts involved in object oriented coding. The main problem is of communication between the modules. Generally this should be done through some application programming interface (API). More properly modularized software is also easy for maintenance work and it can help the developer. In our work we are considering the object oriented java language code for checking modularization quality by applying metrics. Java is open source language. In java the code is residing in directories of some modules and java files are considered as modules. One java file may consist of number of classes but one public class [3]. Classes contain the elements such as methods, interfaces, variables and so on. This code may contain many files with thousands of line of code so we are using code parser to generate the metadata of the code. In this paper we have introduced the code parser for our system. 2. Need of the Code Parser In our work we have used the object oriented java code as a source input to the proposed system. This input code is needed to be broken down in to elements which may contains like the classes, variables, interfaces and so on. This code is divided in to small tokens which will be useful for the further implementation of our project.

ISSN: 0975-5462

7262

Mr. Sunil L. Bangare et. al. / International Journal of Engineering Science and Technology Vol. 2 (12), 2010, 7262-7265 The output generated by this code parser can be called as metadata. This metadata is saved in to the database for the further use. Thus here the code parser is needed. 3. Code Parser Code parsing is the process of where elements of a text are analyzed as tokens to find out the structure text under some constraints. This parses the source code to create some form of internal representation. Here the java source code file is given as input. Code parser breaks the input code in to the small elements which are residing in the software. The output of the source code is in some predetermined format as we have to save this in to database in our system. The Algorithm for the Code Parser can be given as follows: Step 1: To get a source code input file (like java file) Step 2: Perform bit level analysis Step 3: Use Regular expression Step 4: Separate the tokens Step 4: Output is the metadata Step 5: Send and save output in database 3.1 Regular Expression Regular expressions, also known as regex or regexp, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification [1].Software Applications frequently require text processing for features like word searches, email validation and so on. This often involves pattern matching. To pattern match using the Java programming language we required the use of the StringTokenizer class with many charAt substring methods to read through the characters or tokens to process the text [3]. In Java regular expressions can use with the java.util.regex package, for the following common scenarios as examples: 

Simple word replacement



Email validation



Removal of control characters from a file



File Searching

3.2 Basic constructs of Regular Expressions A regular expression is a pattern of characters that describes a set of strings. We have used the java.util.regex package to find, display, or modify some or all of the occurrences of a pattern in an input sequence. The simplest form of a regular expression is a literal string, such as "Java" or "programming." Regular expression matching also allows you to test whether a string fits into a specific syntactic form, such as an email address [2]. To develop regular expressions, ordinary and special characters are used: Table 1. Special Characters

\$

^

.

*

+

?

['

']

\.

ISSN: 0975-5462

7263

Mr. Sunil L. Bangare et. al. / International Journal of Engineering Science and Technology Vol. 2 (12), 2010, 7262-7265 Any other character appearing in a regular expression is ordinary, unless a \ precedes it. We have used Pattern class and Matcher class of java for implementation. 4. Use of Code Parser in this work

Source code Input

Code Parser

Parsed output (Metadata)

Database

Fig. 1. Use of Code Parser in this work

Here for the implementation in our work we have considered the java file as input which may be get separated in to the elements such as class name, methods in the class, argument, external count, internal count, called class and the return type and so on. These all values will be getting saved in database when we execute the code. We can implement our logic to distinguish the elements. External and internal call to and from the system are calculated and used in the metrics calculation. 5. Algorithm for Basic Functions used for Code Parser Here we have provided some basic functions used for the implementation. 5.1 Function: open File Step 1:

Opens a file dialog to select the input file

Step 2:

Reads the selected file using the FileInputStream

Step 3:

Get the directory of the selected file

Step 4:

Finds all the classes in the selected file’s directory, including those of the interfaces, and stores them in a vector

Step 5:

Finds the methods defined in each of those classes (of the .java file) and stores them in a vector mv

Step 6:

These methods are stored in the api table (of the database), under function attribute as per their respective class.

5.2 Function: find Classes - The entire file path is stored in the string file, from which:

Step 1:

DirPath is separated

Step 2:

Filename is extracted

Step 3:

Module number for the respective file is calculated

ISSN: 0975-5462

7264

Mr. Sunil L. Bangare et. al. / International Journal of Engineering Science and Technology Vol. 2 (12), 2010, 7262-7265 Step 4:

Type attribute is sent as “class”

Step 5:

Class name for the file is extracted using Pattern & Matcher classes

5.3 Function: find interface - The entire file path is stored in the string file, from which:

Step 1:

DirPath is separated

Step 2:

Filename is extracted

Step 3:

Module number for the respective file is calculated

Step 4:

Type attribute is sent as “interface”

Step 5:

Interface name for the file is extracted using Pattern & Matcher classes

6. Sample Output of Code Parser CN ValueD:\apimodified-1\project-Input-1\ Data1 :13 After return value $class sampleclass sample VCsize 1 vc... [class sample] VIsize.....0 vi...[] Final Output: [[class barchart], [class catchreturn], [class functionarg], [class outer, class functionparam], [class functionreturn], [class myimpl1], [interface myinf1], [class myser1], [class Palin_impl], [interface Palin_inter], [class Palin_ser], [class base, class derived, class samp], [class sample]] Fig. 2. Sample Output of Code Parser

7. Work done based on this In our previous work we have proposed the metrics for object oriented code modularization for which we referred Sarkar et al. work as guideline [4]. Now we have implemented the code parser using java language as a part of work for measuring the quality of object oriented software modularization. In code parser we have implemented following features: (1) (2) (3) (4) (5)

How to find out the API functions and total number of arguments, return type, access modifier How to find out the non API functions and total number of arguments, return type, access modifier How to find out the functional dependency in between modules How to find out the Name and number of classes, interfaces, methods How to find out the internal and external function calls and their interdependency

8. Conclusion Here more emphasis is given to MODULE 2 that is CODE PARSER of the work. In this module we have given the role and implementation of code parser where it separates the elements in to tokens as metadata, which is needed to be kept in database. This would be used for next module that is code analyzer. References [1] [2] [3] [4]

http://en.wikipedia.org/wiki/Regular_expression http://java.sun.com/developer/technicalArticles/releases/1.4regex/ Schildt Herbert, The Complete Reference Java 2, Fifth Edition, TATA McGRAW HILL, 2002, pp 13-54. Sarkar S., Kak A. C. and Rama G. M, “API-Based and Information-Theoretic Metrics for measuring the Quality of Software Modularization” IEEE Trans. Software Eng., vol. 33, no. 1, pp.14-30.

ISSN: 0975-5462

7265

Suggest Documents