Skip to content

Commit 49d8eb7

Browse files
author
emmanue1
committed
Refactoring
1 parent 662fa69 commit 49d8eb7

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ public class LocalVariableMaker {
4545
protected CreateLocalVariableVisitor createLocalVariableVisitor;
4646

4747
@SuppressWarnings("unchecked")
48-
public LocalVariableMaker(TypeMaker typeMaker, ClassFileConstructorOrMethodDeclaration comd, boolean constructor, BaseType parameterTypes) {
48+
public LocalVariableMaker(TypeMaker typeMaker, ClassFileConstructorOrMethodDeclaration comd, boolean constructor) {
4949
ClassFile classFile = comd.getClassFile();
5050
Method method = comd.getMethod();
51+
BaseType parameterTypes = comd.getParameterTypes();
5152

5253
this.typeMaker = typeMaker;
5354
this.typeBounds = comd.getTypeBounds();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public class StatementMaker {
6161
protected boolean removeFinallyStatementsFlag = false;
6262
protected boolean mergeTryWithResourcesStatementFlag = false;
6363

64-
public StatementMaker(
65-
TypeMaker typeMaker, LocalVariableMaker localVariableMaker,
66-
ClassFile classFile, ClassFileBodyDeclaration bodyDeclaration, ClassFileConstructorOrMethodDeclaration comd) {
64+
public StatementMaker(TypeMaker typeMaker, LocalVariableMaker localVariableMaker, ClassFileConstructorOrMethodDeclaration comd) {
65+
ClassFile classFile = comd.getClassFile();
66+
6767
this.typeMaker = typeMaker;
6868
this.typeBounds = comd.getTypeBounds();
6969
this.localVariableMaker = localVariableMaker;
7070
this.majorVersion = classFile.getMajorVersion();
7171
this.internalTypeName = classFile.getInternalTypeName();
72-
this.bodyDeclaration = bodyDeclaration;
73-
this.byteCodeParser = new ByteCodeParser(typeMaker, localVariableMaker, classFile, bodyDeclaration, comd);
72+
this.bodyDeclaration = comd.getBodyDeclaration();
73+
this.byteCodeParser = new ByteCodeParser(typeMaker, localVariableMaker, classFile, this.bodyDeclaration, comd);
7474
this.removeFinallyStatementsVisitor = new RemoveFinallyStatementsVisitor(localVariableMaker);
7575
this.removeBinaryOpReturnStatementsVisitor = new RemoveBinaryOpReturnStatementsVisitor(localVariableMaker);
7676
this.updateIntegerConstantTypeVisitor = new UpdateIntegerConstantTypeVisitor(comd.getReturnedType());

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

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,65 +87,57 @@ public void visit(FieldDeclaration declaration) {}
8787

8888
@Override
8989
public void visit(ConstructorDeclaration declaration) {
90-
ClassFileConstructorOrMethodDeclaration comd = (ClassFileConstructorOrMethodDeclaration)declaration;
91-
LocalVariableMaker localVariableMaker = new LocalVariableMaker(typeMaker, comd, true, comd.getParameterTypes());
92-
93-
createParametersVariablesAndStatements(comd, localVariableMaker);
90+
createParametersVariablesAndStatements((ClassFileConstructorOrMethodDeclaration)declaration, true);
9491
}
9592

9693
@Override
9794
public void visit(MethodDeclaration declaration) {
98-
ClassFileConstructorOrMethodDeclaration comd = (ClassFileConstructorOrMethodDeclaration)declaration;
99-
LocalVariableMaker localVariableMaker = new LocalVariableMaker(typeMaker, comd, false, comd.getParameterTypes());
100-
101-
createParametersVariablesAndStatements(comd, localVariableMaker);
95+
createParametersVariablesAndStatements((ClassFileConstructorOrMethodDeclaration)declaration, false);
10296
}
10397

10498
@Override
10599
public void visit(StaticInitializerDeclaration declaration) {
106-
ClassFileConstructorOrMethodDeclaration comd = (ClassFileConstructorOrMethodDeclaration)declaration;
107-
LocalVariableMaker localVariableMaker = new LocalVariableMaker(typeMaker, comd, false, null);
108-
109-
createParametersVariablesAndStatements(comd, localVariableMaker);
100+
createParametersVariablesAndStatements((ClassFileConstructorOrMethodDeclaration)declaration, false);
110101
}
111102

112-
protected void createParametersVariablesAndStatements(ClassFileConstructorOrMethodDeclaration comd, LocalVariableMaker localVariableMaker) {
103+
protected void createParametersVariablesAndStatements(ClassFileConstructorOrMethodDeclaration comd, boolean constructor) {
113104
ClassFile classFile = comd.getClassFile();
114-
ClassFileBodyDeclaration bodyDeclaration = comd.getBodyDeclaration();
115105
Method method = comd.getMethod();
116-
StatementMaker statementMaker = new StatementMaker(typeMaker, localVariableMaker, classFile, bodyDeclaration, comd);
106+
AttributeCode attributeCode = method.getAttribute("Code");
107+
LocalVariableMaker localVariableMaker = new LocalVariableMaker(typeMaker, comd, constructor);
117108

118-
try {
119-
ControlFlowGraph cfg = ControlFlowGraphMaker.make(method);
109+
if (attributeCode == null) {
110+
localVariableMaker.make(false, typeMaker);
111+
} else {
112+
StatementMaker statementMaker = new StatementMaker(typeMaker, localVariableMaker, comd);
113+
boolean containsLineNumber = (attributeCode.getAttribute("LineNumberTable") != null);
120114

121-
if (cfg != null) {
122-
ControlFlowGraphGotoReducer.reduce(cfg);
123-
ControlFlowGraphLoopReducer.reduce(cfg);
115+
try {
116+
ControlFlowGraph cfg = ControlFlowGraphMaker.make(method);
124117

125-
if (ControlFlowGraphReducer.reduce(cfg)) {
126-
comd.setStatements(statementMaker.make(cfg));
127-
} else {
128-
comd.setStatements(new ByteCodeStatement(ByteCodeWriter.write("// ", method)));
118+
if (cfg != null) {
119+
ControlFlowGraphGotoReducer.reduce(cfg);
120+
ControlFlowGraphLoopReducer.reduce(cfg);
121+
122+
if (ControlFlowGraphReducer.reduce(cfg)) {
123+
comd.setStatements(statementMaker.make(cfg));
124+
} else {
125+
comd.setStatements(new ByteCodeStatement(ByteCodeWriter.write("// ", method)));
126+
}
129127
}
128+
} catch (Exception e) {
129+
assert ExceptionUtil.printStackTrace(e);
130+
comd.setStatements(new ByteCodeStatement(ByteCodeWriter.write("// ", method)));
130131
}
131-
} catch (Exception e) {
132-
assert ExceptionUtil.printStackTrace(e);
133-
comd.setStatements(new ByteCodeStatement(ByteCodeWriter.write("// ", method)));
134-
}
135132

136-
if ((classFile.getAccessFlags() & FLAG_INTERFACE) != 0) {
137-
comd.setFlags(comd.getFlags() & ~(FLAG_PUBLIC|FLAG_ABSTRACT));
133+
localVariableMaker.make(containsLineNumber, typeMaker);
138134
}
139135

140-
boolean containsLineNumber = false;
141-
AttributeCode attributeCode = method.getAttribute("Code");
136+
comd.setFormalParameters(localVariableMaker.getFormalParameters());
142137

143-
if (attributeCode != null) {
144-
containsLineNumber = (attributeCode.getAttribute("LineNumberTable") != null);
138+
if ((classFile.getAccessFlags() & FLAG_INTERFACE) != 0) {
139+
comd.setFlags(comd.getFlags() & ~(FLAG_PUBLIC|FLAG_ABSTRACT));
145140
}
146-
147-
localVariableMaker.make(containsLineNumber, typeMaker);
148-
comd.setFormalParameters(localVariableMaker.getFormalParameters());
149141
}
150142

151143
@Override

0 commit comments

Comments
 (0)