1
1
package me .coley .recaf .decompile .fernflower ;
2
2
3
3
import me .coley .recaf .workspace .Workspace ;
4
- import org .jetbrains .java .decompiler .main .*;
5
- import org .jetbrains .java .decompiler .main .extern .*;
6
- import org .jetbrains .java .decompiler .struct .*;
4
+ import org .jetbrains .java .decompiler .main .ClassesProcessor ;
5
+ import org .jetbrains .java .decompiler .main .DecompilerContext ;
6
+ import org .jetbrains .java .decompiler .main .IdentityRenamerFactory ;
7
+ import org .jetbrains .java .decompiler .main .extern .IBytecodeProvider ;
8
+ import org .jetbrains .java .decompiler .main .extern .IFernflowerLogger ;
9
+ import org .jetbrains .java .decompiler .main .extern .IFernflowerPreferences ;
10
+ import org .jetbrains .java .decompiler .main .extern .IResultSaver ;
11
+ import org .jetbrains .java .decompiler .modules .renamer .PoolInterceptor ;
12
+ import org .jetbrains .java .decompiler .struct .IDecompiledData ;
13
+ import org .jetbrains .java .decompiler .struct .StructClass ;
7
14
import org .jetbrains .java .decompiler .struct .lazy .LazyLoader ;
8
15
import org .jetbrains .java .decompiler .util .TextBuffer ;
9
16
10
17
import java .io .IOException ;
11
18
import java .io .PrintWriter ;
12
19
import java .io .StringWriter ;
13
- import java .util .*;
20
+ import java .util .Locale ;
21
+ import java .util .Map ;
14
22
15
23
/**
16
24
* FernFlower accessor. Modified from {@link org.jetbrains.java.decompiler.main.Fernflower} to
@@ -37,13 +45,15 @@ public class FernFlowerAccessor implements IDecompiledData {
37
45
public FernFlowerAccessor (IBytecodeProvider provider , IResultSaver saver , Map <String , Object >
38
46
properties , IFernflowerLogger logger ) {
39
47
String level = (String ) properties .get (IFernflowerPreferences .LOG_LEVEL );
40
- if (level != null ) {
48
+ if (level != null ) {
41
49
logger .setSeverity (IFernflowerLogger .Severity .valueOf (level .toUpperCase (Locale .ENGLISH )));
42
50
}
43
51
structContext = new StructContextDecorator (saver , this , new LazyLoader (provider ));
44
52
classProcessor = new ClassesProcessor (structContext );
45
- DecompilerContext context = new DecompilerContext (properties , logger , structContext ,
46
- classProcessor , null );
53
+ int threadCount = 1 ;
54
+ DecompilerContext context = new DecompilerContext (
55
+ properties , threadCount , logger , structContext , classProcessor ,
56
+ new PoolInterceptor (), new IdentityRenamerFactory ());
47
57
DecompilerContext .setCurrentContext (context );
48
58
}
49
59
@@ -66,8 +76,32 @@ public void addWorkspace(Workspace workspace) throws IOException, ReflectiveOper
66
76
/**
67
77
* Analyze classes in the workspace.
68
78
*/
69
- public void analyze () {
79
+ public void analyze () throws IOException , InterruptedException {
70
80
classProcessor .loadClasses (null );
81
+ // The threading model with FF makes no damn sense and there is NO documentaiton.
82
+ // Uuggggghhhhhhh....
83
+ // Sorry, you get shit performance on a single thread until I find some docs.
84
+ /*
85
+ DecompilerContext root = DecompilerContext.getCurrentContext();
86
+ ExecutorService pool = Executors.newWorkStealingPool();
87
+ for (StructClass cl : structContext.getClasses().values())
88
+ pool.submit(() -> {
89
+ try {
90
+ DecompilerContext.cloneContext(root);
91
+ classProcessor.processClass(cl);
92
+ } catch (Throwable t) {
93
+ t.printStackTrace();
94
+ }
95
+ });
96
+ pool.shutdown();
97
+ pool.awaitTermination(10, TimeUnit.SECONDS);
98
+ */
99
+ for (StructClass cl : structContext .getClasses ().values ())
100
+ try {
101
+ classProcessor .processClass (cl );
102
+ } catch (Throwable t ) {
103
+ t .printStackTrace ();
104
+ }
71
105
}
72
106
73
107
/**
@@ -86,13 +120,23 @@ public String decompile(String name) {
86
120
@ Override
87
121
public String getClassEntryName (StructClass cl , String entryName ) {
88
122
ClassesProcessor .ClassNode node = classProcessor .getMapRootClasses ().get (cl .qualifiedName );
89
- if (node .type != ClassesProcessor .ClassNode .CLASS_ROOT ) {
123
+ if (node .type != ClassesProcessor .ClassNode .CLASS_ROOT ) {
90
124
return null ;
91
125
} else {
92
126
return entryName .substring (0 , entryName .lastIndexOf (".class" )) + ".java" ;
93
127
}
94
128
}
95
129
130
+ @ Override
131
+ public boolean processClass (StructClass structClass ) {
132
+ try {
133
+ classProcessor .processClass (structClass );
134
+ return true ;
135
+ } catch (IOException e ) {
136
+ return false ;
137
+ }
138
+ }
139
+
96
140
@ Override
97
141
public String getClassContent (StructClass cl ) {
98
142
TextBuffer buffer ;
0 commit comments