|
1 | 1 | package com.spun.util.tests; |
2 | 2 |
|
3 | | -import com.spun.util.ClassUtils; |
4 | | -import com.spun.util.ObjectUtils; |
5 | | -import com.spun.util.ThreadUtils; |
6 | | -import com.spun.util.WindowUtils; |
7 | | -import com.spun.util.images.ImageWriter; |
8 | | -import com.spun.util.io.FileUtils; |
9 | | -import com.spun.util.io.StackElementLevelSelector; |
10 | | -import com.spun.util.io.StackElementSelector; |
11 | | -import org.lambda.functions.Function1; |
12 | | -import org.lambda.functions.Function2; |
13 | | - |
14 | 3 | import java.awt.image.BufferedImage; |
15 | 4 | import java.io.File; |
16 | 5 | import java.io.FileNotFoundException; |
|
24 | 13 | import javax.swing.JFileChooser; |
25 | 14 | import javax.swing.JFrame; |
26 | 15 |
|
| 16 | +import org.lambda.functions.Function2; |
| 17 | + |
| 18 | +import com.spun.util.ClassUtils; |
| 19 | +import com.spun.util.ObjectUtils; |
| 20 | +import com.spun.util.ThreadUtils; |
| 21 | +import com.spun.util.WindowUtils; |
| 22 | +import com.spun.util.images.ImageWriter; |
| 23 | +import com.spun.util.io.FileUtils; |
| 24 | +import com.spun.util.io.StackElementLevelSelector; |
| 25 | +import com.spun.util.io.StackElementSelector; |
| 26 | + |
27 | 27 | public class TestUtils |
28 | 28 | { |
29 | | - private static Random random; |
| 29 | + private static Random random; |
| 30 | + private static Function2<Class, String, File> getSourceDirectory = ClassUtils::getSourceDirectory; |
| 31 | + public static void registerSourceDirectoryFinder(Function2<Class, String, File> getSourceDirectory) |
| 32 | + { |
| 33 | + TestUtils.getSourceDirectory = getSourceDirectory; |
| 34 | + } |
30 | 35 | public static File getFile(String startingDir) |
31 | 36 | { |
32 | 37 | JFrame frame = new JFrame(); |
@@ -189,22 +194,20 @@ private static StackTraceReflectionResult getInfo(StackTraceElement element) thr |
189 | 194 | String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1); |
190 | 195 | className = handleInnerClasses(className); |
191 | 196 | String fileName = element.getFileName(); |
192 | | - Function2<Class, String, File> getSourceDirectory = ClassUtils::getSourceDirectory; |
193 | 197 | File dir = getSourceDirectory.call(ObjectUtils.loadClass(fullClassName), fileName); |
194 | 198 | String methodName = unrollLambda(element.getMethodName()); |
195 | 199 | return new StackTraceReflectionResult(dir, className, fullClassName, methodName); |
196 | 200 | } |
197 | | - |
198 | | - private static String handleInnerClasses(String className) { |
| 201 | + private static String handleInnerClasses(String className) |
| 202 | + { |
199 | 203 | return className.replaceAll("\\$", "."); |
200 | 204 | } |
201 | | - |
202 | | - public static String unrollLambda(String methodName) { |
| 205 | + public static String unrollLambda(String methodName) |
| 206 | + { |
203 | 207 | Pattern p = Pattern.compile("lambda\\$(.*)\\$\\d+"); |
204 | 208 | Matcher m = p.matcher(methodName); |
205 | | - if (m.matches()) { |
206 | | - return m.group(1); |
207 | | - } |
| 209 | + if (m.matches()) |
| 210 | + { return m.group(1); } |
208 | 211 | return methodName; |
209 | 212 | } |
210 | 213 | } |
0 commit comments