Untitled
unknown
plain_text
10 months ago
1.2 kB
11
Indexable
private static String getMethodNameFromBatchBase() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
String callerClass = stackTrace[3].getClassName();
try {
Class<?> clazz = Class.forName(callerClass);
// Iterate through the class hierarchy to find the first subclass of BatchBase
while (clazz != null) {
if (BatchBase.class.isAssignableFrom(clazz)) {
// Return the method name from the BatchBase class
StackTraceElement[] batchBaseStackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement element : batchBaseStackTrace) {
if (element.getClassName().equals(clazz.getName())) {
return element.getMethodName();
}
}
}
clazz = clazz.getSuperclass(); // Move up the class hierarchy
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return getCallerMethodName(); // Fallback to the method name if no subclass is found
}Editor is loading...
Leave a Comment