KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > report > AnalysisModuleData


1 /*
2  * @(#)AnalysisModuleData.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.report;
28
29
30 import java.io.IOException JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
35 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
36 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogReader;
37 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogRecord;
38 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader;
39 import net.sourceforge.groboutils.codecoverage.v2.datastore.ClassRecord;
40 import net.sourceforge.groboutils.codecoverage.v2.datastore.IClassMetaDataReader;
41 import net.sourceforge.groboutils.codecoverage.v2.datastore.IMetaDataReader;
42 import net.sourceforge.groboutils.codecoverage.v2.datastore.MarkRecord;
43
44
45 /**
46  * Combine all post-compilation data along with the coverage logs for
47  * a specific analysis module.
48  *
49  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
50  * @version $Date: 2004/04/15 05:48:26 $
51  * @since December 17, 2002
52  * @see IAnalysisMetaData
53  */

54 public class AnalysisModuleData
55 {
56     private IChannelLogReader logReader;
57     private IClassMetaDataReader mdReader;
58     private IAnalysisModule am;
59     
60     
61     /**
62      *
63      */

64     public AnalysisModuleData( IAnalysisModule module,
65             IMetaDataReader mdr, IChannelLogReader clr )
66             throws IOException JavaDoc
67     {
68         if (module == null || mdr == null || clr == null)
69         {
70             throw new IllegalArgumentException JavaDoc( "No null args." );
71         }
72         this.mdReader = mdr.getClassReader( module );
73         this.logReader = clr;
74         this.am = module;
75     }
76     
77     
78     /**
79      * Retrieves the corresponding analysis module.
80      */

81     public IAnalysisModule getAnalysisModule()
82     {
83         return this.am;
84     }
85     
86     
87     /**
88      * Return the list of all class signatures for the module from the
89      * post-compilation reader.
90      */

91     public String JavaDoc[] getClassSignatures()
92             throws IOException JavaDoc
93     {
94         String JavaDoc cs[] = this.mdReader.getClassSignatures();
95         return cs;
96     }
97     
98     
99     /**
100      * Retrieves the class record with all marks.
101      */

102     public ClassRecord getClassRecord( String JavaDoc classSig )
103             throws IOException JavaDoc
104     {
105         return this.mdReader.readClass( classSig );
106     }
107     
108     
109     /**
110      * Retrieves all the mark records for the given class.
111      */

112     public MarkRecord[] getAllClassMarks( String JavaDoc classSig )
113             throws IOException JavaDoc
114     {
115         return getClassRecord( classSig ).getMarksForAnalysisModule( this.am );
116     }
117     
118     
119     /**
120      * Retrieves all unique log records for this module.
121      */

122     public IChannelLogRecord[] getChannelLogRecords( String JavaDoc classSig )
123             throws IOException JavaDoc
124     {
125         Set JavaDoc set = new HashSet JavaDoc();
126         IClassChannelLogReader reader = this.logReader.
127             getReaderForClassSignature( classSig );
128         IChannelLogRecord clr = reader.nextRecord();
129         while (clr != null)
130         {
131             set.add( clr );
132             clr = reader.nextRecord();
133         }
134         
135         IChannelLogRecord[] records = (IChannelLogRecord[])set.toArray(
136             new IChannelLogRecord[ set.size() ] );
137         return records;
138     }
139     
140     
141     /**
142      * Retrieves the sorted (by covered/not covered) set of marks
143      * for the class.
144      */

145     public ClassMarkSet createClassMarkSet( String JavaDoc classSig )
146             throws IOException JavaDoc
147     {
148         ClassRecord cr = getClassRecord( classSig );
149         ClassMarkSet cms = new ClassMarkSet(
150             cr.getClassName(),
151             cr.getMethods(),
152             getAllClassMarks( classSig ),
153             getChannelLogRecords( classSig ) );
154         return cms;
155     }
156 }
157
158
Popular Tags