}, 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(my.module@9.0/MyClass.java:101)"} - 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 "my.module"} is the module name, {@code "9.0"} is the
* module version, and {@code "101"} is the line number of the source
* line containing the execution point.
*
-
* {@code "MyClass.mash(my.module@9.0/MyClass.java)"} - As above, but the
* line number is unavailable.
*
-
* {@code "MyClass.mash(my.module@9.0/Unknown Source)"} - As above, but
* neither the file name nor the line number are available.
*
-
* {@code "MyClass.mash(my.module@9.0/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.
*
* If the execution point is not in a named module, {@code "my.module@9.0/"}
* will be omitted from the above.
*
* @see Throwable#printStackTrace()
*/
public String toString() {
String mid = "";
if (moduleName != null) {
mid = moduleName;
if (moduleVersion != null)
mid += "@" + moduleVersion;
mid += "/";
}
return getClassName() + "." + methodName + "(" + mid +
(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:
* {@code
* equals(a.getFileName(), b.getFileName()) &&
* a.getLineNumber() == b.getLineNumber()) &&
* equals(a.getModuleName(), b.getModuleName()) &&
* equals(a.getModuleVersion(), b.getModuleVersion()) &&
* 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) &&
Objects.equals(moduleName, e.moduleName) &&
Objects.equals(moduleVersion, e.moduleVersion) &&
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(moduleName);
result = 31*result + Objects.hashCode(moduleVersion);
result = 31*result + Objects.hashCode(fileName);
result = 31*result + lineNumber;
return result;
}
private static final long serialVersionUID = 6992337162326171013L;
}