001: /*
002: * @(#)MarkRecord.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.datastore;
028:
029: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
030:
031: /**
032: * Contains data associated with an analysis module's bytecode instruction
033: * mark. It should be associated with a particular class.
034: *
035: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
036: * @version $Date: 2003/11/25 13:10:41 $
037: * @since December 15, 2002
038: */
039: public class MarkRecord {
040: private IAnalysisMetaData amd;
041: private String analysisModule;
042: private String methodSignature;
043: private short markIndex;
044:
045: private short amIndex = -1;
046: private short methIndex = -1;
047: private int lineNo = -1;
048:
049: /**
050: * @param data cannot be <tt>null</tt>.
051: * @param am the analysis module that made this mark.
052: * @param methSig the method signature where this mark was placed.
053: * @param lineNumber the Java source line corresponding to this mark.
054: */
055: public MarkRecord(IAnalysisMetaData data, String am,
056: String methSig, short markId, int lineNumber) {
057: if (data == null || am == null || methSig == null) {
058: throw new IllegalArgumentException("No null args.");
059: }
060: if (markId < 0) {
061: throw new IllegalArgumentException(
062: "Indicies cannot be less than 0.");
063: }
064: this .amd = data;
065: this .analysisModule = am;
066: this .methodSignature = methSig;
067: this .markIndex = markId;
068: this .lineNo = lineNumber;
069: }
070:
071: /**
072: * @see ClassRecord#addMark( MarkRecord )
073: */
074: void processMark(ClassRecord cr, AnalysisModuleSet ams) {
075: if (cr == null) {
076: throw new IllegalArgumentException("No null args.");
077: }
078: if (ams == null) {
079: ams = cr.getAnalysisModuleSet();
080: }
081: this .amIndex = ams.getMeasureIndex(getAnalysisModule());
082: this .methIndex = cr.getMethodIndex(getMethodSignature());
083: }
084:
085: public boolean equals(Object o) {
086: if (o == null || !(o instanceof MarkRecord)) {
087: return false;
088: }
089: if (this == o) {
090: return true;
091: }
092:
093: // line number doesn't add into the equals.
094: MarkRecord mr = (MarkRecord) o;
095: if (mr.analysisModule.equals(this .analysisModule)
096: && mr.methodSignature.equals(this .methodSignature)
097: && mr.markIndex == this .markIndex) {
098: // the amd object doesn't have to match.
099: return true;
100: }
101: // else
102: return false;
103: }
104:
105: public int hashCode() {
106: return (int) this .markIndex + this .analysisModule.hashCode()
107: + this .methodSignature.hashCode();
108: }
109:
110: public IAnalysisMetaData getAnalysisMetaData() {
111: return this .amd;
112: }
113:
114: public String getAnalysisModule() {
115: return this .analysisModule;
116: }
117:
118: public short getAnalysisModuleIndex() {
119: if (this .amIndex < 0) {
120: throw new IllegalStateException(
121: "Never processed or unknown module '"
122: + this .analysisModule + "'.");
123: }
124: return this .amIndex;
125: }
126:
127: public String getMethodSignature() {
128: return this .methodSignature;
129: }
130:
131: public short getMethodIndex() {
132: if (this .methIndex < 0) {
133: throw new IllegalStateException(
134: "Never processed or unknown method '"
135: + this .methodSignature + "'.");
136: }
137: return this .methIndex;
138: }
139:
140: public short getMarkIndex() {
141: return this .markIndex;
142: }
143:
144: public int getLineNumber() {
145: return this .lineNo;
146: }
147:
148: public String toString() {
149: return "Mark Record: " + getMethodSignature() + ", mark "
150: + getMarkIndex();
151: }
152: }
|