001: /*
002: * @(#)AnalysisModuleData.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.report;
028:
029: import java.io.IOException;
030: import java.util.HashSet;
031: import java.util.Set;
032:
033: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
034: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
035: import net.sourceforge.groboutils.codecoverage.v2.IChannelLogReader;
036: import net.sourceforge.groboutils.codecoverage.v2.IChannelLogRecord;
037: import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader;
038: import net.sourceforge.groboutils.codecoverage.v2.datastore.ClassRecord;
039: import net.sourceforge.groboutils.codecoverage.v2.datastore.IClassMetaDataReader;
040: import net.sourceforge.groboutils.codecoverage.v2.datastore.IMetaDataReader;
041: import net.sourceforge.groboutils.codecoverage.v2.datastore.MarkRecord;
042:
043: /**
044: * Combine all post-compilation data along with the coverage logs for
045: * a specific analysis module.
046: *
047: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
048: * @version $Date: 2004/04/15 05:48:26 $
049: * @since December 17, 2002
050: * @see IAnalysisMetaData
051: */
052: public class AnalysisModuleData {
053: private IChannelLogReader logReader;
054: private IClassMetaDataReader mdReader;
055: private IAnalysisModule am;
056:
057: /**
058: *
059: */
060: public AnalysisModuleData(IAnalysisModule module,
061: IMetaDataReader mdr, IChannelLogReader clr)
062: throws IOException {
063: if (module == null || mdr == null || clr == null) {
064: throw new IllegalArgumentException("No null args.");
065: }
066: this .mdReader = mdr.getClassReader(module);
067: this .logReader = clr;
068: this .am = module;
069: }
070:
071: /**
072: * Retrieves the corresponding analysis module.
073: */
074: public IAnalysisModule getAnalysisModule() {
075: return this .am;
076: }
077:
078: /**
079: * Return the list of all class signatures for the module from the
080: * post-compilation reader.
081: */
082: public String[] getClassSignatures() throws IOException {
083: String cs[] = this .mdReader.getClassSignatures();
084: return cs;
085: }
086:
087: /**
088: * Retrieves the class record with all marks.
089: */
090: public ClassRecord getClassRecord(String classSig)
091: throws IOException {
092: return this .mdReader.readClass(classSig);
093: }
094:
095: /**
096: * Retrieves all the mark records for the given class.
097: */
098: public MarkRecord[] getAllClassMarks(String classSig)
099: throws IOException {
100: return getClassRecord(classSig).getMarksForAnalysisModule(
101: this .am);
102: }
103:
104: /**
105: * Retrieves all unique log records for this module.
106: */
107: public IChannelLogRecord[] getChannelLogRecords(String classSig)
108: throws IOException {
109: Set set = new HashSet();
110: IClassChannelLogReader reader = this .logReader
111: .getReaderForClassSignature(classSig);
112: IChannelLogRecord clr = reader.nextRecord();
113: while (clr != null) {
114: set.add(clr);
115: clr = reader.nextRecord();
116: }
117:
118: IChannelLogRecord[] records = (IChannelLogRecord[]) set
119: .toArray(new IChannelLogRecord[set.size()]);
120: return records;
121: }
122:
123: /**
124: * Retrieves the sorted (by covered/not covered) set of marks
125: * for the class.
126: */
127: public ClassMarkSet createClassMarkSet(String classSig)
128: throws IOException {
129: ClassRecord cr = getClassRecord(classSig);
130: ClassMarkSet cms = new ClassMarkSet(cr.getClassName(), cr
131: .getMethods(), getAllClassMarks(classSig),
132: getChannelLogRecords(classSig));
133: return cms;
134: }
135: }
|