blob: f105ea84612ef1e38a7f224ea656d1bc7d968382 [file] [log] [blame]
mparker6a0e4c22009-05-27 22:20:30 +00001<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
2 xmlns:lxslt="http://xml.apache.org/xslt"
3 xmlns:xalan="http://xml.apache.org/xalan"
4 xmlns:redirect="org.apache.xalan.lib.Redirect"
5 exclude-result-prefixes="xalan"
6 extension-element-prefixes="redirect">
7<xsl:output method="html" indent="yes" encoding="US-ASCII"/>
8<xsl:decimal-format decimal-separator="." grouping-separator="," />
9<!--
10 Copyright 2001-2004 The Apache Software Foundation
11
12 Licensed under the Apache License, Version 2.0 (the "License");
13 you may not use this file except in compliance with the License.
14 You may obtain a copy of the License at
15
16 http://www.apache.org/licenses/LICENSE-2.0
17
18 Unless required by applicable law or agreed to in writing, software
19 distributed under the License is distributed on an "AS IS" BASIS,
20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 See the License for the specific language governing permissions and
22 limitations under the License.
23
24-->
25<!--
26 @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/>
27 -->
28<xsl:param name="output.dir" select="'.'"/>
29
30<!-- default max value for the metrics -->
31<xsl:param name="vg.max" select="10"/>
32<xsl:param name="loc.max" select="1000"/>
33<xsl:param name="dit.max" select="10"/>
34<xsl:param name="noa.max" select="250"/>
35<xsl:param name="nrm.max" select="50"/>
36<xsl:param name="nlm.max" select="250"/>
37<xsl:param name="wmc.max" select="250"/>
38<xsl:param name="rfc.max" select="50"/>
39<xsl:param name="dac.max" select="10"/>
40<xsl:param name="fanout.max" select="10"/>
41<xsl:param name="cbo.max" select="15"/>
42<xsl:param name="lcom.max" select="10"/>
43<xsl:param name="nocl.max" select="10"/>
44
45
46<!-- create a tree fragment to speed up processing -->
47<xsl:variable name="doctree.var">
48 <xsl:element name="classes">
49 <xsl:for-each select=".//class">
50 <xsl:element name="class">
51 <xsl:attribute name="package">
52 <xsl:value-of select="(ancestor::package)[last()]/@name"/>
53 </xsl:attribute>
54 <xsl:copy-of select="@*"/>
55 <xsl:attribute name="name">
56 <xsl:apply-templates select="." mode="class.name"/>
57 </xsl:attribute>
58 <xsl:copy-of select="method"/>
59 </xsl:element>
60 </xsl:for-each>
61 </xsl:element>
62</xsl:variable>
63
64<xsl:variable name="doctree" select="xalan:nodeset($doctree.var)"/>
65
66<xsl:template match="metrics">
67
68 <!-- create the index.html -->
69 <redirect:write file="{$output.dir}/index.html">
70 <xsl:call-template name="index.html"/>
71 </redirect:write>
72
73 <!-- create the stylesheet.css -->
74 <redirect:write file="{$output.dir}/stylesheet.css">
75 <xsl:call-template name="stylesheet.css"/>
76 </redirect:write>
77
78 <redirect:write file="{$output.dir}/metrics-reference.html">
79 <xsl:call-template name="metrics-reference.html"/>
80 </redirect:write>
81
82 <!-- create the overview-packages.html at the root -->
83 <redirect:write file="{$output.dir}/overview-summary.html">
84 <xsl:apply-templates select="." mode="overview.packages"/>
85 </redirect:write>
86
87 <!-- create the all-packages.html at the root -->
88 <redirect:write file="{$output.dir}/overview-frame.html">
89 <xsl:apply-templates select="." mode="all.packages"/>
90 </redirect:write>
91
92 <!-- create the all-classes.html at the root -->
93 <redirect:write file="{$output.dir}/allclasses-frame.html">
94 <xsl:apply-templates select="." mode="all.classes"/>
95 </redirect:write>
96
97 <!-- process all packages -->
98 <xsl:apply-templates select=".//package"/>
99</xsl:template>
100
101
102<xsl:template match="package">
103 <xsl:variable name="package.name" select="@name"/>
104 <xsl:variable name="package.dir">
105 <xsl:if test="not($package.name = 'unnamed package')"><xsl:value-of select="translate($package.name,'.','/')"/></xsl:if>
106 <xsl:if test="$package.name = 'unnamed package'">.</xsl:if>
107 </xsl:variable>
108 <!-- create a classes-list.html in the package directory -->
109 <redirect:write file="{$output.dir}/{$package.dir}/package-frame.html">
110 <xsl:apply-templates select="." mode="classes.list"/>
111 </redirect:write>
112
113 <!-- create a package-summary.html in the package directory -->
114 <redirect:write file="{$output.dir}/{$package.dir}/package-summary.html">
115 <xsl:apply-templates select="." mode="package.summary"/>
116 </redirect:write>
117
118 <!-- for each class, creates a @name.html -->
119 <!-- @bug there will be a problem with inner classes having the same name, it will be overwritten -->
120 <xsl:for-each select="$doctree/classes/class[@package = current()/@name]">
121 <!--Processing <xsl:value-of select="$class.name"/><xsl:text>&#10;</xsl:text> -->
122 <redirect:write file="{$output.dir}/{$package.dir}/{@name}.html">
123 <xsl:apply-templates select="." mode="class.details"/>
124 </redirect:write>
125 </xsl:for-each>
126</xsl:template>
127
128<!-- little trick to compute the classname for inner and non inner classes -->
129<!-- this is all in one line to avoid CRLF in the name -->
130<xsl:template match="class" mode="class.name">
131 <xsl:if test="parent::class"><xsl:apply-templates select="parent::class" mode="class.name"/>.<xsl:value-of select="@name"/></xsl:if><xsl:if test="not(parent::class)"><xsl:value-of select="@name"/></xsl:if>
132</xsl:template>
133
134
135<xsl:template name="index.html">
136<HTML>
137 <HEAD><TITLE>Metrics Results.</TITLE></HEAD>
138 <FRAMESET cols="20%,80%">
139 <FRAMESET rows="30%,70%">
140 <FRAME src="overview-frame.html" name="packageListFrame"/>
141 <FRAME src="allclasses-frame.html" name="classListFrame"/>
142 </FRAMESET>
143 <FRAME src="overview-summary.html" name="classFrame"/>
144 </FRAMESET>
145 <noframes>
146 <H2>Frame Alert</H2>
147 <P>
148 This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
149 </P>
150 </noframes>
151</HTML>
152</xsl:template>
153
154<!-- this is the stylesheet css to use for nearly everything -->
155<xsl:template name="metrics-reference.html">
156<html>
157<head>
158<link title="Style" type="text/css" rel="stylesheet" href="stylesheet.css"/>
159</head>
160<body style="text-align:justify;">
161<h2>Metrics Reference</h2>
162<a href="#V(G)">V(G)</a> |
163<a href="#LOC">LOC</a> |
164<a href="#DIT">DIT</a> |
165<a href="#NOA">NOA</a> |
166<a href="#NRM">NRM</a> |
167<a href="#NLM">NLM</a> |
168<a href="#WMC">WMC</a> |
169<a href="#RFC">RFC</a> |
170<a href="#DAC">DAC</a> |
171<a href="#FANOUT">FANOUT</a> |
172<a href="#CBO">CBO</a> |
173<a href="#LCOM">LCOM</a> |
174<a href="#NOC">NOC</a>
175
176<a name="V(G)"/>
177<h3>Cyclomatic Complexity - V(G)</h3>
178This metric was introduced in the 1970s to measure the amount of control
179flow complexity or branching complexity in a module such as a
180subroutine. It gives the number of paths that may be taken through the
181code, and was initially developed to give some measure of the cost of
182producing a test case for the module by executing each path.
183<p/>
184Methods with a high cyclomatic complexity tend to be more difficult to
185understand and maintain. In general the more complex the methods of an
186application, the more difficult it will be to test it, and this will adversely
187affect its reliability.
188<p/>
189V(G) is a measure of the control flow complexity of a method or
190constructor. It counts the number of branches in the body of the method,
191defined as:
192<ul>
193<li>while statements;</li>
194<li>if statements;</li>
195<li>for statements.</li>
196</ul>
197
198The metric can also be configured to count each case of a switch
199statement as well.
200
201<a name="LOC"/>
202<h3>Lines of Code - LOC</h3>
203
204This is perhaps the simplest of all the metrics to define and compute.
205Counting lines has a long history as a software metric dating from before
206the rise of structured programming, and it is still in widespread use today.
207The size of a method affects the ease with which it can be understood, its
208reusability and its maintainability. There are a variety of ways that the size
209can be calculated. These include counting all the lines of code, the number
210of statements, the blank lines of code, the lines of commentary, and the
211lines consisting only of syntax such as block delimiters.
212<p/>
213This metric can also be used for sizing other constructs as well, for
214example, the overall size of a Java class or package can be measured by
215counting the number of source lines it consists of.
216<p/>
217LOC can be used to determine the size of a compilation unit (source file),
218class or interface, method, constructor, or field. It can be configured to
219ignore:
220<ul>
221<li>blank lines;</li>
222<li>lines consisting only of comments;</li>
223<li>lines consisting only of opening and closing braces.</li>
224</ul>
225
226<a name="DIT"/>
227<h3>Depth of Inheritance Hierarchy - DIT</h3>
228
229This metric calculates how far down the inheritance hierarchy a class is
230declared. In Java all classes have java.lang.Object as their ultimate
231superclass, which is defined to have a depth of 1. So a class that
232immediately extends java.lang.Object has a metric value of 2; any of its
233subclasses will have a value of 3, and so on.
234<p/>
235A class that is deep within the tree inherits more methods and state
236variables, thereby increasing its complexity and making it difficult to
237predict its behavior. It can be harder to understand a system with many
238inheritance layers.
239<p/>
240DIT is defined for classes and interfaces:
241<ul>
242<li>all interface types have a depth of 1;</li>
243<li>the class java.lang.Object has a depth of 1;</li>
244<li>all other classes have a depth of 1 + the depth of their super class.</li>
245</ul>
246
247<a name="NOA"/>
248<h3>Number of Attributes - NOA</h3>
249
250The number of distinct state variables in a class serves as one measure of
251its complexity. The more state a class represents the more difficult it is to
252maintain invariants for it. It also hinders comprehensibility and reuse.
253<p/>
254In Java, state can be exposed to subclasses through protected fields, which
255entails that the subclass also be aware of and maintain any invariants. This
256interference with the class's data encapsulation can be a source of defects
257and hidden dependencies between the state variables.
258<p/>
259NOA is defined for classes and interfaces. It counts the number of fields
260declared in the class or interface.
261
262<a name="NRM"/>
263<h3>Number of Remote Methods - NRM</h3>
264
265NRM is defined for classes. A remote method call is defined as an
266invocation of a method that is not declared in any of:
267<ul>
268<li>the class itself;</li>
269<li>a class or interface that the class extends or implements;</li>
270<li>a class or method that extends the class.</li>
271</ul>
272
273The value is the count of all the remote method calls in all of the methods
274and constructors of the class.
275
276<a name="NLM"/>
277<h3>Number of Local Methods - NLM</h3>
278
279NLM is defined for classes and interfaces. A local method is defined as a
280method that is declared in the class or interface. NLM can be configured to
281include the local methods of all of the class's superclasses. Methods with
282public, protected, package and private visibility can be independently
283counted by setting configuration parameters.
284
285<a name="WMC"/>
286<h3>Weighted Methods per Class - WMC</h3>
287
288If the number of methods in a class can be determined during the design
289and modeling phase of a project, it can be used as a predictor of how
290much time and effort is needed to develop, debug and maintain it. This
291metric can be further refined by incorporating a weighting for the
292complexity of each method. The usual weighting is given by the cyclomatic
293complexity of the method.
294<p/>
295The subclasses of a class inherit all of its public and protected methods,
296and possibly its package methods as well, so the number of methods a
297class has directly impacts the complexity of its subclasses. Classes with
298large numbers of methods are often specific to a particular application,
299reducing the ability to reuse them.
300<p/>
301The definition of WMC is based upon NLM, and it provides the same
302configuration parameters for counting inherited methods and of varying
303visibility. The main difference is that NLM always counts each method as 1,
304whereas WMC will weight each method. There are two weighting schemes:
305<ul>
306<li>V(G) the cyclomatic complexity of the method is used as its weight.
307 Methods from class files are given a V(G) of 1.</li>
308<li>the arity, or the number of parameters of the method are used to
309 determine the weight.</li>
310</ul>
311
312<a name="RFC"/>
313<h3>Response For Class - RFC</h3>
314
315The response set of a class is the set of all methods that can be invoked as
316a result of a message sent to an object of the class. This includes methods
317in the class's inheritance hierarchy and methods that can be invoked on
318other objects. The Response For Class metric is defined to be size of the
319response set for the class. A class which provides a larger response set is
320considered to be more complex than one with a smaller response set.
321<p/>
322One reason for this is that if a method call on a class can result in a large
323number of different method calls on the target and other classes, then it
324can be harder to test the behavior of the class and debug problems. It will
325typically require a deeper understanding of the potential interactions that
326objects of the class can have with the rest of the system.
327<p/>
328RFC is defined as the sum of NLM and NRM for the class. The local methods
329include all of the public, protected, package and private methods, but not
330methods declared only in a superclass.
331
332<a name="DAC"/>
333<h3>Data Abstraction Coupling - DAC</h3>
334
335DAC is defined for classes and interfaces. It counts the number of reference
336types that are used in the field declarations of the class or interface. The
337component types of arrays are also counted. Any field with a type that is
338either a supertype or a subtype of the class is not counted.
339
340<a name="FANOUT"/>
341<h3>Fan Out - FANOUT</h3>
342
343FANOUT is defined for classes and interfaces, constructors and methods. It
344counts the number of reference types that are used in:
345<ul>
346<li>field declarations;</li>
347<li>formal parameters and return types;</li>
348<li>throws declarations;</li>
349<li>local variables.</li>
350</ul>
351
352The component types of arrays are also counted. Any type that is either a
353supertype or a subtype of the class is not counted.
354
355<a name="CBO"/>
356<h3>Coupling Between Objects - CBO</h3>
357
358When one object or class uses another object or class they are said to be
359coupled. One major source of coupling is that between a superclass and a
360subclass. A coupling is also introduced when a method or field in another
361class is accessed, or when an object of another class is passed into or out
362of a method invocation. Coupling Between Objects is a measure of the
363non-inheritance coupling between two objects.
364<p/>
365A high value of coupling reduces the modularity of the class and makes
366reuse more difficult. The more independent a class is the more likely it is
367that it will be possible to reuse it in another part of the system. When a
368class is coupled to another class it becomes sensitive to changes in that
369class, thereby making maintenance for difficult. In addition, a class that is
370overly dependent on other classes can be difficult to understand and test in
371isolation.
372<p/>
373CBO is defined for classes and interfaces, constructors and methods. It
374counts the number of reference types that are used in:
375<ul>
376<li>field declarations</li>
377<li>formal parameters and return types</li>
378<li>throws declarations</li>
379<li>local variables</li>
380</ul>
381
382It also counts:
383<ul>
384<li>types from which field and method selections are made</li>
385</ul>
386
387The component types of arrays are also counted. Any type that is either a
388supertype or a subtype of the class is not counted.
389
390<a name="LCOM"/>
391<h3>Lack of Cohesion Of Methods - LCOM</h3>
392
393The cohesion of a class is the degree to which its methods are related to
394each other. It is determined by examining the pattern of state variable
395accesses within the set of methods. If all the methods access the same state
396variables then they have high cohesion; if they access disjoint sets of
397variables then the cohesion is low. An extreme example of low cohesion
398would be if none of the methods accessed any of the state variables.
399
400If a class exhibits low method cohesion it indicates that the design of the
401class has probably been partitioned incorrectly, and could benefit by being
402split into more classes with individually higher cohesion. On the other
403hand, a high value of cohesion (a low lack of cohesion) implies that the
404class is well designed. A cohesive class will tend to provide a high degree
405of encapsulation, whereas a lack of cohesion decreases encapsulation and
406increases complexity.
407<p/>
408Another form of cohesion that is useful for Java programs is cohesion
409between nested and enclosing classes. A nested class that has very low
410cohesion with its enclosing class would probably better designed as a peer
411class rather than a nested class.
412<p/>
413LCOM is defined for classes. Operationally, LCOM takes each pair of
414methods in the class and determines the set of fields they each access. If
415they have disjoint sets of field accesses increase the count P by one. If they
416share at least one field access then increase Q by one. After considering
417each pair of methods,
418LCOM = (P > Q) ? (P - Q) : 0
419<p/>
420Indirect access to fields via local methods can be considered by setting a
421metric configuration parameter.
422
423<a name="NOC"/>
424<h3>Number Of Classes - NOC</h3>
425
426The overall size of the system can be estimated by calculating the number
427of classes it contains. A large system with more classes is more complex
428than a smaller one because the number of potential interactions between
429objects is higher. This reduces the comprehensibility of the system which
430in turn makes it harder to test, debug and maintain.
431<p/>
432If the number of classes in the system can be projected during the initial
433design phase of the project it can serve as a base for estimating the total
434effort and cost of developing, debugging and maintaining the system.
435<p/>
436The NOC metric can also usefully be applied at the package and class level
437as well as the total system.
438<p/>
439NOCL is defined for class and interfaces. It counts the number of classes or
440interfaces that are declared. This is usually 1, but nested class declarations
441will increase this number.
442</body>
443</html>
444</xsl:template>
445
446<!-- this is the stylesheet css to use for nearly everything -->
447<xsl:template name="stylesheet.css">
448 .bannercell {
449 border: 0px;
450 padding: 0px;
451 }
452 body {
453 margin-left: 10;
454 margin-right: 10;
455 font:normal 80% arial,helvetica,sanserif;
456 background-color:#FFFFFF;
457 color:#000000;
458 }
459 .a td {
460 background: #efefef;
461 }
462 .b td {
463 background: #fff;
464 }
465 th, td {
466 text-align: left;
467 vertical-align: top;
468 }
469 th {
470 font-weight:bold;
471 background: #ccc;
472 color: black;
473 }
474 table, th, td {
475 font-size:100%;
476 border: none
477 }
478 table.log tr td, tr th {
479
480 }
481 h2 {
482 font-weight:bold;
483 font-size:140%;
484 margin-bottom: 5;
485 }
486 h3 {
487 font-size:100%;
488 font-weight:bold;
489 background: #525D76;
490 color: white;
491 text-decoration: none;
492 padding: 5px;
493 margin-right: 2px;
494 margin-left: 2px;
495 margin-bottom: 0;
496 }
497 .Error {
498 font-weight:bold; color:red;
499 }
500
501</xsl:template>
502
503<!-- print the metrics of the class -->
504<xsl:template match="class" mode="class.details">
505 <!--xsl:variable name="package.name" select="(ancestor::package)[last()]/@name"/-->
506 <xsl:variable name="package.name" select="@package"/>
507 <HTML>
508 <HEAD>
509 <xsl:call-template name="create.stylesheet.link">
510 <xsl:with-param name="package.name" select="$package.name"/>
511 </xsl:call-template>
512 </HEAD>
513 <BODY>
514 <xsl:call-template name="pageHeader"/>
515
516 <H3>Class <xsl:if test="not($package.name = 'unnamed package')"><xsl:value-of select="$package.name"/>.</xsl:if><xsl:value-of select="@name"/></H3>
517 <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
518 <xsl:call-template name="all.metrics.header"/>
519 <xsl:apply-templates select="." mode="print.metrics"/>
520 </table>
521
522 <H3>Methods</H3>
523 <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
524 <xsl:call-template name="method.metrics.header"/>
525 <xsl:apply-templates select="method" mode="print.metrics"/>
526 </table>
527
528 <xsl:call-template name="pageFooter"/>
529 </BODY>
530 </HTML>
531</xsl:template>
532
533
534<!-- list of classes in a package -->
535<xsl:template match="package" mode="classes.list">
536 <HTML>
537 <HEAD>
538 <xsl:call-template name="create.stylesheet.link">
539 <xsl:with-param name="package.name" select="@name"/>
540 </xsl:call-template>
541 </HEAD>
542 <BODY>
543 <table width="100%">
544 <tr>
545 <td nowrap="nowrap">
546 <H2><a href="package-summary.html" target="classFrame"><xsl:value-of select="@name"/></a></H2>
547 </td>
548 </tr>
549 </table>
550
551 <H2>Classes</H2>
552 <TABLE WIDTH="100%">
553 <!-- xalan-nodeset:nodeset for Xalan 1.2.2 -->
554 <xsl:for-each select="$doctree/classes/class[@package = current()/@name]">
555 <xsl:sort select="@name"/>
556 <tr>
557 <td nowrap="nowrap">
558 <a href="{@name}.html" target="classFrame"><xsl:value-of select="@name"/></a>
559 </td>
560 </tr>
561 </xsl:for-each>
562 </TABLE>
563 </BODY>
564 </HTML>
565</xsl:template>
566
567
568<!--
569 Creates an all-classes.html file that contains a link to all package-summary.html
570 on each class.
571-->
572<xsl:template match="metrics" mode="all.classes">
573 <html>
574 <head>
575 <xsl:call-template name="create.stylesheet.link">
576 <xsl:with-param name="package.name" select="''"/>
577 </xsl:call-template>
578 </head>
579 <body>
580 <h2>Classes</h2>
581 <table width="100%">
582 <xsl:for-each select="$doctree/classes/class">
583 <xsl:sort select="@name"/>
584 <xsl:apply-templates select="." mode="all.classes"/>
585 </xsl:for-each>
586 </table>
587 </body>
588 </html>
589</xsl:template>
590
591<xsl:template match="class" mode="all.classes">
592 <xsl:variable name="package.name" select="@package"/>
593 <xsl:variable name="class.name" select="@name"/>
594 <tr>
595 <td nowrap="nowrap">
596 <a target="classFrame">
597 <xsl:attribute name="href">
598 <xsl:if test="not($package.name='unnamed package')">
599 <xsl:value-of select="translate($package.name,'.','/')"/><xsl:text>/</xsl:text>
600 </xsl:if>
601 <xsl:value-of select="$class.name"/><xsl:text>.html</xsl:text>
602 </xsl:attribute>
603 <xsl:value-of select="$class.name"/>
604 </a>
605 </td>
606 </tr>
607</xsl:template>
608
609<!--
610 Creates an html file that contains a link to all package-summary.html files on
611 each package existing on testsuites.
612 @bug there will be a problem here, I don't know yet how to handle unnamed package :(
613-->
614<xsl:template match="metrics" mode="all.packages">
615 <html>
616 <head>
617 <xsl:call-template name="create.stylesheet.link">
618 <xsl:with-param name="package.name" select="./package/@name"/>
619 </xsl:call-template>
620 </head>
621 <body>
622 <h2><a href="overview-summary.html" target="classFrame">Home</a></h2>
623 <h2>Packages</h2>
624 <table width="100%">
625 <xsl:apply-templates select=".//package[not(./@name = 'unnamed package')]" mode="all.packages">
626 <xsl:sort select="@name"/>
627 </xsl:apply-templates>
628 </table>
629 </body>
630 </html>
631</xsl:template>
632
633<xsl:template match="package" mode="all.packages">
634 <tr>
635 <td nowrap="nowrap">
636 <a href="{translate(@name,'.','/')}/package-summary.html" target="classFrame">
637 <xsl:value-of select="@name"/>
638 </a>
639 </td>
640 </tr>
641</xsl:template>
642
643
644<xsl:template match="metrics" mode="overview.packages">
645 <html>
646 <head>
647 <xsl:call-template name="create.stylesheet.link">
648 <xsl:with-param name="package.name" select="''"/>
649 </xsl:call-template>
650 </head>
651 <body onload="open('allclasses-frame.html','classListFrame')">
652 <xsl:call-template name="pageHeader"/>
653 <h3>Summary</h3>
654 <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
655 <tr>
656 <th><a href="metrics-reference.html#V(G)">V(G)</a></th>
657 <th><a href="metrics-reference.html#LOC">LOC</a></th>
658 <th><a href="metrics-reference.html#DIT">DIT</a></th>
659 <th><a href="metrics-reference.html#NOA">NOA</a></th>
660 <th><a href="metrics-reference.html#NRM">NRM</a></th>
661 <th><a href="metrics-reference.html#NLM">NLM</a></th>
662 <th><a href="metrics-reference.html#WMC">WMC</a></th>
663 <th><a href="metrics-reference.html#RFC">RFC</a></th>
664 <th><a href="metrics-reference.html#DAC">DAC</a></th>
665 <th><a href="metrics-reference.html#FANOUT">FANOUT</a></th>
666 <th><a href="metrics-reference.html#CBO">CBO</a></th>
667 <th><a href="metrics-reference.html#LCOM">LCOM</a></th>
668 <th><a href="metrics-reference.html#NOCL">NOCL</a></th>
669 </tr>
670 <xsl:apply-templates select="." mode="print.metrics"/>
671 </table>
672 <table border="0" width="100%">
673 <tr>
674 <td style="text-align: justify;">
675 Note: Metrics evaluate the quality of software by analyzing the program source and quantifying
676 various kind of complexity. Complexity is a common source of problems and defects in software.
677 High complexity makes it more difficult to develop, understand, maintain, extend, test and debug
678 a program.
679 <p/>
680 The primary use of metrics is to focus your attention on those parts of code that potentially are
681 complexity hot spots. Once the complex areas your program have been uncovered, you can take remedial
682 actions.
683 For additional information about metrics and their meaning, please consult
684 Metamata Metrics manual.
685 </td>
686 </tr>
687 </table>
688
689 <h3>Packages</h3>
690 <table border="0" cellpadding="5" cellspacing="2" width="100%">
691 <xsl:call-template name="all.metrics.header"/>
692 <xsl:for-each select=".//package[not(@name = 'unnamed package')]">
693 <xsl:sort select="@name" order="ascending"/>
694 <xsl:apply-templates select="." mode="print.metrics"/>
695 </xsl:for-each>
696 </table>
697 <!-- @bug there could some classes at this level (classes in unnamed package) -->
698 <xsl:call-template name="pageFooter"/>
699 </body>
700 </html>
701</xsl:template>
702
703<xsl:template match="package" mode="package.summary">
704 <HTML>
705 <HEAD>
706 <xsl:call-template name="create.stylesheet.link">
707 <xsl:with-param name="package.name" select="@name"/>
708 </xsl:call-template>
709 </HEAD>
710 <body onload="open('package-frame.html','classListFrame')">
711 <xsl:call-template name="pageHeader"/>
712 <!-- create an anchor to this package name -->
713 <h3>Package <xsl:value-of select="@name"/></h3>
714
715 <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
716 <xsl:call-template name="all.metrics.header"/>
717 <xsl:apply-templates select="." mode="print.metrics"/>
718 </table>
719
720 <table border="0" width="100%">
721 <tr>
722 <td style="text-align: justify;">
723 Note: Metrics evaluate the quality of software by analyzing the program source and quantifying
724 various kind of complexity. Complexity is a common source of problems and defects in software.
725 High complexity makes it more difficult to develop, understand, maintain, extend, test and debug
726 a program.
727 <p/>
728 The primary use of metrics is to focus your attention on those parts of code that potentially are
729 complexity hot spots. Once the complex areas your program have been uncovered, you can take remedial
730 actions.
731 For additional information about metrics and their meaning, please consult
732 Metamata Metrics manual.
733 </td>
734 </tr>
735 </table>
736
737 <xsl:variable name="classes-in-package" select="$doctree/classes/class[@package = current()/@name]"/>
738 <xsl:if test="count($classes-in-package) &gt; 0">
739 <H3>Classes</H3>
740 <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
741 <xsl:call-template name="all.metrics.header"/>
742 <xsl:for-each select="$classes-in-package">
743 <xsl:sort select="@name"/>
744 <xsl:apply-templates select="." mode="print.metrics"/>
745 </xsl:for-each>
746 </table>
747 </xsl:if>
748
749 <xsl:call-template name="pageFooter"/>
750 </body>
751 </HTML>
752</xsl:template>
753
754
755<!--
756 transform string like a.b.c to ../../../
757 @param path the path to transform into a descending directory path
758-->
759<xsl:template name="path">
760 <xsl:param name="path"/>
761 <xsl:if test="contains($path,'.')">
762 <xsl:text>../</xsl:text>
763 <xsl:call-template name="path">
764 <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param>
765 </xsl:call-template>
766 </xsl:if>
767 <xsl:if test="not(contains($path,'.')) and not($path = '')">
768 <xsl:text>../</xsl:text>
769 </xsl:if>
770</xsl:template>
771
772
773<!-- create the link to the stylesheet based on the package name -->
774<xsl:template name="create.stylesheet.link">
775 <xsl:param name="package.name"/>
776 <LINK REL ="stylesheet" TYPE="text/css" TITLE="Style"><xsl:attribute name="href"><xsl:if test="not($package.name = 'unnamed package')"><xsl:call-template name="path"><xsl:with-param name="path" select="$package.name"/></xsl:call-template></xsl:if>stylesheet.css</xsl:attribute></LINK>
777</xsl:template>
778
779
780<!-- Page Header -->
781<xsl:template name="pageHeader">
782
783 <!-- jakarta logo -->
784 <table border="0" cellpadding="0" cellspacing="0" width="100%">
785 <tr>
786 <td class="bannercell" rowspan="2">
787 <a href="http://jakarta.apache.org/">
788 <img src="http://jakarta.apache.org/images/jakarta-logo.gif" alt="http://jakarta.apache.org" align="left" border="0"/>
789 </a>
790 </td>
791 <td style="text-align:right"><h2>Source Code Metrics</h2></td>
792 </tr>
793 <tr>
794 <td style="text-align:right">Designed for use with <a href='http://www.webgain.com/products/quality_analyzer/'>Webgain QA/Metamata Metrics</a> and <a href='http://jakarta.apache.org'>Ant</a>.</td>
795 </tr>
796 </table>
797 <hr size="1"/>
798</xsl:template>
799
800<!-- Page Footer -->
801<xsl:template name="pageFooter">
802 <table width="100%">
803 <tr><td><hr noshade="yes" size="1"/></td></tr>
804 <tr><td>
805 <div align="center"><font color="#525D76" size="-1"><em>
806 Copyright &#169; 1999-2001, Apache Software Foundation
807 </em></font></div>
808 </td></tr>
809 </table>
810</xsl:template>
811
812<!-- class header -->
813<xsl:template name="all.metrics.header">
814 <tr>
815 <th width="80%">Name</th>
816 <th nowrap="nowrap">V(G)</th>
817 <th>LOC</th>
818 <th>DIT</th>
819 <th>NOA</th>
820 <th>NRM</th>
821 <th>NLM</th>
822 <th>WMC</th>
823 <th>RFC</th>
824 <th>DAC</th>
825 <th>FANOUT</th>
826 <th>CBO</th>
827 <th>LCOM</th>
828 <th>NOCL</th>
829 </tr>
830</xsl:template>
831
832<!-- method header -->
833<xsl:template name="method.metrics.header">
834 <tr>
835 <th width="80%">Name</th>
836 <th nowrap="nowrap">V(G)</th>
837 <th>LOC</th>
838 <th>FANOUT</th>
839 <th>CBO</th>
840 </tr>
841</xsl:template>
842
843<!-- method information -->
844<xsl:template match="method" mode="print.metrics">
845 <tr>
846 <xsl:call-template name="alternate-row"/>
847 <td><xsl:apply-templates select="@name"/></td>
848 <td><xsl:apply-templates select="@vg"/></td>
849 <td><xsl:apply-templates select="@loc"/></td>
850 <td><xsl:apply-templates select="@fanout"/></td>
851 <td><xsl:apply-templates select="@cbo"/></td>
852 </tr>
853</xsl:template>
854
855<!-- class information -->
856<xsl:template match="class" mode="print.metrics">
857 <tr>
858 <xsl:call-template name="alternate-row"/>
859 <td><a href="{@name}.html"><xsl:value-of select="@name"/></a></td>
860 <td><xsl:apply-templates select="@vg"/></td>
861 <td><xsl:apply-templates select="@loc"/></td>
862 <td><xsl:apply-templates select="@dit"/></td>
863 <td><xsl:apply-templates select="@noa"/></td>
864 <td><xsl:apply-templates select="@nrm"/></td>
865 <td><xsl:apply-templates select="@nlm"/></td>
866 <td><xsl:apply-templates select="@wmc"/></td>
867 <td><xsl:apply-templates select="@rfc"/></td>
868 <td><xsl:apply-templates select="@dac"/></td>
869 <td><xsl:apply-templates select="@fanout"/></td>
870 <td><xsl:apply-templates select="@cbo"/></td>
871 <td><xsl:apply-templates select="@lcom"/></td>
872 <td><xsl:apply-templates select="@nocl"/></td>
873 </tr>
874</xsl:template>
875
876<xsl:template match="file|package" mode="print.metrics">
877 <tr>
878 <xsl:call-template name="alternate-row"/>
879 <td>
880 <a href="{translate(@name,'.','/')}/package-summary.html" target="classFrame">
881 <xsl:value-of select="@name"/>
882 </a>
883 </td>
884 <td><xsl:apply-templates select="@vg"/></td>
885 <td><xsl:apply-templates select="@loc"/></td>
886 <td><xsl:apply-templates select="@dit"/></td>
887 <td><xsl:apply-templates select="@noa"/></td>
888 <td><xsl:apply-templates select="@nrm"/></td>
889 <td><xsl:apply-templates select="@nlm"/></td>
890 <td><xsl:apply-templates select="@wmc"/></td>
891 <td><xsl:apply-templates select="@rfc"/></td>
892 <td><xsl:apply-templates select="@dac"/></td>
893 <td><xsl:apply-templates select="@fanout"/></td>
894 <td><xsl:apply-templates select="@cbo"/></td>
895 <td><xsl:apply-templates select="@lcom"/></td>
896 <td><xsl:apply-templates select="@nocl"/></td>
897 </tr>
898</xsl:template>
899
900<xsl:template match="metrics" mode="print.metrics">
901 <tr>
902 <xsl:call-template name="alternate-row"/>
903 <!-- the global metrics is the top package metrics -->
904 <td><xsl:apply-templates select="./package/@vg"/></td>
905 <td><xsl:apply-templates select="./package/@loc"/></td>
906 <td><xsl:apply-templates select="./package/@dit"/></td>
907 <td><xsl:apply-templates select="./package/@noa"/></td>
908 <td><xsl:apply-templates select="./package/@nrm"/></td>
909 <td><xsl:apply-templates select="./package/@nlm"/></td>
910 <td><xsl:apply-templates select="./package/@wmc"/></td>
911 <td><xsl:apply-templates select="./package/@rfc"/></td>
912 <td><xsl:apply-templates select="./package/@dac"/></td>
913 <td><xsl:apply-templates select="./package/@fanout"/></td>
914 <td><xsl:apply-templates select="./package/@cbo"/></td>
915 <td><xsl:apply-templates select="./package/@lcom"/></td>
916 <td><xsl:apply-templates select="./package/@nocl"/></td>
917 </tr>
918</xsl:template>
919
920<!-- alternated row style -->
921<xsl:template name="alternate-row">
922<xsl:attribute name="class">
923 <xsl:if test="position() mod 2 = 1">a</xsl:if>
924 <xsl:if test="position() mod 2 = 0">b</xsl:if>
925</xsl:attribute>
926</xsl:template>
927
928
929<!-- how to display the metrics with their max value -->
930<!-- @todo the max values must be external to the xsl -->
931
932 <xsl:template match="@vg">
933 <xsl:call-template name="display-value">
934 <xsl:with-param name="value" select="current()"/>
935 <xsl:with-param name="max" select="$vg.max"/>
936 </xsl:call-template>
937 </xsl:template>
938
939 <xsl:template match="@loc">
940 <xsl:call-template name="display-value">
941 <xsl:with-param name="value" select="current()"/>
942 <xsl:with-param name="max" select="$loc.max"/>
943 </xsl:call-template>
944 </xsl:template>
945
946 <xsl:template match="@dit">
947 <xsl:call-template name="display-value">
948 <xsl:with-param name="value" select="current()"/>
949 <xsl:with-param name="max" select="$dit.max"/>
950 </xsl:call-template>
951 </xsl:template>
952
953 <xsl:template match="@noa">
954 <xsl:call-template name="display-value">
955 <xsl:with-param name="value" select="current()"/>
956 <xsl:with-param name="max" select="$noa.max"/>
957 </xsl:call-template>
958 </xsl:template>
959
960 <xsl:template match="@nrm">
961 <xsl:call-template name="display-value">
962 <xsl:with-param name="value" select="current()"/>
963 <xsl:with-param name="max" select="$nrm.max"/>
964 </xsl:call-template>
965 </xsl:template>
966
967 <xsl:template match="@nlm">
968 <xsl:call-template name="display-value">
969 <xsl:with-param name="value" select="current()"/>
970 <xsl:with-param name="max" select="$nlm.max"/>
971 </xsl:call-template>
972 </xsl:template>
973
974 <xsl:template match="@wmc">
975 <xsl:call-template name="display-value">
976 <xsl:with-param name="value" select="current()"/>
977 <xsl:with-param name="max" select="$wmc.max"/>
978 </xsl:call-template>
979 </xsl:template>
980
981 <xsl:template match="@rfc">
982 <xsl:call-template name="display-value">
983 <xsl:with-param name="value" select="current()"/>
984 <xsl:with-param name="max" select="$rfc.max"/>
985 </xsl:call-template>
986 </xsl:template>
987
988 <xsl:template match="@dac">
989 <xsl:call-template name="display-value">
990 <xsl:with-param name="value" select="current()"/>
991 <xsl:with-param name="max" select="$dac.max"/>
992 </xsl:call-template>
993 </xsl:template>
994
995 <xsl:template match="@fanout">
996 <xsl:call-template name="display-value">
997 <xsl:with-param name="value" select="current()"/>
998 <xsl:with-param name="max" select="$fanout.max"/>
999 </xsl:call-template>
1000 </xsl:template>
1001
1002 <xsl:template match="@cbo">
1003 <xsl:call-template name="display-value">
1004 <xsl:with-param name="value" select="current()"/>
1005 <xsl:with-param name="max" select="$cbo.max"/>
1006 </xsl:call-template>
1007 </xsl:template>
1008
1009 <xsl:template match="@lcom">
1010 <xsl:call-template name="display-value">
1011 <xsl:with-param name="value" select="current()"/>
1012 <xsl:with-param name="max" select="$lcom.max"/>
1013 </xsl:call-template>
1014 </xsl:template>
1015
1016 <xsl:template match="@nocl">
1017 <xsl:call-template name="display-value">
1018 <xsl:with-param name="value" select="current()"/>
1019 <xsl:with-param name="max" select="$nocl.max"/>
1020 </xsl:call-template>
1021 </xsl:template>
1022
1023 <xsl:template name="display-value">
1024 <xsl:param name="value"/>
1025 <xsl:param name="max"/>
1026 <xsl:if test="$value > $max">
1027 <xsl:attribute name="class">Error</xsl:attribute>
1028 </xsl:if>
1029 <xsl:value-of select="$value"/>
1030 </xsl:template>
1031
1032</xsl:stylesheet>
1033