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 {
11 public static final String METHOD_CALLED = "METHOD_CALLED";
20 public Location(SourceLine sourceLine)
25 public Location(BugMethod method)
27 init(method.getSourceLines());
28 m_className = method.getClassName();
29 m_methodName = method.getMethodName();
30 m_methodRole = method.getRole();
33 public Location(BugMethod method, SourceLine sourceLine)
36 m_className = method.getClassName();
37 m_methodName = method.getMethodName();
38 m_methodRole = method.getRole();
41 public Location(BugClass bugClass)
43 init(bugClass.getSourceLines());
44 m_className = bugClass.getClassName();
47 public Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
50 m_className = className;
51 m_methodName = methodName;
52 m_methodRole = methodRole;
53 m_startLine = startLine;
57 public String getClassName() { return m_className; }
58 public String getMethodName() { return m_methodName; }
59 public String getMethodRole() { return m_methodRole; }
60 public int getStart() { return (null == m_startLine) ? (-1) : m_startLine.intValue(); }
61 public int getEnd() { return (null == m_endLine) ? (-1) : m_endLine.intValue(); }
63 public void dump(PrintWriter pw, int indent)
65 String margin = String.format("%" + indent + "s", "");
66 String tab = margin + " ";
67 pw.println(margin + "Location");
68 if (null != m_className) {
69 pw.println(tab + "classname = " + m_className);
71 if (null != m_methodName) {
72 if (null != m_methodRole) {
73 pw.println(tab + "method = " + m_methodName + " (" + m_methodRole + ")");
76 pw.println(tab + "method = " + m_methodName);
79 if (null != m_startLine) {
80 pw.println(tab + "lines = " + m_startLine + " .. " + m_endLine);
84 public boolean fuzzyEquals(Location that)
90 if (! Util.objsAreEqual(this.m_className, that.m_className)) {
94 if (! Util.objsAreEqual(this.m_methodName, that.m_methodName)) {
98 if (! Util.objsAreEqual(this.m_methodRole, that.m_methodRole)) {
106 public boolean equals(Object other)
111 if (other instanceof Location) {
112 return fuzzyEquals((Location)other);
118 public int hashCode()
120 return Util.objHashCode(m_className)
121 ^ Util.objHashCode(m_methodName)
122 ^ Util.objHashCode(m_methodRole);
125 private void init(SourceLine[] sourceLines)
127 if (sourceLines.length > 0) {
128 assert(null != sourceLines[0]);
129 init(sourceLines[0]);
133 private void init(SourceLine sourceLine)
135 init(sourceLine.getClassName(), sourceLine.getStart(), sourceLine.getEnd());
138 private void init(String className, int startLine, int endLine)
141 m_className = className;
144 m_startLine = startLine;