1
1
package com .chocohead .cc ;
2
2
3
- import java .lang .reflect .Field ;
4
3
import java .util .HashMap ;
5
4
import java .util .Map ;
6
- import java .util .Set ;
7
5
8
- import com .google .common .collect .Iterables ;
9
-
10
- import org .apache .commons .lang3 .reflect .FieldUtils ;
11
-
12
- import org .spongepowered .asm .mixin .Mixins ;
13
6
import org .spongepowered .asm .mixin .extensibility .IMixinInfo ;
14
- import org .spongepowered .asm .mixin .transformer .ClassInfo ;
15
7
16
8
import com .chocohead .cc .smap .FileInfo ;
17
9
import com .chocohead .cc .smap .LineInfo ;
18
10
import com .chocohead .cc .smap .SMAP ;
19
11
20
12
public class SMAPper {
21
- private static final Field MIXINS = FieldUtils .getDeclaredField (ClassInfo .class , "mixins" , true );
22
-
23
- private static boolean hasMixins (ClassInfo type ) {
24
- try {
25
- return !((Set <?>) MIXINS .get (type )).isEmpty ();
26
- } catch (ReflectiveOperationException e ) {
27
- throw new RuntimeException ("Failed to find mixins for " + type .getName (), e );
28
- }
29
- }
30
-
31
13
public static void apply (Throwable t , String ... skippedPackages ) {
32
14
apply (t , new HashMap <String , SMAP >(), skippedPackages );
33
15
}
@@ -68,14 +50,10 @@ private static boolean apply(StackTraceElement[] elements, Map<String, SMAP> cac
68
50
69
51
smap = null ;
70
52
if (!skip ) {
71
- ClassInfo info = ClassInfo .fromCache (className );
72
-
73
- if (info != null && hasMixins (info )) {
74
- String source = SourcePool .get (className );
53
+ String source = SourcePool .get (className );
75
54
76
- if (source != null && source .startsWith ("SMAP" )) {
77
- smap = SMAP .forResolved (source );
78
- }
55
+ if (source != null && source .startsWith ("SMAP" )) {
56
+ smap = SMAP .forResolved (source );
79
57
}
80
58
}
81
59
@@ -97,13 +75,8 @@ private static boolean apply(StackTraceElement[] elements, Map<String, SMAP> cac
97
75
return modified ;
98
76
}
99
77
100
- private static String findMixin (FileInfo info ) {
101
- if (info .path != null && info .path .endsWith (".java" )) {//This is very silly but also useful
102
- IMixinInfo mixin = Iterables .getOnlyElement (Mixins .getMixinsForClass (info .path .substring (0 , info .path .length () - 5 )));
103
-
104
- if (mixin != null ) return " [" + mixin .getConfig ().getName () + ']' ;
105
- }
106
-
107
- return "" ;
78
+ private static String findMixin (FileInfo file ) {
79
+ IMixinInfo mixin = SourcePool .findFor (file );
80
+ return mixin != null ? " [" + mixin .getConfig ().getName () + ']' : "" ;
108
81
}
109
82
}
0 commit comments