Changeset 10899 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-08-25T23:21:10+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
r10886 r10899 6 6 import java.io.StringWriter; 7 7 import java.util.concurrent.CopyOnWriteArrayList; 8 import java.util.function.Predicate; 8 9 9 10 import org.openstreetmap.josm.actions.ShowStatusReportAction; … … 185 186 */ 186 187 public static String getCallingMethod(int offset) { 188 String className = BugReport.class.getName(); 189 String methodName = "getCallingMethod"; 190 StackTraceElement found = getCallingMethod(offset, className, methodName::equals); 191 if (found != null) { 192 return found.getClassName().replaceFirst(".*\\.", "") + '#' + found.getMethodName(); 193 } else { 194 return "?"; 195 } 196 } 197 198 /** 199 * Find the method that called the given method on the current stack trace. 200 * @param offset 201 * How many methods to look back in the stack trace. 1 gives the method calling this method, 0 gives you getCallingMethod(). 202 * @param className The name of the class to search for 203 * @param methodName The name of the method to search for 204 * @return The class and method name or null if it is unknown. 205 */ 206 public static StackTraceElement getCallingMethod(int offset, String className, Predicate<String> methodName) { 187 207 StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); 188 String className = BugReport.class.getName();189 208 for (int i = 0; i < stackTrace.length - offset; i++) { 190 209 StackTraceElement element = stackTrace[i]; 191 if (className.equals(element.getClassName()) && "getCallingMethod".equals(element.getMethodName())) {210 if (className.equals(element.getClassName()) && methodName.test(element.getMethodName())) { 192 211 StackTraceElement toReturn = stackTrace[i + offset]; 193 return toReturn .getClassName().replaceFirst(".*\\.", "") + '#' + toReturn.getMethodName();212 return toReturn; 194 213 } 195 214 } 196 return "?";215 return null; 197 216 } 198 217
Note:
See TracChangeset
for help on using the changeset viewer.