1 package net.jaekl.cfb.store;
3 import java.io.PrintWriter;
5 import net.jaekl.cfb.util.Util;
6 import net.jaekl.cfb.xml.BugClass;
7 import net.jaekl.cfb.xml.BugMethod;
8 import net.jaekl.cfb.xml.SourceLine;
10 public class Location {
18 public Location(SourceLine sourceLine)
23 public Location(BugMethod method)
25 init(method.getSourceLines());
26 m_className = method.getClassName();
27 m_methodName = method.getMethodName();
28 m_methodRole = method.getRole();
31 public Location(BugMethod method, SourceLine sourceLine)
34 m_className = method.getClassName();
35 m_methodName = method.getMethodName();
36 m_methodRole = method.getRole();
39 public Location(BugClass bugClass)
41 init(bugClass.getSourceLines());
42 m_className = bugClass.getClassName();
45 public Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
48 m_className = className;
49 m_methodName = methodName;
50 m_methodRole = methodRole;
51 m_startLine = startLine;
55 public String getClassName() { return m_className; }
56 public String getMethodName() { return m_methodName; }
57 public String getMethodRole() { return m_methodRole; }
58 public int getStart() { return m_startLine; }
59 public int getEnd() { return m_endLine; }
61 public void dump(PrintWriter pw, int indent)
63 String margin = String.format("%" + indent + "s", "");
64 String tab = margin + " ";
65 pw.println(margin + "Location");
66 if (null != m_className) {
67 pw.println(tab + "classname = " + m_className);
69 if (null != m_methodName) {
70 if (null != m_methodRole) {
71 pw.println(tab + "method = " + m_methodName + " (" + m_methodRole + ")");
74 pw.println(tab + "method = " + m_methodName);
77 if (null != m_startLine) {
78 pw.println(tab + "lines = " + m_startLine + " .. " + m_endLine);
82 public boolean fuzzyEquals(Location that)
88 if (! Util.objsAreEqual(this.m_className, that.m_className)) {
92 if (! Util.objsAreEqual(this.m_methodName, that.m_methodName)) {
96 if (! Util.objsAreEqual(this.m_methodRole, that.m_methodRole)) {
104 public boolean equals(Object other)
109 if (other instanceof Location) {
110 return fuzzyEquals((Location)other);
116 public int hashCode()
118 return Util.objHashCode(m_className)
119 ^ Util.objHashCode(m_methodName)
120 ^ Util.objHashCode(m_methodRole);
123 private void init(SourceLine[] sourceLines)
125 if (sourceLines.length > 0) {
126 assert(null != sourceLines[0]);
127 init(sourceLines[0]);
131 private void init(SourceLine sourceLine)
133 init(sourceLine.getClassName(), sourceLine.getStart(), sourceLine.getEnd());
136 private void init(String className, int startLine, int endLine)
139 m_className = className;
142 m_startLine = startLine;