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