001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.com
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: *
023: * * Created on Apr 11, 2004
024: *
025: */
026: package org.hammurapi.inspectors.metrics;
027:
028: import java.util.HashSet;
029: import java.util.Set;
030:
031: import org.w3c.dom.Document;
032: import org.w3c.dom.Element;
033:
034: import com.pavelvlasov.jsel.JselException;
035: import com.pavelvlasov.jsel.TypeBody;
036: import com.pavelvlasov.jsel.TypeDefinition;
037: import com.pavelvlasov.jsel.TypeSpecification;
038: import com.pavelvlasov.review.SourceMarker;
039:
040: /**
041: * @author mucbj0
042: *
043: * JDepend
044: *
045: * Afferent Couplings (Ca)
046: * The number of other packages that depend upon classes within the package
047: * is an indicator of the package's responsibility.
048: *
049: * Efferent Couplings (Ce)
050: * The number of other packages that the classes in the package depend upon
051: * is an indicator of the package's independence.
052: *
053: * */
054: public class CouplingMetricOfClass extends CouplingMetric {
055: public SourceMarker srcMrk = null;
056: public String name = "";
057: public Set listAfferentTypes = new HashSet();
058: public Set listEfferentTypes = new HashSet();
059:
060: public CouplingMetricOfClass(TypeDefinition c) {
061: super ();
062: name = c.getFcn();
063:
064: srcMrk = (SourceMarker) c;
065: }
066:
067: public CouplingMetricOfClass(TypeBody c) {
068: super ();
069: name = c.getFcn();
070:
071: srcMrk = (SourceMarker) c;
072: }
073:
074: public CouplingMetricOfClass(TypeSpecification c)
075: throws JselException {
076: super ();
077: name = c.getName();
078: srcMrk = (SourceMarker) c;
079: }
080:
081: public String toString() {
082: return this .name + " CaV: " + afferentVariableCounter
083: + " CeV: " + efferentVariableCounter;
084: }
085:
086: /*
087: public StringBuffer toXml() {
088: StringBuffer sb = new StringBuffer();
089:
090: sb.append("<CouplingMetricOfClass ");
091: sb.append(" type=\"");
092: sb.append(type.getClassName());
093: sb.append("\" signature=\"");
094: sb.append(type.getSignature());
095: sb.append("\" isAbstract=\"");
096: sb.append(type.isAbstract());
097: sb.append("\" isInterface=\"");
098: sb.append(type.isInterface());
099:
100: sb.append("\">");
101: sb.append( super.toXmlCore() );
102:
103: sb.append("<ListAfferentTypes>");
104: for (Iterator it = this.listAfferentTypes.iterator(); it.hasNext();){
105: Type t = (Type)it.next();
106: sb.append( t.toXmlSlim() );
107: }
108: sb.append("</ListAfferentTypes>");
109: sb.append("<ListEfferentTypes>");
110: for (Iterator it = this.listEfferentTypes.iterator(); it.hasNext();){
111: Type t = (Type)it.next();
112: sb.append( t.toXmlSlim() );
113: }
114: sb.append("</ListEfferentTypes>");
115:
116: sb.append("</CouplingMetricOfClass>");
117: return sb;
118: }
119: */
120:
121: public Element toDom(Document document) {
122:
123: Element ret = document.createElement("CouplingMetricOfClass");
124: ret.setAttribute("type", name);
125: ret.setAttribute("sourceMarker", srcMrk.getSourceURL());
126: ret.setAttribute("sourceMarkerLine", String.valueOf(srcMrk
127: .getLine()));
128: ret.setAttribute("sourceMarkerColumn", String.valueOf(srcMrk
129: .getColumn()));
130: // ret.setAttribute("signature", type.getSignature() );
131: // ret.setAttribute("isAbstract", type.isAbstract() );
132: // ret.setAttribute("isInterface", type.isInterface() );
133: super .toDom(document, ret);
134:
135: Element lat = document.createElement("ListAfferentTypes");
136: ret.appendChild(lat);
137:
138: return ret;
139: }
140:
141: }
|