}, as per Section 3.9 of The Java Virtual
jaroslav@52: * Machine Specification.
jaroslav@52: *
jaroslav@52: * @return the name of the method containing the execution point
jaroslav@52: * represented by this stack trace element.
jaroslav@52: */
jaroslav@52: public String getMethodName() {
jaroslav@52: return methodName;
jaroslav@52: }
jaroslav@52:
jaroslav@52: /**
jaroslav@52: * Returns true if the method containing the execution point
jaroslav@52: * represented by this stack trace element is a native method.
jaroslav@52: *
jaroslav@52: * @return {@code true} if the method containing the execution point
jaroslav@52: * represented by this stack trace element is a native method.
jaroslav@52: */
jaroslav@52: public boolean isNativeMethod() {
jaroslav@52: return lineNumber == -2;
jaroslav@52: }
jaroslav@52:
jaroslav@52: /**
jaroslav@52: * Returns a string representation of this stack trace element. The
jaroslav@52: * format of this string depends on the implementation, but the following
jaroslav@52: * examples may be regarded as typical:
jaroslav@52: *
jaroslav@52: * -
jaroslav@52: * {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
jaroslav@52: * is the fully-qualified name of the class containing the
jaroslav@52: * execution point represented by this stack trace element,
jaroslav@52: * {@code "mash"} is the name of the method containing the execution
jaroslav@52: * point, {@code "MyClass.java"} is the source file containing the
jaroslav@52: * execution point, and {@code "9"} is the line number of the source
jaroslav@52: * line containing the execution point.
jaroslav@52: *
-
jaroslav@52: * {@code "MyClass.mash(MyClass.java)"} - As above, but the line
jaroslav@52: * number is unavailable.
jaroslav@52: *
-
jaroslav@52: * {@code "MyClass.mash(Unknown Source)"} - As above, but neither
jaroslav@52: * the file name nor the line number are available.
jaroslav@52: *
-
jaroslav@52: * {@code "MyClass.mash(Native Method)"} - As above, but neither
jaroslav@52: * the file name nor the line number are available, and the method
jaroslav@52: * containing the execution point is known to be a native method.
jaroslav@52: *
jaroslav@52: * @see Throwable#printStackTrace()
jaroslav@52: */
jaroslav@52: public String toString() {
jaroslav@52: return getClassName() + "." + methodName +
jaroslav@52: (isNativeMethod() ? "(Native Method)" :
jaroslav@52: (fileName != null && lineNumber >= 0 ?
jaroslav@52: "(" + fileName + ":" + lineNumber + ")" :
jaroslav@52: (fileName != null ? "("+fileName+")" : "(Unknown Source)")));
jaroslav@52: }
jaroslav@52:
jaroslav@52: /**
jaroslav@52: * Returns true if the specified object is another
jaroslav@52: * {@code StackTraceElement} instance representing the same execution
jaroslav@52: * point as this instance. Two stack trace elements {@code a} and
jaroslav@52: * {@code b} are equal if and only if:
jaroslav@52: *
jaroslav@52: * equals(a.getFileName(), b.getFileName()) &&
jaroslav@52: * a.getLineNumber() == b.getLineNumber()) &&
jaroslav@52: * equals(a.getClassName(), b.getClassName()) &&
jaroslav@52: * equals(a.getMethodName(), b.getMethodName())
jaroslav@52: *
jaroslav@52: * where {@code equals} has the semantics of {@link
jaroslav@52: * java.util.Objects#equals(Object, Object) Objects.equals}.
jaroslav@52: *
jaroslav@52: * @param obj the object to be compared with this stack trace element.
jaroslav@52: * @return true if the specified object is another
jaroslav@52: * {@code StackTraceElement} instance representing the same
jaroslav@52: * execution point as this instance.
jaroslav@52: */
jaroslav@52: public boolean equals(Object obj) {
jaroslav@52: if (obj==this)
jaroslav@52: return true;
jaroslav@52: if (!(obj instanceof StackTraceElement))
jaroslav@52: return false;
jaroslav@52: StackTraceElement e = (StackTraceElement)obj;
jaroslav@52: return e.declaringClass.equals(declaringClass) &&
jaroslav@52: e.lineNumber == lineNumber &&
jaroslav@65: equals(methodName, e.methodName) &&
jaroslav@65: equals(fileName, e.fileName);
jaroslav@52: }
jaroslav@52:
jaroslav@52: /**
jaroslav@52: * Returns a hash code value for this stack trace element.
jaroslav@52: */
jaroslav@52: public int hashCode() {
jaroslav@52: int result = 31*declaringClass.hashCode() + methodName.hashCode();
jaroslav@65: result = 31*result + (fileName == null ? 0 : fileName.hashCode());
jaroslav@52: result = 31*result + lineNumber;
jaroslav@52: return result;
jaroslav@52: }
jaroslav@65:
jaroslav@65: private static boolean equals(Object a, Object b) {
jaroslav@65: return (a == b) || (a != null && a.equals(b));
jaroslav@65: }
jaroslav@52:
jaroslav@52: private static final long serialVersionUID = 6992337162326171013L;
jaroslav@52: }