public static String extractPackageFromStackTraceElement ( StackTraceElement element ) { String className = element . getClassName ( ) ; int lastDotIndex = className . lastIndexOf ( "." ) ; String packageName ; if ( lastDotIndex > 0 ) { packageName = className . substring ( 0 , lastDotIndex ) ; } else { packageName = className ; } return packageName ; }
Work out the package name from a StackTraceElement . This is easier than a stack trace line because we already know the class name .