static public String getSourceCodeRelativePathForStackTraceElement ( StackTraceElement ste ) { String packageName = ste . getClassName ( ) ; // e.g. com.fizzed.test.Application$1 for an internal class int pos = packageName . lastIndexOf ( ' ' ) ; if ( pos > 0 ) { packageName = packageName . substring ( 0 , pos ) ; return packageName . replace ( "." , File . separator ) + File . separator + ste . getFileName ( ) ; } else { // must be in default package return ste . getFileName ( ) ; } }
Calculates the relative path of the source code file of a StackTrace element if its available . Uses the packageName of the class to create a relative path and appends the filename included with the stack trace element .