Skip to content

Commit a33952c

Browse files
committed
refactor: make process more readable
1 parent 93586ef commit a33952c

File tree

9 files changed

+30
-40
lines changed

9 files changed

+30
-40
lines changed

src/main/java/org/jd/core/v1/ClassFileToJavaSourceDecompiler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jd.core.v1.api.loader.Loader;
1212
import org.jd.core.v1.api.printer.Printer;
1313
import org.jd.core.v1.model.classfile.ClassFile;
14+
import org.jd.core.v1.model.javasyntax.CompilationUnit;
1415
import org.jd.core.v1.model.message.DecompileContext;
1516
import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor;
1617
import org.jd.core.v1.service.deserializer.classfile.ClassFileDeserializer;
@@ -55,8 +56,8 @@ protected void decompile(DecompileContext decompileContext) throws Exception {
5556
decompileContext.getMainInternalTypeName());
5657
decompileContext.setClassFile(classFile);
5758

58-
this.converter.process(decompileContext);
59-
this.fragmenter.process(decompileContext);
59+
CompilationUnit compilationUnit = this.converter.process(decompileContext);
60+
this.fragmenter.process(compilationUnit, decompileContext);
6061
this.layouter.process(decompileContext);
6162
this.tokenizer.process(decompileContext);
6263
this.writer.process(decompileContext);

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/ClassFileToJavaSyntaxProcessor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.jd.core.v1.service.converter.classfiletojavasyntax;
99

1010
import org.jd.core.v1.api.loader.Loader;
11+
import org.jd.core.v1.model.javasyntax.CompilationUnit;
1112
import org.jd.core.v1.model.message.DecompileContext;
1213
import org.jd.core.v1.service.converter.classfiletojavasyntax.processor.ConvertClassFileProcessor;
1314
import org.jd.core.v1.service.converter.classfiletojavasyntax.processor.UpdateJavaSyntaxTreeProcessor;
@@ -27,15 +28,14 @@ public class ClassFileToJavaSyntaxProcessor {
2728
protected static final ConvertClassFileProcessor CONVERT_CLASS_FILE_PROCESSOR = new ConvertClassFileProcessor();
2829
protected static final UpdateJavaSyntaxTreeProcessor UPDATE_JAVA_SYNTAX_TREE_PROCESSOR = new UpdateJavaSyntaxTreeProcessor();
2930

30-
public void process(DecompileContext decompileContext) throws Exception {
31+
public CompilationUnit process(DecompileContext decompileContext) throws Exception {
3132
Loader loader = decompileContext.getLoader();
3233
Map<String, Object> configuration = decompileContext.getConfiguration();
3334

35+
TypeMaker typeMaker = null;
3436
if (configuration == null) {
35-
decompileContext.setTypeMaker(new TypeMaker(loader));
37+
typeMaker = new TypeMaker(loader);
3638
} else {
37-
TypeMaker typeMaker = null;
38-
3939
try {
4040
typeMaker = (TypeMaker)configuration.get("typeMaker");
4141

@@ -49,10 +49,13 @@ public void process(DecompileContext decompileContext) throws Exception {
4949
}
5050
}
5151

52-
decompileContext.setTypeMaker(typeMaker);
5352
}
53+
decompileContext.setTypeMaker(typeMaker);
54+
55+
CompilationUnit compilationUnit = CONVERT_CLASS_FILE_PROCESSOR.process(decompileContext.getClassFile(), typeMaker, decompileContext);
56+
decompileContext.setCompilationUnit(compilationUnit);
5457

55-
CONVERT_CLASS_FILE_PROCESSOR.process(decompileContext);
56-
UPDATE_JAVA_SYNTAX_TREE_PROCESSOR.process(decompileContext);
58+
UPDATE_JAVA_SYNTAX_TREE_PROCESSOR.process(compilationUnit, typeMaker);
59+
return compilationUnit;
5760
}
5861
}

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/processor/ConvertClassFileProcessor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ public void visit(TypeParameterWithTypeBounds parameter) {
9191
}
9292
};
9393

94-
public void process(DecompileContext decompileContext) throws Exception {
95-
TypeMaker typeMaker = decompileContext.getTypeMaker();
96-
ClassFile classFile = decompileContext.getClassFile();
97-
94+
public CompilationUnit process(ClassFile classFile, TypeMaker typeMaker, DecompileContext decompileContext) throws Exception {
9895
AnnotationConverter annotationConverter = new AnnotationConverter(typeMaker);
9996

10097
TypeDeclaration typeDeclaration;
@@ -113,7 +110,7 @@ public void process(DecompileContext decompileContext) throws Exception {
113110

114111
decompileContext.setMajorVersion(classFile.getMajorVersion());
115112
decompileContext.setMinorVersion(classFile.getMinorVersion());
116-
decompileContext.setCompilationUnit(new CompilationUnit(typeDeclaration));
113+
return new CompilationUnit(typeDeclaration);
117114
}
118115

119116
protected ClassFileInterfaceDeclaration convertInterfaceDeclaration(TypeMaker parser, AnnotationConverter converter, ClassFile classFile, ClassFileBodyDeclaration outerClassFileBodyDeclaration) {

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/processor/UpdateJavaSyntaxTreeProcessor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
*/
2323
public class UpdateJavaSyntaxTreeProcessor {
2424

25-
public void process(DecompileContext decompileContext) throws Exception {
26-
TypeMaker typeMaker = decompileContext.getTypeMaker();
27-
CompilationUnit compilationUnit = decompileContext.getCompilationUnit();
28-
25+
public void process(CompilationUnit compilationUnit, TypeMaker typeMaker) throws Exception {
2926
new UpdateJavaSyntaxTreeStep0Visitor(typeMaker).visit(compilationUnit);
3027
new UpdateJavaSyntaxTreeStep1Visitor(typeMaker).visit(compilationUnit);
3128
new UpdateJavaSyntaxTreeStep2Visitor(typeMaker).visit(compilationUnit);

src/main/java/org/jd/core/v1/service/fragmenter/javasyntaxtojavafragment/JavaSyntaxToJavaFragmentProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
*/
2323
public class JavaSyntaxToJavaFragmentProcessor {
2424

25-
public void process(DecompileContext decompileContext) throws Exception {
25+
public void process(CompilationUnit compilationUnit, DecompileContext decompileContext) throws Exception {
2626
Loader loader = decompileContext.getLoader();
2727
String mainInternalTypeName = decompileContext.getMainInternalTypeName();
2828
int majorVersion = decompileContext.getMajorVersion();
29-
CompilationUnit compilationUnit = decompileContext.getCompilationUnit();
3029

3130
SearchImportsVisitor importsVisitor = new SearchImportsVisitor(loader, mainInternalTypeName);
3231
importsVisitor.visit(compilationUnit);

src/test/java/org/jd/core/v1/AbstractJdTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.jd.core.v1.api.loader.Loader;
55
import org.jd.core.v1.api.printer.Printer;
66
import org.jd.core.v1.model.classfile.ClassFile;
7+
import org.jd.core.v1.model.javasyntax.CompilationUnit;
78
import org.jd.core.v1.model.message.DecompileContext;
89
import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor;
910
import org.jd.core.v1.service.deserializer.classfile.ClassFileDeserializer;
@@ -33,8 +34,8 @@ protected String decompile(Loader loader, Printer printer, String internalTypeNa
3334
ClassFile classFile = deserializer.loadClassFile(loader, internalTypeName);
3435
decompileContext.setClassFile(classFile);
3536

36-
converter.process(decompileContext);
37-
fragmenter.process(decompileContext);
37+
CompilationUnit compilationUnit = converter.process(decompileContext);
38+
fragmenter.process(compilationUnit, decompileContext);
3839
layouter.process(decompileContext);
3940
tokenizer.process(decompileContext);
4041
writer.process(decompileContext);

src/test/java/org/jd/core/v1/ControlFlowGraphTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,9 +2673,7 @@ protected Method searchMethod(Loader loader, TypeMaker typeMaker, String interna
26732673
ClassFile classFile = deserializer.loadClassFile(loader, internalTypeName);
26742674
decompileContext.setClassFile(classFile);
26752675

2676-
converter.process(decompileContext);
2677-
2678-
CompilationUnit compilationUnit = decompileContext.getCompilationUnit();
2676+
CompilationUnit compilationUnit = converter.process(classFile, typeMaker, decompileContext);
26792677

26802678
assertNotNull(compilationUnit);
26812679

src/test/java/org/jd/core/v1/JarFileToJavaSourceTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77

88
package org.jd.core.v1;
99

10-
import junit.framework.TestCase;
1110
import org.jd.core.v1.compiler.CompilerUtil;
1211
import org.jd.core.v1.compiler.JavaSourceFileObject;
1312
import org.jd.core.v1.loader.ZipLoader;
1413
import org.jd.core.v1.model.classfile.ClassFile;
14+
import org.jd.core.v1.model.javasyntax.CompilationUnit;
1515
import org.jd.core.v1.model.message.DecompileContext;
1616
import org.jd.core.v1.printer.PlainTextPrinter;
17-
import org.jd.core.v1.service.converter.classfiletojavasyntax.ClassFileToJavaSyntaxProcessor;
18-
import org.jd.core.v1.service.deserializer.classfile.ClassFileDeserializer;
19-
import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.JavaSyntaxToJavaFragmentProcessor;
20-
import org.jd.core.v1.service.layouter.LayoutFragmentProcessor;
21-
import org.jd.core.v1.service.tokenizer.javafragmenttotoken.JavaFragmentToTokenProcessor;
22-
import org.jd.core.v1.service.writer.WriteTokenProcessor;
2317
import org.jd.core.v1.util.DefaultList;
2418
import org.junit.Test;
2519

@@ -165,8 +159,8 @@ protected void test(InputStream inputStream) throws Exception {
165159
ClassFile classFile = deserializer.loadClassFile(loader, internalTypeName);
166160
decompileContext.setClassFile(classFile);
167161

168-
converter.process(decompileContext);
169-
fragmenter.process(decompileContext);
162+
CompilationUnit compilationUnit = converter.process(decompileContext);
163+
fragmenter.process(compilationUnit, decompileContext);
170164
layouter.process(decompileContext);
171165
tokenizer.process(decompileContext);
172166
writer.process(decompileContext);

src/test/java/org/jd/core/v1/JavaSyntaxToJavaSourceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void testClassDeclaration() throws Exception {
151151
decompileContext.setMajorVersion(0);
152152
decompileContext.setMinorVersion(0);
153153

154-
fragmenter.process(decompileContext);
154+
fragmenter.process(compilationUnit, decompileContext);
155155
layouter.process(decompileContext);
156156
tokenizer.process(decompileContext);
157157
writer.process(decompileContext);
@@ -192,7 +192,7 @@ public void testInterfaceDeclaration() throws Exception {
192192
decompileContext.setMajorVersion(49);
193193
decompileContext.setMinorVersion(0);
194194

195-
fragmenter.process(decompileContext);
195+
fragmenter.process(compilationUnit, decompileContext);
196196
layouter.process(decompileContext);
197197
tokenizer.process(decompileContext);
198198
writer.process(decompileContext);
@@ -243,7 +243,7 @@ public void testEnumDayDeclaration() throws Exception {
243243
decompileContext.setMajorVersion(0);
244244
decompileContext.setMinorVersion(0);
245245

246-
fragmenter.process(decompileContext);
246+
fragmenter.process(compilationUnit, decompileContext);
247247
layouter.process(decompileContext);
248248
tokenizer.process(decompileContext);
249249
writer.process(decompileContext);
@@ -528,7 +528,7 @@ public void testEnumPlanetDeclaration() throws Exception {
528528
decompileContext.setMajorVersion(0);
529529
decompileContext.setMinorVersion(0);
530530

531-
fragmenter.process(decompileContext);
531+
fragmenter.process(compilationUnit, decompileContext);
532532
layouter.process(decompileContext);
533533
//tokenizer.process(message);
534534
new JavaFragmentToTokenProcessor().process(decompileContext);
@@ -598,7 +598,7 @@ public void testSwitch() throws Exception {
598598
decompileContext.setMajorVersion(0);
599599
decompileContext.setMinorVersion(0);
600600

601-
fragmenter.process(decompileContext);
601+
fragmenter.process(compilationUnit, decompileContext);
602602
layouter.process(decompileContext);
603603
tokenizer.process(decompileContext);
604604
writer.process(decompileContext);
@@ -655,7 +655,7 @@ public void testBridgeAndSyntheticAttributes() throws Exception {
655655
decompileContext.setMajorVersion(0);
656656
decompileContext.setMinorVersion(0);
657657

658-
fragmenter.process(decompileContext);
658+
fragmenter.process(compilationUnit, decompileContext);
659659
layouter.process(decompileContext);
660660
tokenizer.process(decompileContext);
661661
writer.process(decompileContext);

0 commit comments

Comments
 (0)