decompiler: fixed line mapping in try-catch block

master
Egor.Ushakov 10 years ago
parent d00bc545fe
commit 0d80e663ae
  1. 20
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
  2. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class
  3. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class
  4. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping.class
  5. BIN
      testData/classes/pkg/TestTryCatchFinally.class
  6. 26
      testData/results/TestClassSimpleBytecodeMapping.dec
  7. 15
      testData/results/TestTryCatchFinally.dec
  8. 2
      testData/src/pkg/TestClassSimpleBytecodeMapping.java
  9. 16
      testData/src/pkg/TestTryCatchFinally.java

@ -26,7 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor; import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor;
import org.jetbrains.java.decompiler.struct.gen.VarType; import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -113,9 +112,6 @@ public class CatchAllStatement extends Statement {
} }
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
String indstr = InterpreterUtil.getIndentString(indent);
String indstr1 = null;
String new_line_separator = DecompilerContext.getNewLineSeparator(); String new_line_separator = DecompilerContext.getNewLineSeparator();
TextBuffer buf = new TextBuffer(); TextBuffer buf = new TextBuffer();
@ -124,7 +120,7 @@ public class CatchAllStatement extends Statement {
boolean labeled = isLabeled(); boolean labeled = isLabeled();
if (labeled) { if (labeled) {
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator); buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
@ -133,33 +129,33 @@ public class CatchAllStatement extends Statement {
!labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) { !labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) {
TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer); TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer);
content.setLength(content.length() - new_line_separator.length()); content.setLength(content.length() - new_line_separator.length());
tracer.incrementCurrentSourceLine(-1);
buf.append(content); buf.append(content);
} }
else { else {
buf.append(indstr).append("try {").append(new_line_separator); buf.appendIndent(indent).append("try {").appendLineSeparator();
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer)); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(indstr).append("}"); buf.appendIndent(indent).append("}");
} }
buf.append(isFinally ? " finally" : buf.append(isFinally ? " finally" :
" catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").append(new_line_separator); " catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").appendLineSeparator();
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
if (monitor != null) { if (monitor != null) {
indstr1 = InterpreterUtil.getIndentString(indent + 1); buf.appendIndent(indent+1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").appendLineSeparator();
buf.append(indstr1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").append(new_line_separator);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer)); buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer));
if (monitor != null) { if (monitor != null) {
buf.append(indstr1).append("}").append(new_line_separator); buf.appendIndent(indent + 1).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
} }
buf.append(indstr).append("}").append(new_line_separator); buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf; return buf;

@ -21,8 +21,10 @@ public class TestClassSimpleBytecodeMapping {
public void test2(String var1) { public void test2(String var1) {
try { try {
Integer.parseInt(var1); Integer.parseInt(var1);
} catch (Exception var3) { } catch (Exception var6) {
System.out.println(var3); System.out.println(var6);
} finally {
System.out.println("Finally");
} }
} }
@ -81,23 +83,23 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
} }
method 'run (Ljava/lang/Runnable;)V' { method 'run (Ljava/lang/Runnable;)V' {
1 30 1 32
} }
} }
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass2' { class 'pkg/TestClassSimpleBytecodeMapping$InnerClass2' {
method 'print ()V' { method 'print ()V' {
0 35 0 37
3 35 3 37
5 35 5 37
} }
} }
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass' { class 'pkg/TestClassSimpleBytecodeMapping$InnerClass' {
method 'print ()V' { method 'print ()V' {
0 41 0 43
3 41 3 43
5 41 5 43
} }
} }
@ -112,6 +114,6 @@ Lines mapping:
27 <-> 16 27 <-> 16
28 <-> 17 28 <-> 17
34 <-> 23 34 <-> 23
42 <-> 42 44 <-> 44
47 <-> 31 49 <-> 33
52 <-> 36 54 <-> 38

@ -1,6 +1,21 @@
package pkg; package pkg;
public class TestTryCatchFinally { public class TestTryCatchFinally {
public void test1(String var1) {
try {
System.out.println("sout1");
} catch (Exception var9) {
try {
System.out.println("sout2");
} catch (Exception var8) {
;
}
} finally {
System.out.println("finally");
}
}
public int test(String var1) { public int test(String var1) {
try { try {
int var2 = Integer.parseInt(var1); int var2 = Integer.parseInt(var1);

@ -34,6 +34,8 @@ public class TestClassSimpleBytecodeMapping {
Integer.parseInt(a); Integer.parseInt(a);
} catch (Exception e) { } catch (Exception e) {
System.out.println(e); System.out.println(e);
} finally {
System.out.println("Finally");
} }
} }

@ -16,6 +16,22 @@
package pkg; package pkg;
public class TestTryCatchFinally { public class TestTryCatchFinally {
public void test1(String x) {
try {
System.out.println("sout1");
} catch (Exception e) {
try {
System.out.println("sout2");
} catch (Exception e2) {
// Empty
// Empty
// Empty
}
} finally {
System.out.println("finally");
}
}
public int test(String a) { public int test(String a) {
try { try {
return Integer.parseInt(a); return Integer.parseInt(a);

Loading…
Cancel
Save