Skip to content

Commit 64a317c

Browse files
author
emmanue1
committed
Fix syntax errors in decompiled sources
1 parent e969802 commit 64a317c

File tree

1 file changed

+32
-20
lines changed
  • src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/localvariable

1 file changed

+32
-20
lines changed

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/model/localvariable/Frame.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.jd.core.v1.model.javasyntax.statement.Statements;
1616
import org.jd.core.v1.model.javasyntax.type.*;
1717
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.javasyntax.expression.ClassFileLocalVariableReferenceExpression;
18+
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.javasyntax.expression.ClassFileSuperConstructorInvocationExpression;
1819
import org.jd.core.v1.service.converter.classfiletojavasyntax.model.javasyntax.statement.ClassFileForStatement;
1920
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.LocalVariableMaker;
2021
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.SearchUndeclaredLocalVariableVisitor;
@@ -170,13 +171,6 @@ public void addChild(Frame child) {
170171
children.add(child);
171172
}
172173

173-
public void addNewExpression(NewExpression ne, AbstractLocalVariable lv) {
174-
if (newExpressions == null) {
175-
newExpressions = new HashMap<>();
176-
}
177-
newExpressions.put(ne, lv);
178-
}
179-
180174
public void close() {
181175
// Update lastType for 'new' expression
182176
if (newExpressions != null) {
@@ -340,17 +334,6 @@ protected boolean createInlineDeclarations() {
340334
break;
341335
}
342336
}
343-
344-
if (!undeclaredLocalVariables.isEmpty()) {
345-
DefaultList<AbstractLocalVariable> sorted = new DefaultList<>(undeclaredLocalVariables);
346-
sorted.sort(ABSTRACT_LOCAL_VARIABLE_COMPARATOR);
347-
348-
for (AbstractLocalVariable lv : sorted) {
349-
// Create start-block declarations
350-
statements.add(0, new LocalVariableDeclarationStatement(lv.getType(), new LocalVariableDeclarator(lv.getName())));
351-
lv.setDeclared(true);
352-
}
353-
}
354337
}
355338
}
356339

@@ -610,14 +593,18 @@ protected LocalVariableDeclarators createDeclarators1(DefaultList<BinaryOperator
610593

611594
@SuppressWarnings("unchecked")
612595
protected void createStartBlockDeclarations() {
596+
int addIndex = -1;
613597
int i = localVariableArray.length;
614598

615599
while (i-- > 0) {
616600
AbstractLocalVariable lv = localVariableArray[i];
617601

618602
while (lv != null) {
619-
if ((this != lv.getFrame()) && !lv.isDeclared()) {
620-
statements.add(0, new LocalVariableDeclarationStatement(lv.getType(), new LocalVariableDeclarator(lv.getName())));
603+
if (!lv.isDeclared()) {
604+
if (addIndex == -1) {
605+
addIndex = getAddIndex();
606+
}
607+
statements.add(addIndex, new LocalVariableDeclarationStatement(lv.getType(), new LocalVariableDeclarator(lv.getName())));
621608
lv.setDeclared(true);
622609
}
623610

@@ -626,6 +613,31 @@ protected void createStartBlockDeclarations() {
626613
}
627614
}
628615

616+
protected int getAddIndex() {
617+
int addIndex = 0;
618+
619+
if (parent.parent == null) {
620+
// Insert declarations after 'super' call invocation => Search index of SuperConstructorInvocationExpression.
621+
int len = statements.size();
622+
623+
while (addIndex < len) {
624+
Statement statement = statements.get(addIndex++);
625+
if (statement.getClass() == ExpressionStatement.class) {
626+
Expression expression = ((ExpressionStatement)statement).getExpression();
627+
if (expression.getClass() == ClassFileSuperConstructorInvocationExpression.class) {
628+
break;
629+
}
630+
}
631+
}
632+
633+
if (addIndex >= len) {
634+
addIndex = 0;
635+
}
636+
}
637+
638+
return addIndex;
639+
}
640+
629641
@SuppressWarnings("unchecked")
630642
protected void mergeDeclarations() {
631643
int size = statements.size();

0 commit comments

Comments
 (0)