Skip to content

Commit b417028

Browse files
author
emmanue1
committed
Fix corrects syntax errors in decompiled sources
1 parent 57b5bb9 commit b417028

File tree

8 files changed

+68
-52
lines changed

8 files changed

+68
-52
lines changed

src/main/java/org/jd/core/v1/model/javasyntax/statement/TryStatement.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2019 Emmanuel Dupuy.
2+
* Copyright (c) 2008, 2019 Emmanuel Dupuy.
33
* This project is distributed under the GPLv3 license.
44
* This is a Copyleft license that gives the user the right to use,
55
* copy and modify the code freely for non-commercial purposes.
@@ -11,29 +11,27 @@
1111
import org.jd.core.v1.model.javasyntax.type.ObjectType;
1212
import org.jd.core.v1.util.DefaultList;
1313

14-
import java.util.List;
15-
1614
public class TryStatement implements Statement {
17-
protected List<Resource> resources;
15+
protected DefaultList<Resource> resources;
1816
protected BaseStatement tryStatements;
19-
protected List<CatchClause> catchClauses;
17+
protected DefaultList<CatchClause> catchClauses;
2018
protected BaseStatement finallyStatements;
2119

22-
public TryStatement(BaseStatement tryStatements, List<CatchClause> catchClauses, BaseStatement finallyStatements) {
20+
public TryStatement(BaseStatement tryStatements, DefaultList<CatchClause> catchClauses, BaseStatement finallyStatements) {
2321
this.resources = null;
2422
this.tryStatements = tryStatements;
2523
this.catchClauses = catchClauses;
2624
this.finallyStatements = finallyStatements;
2725
}
2826

29-
public TryStatement(List<Resource> resources, BaseStatement tryStatements, List<CatchClause> catchClauses, BaseStatement finallyStatements) {
27+
public TryStatement(DefaultList<Resource> resources, BaseStatement tryStatements, DefaultList<CatchClause> catchClauses, BaseStatement finallyStatements) {
3028
this.resources = resources;
3129
this.tryStatements = tryStatements;
3230
this.catchClauses = catchClauses;
3331
this.finallyStatements = finallyStatements;
3432
}
3533

36-
public List<Resource> getResources() {
34+
public DefaultList<Resource> getResources() {
3735
return resources;
3836
}
3937

@@ -45,7 +43,7 @@ public void setTryStatements(BaseStatement tryStatements) {
4543
this.tryStatements = tryStatements;
4644
}
4745

48-
public List<CatchClause> getCatchClauses() {
46+
public DefaultList<CatchClause> getCatchClauses() {
4947
return catchClauses;
5048
}
5149

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/javasyntax/statement/ClassFileTryStatement.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@
1111
import org.jd.core.v1.model.javasyntax.statement.TryStatement;
1212
import org.jd.core.v1.model.javasyntax.type.ObjectType;
1313
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.localvariable.AbstractLocalVariable;
14-
15-
import java.util.List;
14+
import org.jd.core.v1.util.DefaultList;
1615

1716
public class ClassFileTryStatement extends TryStatement {
1817
protected boolean jsr;
1918
protected boolean eclipse;
2019

21-
public ClassFileTryStatement(BaseStatement tryStatements, List<TryStatement.CatchClause> catchClauses, BaseStatement finallyStatements, boolean jsr, boolean eclipse) {
20+
public ClassFileTryStatement(BaseStatement tryStatements, DefaultList<TryStatement.CatchClause> catchClauses, BaseStatement finallyStatements, boolean jsr, boolean eclipse) {
2221
super(tryStatements, catchClauses, finallyStatements);
2322
this.jsr = jsr;
2423
this.eclipse = eclipse;
2524
}
2625

27-
public ClassFileTryStatement(List<Resource> resources, BaseStatement tryStatements, List<TryStatement.CatchClause> catchClauses, BaseStatement finallyStatements, boolean jsr, boolean eclipse) {
26+
public ClassFileTryStatement(DefaultList<Resource> resources, BaseStatement tryStatements, DefaultList<TryStatement.CatchClause> catchClauses, BaseStatement finallyStatements, boolean jsr, boolean eclipse) {
2827
super(resources, tryStatements, catchClauses, finallyStatements);
2928
this.jsr = jsr;
3029
this.eclipse = eclipse;
3130
}
3231

33-
public void addResources(List<Resource> resources) {
32+
public void addResources(DefaultList<Resource> resources) {
3433
if (resources != null) {
3534
if (this.resources == null) {
3635
this.resources = resources;

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ public class ByteCodeParser {
4949

5050
private TypeMaker typeMaker;
5151
private LocalVariableMaker localVariableMaker;
52+
private ClassFile classFile;
5253
private String internalTypeName;
5354
private AttributeBootstrapMethods attributeBootstrapMethods;
5455
private ClassFileBodyDeclaration bodyDeclaration;
5556
private MemberVisitor memberVisitor = new MemberVisitor();
5657
private SearchFirstLineNumberVisitor searchFirstLineNumberVisitor = new SearchFirstLineNumberVisitor();
5758

58-
public ByteCodeParser(
59-
TypeMaker typeMaker, LocalVariableMaker localVariableMaker, String internalTypeName,
60-
ClassFile classFile, ClassFileBodyDeclaration bodyDeclaration) {
59+
public ByteCodeParser(TypeMaker typeMaker, LocalVariableMaker localVariableMaker, ClassFile classFile, ClassFileBodyDeclaration bodyDeclaration) {
6160
this.typeMaker = typeMaker;
6261
this.localVariableMaker = localVariableMaker;
63-
this.internalTypeName = internalTypeName;
62+
this.classFile = classFile;
63+
this.internalTypeName = classFile.getInternalTypeName();
6464
this.attributeBootstrapMethods = classFile.getAttribute("BootstrapMethods");
6565
this.bodyDeclaration = bodyDeclaration;
6666
}
@@ -722,7 +722,7 @@ public void parse(BasicBlock basicBlock, Statements<Statement> statements, Defau
722722
BaseExpression parameters = extractParametersFromStack(statements, stack, methodTypes.parameterTypes);
723723

724724
if (opcode == 184) { // INVOKESTATIC
725-
Type returnedType = bindParameterTypesWithArgumentTypes(ot, methodTypes.returnedType);
725+
Type returnedType = bindParameterTypesWithArgumentType(ot, methodTypes.returnedType);
726726
BaseType parameterTypes = bindParameterTypesWithArgumentTypes(ot, methodTypes.parameterTypes);
727727
parameters = prepareParameters(parameters, parameterTypes);
728728
expression1 = new ClassFileMethodInvocationExpression(lineNumber, methodTypes.typeParameters, returnedType, new ObjectTypeReferenceExpression(lineNumber, ot), typeName, name, descriptor, parameterTypes, parameters);
@@ -733,9 +733,9 @@ public void parse(BasicBlock basicBlock, Statements<Statement> statements, Defau
733733
}
734734
} else {
735735
expression1 = stack.pop();
736-
Type returnedType = bindParameterTypesWithArgumentTypes(ot, methodTypes.returnedType);
736+
Type returnedType = bindParameterTypesWithArgumentType(ot, methodTypes.returnedType);
737737
BaseType parameterTypes = bindParameterTypesWithArgumentTypes(ot, methodTypes.parameterTypes);
738-
//BaseType parameterTypes = bindParameterTypesWithArgumentTypes(expression1, ot, methodTypes.parameterTypes);
738+
//BaseType parameterTypes = getRawType(expression1, ot, methodTypes.parameterTypes);
739739
parameters = prepareParameters(parameters, parameterTypes);
740740
if (expression1.getClass() == ClassFileLocalVariableReferenceExpression.class) {
741741
((ClassFileLocalVariableReferenceExpression)expression1).getLocalVariable().typeOnLeft(ot);
@@ -934,7 +934,7 @@ private BaseExpression extractParametersFromStack(Statements statements, Default
934934
}
935935
}
936936

937-
private Type bindParameterTypesWithArgumentTypes(Type type) {
937+
private Type getRawType(Type type) {
938938
if (type.isGeneric()) {
939939
return TYPE_OBJECT.createType(type.getDimension());
940940
}
@@ -950,7 +950,7 @@ private Type bindParameterTypesWithArgumentTypes(Type type) {
950950
return type;
951951
}
952952

953-
private Type bindParameterTypesWithArgumentTypes(ObjectType objectType, Type type) {
953+
private Type bindParameterTypesWithArgumentType(ObjectType objectType, Type type) {
954954
if (type == null) {
955955
return null;
956956
}
@@ -959,7 +959,7 @@ private Type bindParameterTypesWithArgumentTypes(ObjectType objectType, Type typ
959959
return type;
960960
}
961961

962-
return bindParameterTypesWithArgumentTypes(type);
962+
return getRawType(type);
963963
}
964964

965965
private BaseType bindParameterTypesWithArgumentTypes(ObjectType objectType, BaseType parameterTypes) {
@@ -975,7 +975,7 @@ private BaseType bindParameterTypesWithArgumentTypes(ObjectType objectType, Base
975975
case 0:
976976
return null;
977977
case 1:
978-
return bindParameterTypesWithArgumentTypes(parameterTypes.getFirst());
978+
return getRawType(parameterTypes.getFirst());
979979
default:
980980
DefaultList<Type> list = parameterTypes.getList();
981981
int count = list.size();
@@ -985,7 +985,7 @@ private BaseType bindParameterTypesWithArgumentTypes(ObjectType objectType, Base
985985
Types<Type> types = new Types<>(list);
986986
for (i=0; i<count; i++) {
987987
Type type = list.get(i);
988-
types.set(i, bindParameterTypesWithArgumentTypes(type));
988+
types.set(i, getRawType(type));
989989
}
990990
return types;
991991
}

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,32 @@ protected AbstractLocalVariable searchLocalVariable(int index, int offset) {
337337
}
338338

339339
protected boolean isCompatible(AbstractLocalVariable lv, Type valueType) {
340-
if (lv.getType().isObject() && valueType.isObject() && (lv.getType().getDimension() == valueType.getDimension())) {
341-
ObjectType lvObjectType = (ObjectType)lv.getType();
342-
ObjectType valueObjectType = (ObjectType)valueType;
340+
if (valueType.isObject() && (lv.getType().getDimension() == valueType.getDimension())) {
341+
ObjectType valueObjectType = (ObjectType) valueType;
343342

344-
BaseTypeArgument lvTypeArguments = lvObjectType.getTypeArguments();
345-
BaseTypeArgument valueTypeArguments = valueObjectType.getTypeArguments();
343+
if (lv.getType().isObject()) {
344+
ObjectType lvObjectType = (ObjectType) lv.getType();
346345

347-
if ((lvTypeArguments == null) || (valueTypeArguments == null)) {
348-
return typeMaker.isAssignable(lvObjectType, valueObjectType);
349-
}
346+
BaseTypeArgument lvTypeArguments = lvObjectType.getTypeArguments();
347+
BaseTypeArgument valueTypeArguments = valueObjectType.getTypeArguments();
350348

351-
searchInTypeArgumentVisitor.init();
352-
lvTypeArguments.accept(searchInTypeArgumentVisitor);
349+
if ((lvTypeArguments == null) || (valueTypeArguments == null)) {
350+
return typeMaker.isAssignable(lvObjectType, valueObjectType);
351+
}
353352

354-
if (!searchInTypeArgumentVisitor.containsGeneric()) {
355353
searchInTypeArgumentVisitor.init();
356-
valueTypeArguments.accept(searchInTypeArgumentVisitor);
354+
lvTypeArguments.accept(searchInTypeArgumentVisitor);
357355

358-
if (searchInTypeArgumentVisitor.containsGeneric()) {
359-
return typeMaker.isAssignable(lvObjectType, valueObjectType);
356+
if (!searchInTypeArgumentVisitor.containsGeneric()) {
357+
searchInTypeArgumentVisitor.init();
358+
valueTypeArguments.accept(searchInTypeArgumentVisitor);
359+
360+
if (searchInTypeArgumentVisitor.containsGeneric()) {
361+
return typeMaker.isAssignable(lvObjectType, valueObjectType);
362+
}
360363
}
364+
} else if (lv.getType().isGeneric() && valueObjectType.getInternalName().equals(ObjectType.TYPE_OBJECT.getInternalName())) {
365+
return true;
361366
}
362367
}
363368

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public StatementMaker(
6767
this.majorVersion = classFile.getMajorVersion();
6868
this.internalTypeName = classFile.getInternalTypeName();
6969
this.bodyDeclaration = bodyDeclaration;
70-
this.byteCodeParser = new ByteCodeParser(typeMaker, localVariableMaker, internalTypeName, classFile, bodyDeclaration);
70+
this.byteCodeParser = new ByteCodeParser(typeMaker, localVariableMaker, classFile, bodyDeclaration);
7171
this.removeFinallyStatementsVisitor = new RemoveFinallyStatementsVisitor(localVariableMaker);
7272
this.removeBinaryOpReturnStatementsVisitor = new RemoveBinaryOpReturnStatementsVisitor(localVariableMaker);
7373
this.updateIntegerConstantTypeVisitor = new UpdateIntegerConstantTypeVisitor(returnedType);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public static Expression create(Expression expression, int lineNumber, String ty
4848
return concatenatedStringExpression;
4949
}
5050
} else if (!ne.getParameters().isList()) {
51-
expression = ne.getParameters().getFirst();
51+
expr = ne.getParameters().getFirst();
5252

53-
if (ObjectType.TYPE_STRING.equals(expression.getType())) {
54-
return new BinaryOperatorExpression(ne.getLineNumber(), ObjectType.TYPE_STRING, expression, "+", concatenatedStringExpression, 4);
53+
if (ObjectType.TYPE_STRING.equals(expr.getType())) {
54+
return new BinaryOperatorExpression(ne.getLineNumber(), ObjectType.TYPE_STRING, expr, "+", concatenatedStringExpression, 4);
5555
}
5656
}
5757
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2019 Emmanuel Dupuy.
2+
* Copyright (c) 2008, 2019 Emmanuel Dupuy.
33
* This project is distributed under the GPLv3 license.
44
* This is a Copyleft license that gives the user the right to use,
55
* copy and modify the code freely for non-commercial purposes.
@@ -17,8 +17,15 @@
1717
import org.jd.core.v1.model.javasyntax.statement.SwitchStatement;
1818
import org.jd.core.v1.model.javasyntax.statement.TryStatement;
1919
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.javasyntax.expression.ClassFileLocalVariableReferenceExpression;
20+
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.localvariable.AbstractLocalVariable;
21+
import org.jd.core.v1.util.DefaultList;
2022

2123
public class DeclaredSyntheticLocalVariableVisitor extends AbstractJavaSyntaxVisitor {
24+
protected DefaultList<LocalVariableReferenceExpression> localVariableReferenceExpressions = new DefaultList<>();
25+
26+
public void init() {
27+
localVariableReferenceExpressions.clear();
28+
}
2229

2330
@Override
2431
public void visit(FieldDeclaration declaration) {
@@ -66,7 +73,13 @@ public void visit(InstanceOfExpression expression) {
6673

6774
@Override
6875
public void visit(LocalVariableReferenceExpression expression) {
69-
((ClassFileLocalVariableReferenceExpression)expression).getLocalVariable().setDeclared(true);
76+
AbstractLocalVariable localVariable = ((ClassFileLocalVariableReferenceExpression)expression).getLocalVariable();
77+
78+
localVariableReferenceExpressions.add(expression);
79+
80+
if (localVariableReferenceExpressions.containsAll(localVariable.getReferences())) {
81+
localVariable.setDeclared(true);
82+
}
7083
}
7184

7285
@Override

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2019 Emmanuel Dupuy.
2+
* Copyright (c) 2008, 2019 Emmanuel Dupuy.
33
* This project is distributed under the GPLv3 license.
44
* This is a Copyleft license that gives the user the right to use,
55
* copy and modify the code freely for non-commercial purposes.
@@ -16,8 +16,7 @@
1616
import java.util.List;
1717

1818
public class RemoveFinallyStatementsVisitor implements StatementVisitor {
19-
protected static final DeclaredSyntheticLocalVariableVisitor DECLARED_SYNTHETIC_LOCAL_VARIABLE_VISITOR = new DeclaredSyntheticLocalVariableVisitor();
20-
19+
protected DeclaredSyntheticLocalVariableVisitor declaredSyntheticLocalVariableVisitor = new DeclaredSyntheticLocalVariableVisitor();
2120
protected LocalVariableMaker localVariableMaker;
2221
protected int statementCountInFinally;
2322
protected int statementCountToRemove;
@@ -63,24 +62,26 @@ public void visit(Statements statements) {
6362
}
6463

6564
// Remove 'finally' statements
65+
declaredSyntheticLocalVariableVisitor.init();
66+
6667
if (statementCountToRemove > 0) {
6768
// Remove 'finally' statements
6869
if (i > statementCountToRemove) {
6970
List<Statement> list = statements.subList(i - statementCountToRemove, i);
7071

7172
for (Statement statement : list) {
72-
statement.accept(DECLARED_SYNTHETIC_LOCAL_VARIABLE_VISITOR);
73+
statement.accept(declaredSyntheticLocalVariableVisitor);
7374
}
7475

75-
lastStatement.accept(DECLARED_SYNTHETIC_LOCAL_VARIABLE_VISITOR);
76+
lastStatement.accept(declaredSyntheticLocalVariableVisitor);
7677
list.clear();
7778
i -= statementCountToRemove;
7879
statementCountToRemove = 0;
7980
} else {
8081
List<Statement> list = statements;
8182

8283
for (Statement statement : list) {
83-
statement.accept(DECLARED_SYNTHETIC_LOCAL_VARIABLE_VISITOR);
84+
statement.accept(declaredSyntheticLocalVariableVisitor);
8485
}
8586

8687
list.clear();

0 commit comments

Comments
 (0)