Home
as a PDF
Contents
1. handle that without changing the parser but it is left for the next release 4 2 Exceptions and coupling When we consider coupling between a class and a method we consider method return and parameter types However in Java exception handling can be done by adding a throws clause after a method signature This means that by parsing a method signature we can find which exception the class throws If this exception is our project s class we could consider coupling between the class that contains that method and the exception class It would be a special kind of coupling between classes and exception classes Of course all exception handling would not be covered by parsing only the method signature try catch clause is in a method s body so if we would like to cover it all there should be a major 30 change in the Java parser This type of coupling could possibly be measured for C code too as C also has a try catch clause 4 2 8 File extensions Source Navigator will automatically recognize only java file extensions and not Java jav or similar but this can be easily configured in File Project Preferences window of Source Navigator 5 Software License This software is copyright 2000 2001 by the National Research Council of Canada It is published under the GNU General Public License which is reproduced in the distribution in a file called GNUGPL txt for the benefit of the software engineering community
2. 2 4 7 The metrics that are collected by the tool are summarized in Table 1 Before proceeding further it is important to realize that we are focusing only on metrics that were properly validated That is why the tool does not collect all or many metrics that have been defined in the literature As evidence accumulates demonstrating the efficacy of other metrics they will certainly be included within our tool Coupling Metrics OCAIC instances Class attribute import coupling number of coupled attributes OCAIC classes Class attribute import coupling number of coupled classes OCAEC instances Class attribute export coupling number of coupled attributes OCAEC classes Class attribute export coupling number of coupled classes OCMIC instances Class method import coupling number of coupled method parameters and return types OCMIC classes Class method import coupling number of coupled classes OCMEC instances Class method export coupling number of coupled method oarameters and return types OCMEC classes Class method export coupling number of coupled classes CAIC i Ancestor class attribute import coupling number of coupled attributes ACAIC classes Ancestor class attribute import coupling number of coupled classes DCAEC instances Descendant class attribute export coupling number of coupled attributes DCAEC classes Descendant class attribute export coupling number of coupled classes
3. 4 1 1 Method pointers Method pointers are not parsed well by Source Navigator In the case showed in Figure 19 method typedef int ACE QOS CONDITION FUNC iovec caller ig iovec caller data ACE QoS socket qos ACE QoS group socket gos iovec callee ig iovec callee data ACE SOCR GROUP g u_long callbackdata CM coupling class ACE_Export ACE_Accept_QoS_Params ACE Accept QoS Params ACE QOS CONDITION FUNC qos condition callback u long callback data 0 ACE QOS CONDITION FUNC qos condrtrionucaliback s Figure 19 Example of a method pointer to illustrate its impact on computed metrics 20 CA coupling pointer ACE QOS CONDITION FUNC would be presented in the database as int i e only the return type int will be present in the database whereas method argument types will be omitted iovec AC QoS ACE SOCK GROUP u long So we had no choice without changing the parser than to limit coupling measurements involving method pointers to their return types The question is how to consider coupling with method pointers as class attribute or class method coupling We decided to treat it as class attribute coupling if a method pointer is used as an attribute and as class method coupling if it is used as a method s return type or as a method s argument In fact in the above case there will be no coupling because the method pointer s return type is int If the method pointers argume
4. List of SN database files used as inputs to ES2 16 3 3 Using ES2 Now that a Source Navigator project is created along with the database files we can invoke ES2 Currently ES2 works only from the command line 1 ES2 is invoked in a similar way as Source Navigator but with arguments Type Shome directory SN452 ES2 bin ES2 projdir projname access option where nome directory Should be replaced with the real home directory of SN452 ES2 The command line arguments are projdir the directory of the proj file projname project name without proj acces option Can be priv prot pub Or a11 depending on whether we want to analyze private protected public or all variables and methods myhelp prints help message Figure 15 Edit Settings Help nartaz ES Usage home marta Sh452_E52 binzES2 prajectdir project name access option pub prot priv or all For help homezmartaz 5M452 ES2 binzES52 muhelp martaz ES muhelp Usage hame marta 5M4b2 ES2 bin ES2 projectdir project name acces opti on pub prot priv or all For help home martaz5M452 ES2 bin ES2 muhelp projectdir home directory of the Source Navigator project director y L snpr i project name name of the SN project without proj pub treat only public attributes or methods priv treat only private attributes or methods prot treat only protected attributes or methods all treat all attributes or methods muhelp this help mes
5. command line by typing Shome directory SN452 ES2 bin snavigator where nome directory should be replaced with the real home directory of SN452 ES2 If the environment variable PATH is set it can be invoked just by typing snavigator at the prompt Here we will explain how to make a Source Navigator project from the sample code included with the ES2 tool We start with a number of n files from the application called v 1 Upon invoking Source Navigator for the first time it offers the user to create a new project or to find existing ones Figure 10 Mew Project Browse Gren som Cancel Figure 10 The SN startup screen when there are no projects defined 2 When the user clicks on the New Project button a window pops up asking for a project name and source files destination It offers a default project name and directory Figure 11 but we will change it We will call this project v proj put it in the home marta directory and use an example from SN452_ES2 share ES2 examples CPP BigExample v directory Figure 12 13 n Do vou want to automatically create a Source Navigator Project based on Project File home marta SN452 ES2 bin bin proj S Add Directory hone marta SN452 ES2 bin Ey mare W Include Subdirectories ES Build Cross Reference database Project Editor Cancel 2 Do you want to automatically create a source Navigator Project based on Project File home marta v
6. cost metrics analyzers Commercial tools tend to collect basic size metrics and many variants of these size metrics Other potentially powerful coupling metrics are typically not collected This report is the user manual for a publicly available open source metrics analyzer for the C and Java languages This analyzer collects a set of design metrics that have been empirically demonstrated to be beneficial for making quality management decisions in practice 1 Introduction Recent evidence indicates that most faults in software applications are found in only a few of a system s components 6 9 11 The early identification of these components allows an organization to take mitigating actions such as focus defect detection activities on high risk components for example by optimally allocating testing resources 8 or redesigning components that are likely to cause field failures In the realm of object oriented systems one approach to identify faulty classes early in development is to construct prediction models using object oriented design metrics Such models are developed using historical data and can then be applied for identifying potentially faulty classes in future applications or future releases The usage of design metrics allows the organization to take mitigating actions early and consequently avoid costly rework Recent evidence suggests that taking such actions in this case design inspections can result in an estimated 42 savin
7. effect in every newly created terminal you should create or modify the startup file of your shell to add ES2 to your PATH In order to do this you should edit the basnrc file found in your home directory using the Emacs as editor for instance by adding the line which sets PATH see Figure 9 complete Please include home marta 3H452 ES27hin in your PATH environment variable To start Source Havigator type momemartarsSH452 ES2hin snavigatar To use E52 C and Java design metrics analyzer please refer to the documentation in momemartarsH452 ES2 share ES2 Figure 7 The screen informing the user to modify the PATH environment variable The startup file maybe different if you are not using the bash shell 10 Edit Help martaz 5M452 ES2 linux unpacked cd martaz cd SN452 ES2 marta 5M452 ES2 cd bin marta 5M452 ESZ bin ls marta 5M452 ESZ bin f export PATH martat 5M452 ES2 bin snavigator amp 1 30754 marta SM452 ES2 bin B Setting PATH i marta SN452 ES2 bin PRTH Z PRTH home marta SN452 ES2 bin Launching SN Figure 8 Setting the PATH environment variable on the command line OL Buffers Files Tools Edit bashrc User specific aliases and functions Source global definitions if f fetc bashre J then fetc bashre fi PATH PATH home marta son4a2 ESZ bin Shell scriptij Lii Taonp Figure 9 Setting PATH in bashrc file 10 Now both Source
8. or method argument or return type whose type is of the template argument s type If that template argument is of class type there should be coupling between these two classes The problem is that we cannot know the exact type of the template argument until that template class is used and template arguments are set with real types So in order to measure this kind of coupling we have to find every single usage 22 of that particular class in attributes or in methods and to associate template arguments with all the types they can possibly have Figure 22 illustrates this case template ACE MEM POOL 1 class ACE_LOCK gt class ACE Local Name Space public ACE Name Space typedef ACE Allocator Adapter ACE Malloc ACE MEM POOL 2 ACE_LOCK gt gt ALLOCATOR ACE Name Space Map lt ALLOCATOR gt name space map template class ALLOCATOR gt class ACE Name Space Map public MAP MANAGER pubes ACE Name Space Map ALLOCATOR alloc Figure 22 Example of template class usage As we can see in Figure 22 class ACE Name Space Map has a method argument of type ALLOCATOR which is its template argument type To calculate coupling we have to know the exact type of ALLOCATOR Therefore we have to look for uses of that class One of them is in the class ACE Local Name Space that has an attribute of the type ACE Name Space Map lt ALLOCATOR gt Where ALLOCATOR is in fact ACE Allocator Adapter ACE Malloc ACE MEM POOL 2 A
9. the already mentioned interface java util List anda class java awt List As the package java awt is not imported by this file there is no ambiguity for the compiler here List is in fact java util List But as SN does not distinguish between packages we do not have enough information to know the exact type of List Therefore we have no choice but to take into account both of them In this case class AbstractList Will have OCMIC 1 larger than expected and java awt List wil have OCMEC 1 larger than expected 29 package java util public abstract class AbstractList extends AbstractCollection implements List public List subList int fromIndex int toIndex return new SubList this fromIndex toIndex class SubList extends AbstractList package java util public interface List extends Collection package java awt public class List extends Component implements ItemSelectable Serializable Figure 24 Example of a class and an interface with the same name 4 2 6 2 Fully qualified class names As we mentioned Java uses fully qualified names for classes even if programmers usually use short names for convenience Unfortunately Source Navigator puts only short names in the database files which means that long names are not recognized as class types So if there is a return parameter or parent type written as a fully qualified name the coupling will not be seen There is probably a way to
10. ACMIC instances Ancestor class method import coupling number of coupled method parameters and return types ACMIC classes Ancestor class method import coupling number of coupled classes DCMEC instances Descendant class method export coupling number of coupled method parameters and return types DCMEC classes Descendant class method export coupling number of coupled classes Inheritance Metrics DIT Depth of inheritance tree Number of pub priv prot all Number of attributes depending on the access option public attributes orivate protected all Number of pub priv prot all Number of methods depending on the access option public methods orivate protected all Lines of code physical Table 1 Metrics collected by the ES2 tool 1 1 Examples of Calculating the Metrics Just to illustrate what the metrics mean in this subsection we describe using an example a simple calculation of all of these metrics for C soource code From Table 1 we can see that there are three types of interactions between 2 classes their relationship whether it is a parent child relationship or other type of interaction whether a class has an attribute method parameter or return type of another class and locus of impact whether a class is using another class through its attributes or method types Only defined for the C code see section 4 2 2 import or it is used by another class export Letters in the acronyms s
11. CE LOCK Now we can say that the class ACE Name Space Map IS coupled to ACE Allocator Adapter and ACE Malloc as well as with types of ACE MEM POOL 2 macro not treated and ACE Lock template argument whose type will be found in a similar way It is obvious that we can only consider coupling between template classes and template arguments after the whole code is processed and every single usage of each template class is found Template arguments can be of template class parent type we check for it when we find that there is coupling in order to treat it as ancestor descendant coupling 23 Template structures are not parsed in Source Navigator and therefore are not considered by our tool In the following case template lt class T gt Struct pong rung The ES2 tool will not see coupling between conj_func and template argument T but the struct itself will be considered for coupling i e only the template arguments will not be 4 1 4 Forward declarations If a class is not in the scope of our class it can still be used for attribute and method types using forward declaration class A class B B b We will consider class attribute coupling between class A and class B if class B is defined somewhere in the code i e if it can be found in the class database If not which can be the case if B is supposed to be defined in some cpp file we do not consider this as a coupling The reason is simple we do not ha
12. MetaKit for more information visit http equi4 com metakit It can be found in the subdirectory SmallExample The other one is a more substantial system a GUI framework called V lt http objectcentral com vgui vrefman install htm gt It can be found in the subdirectory BigExample For both examples we extracted only n files from the source code since header files are sufficient for our tool although it also works well with cpp files Java examples The subdirectory SN452_ES2 share ES2 examples Java contains three Java examples graph JPublish and J Top The Graph class library is a package of Java classes designed to facilitate plotting data using Java applets It can be downloaded from http www sci usq edu au staff leighb graph Both JPublish and J Top are created by Anthony Eden and can be downloaded from his Web site http www anthonyeden com JPublish is a web application framework which combines the Velocity template engine from the Apache Group with a 12 content repository and application control framework J Top is a Java application that presents data output from top applications on Linux UNIX machines In the next section we show how to use ES2 on the V C example Note that the usage is the same for Java source code 3 2 Using Source Navigator As noted earlier SN is an open source code navigation tool in which we incorporated our C and Java design metrics analyzer It is invoked from the
13. Navigator 4 52 and ES2 are installed and ready to use Directory SN452 ES2 bin contains among others snavigator the script for running Source Navigator and zs2 the script for running the design metrics analyzer Figure 8 illustrates how SN is started using the snavigator script 11 N B You can remove the directory SN452 ES2 linux unpacked by typing rm rf SN452 ES2 linux unpacked 11 in its parent directory It is advised to keep the downloaded file 6N452 ES2 linux tar gz for eventual future installations 3 Example of Using ES2 ES2 is a Tcl script see 12 15 that extracts information from database files produced by Source Navigator calculates design metrics and outputs them in a file easily imported by MS Excel or Sun s StarCalc It is therefore necessary to first create a Source Navigator project from the source C or Java files to be analyzed and then to run ES2 Note that for C only the n files are required so it does not matter if the cpp files are not available Here we explain in details how to use both tools Metrics file can be imported SN database into MS Excel Source code 3 1 Example Systems The ES2 distribution comes with example systems that can be used to get used to how ES2 works They can be found in the SN452_ES2 share ES2 examples directory C examples The subdirectory sN452 ES2 share ES2 examples CPP contains two C example systems One is a smaller database library called
14. This software comes with absolutely no warranty but we would appreciate bug reports and we will endeavor to fix them 6 1 2 3 4 5 6 7 8 References S Chidamber and C Kemerer A Metrics Suite for Object Oriented Design In EEE Transactions on Software Engineering vol 20 no 6 pp 476 493 1994 K El Emam Object Oriented Metrics A Review of Theory and Practice in Advances in Software Engineering Topics in Comprehension Evolution and Evaluation to appear O Tanir and H Erdogmus eds Spinger Verlag 2000 K El Emam S Benlarbi N Goel and S Rai A Validation of Object Oriented Metrics Technical Report National Research Council of Canada NRC ERB 1063 1999 K El Emam and W Melo The Prediction of Faulty Classes Using Object Oriented Design Metrics Technical Report National Research Council of Canada NRC ERB 1064 1999 K El Emam S Benlarbi N Goel and S Rai The Confounding Effect of Class Size on the Validity of Object Oriented Metrics In EEE Transactions on Software Engineering to appear 2001 N Fenton and N Ohlsson Quantitative Analysis of Faults and Failures in a Complex Software System In EEE Transactions on Software Engineering vol 26 no 8 pp 797 814 2000 D Glasberg K El Emam W Melo and N Madhavji Validating Object oriented Design Metrics on a Commercial Java Application Technical Report National Research Council of Can
15. ackages Java core classes are organized in packages User defined classes can be organized in user defined packages or if not they are put in a default package Classes are distinguished by their package which is included in their fully qualified name For instance class String s fully qualified name is in fact java lang String java lang package is imported by default We can use its short name String if there is no other class with the same short name in other imported packages But if there is such a case fully qualified names should be used to distinguish between them Source Navigator unfortunately does not recognize packages Therefore it does not recognize fully qualified names nor does it recognize which class of two classes with the same short name is part of our package or if its in an imported package This leads to some limitations of our tool which are presented below 4 2 6 1 Classes with the same short name Due to the above mentioned limitations of Source Navigators Java parser if a project contains more classes or interfaces with the same short name it is not possible to distinguish which one of them is coupled to a class that contains such a type For example in Figure 24 we see that the class AbstractList which implements interface List found in the same package java util has a method subList whose return type is of type List The project contains two classes with the name List but in different packages
16. acked and all the subdirectories Figure 2 File Edit Settings Help marta tar xvFz SN452_ES2_linux tar gz S452 ES2 linux_unpacked SN4b2 ES2 linux unpacked share SM4B ES2 linux unpacked share sdkz SM4b ES2 linux unpacked share sdk lib SM4b ES2 linux unpacked share sdkzlib libutilz a SM4b E52 linux unpacked share sdk lib libdbutilz a SN4b2 ES2 linux unpacked zshare sdk lib libpafdb a SH4b2 E52 linux unpacked share sdk lib libtcl8 1 a SN4b2 E52 linux unpacked share sdk libz libsnptaolz a SN4b2 E52 linux unpacked share sdk api SN4b2 ES2 linux unpacked share zdk api c SN4b2 ES2 linux unpacked share zdk api c database SM4b ES2 linux unpacked share sdk api c database examplez SM4b ES2 linux unpacked share sdk api c database examplezs Makefile SM4B ES2 linux unpacked share zdk api c database examplez dbqru c SH4b2 ES2 linux unpacked share sdk apiz tcl SN4b2 ES2 linux unpacked share sdk apiz tcl database SN4b2 F52 linux unpacked zhare zdk apiz tclz database examplez SM4B 2 E52 linux unpacked share sdk api tcl database examples call freq tk SM4B 2 E52 linux unpacked share sdk api tclzdatabase examplez clobber tcl SN4b2 ES2 linux unpacked share sdk apiz tcl database examplez constants tcl SM4B ES2 linux unpacked share sdk api tclz database examples diamonds tcl SM4b E52 linux unpacked share sdk api tcl database examplezs multicludez tcl Figure 2 The tar command to show the directories that are c
17. ada to appear in the Journal of Systems and Software NRC ERB 1080 2000 W Harrison Using Software Metrics to Allocate Testing Resources In Journal of Management Information Systems vol 4 no 4 pp 93 105 1988 3l 9 10 11 12 13 14 15 M Kaaniche and K Kanoun Reliability of a Commercial Telecommunications System In Proceedings of the International Symposium on Software Reliability Engineering pp 207 212 1996 K H Moller and D Paulish An Empirical Investigation of Software Fault Distribution In Proceedings of the First International Software Metrics Symposium pp 82 90 1993 N Ohlsson and H Alberg Predicting Fault Prone Software Modules in Telephone Switches In IEEE Transactions on Software Engineering vol 22 no 12 pp 886 894 1996 J Ousterhout Tcl and the Tk Toolkit Addison Wesley 1994 D Schmidt A System of Reusable Design Patterns for Communication Software in The Theory and Practice of Object Systems S Berzuk ed Wiley 1995 D Schmidt and P Stephenson Experiences Using Design Patterns to Evolve System Software Across Diverse OS Platforms In Proceedings of the 9th European Conference on Object Oriented Programming 1995 B Welch Practical Programming with Tcl and Tk Prentice Hall 1997 32
18. and3dPari 92 016 136154452 EE eal CommandCtyact 253 43 7237 28453 EE 14 l jDIg mL ist 23 019 m7 Sab EE JawaP rajariLiialag 19 006 3B 1 hM5 EE LabaGdC laser ort 3 16 B3 H LEE LabaGdP art 016 121 1 hM8523 Es MARK RANGE 104 013 T AA ES i MenuButtan 44 019 5B T 5h53 EE Hanli 31 013 Ab MS EE PhenuButtan 4 13 5 TBI EE PIManulmf 24 013 45 7 A EE Panelit 26 013 OT Stab EE Picture ajii ES T SHG EE ScralbaradClarzP ard 114 i5 114 aT Sha EE amp cnilibarsefP art 74 016 106 1 ERMG2 EE Shape 13 01 26 7 Stab EE 22 SimpkeSdClassPon 64 018 TD inh Es A SImpledP art 81 016 JD Stud EE 3X SlidesrSdassP ari 114 016 11427 5452 EE 23 ule 74 5 IDs Tio EE 26 Ststusl irl 21 019 26 7 Shab EE TaakLsl 41 013 JET SHS EE Three 0ClsssF ar bd Dib 70 3 Shab EE ThraaLiPart 45 016 260 3 Shoo EE Toggle3dPar B 016 SUO 1 SAn EE ey imala T 4 lg Lo m Lo ooo Ooo oe ooo eo eo ooh oe a Lie ho oo ea sooo ow ooo SH eo eo oo bh Oo op rr mcmnaoruuumumruucoOmiumuUmmnmnmuuuulmcom mc comnr ti oOo oon oe ee oan oe oe ee ean eat ee oes ooo ed ee ee a G e a A a Aa G a Ga G a a a G a Giaa Gi a 31 VeindList 23 013 BT SAHI EE Be Dame 52 D17 G7 5 dB EE 43 CummandddClzsPuc 106 015 111 1 5h53 Es U CommandadE gc 143 013 43 SnAg ES X LahbeDdClassP ec f 015 Sr i ShA ES Hale Ue v all comuptiong e m PRENMEEHEMENENEN i kaak IF t HHI Sahat Figure 18 Example of what you should see when o
19. ce can be in a file not included by our class file and still be visible by our class If we decide not to define the scope as we did and to consider all project files we can have an error in scope when namespace is not used So for now until the C parser is changed it is not advised to use this tool for C code that makes extensive use of namespaces Even when namespaces are in the same file classes are not seen by SN if they are declared out of the namespace in the example below class A is declared as N A because it is part of namespace N In this case SN will find only class B and not class A which again can lead to erroneous metrics namespace N class A class N A 1 namespace M class B 4 1 11 Other keywords Keyword typename is not supported by Source Navigator and our tool simply ignores it like it ignores keywords virtual and inline and primitive types It treats everything as possible types so this should not be an issue 27 4 2 Java The Java parser in Source Navigator is considerably younger than the C parser Therefore it tends to have more limitations 4 2 4 Java version Source Navigator parses Java 1 0 For changes in the Java grammar from Java 1 0 to Java 1 1 and 1 2 see Java grammars from the following site lt http www cs princeton edu appel modern java CUP gt 4 2 2 Types of local and instance variables Source Navigator s Java parser is not ful
20. d ACE PI Control Block but not with ACE MMAP Memory Pool and ACE MMAP Memory Pool Option macro ACE MMAP MEMORY POOL is not treated 4 1 2 2 Macro if else statements Macro if else statements pose a different problem If definitions are protected by macro statements there can be more than one typedef or class with the same name in the same file Preprocessing would certainly remove this ambiguity but when trying to use unprocessed code one would have to check both definitions For this reason we treat them as distinct couplings Figure 21 shows such a case Here our tool would find class attribute coupling between ACE ATM Acceptor and both ACE SOCK Acceptor and ACE TLI Acceptor Furthermore from a cognitive perspective see 7 for a detailed cognitive model justifying the object oriented computed by ES2 someone comprehending the code will likely trace through the links to other classes for all parts of a guarded ifdef fif defined ACE HAS FORE ATM WS2 include SOCK Acceptor h typedef ACE SOCK Acceptor ATM Acceptor elif defined ACE HAS FORE ATM XTI include TLI_Acceptor h typedef ACE TLI Acceptor ATM Acceptor endif class ACE_Export ACE_ATM Acceptor Figure 21 Example of macro if else statements 4 1 3 Templates Template classes are treated as any other class for import and export coupling between themselves and other classes But template arguments pose a problem a template class can have an attribute
21. g in post release costs for a Java application 7 One of the difficulties in implementing quality management using object oriented design metrics is that there have not been too many good tools available A number of commercial tools collect the CK metrics Suite 1 for the tools see 2 and also visit www object oriented org However doubt has been raised about the validity of some of these metrics and about the methodology used in previous studies that validated these metrics 5 Therefore there is a need for tools that implement other metrics that have been empirically validated in a methodologically sound manner This document describes a tool that can be used for collecting interface object oriented metrics This means that the metrics can be calculated from interface specifications which are usually available at the design stage of a project The current version of the tool works with the C and Java language For C it can compute the metrics from the h files which are in fact the interface specifications For Java the java files are used but they can contain only method signatures and not their actual implementation in order to calculate the metrics which enables us again to calculate metrics in the design phase The metrics that are actually collected capture size coupling and inheritance We only collect these metrics because previous research has indicated that they are good predictors of class fault proneness
22. ga it By contrast ihe GNU General Public Licanse Is Intended tv quarantee your feedom ta share and change free j sartwara it make sure Ihe software is free for all iis users This General E Accept License Decline Figure 4 The opening screen when installing ES2 D source Navigator 4 5 7 with Es2 A C and java Design Metri f Enter Installation Target Directory Figure 5 The window where you will need to provide the installation directory The installation then continues and asks for the mail tool to use to send bugs If you are not certain what to put leave it as is the default is mailhost screenshot not shown 8 The installation then prompts for the type of demo projects to install see Figure 6 These are demo projects for Source Navigator and it is up to you to make a choice They are not essential for the ES2 tool select demonstration projects to install J CiC Project J Java Project Fortran Project J Cobol Project j 4ssembly Project J Monop game Figure 6 The window where you can select demo projects for SN 9 The installation proceeds and shows a message to add the installation directory to the environment variable PATH when finished Figure 7 If you want to have easy access to the tool from any directory it is useful to set PATH If you want PATH to take effect only localy to the current terminal window you should set it in the command line Figure 8 If you want it to take
23. i i National Research Conseil national ERB 1088 Council Canada de recherches Canada Institute for Institut de Technologie Information Technology de l information NiC CNC ES2 A Tool for Collecting Object Oriented Design Metrics from C and J ava Source Code Stojanovic M and El Emam K J une 2001 i Canada NRC 44888 National Research Conseil national Council Canada de recherches Canada Institute for Institut de Technologie Information Technology de l information ES2 A Tool for Collecting Object Oriented Design Metrics from C and Java Source Code Stojanovic M and El Emam K J une 2001 Copyright 2001 by National Research Council of Canada Permission is granted to quote short excerpts and to reproduce figures and tables from this report provided that the source of such material is fully acknowledged ES2 A Tool for Collecting Object Oriented Design Metrics from C and Java Source Code Marta Stojanovic Khaled El Emam National Research Council of Canada Institute for Information Technology Building M 50 Montreal Road Ottawa Ontario Canada K1A OR6 marta stojanovic khaled el emam nrc ca Abstract There is considerable evidence that object oriented design metrics can be used to make quality management decisions leading to substantial cost savings However one of the major impediments to the wider adoption of object oriented metrics in practice has been the unavailability of robust and low
24. ing OCAEC with class C 2 instances Dube void mdi int Figure 1 A simple C example for calculating metrics This type of class definition code is typically in the interface h files If we consider all the access types public and private in this case we can see that class B for example has two attributes which are both of type C If we count coupling instances then it means that OCAIC B 22 Class B has one method whose argument type is of type D As class D is a parent class of class B we are talking about ancestor coupling i e ACMIC B 1 Class B has only one parent class D so its DIT is 1 the DIT of class A is 2 because it is a subclass of class B which is a subclass of class D oimilarly we can calculate all the metrics for all the classes At the end we would obtain the results presented in Table 2 Metric Class A Class B Class C Class D Class A Class B Class C Class D OCAIC instances 0 2 2 0 0 0 0 0 OCAIC classes 0 1 1 0 0 0 0 0 OCAEC instances 2 0 2 0 0 0 0 0 OCAEC classes 1 0 1 0 0 0 0 0 OCMIC instances 1 0 0 0 1 0 0 0 OCMIC classes 1 0 0 0 1 0 0 0 OCMEC instances 0 0 1 0 0 0 1 0 OCMEC classes 0 0 1 0 0 0 1 0 ACAIC instances 2 0 0 0 0 0 0 0 ACAIC classes 2 0 0 0 0 0 0 0 DCAEC instances 0 1 0 1 0 0 0 0 DCAEC classes 0 1 0 1 0 0 0 0 ACMIC instances 0 1 0 0 0 1 0 0 ACMIC classes 0 1 0 0 0 1 0 0 DCMEC instances 0 0 0 1 0 0 0 0 DCMEC classes 0 0 0 1 0 0 0 0 Number of att
25. ly functional it does not recognize instance and local variable types It recognizes however method parameters and return type This means that we are able to extract information about class method coupling see section 1 1 but not about class attribute coupling In the output file the values for class attribute couplings are therefore all set to O 4 2 3 Inner classes Inner classes in Java are treated the same way as in C see section 4 1 5 4 2 4 JAR files Source Navigator does not recognize jar files so any class in a jar file will not be considered as a part of the system Jar files are usually used for class files If that is the case even if they are not zipped they would not be considered because it is not source code If you want those classes to be considered as a part of the system you should leave them unzipped and in java format to allow the Java parser to recognize them 4 2 5 Interfaces Interfaces are considered as classes if a class has a method return or argument type of an interface type it will be considered as coupling Interfaces can be inherited so DIT depth of inheritance tree is calculated for them also In the output file no distinction is made between classes and interfaces This can be visualised in the Source Navigator s Symbols window if we choose to see only instance variables we will see that the column for their type is empty the same goes for local variables 28 4 2 6 P
26. nts were in the database there would be coupling between ACE Accept QoS Params and the method pointers argument class types iovec and ACE Qos 4 1 2 Macros 4 1 2 1 Macro definitions Source Navigator does not pre process the code so we did not treat macro definitions even if they can introduce coupling Figure 20 shows an example of such non treated coupling The advantage of not performing any pre processing is that SN can be very robust compared to other C metrics analyzers that we have worked with For instance we have been able to start collecting metrics from systems using ES2 within 5 minutes of installation For other metrics analyzers we sometimes had to spend a few months setting up the environment before metrics could be computed if defined ACE HAS TEMPLATE TYPEDEFS define ACE MMAP MEMORY POOL ACE MMAP Memory Pool else define ACE MMAP MEMORY POOL ACE MMAP Memory Pool ACE MMAP Memory Pool Option endif class ACE_Export ACE_MEM_SAP dif ACE HAS POSITION INDEPENDENT POINTERS 1 typedef ACE Malloc TXKACE MMAP MEMORY POOL ACE Process Mutex ACE PI Control Block MALLOC TYPE else typedef ACE Malloc T ACE MMAP MEMORY POOL ACE Process Mutex ACE Control Block MALLOC TYPE dendif MALLOC TYPE shm malloc Figure 20 Example of macro definitions ZI In this case our tool will find class attribute coupling between ACE MEM SAP and ACE Process Mutex ACE PI Control Block an
27. pening the csv file in MS Excel 19 Note that the first two columns after the class name give start and end positions of the class the first number before the dot is the line number and the second one is the position of the character on that line The format is taken directly from Source Navigator It is important to have the position in order to distinguish between classes with the same name which happens in C if you have ifdef 4 Special Cases 4 1 C ES2 works on C code but not all the subtleties of the C language are covered This is partially because Source Navigators parser does not provide enough information or because it has been left for future development by us In this section we will explain the limitations of ES2 In addition some cases demand more explanations on how the coupling is measured because there were implementation choices that had to be made Most of the examples are taken from the ACE Adaptive Communications Environment library 13 14 It should be noted that based on our experiences extracting metrics from a number of different systems the limitations of ES2 are minor given that they deal with some cases that do not occur very often at least in the systems that we have studied thus far Furthermore in practice the extracted metrics are used in statistical analyses The choices we made explained below will usually not have a noticeable influence on the results of the statistical analyses
28. proj Add Directory home mar ta SN452 E 52 share ES2 examples CPP Bi gExample iy more Include Subdirectories Build Cross Reference database DK Project Editor Cancel Figure 12 Window when the default project specifics are edited Actual directories that should be added to the project for all the included examples are For Java SN452_ES2 share ES2 examples Java graph or SN452 ES2 share ES2 examples Java JPublish or SN452 ES2 share ES2 examples Java JTop For C SN452 ES2 share ES2 examples CPP SmallExample metakit 2 3 4 29 or SN452_ES2 share ES2 examples CPP BigExample v Use these exact directories and not their subdirectories in order to preserve the Original source directory structure 14 3 After clicking on OK Source Navigator starts parsing the project files and at the end pops up a window with the information on all files Figure 13 search abtvdlg h aw3d h aw3dp h awcmd3d h awcmd3dp h awlbl3d h awlbl3dp h awscl3d h awscl3dp h awsim3d h awsim3dp h awsld3d h awsld3dp h ewtog3d h ewtog3dp h bncapp h bnccmdw h bnccnv h brshdlg h canvas h canvasp h cnewmdlg h coldlg h cprojdlg h cubespp h cubecmdw h 1 cubecnv h drawapp h drawcmdw h drawcnv h Bl h 1 Blut h qgdbdlg h Directory BigExample v wvide ample v includex wv ample v includex wv ample v includex wv ample v include
29. reated when you unpack the ES file 4 Change directory to SN452_ES2 by typing 5 Run INSTALL by typing see Figure 3 Edit Help marta cd SN452 ES2 linux unpacked marta SM4B2 ES linux unpacked f INSTALL j Figure 3 Running the installation command 6 The tool installation starts It asks the user to accept the licence Figure 4 and after that it prompts the user to accept or change the offered installation directory Figure 5 Make sure you have write permission for that directory Don t choose for installation the directory SN452 ES2 unpacked atv ia tor C Copyright 1997 2000 Red Hat inet All rights reserved Tel 1 did 542 S600 Fax 1 408 542 9699 Email sugar cc vgnus com http f suppart cygnis com E82 A Ce and Java Design Metrics Analyzer C Copyright Z001 National Research Council All rights reserved Contact information Technical suppart Khaled El Emar barla STojpaovic Tel T 513 998 460 Tel 1 amp 13 S93 3857 Email kWialeif el enam nrc ca Email marta stojanovic nrc ca I GNU GENERAL PUBLIC LICENSE Version 2 June 1991 Copyright iC 1989 1391 Free Software F oumdabon Inc ja3 Temple Place Sulle 330 Boslon MA 02111 1307 USA Evenpone is ipermitted 1o copy and distibule verbalim copies of ihis license document ibut changing itis nat allowed Fraamhnla The licenses for most software are designed to Take away your fresdam ito share and chan
30. ributes 2 2 3 0 0 0 0 0 Number of methods 1 1 1 1 1 1 1 1 DIT 2 1 0 0 2 1 0 0 LOC 11 10 11 7 11 10 11 7 all attributes and methods only public attributes and methods Table 2 Metrics as calculated for the sample code from Figure 1 Note that the second part of the table shows metrics if only public attributes and methods are taken into account We can see that there is less coupling because all the attributes in the sample code in Figure 1 are private so the coupling is related only to methods which are all public in this case 1 2 The ES2 Environment The ES2 metrics analyzer has been implemented on top of the Source Navigator SN IDE SN is a very powerful IDE by itself especially for the purpose of going through large amounts of code trying to find cross references and links amongst classes We will take a few moments here to explain the choice of using SN and its advantages and disadvantages SN is a product made available by RedHat under the GNU General Public License You can download and install it right away from lt http sources redhat com sourcenav gt It has been around for a number of years and therefore it is stable and has a relatively large user community SN extracts quite a number of relevant elements from the source code and stores them in databases which we then use to compute the metrics This is ideal since in principle for any object oriented language the same analyzer can compute the metrics from the databa
31. s another case which is also considered as ancestor descendant coupling If for instance an attribute or method type is a typedef defined in a parent class we consider it as ancestor descendants coupling even if the typedef turns out to be a primitive type The reason is that in such a case when trying to understand the code we will have to look into the parent class to resolve the typedef 4 1 7 Complex types We call complex types of the form X Y X can be either a class or a typedef in which case its redefined type is found Y can be either an inner class in which case we consider only coupling with X and not Y Ora typedef defined in the class X or its parent class in which case an effort is made to find a type redefined by that typedef if it is of a class type we consider it as coupling 25 In the case of templates we could have the following case template lt class A gt class B POC Gs In this case we consider coupling between class B and a class that can be a type of the template argument A But we do not go further we do not test if that class has a field of the name C inner class or typedef Eventually tt could be done but as we did not encounter such cases in a number of large systems that we analyzed we left it unconsidered 4 1 8 Unions Unions are not considered as base classes but we treat them as such and consider that there is coupling between a union and its elements if they are of a class
32. s missing for example This is illustrated in Figure 17 18 E inarta Phomeymarta File Edit Settings Help Lmartat ls snprjzv snprj w all couplina cgv snprj v e snprj v fu snprj v ma snprjz v 1 snprj amp v ec snprj v gv snprj v md snpr j v bu Snpr j v f snprj w icl snprjz v mi snprjz w cl snprj v fd snprj v in snprj w t Snpr j v can snprj v fil snprj v iu snprj v ta anpr j wv ctr snprj v fr snprj v iv snprj v coupling log marta z more snprj v coupling log File snprj v un doesn t exist Mo templates in the project marta Bi Figure 17 After extracting the metrics two additional files are created Finally we should use MS Excel or Sun s StarCalc to visualize the metrics file Use comma separated columns when importing the file if it is not imported automatically Figure 18 2X Miores oft Evrel oall ooupdingy 18 E ole pit uem quet Pirni pos peta Windom Helo _ olf xj Cm i Bik m ma n ce EEL i oe d jee ee ee le A r a ow Glass Nane a A Gis PS Se BE ee ae el ease i eae oe eT el L Clace Mame Stat pont Em posrtiiF lename CAIC Inet CAIC cba CAEC ns CAEC cla Chat est CMIC ilat CMEC ng CMEC rb ACAIC fnelcac zx BreakPoint 170 008 200 6 sna ES 1 i E 2 ChewPmjMplg 14 01 WT Shudae EE 1 E od Camna 7 007 43T7 5h52 EE Color Pal br 012 BSS SRM EE g Fil Comm
33. sage martat Figure 15 Example with ES2 giving the usage and help outputs when invoked 17 2 For our example v proj we should type if PATH is set ES2 home marta v all If PATH is not set it should be Shome directory SN452 ES2 bin ES2 home marta v all Upon pressing ENTER the metrics extraction starts Messages are displayed while waiting Figure 16 For large projects it can take some time For example analyzing the V project on a Pentium Il 400MHz 128MB RAM takes about 2 minutes martat E52 v all Extracting classes please wait Extracting tupedefs please wait Extracting included files please wait Extracting inheritance info please wait Extracting unions please wait Analyzing attribute types please wait Analyzing method return and argument tupes please wait Creating metrics file please wait Finished collecting metrics thanks for waiting MOTE Metrics can be found in a file snprj v all couplinga csv For best read ability open it with Sun s StarCalc Linux or MS Excel Windows using comma se parated columns martat Figure 16 The notification messages provided by ES2 while it is executing 3 When the execution is finished two new files will appear in the snprj directory v all coupling csv and v coupling log The first file contains calculated metrics and the second one log messages like whether a database file wa
34. se Furthermore eventually the ES2 system and its successors will be integrated directly into SN so that metrics will be available as a user navigates through the code If you wish to use SN by itself i e you are not interested in the ES2 system you can download SN directly from the address above However if you wish to use ES2 you must use the version of SN bundled in the ES2 distribution as we have made some changes to SN see section 2 for downloading instructions ES2 is based on SN version 4 52 Currently there is an SN verison 5 0 just released a few weeks ago We have not completed evaluation of SN 5 0 with ES2 Therefore we reiterate that you must use the SN system that is bundled with ES2 2 Downloading and Installing ES2 The current version of the ES2 tool works only on Linux RedHat 7 0 and 7 1 We do not make any claims about its suitability or applicability under any other conditions Please check the ES2 Web site for porting to other platforms There is a continuous effort to port ES2 to other platforms To download and install ES2 follow these steps 1 Download the file SN452_ES2_linux tar gz from the http www seg iit nrc ca elemam under the Tools Metrics tab 2 Save it in the directory where you want it installed 3 Unpack the downloaded file Type in the console window in the same directory tar xv z ON4ISZ ES2 linux ytar Coz This will create the directory SN452 ES2 linux unp
35. snpr jeu Snprjz v e Snprjz v fr snprj v iu snprjz v t snprj v ec snprj v fu snprj v iv snprj v to Snpr jv f Snprj v gw snprj v ma snprj v fd snprjz v icl snprj v md Snprjz v fil snprjz v in snprj v mi Figure 14 A listing of the database files that are generated by SN Some of the database files are used by ES2 to extract all the needed information for calculating metrics Each file is a table that contains specific symbol information A list of the database files used along with a short explanation of their content is given in Table 3 Record Format Suffix Description File Table cl Classes in Inheritances iu Include IV Instance variables ma Macros md Method definitions t Typedefs un Unions name start_position filename end_position attributes class template comment class base class start_position filename end_position attributes class template inheritance template comment included file start position include from file 0 0 0x0 0 class variable name start position filename end position attributes type comment name start_position filename end_position attributes comment class name start_position filename end_position attributes ret_type arg_types arg_names comment name position filename attributes original comment name position filename attributes comment Table 3
36. tand for these 3 types of interactions A for ancestor D for descendant O for other neither ancestor nor descendant CA for class attribute CM for class method IC for import coupling and EC for export coupling Figure 1 shows a simple example of C code and how every type of coupling is captured class A public class B For class A Class method import coupling OCMIC with class C For class C Class method export coupling OCMEC with class A public C mal int i For class A Ancestor class attribute import coupling ACAIC with class B private For class B Descendant class attribute export coupling DCAEC with i class A B bl E er For class A Ancestor class attribute import coupling ACAIC with class D For class D Descendant class attribute export coupling DCAEC with class A iS Class B public class D publ Ae 3 gt For class B Ancestor class method import coupling ACMIC with class D For class D Descendant class method export coupling DCMEC with class A int mbl D amp d private CCL 02s For class B Class attribute import coupling OCAIC with class C 2 instances For class C Class attribute export coupling OCAEC with class B 2 instances pubes int mc1 void private int k A al a2 For class C Class attribute import coupling OCAIC with class A 2 instances For class A Class attribute export coupl
37. type as we do for structures 4 1 9 Operator overloading In the case of operator overloading the Source Navigator s C parser does not parse correctly the return types in the following three situations in each of these situations the return type will be int when the return type is a class type returned by value if it is returned by reference it parses it correctly when the return type is a template argument type when the return type is a typedef Hereafter we show two examples of wrongly calculated coupling caused by this problem In the following example instead of c4 Row the database file shows int coupling between c4StringProp and c4 Row IS therefore not taken into account class c4 StringProp public c4 Property public c4 Row operator const char const Or in this example instead of template argument TYPE the database shows int coupling between a class that could be TYPE and ACE Atomic op not counted 26 template lt class ACE_LOCK class TYPE gt class ACE Atomic Op public TYPE operator int 4 1 10 Namespace keyword Source Navigator does not support the C keyword namespace This leads to scoping problems which cannot be resolved if namespace support is not added Right now the scope of a class is the file in which that class is defined and all the files included by that file The namespace keyword does not require file inclusion a type defined in the same namespa
38. ve any other way to prove that B is a class other than to look for it in the class database In some cases the system is a library and the declared classes will be defined in applications that use the library For such cases it is not possible to account for any coupling 24 4 1 5 Inner classes As metrics such as defects or effort are usually not calculated for inner classes we do not consider inner classes in our coupling measurements But as the parser does not distinguish inner classes from others we have to explicitly check for them Figure 23 shows an example of an inner class and its interaction with other classes If an inner class has an attribute or method type of some other class we consider that there is coupling between its outmost class and that class in our example class A is coupled with class C because of the attribute c in the inner class B If an outer class has an attribute or method type of an inner class there is no coupling between them no coupling between class A and class B because of the attribute b Figure 23 Example of an inner class If a class is coupled to an inner class of some other class only coupling with the outer class is considered class C is coupled only with the class A and not with the inner class B because of the attribute ab 4 1 6 Parent classes The simplest case of ancestor descendant coupling would be if an attribute or method type is of the parent s class But there i
39. x wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv ample v includex wv E v vopengl bounce E v vopengl bounce E v vopengl bounce LgExamp Lev iconed ample v includex v ample includex v BigExample v vide i1gExample v iconed BigExample v vide le v vopengl cube le v vopengl cube le v vopengl cuhbe igExemple v drawex igExaemple v drawex igExample v drawex nuwin3z include gl nuwin3z include ugl BigExample v vide Figure 13 The SN window with all the files in the project 4 Now we have created a SN project By doing so SN has created a number of database files that we use for the purpose of calculating design metrics Here we can close Source Navigator windows Of course it is an excellent code navigation tool and we encourage the user to use it as such For more information on how to use Source Navigator see lt http sources redhat com sourcenav online docs userguide index_ug html gt 5 By parsing the source files SN created the database files that are put by default in project home directory snprj directory Figure 14 15 Settings Help marta 5N452 ES bin cd marta ls Yw praj martaz ls npr jrw 1 snpr jv by snprj v cl Snpr j v con Snpr jz v ctr marta Y proj
Download Pdf Manuals
Related Search
Related Contents
User Guide - TP-Link User`s Manual AirLive POE-FSH2422G-390 network switch Terminal Controller pour les unités Aqualia 42EL et Ultra 42BJ 50 Hz quadrapaddle receiver insert part identification Jumpstarter 18 Amp 5x1 Manual de usuario YLHA 50 to 80 IMPORTANT SAFETY INSTRUCTIONS Copyright © All rights reserved.
Failed to retrieve file