From 0d80e663ae52c28312b7253ebb24ec6f46620113 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 21 Oct 2014 19:10:42 +0400 Subject: [PATCH] decompiler: fixed line mapping in try-catch block --- .../decompiler/stats/CatchAllStatement.java | 20 ++++++-------- ...lassSimpleBytecodeMapping$InnerClass.class | Bin 647 -> 647 bytes ...assSimpleBytecodeMapping$InnerClass2.class | Bin 650 -> 650 bytes .../pkg/TestClassSimpleBytecodeMapping.class | Bin 1234 -> 1338 bytes .../classes/pkg/TestTryCatchFinally.class | Bin 890 -> 1172 bytes .../TestClassSimpleBytecodeMapping.dec | 26 ++++++++++-------- testData/results/TestTryCatchFinally.dec | 15 ++++++++++ .../pkg/TestClassSimpleBytecodeMapping.java | 2 ++ testData/src/pkg/TestTryCatchFinally.java | 16 +++++++++++ 9 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java index f2321ac..a3d597d 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.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.vars.VarProcessor; import org.jetbrains.java.decompiler.struct.gen.VarType; -import org.jetbrains.java.decompiler.util.InterpreterUtil; import java.util.ArrayList; import java.util.Arrays; @@ -113,9 +112,6 @@ public class CatchAllStatement extends Statement { } public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { - String indstr = InterpreterUtil.getIndentString(indent); - String indstr1 = null; - String new_line_separator = DecompilerContext.getNewLineSeparator(); TextBuffer buf = new TextBuffer(); @@ -124,7 +120,7 @@ public class CatchAllStatement extends Statement { boolean labeled = isLabeled(); 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(); } @@ -133,33 +129,33 @@ public class CatchAllStatement extends Statement { !labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) { TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer); content.setLength(content.length() - new_line_separator.length()); + tracer.incrementCurrentSourceLine(-1); buf.append(content); } else { - buf.append(indstr).append("try {").append(new_line_separator); + buf.appendIndent(indent).append("try {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer)); - buf.append(indstr).append("}"); + buf.appendIndent(indent).append("}"); } 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(); if (monitor != null) { - indstr1 = InterpreterUtil.getIndentString(indent + 1); - buf.append(indstr1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").append(new_line_separator); + buf.appendIndent(indent+1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer)); if (monitor != null) { - buf.append(indstr1).append("}").append(new_line_separator); + buf.appendIndent(indent + 1).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } - buf.append(indstr).append("}").append(new_line_separator); + buf.appendIndent(indent).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); return buf; diff --git a/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class b/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class index bd3481b595d2962323804b5798c3af2f8536d2af..7c87161ed506b83d595000fb4e80ac07b527bb4e 100644 GIT binary patch delta 23 ecmZo?ZD-wJ$;7BN*@{VzRfmCtL3eU4lN10yZ3M0W delta 23 ecmZo?ZD-wJ$;7BJ*@{VzRf~axL3?s8lN10yGX$sr diff --git a/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class b/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class index b28c357352dddde5e162f26a2954c2098c9371a0..64638d907d634d5735c4c6dbabe5313df6a5567f 100644 GIT binary patch delta 23 ecmeBT?PA?v!^CJZ*_KI<)r^6I!F+N7lN10!c?8=4 delta 23 ecmeBT?PA?v!^CJb*_KI<)r5hA!E|x~lN10!KLphP diff --git a/testData/classes/pkg/TestClassSimpleBytecodeMapping.class b/testData/classes/pkg/TestClassSimpleBytecodeMapping.class index 010c748a4b0e901939b82ec4ac0a9fd151508f08..2d9a8beca899d1c4d239c59b703dae9264fea809 100644 GIT binary patch delta 629 zcmYk3TTc^F6otPtZ8_7^0b4+&MFra0DlL>&RJ`E@0Z~C?ygUy&DrPb@t?`nW^e;&I z=&Om(XoAXvzH8!x|H8!IVB9m&)Opxz@3q(2dz~{sk~^mJ_4m$aV3uo!LCQ%EaoA?k zP@$@sG9;KbWT@H9gjhE;IASwvILa}bTpsg)q`S_{70ZZ{N8 zukzZOvkDV2n=k$NoaWr-&s$?7WHsjen4$Wq8OFf7m>Ea zeUT*BeG^+&qupPza_4~bW2mY$#kRz7&MPdL47JKfoICHZ2K%>(zhz=o^6ECbdep$$ zzkKS;mQ0f6q#1~?ATcfWLbM_$C6bcoMN^`mGU<*qGZaNslI>-wN=(ZS4{fE0UDr(9 z(BzGj^1OfT6$C9|bmbFiMem{}qU&|}&(|x+{x!rvk+(f@!-(6k-6D$U_(;sDkL7$<3VMZ+3 zfCuCP+8Fg2bC?e(Fz)jr;3X55N!K~m!Zb6MSC(1J>)J}nyr~@?n916|@4X4SEN?^J z@!rt9R@vCyuUO_nK9H)fn&HI+^C8bj8_amfQ&N_XA)iD`x-l$jou7*fgYq2A|is1w|S0p2QvtlbWVO OvN3gb3gbfet?VAAjy2=} diff --git a/testData/classes/pkg/TestTryCatchFinally.class b/testData/classes/pkg/TestTryCatchFinally.class index 16dc30dc15fb6b2ac725db6c2c0b506e0cbf9540..244dfad62acaff777b67a3cdb983b0607dfb458a 100644 GIT binary patch literal 1172 zcmaJ>OHUJF6g|@iGYkWT@>Z}E6!=#Og%b^|1K$&T#Q*;!lkdl`FW&&nU{ysI;;k6PeFYCxJj9rSaTy5( zNfi@FDVUUzR-q!UU`qImFpq?pmho7|6A3K~re(TI5`u~3YYCw>yJ$#=Y?+p^Q#;x- zoV>nQW+vd^LT*tIZSy9-YbM?aEwqEh@WZ?~%k@1vGMeRRI zHzlY!yXF*(4O7e+$P=4)j@NXzu)kqidbxZ&B_?W!qFcr@4bL%4K2^KsQpKExdGt$= z-}+by-A#V$9|}grHEpYbr{t`L1>7UP(OW`)6YuL;t(oPb;jm`iacoD!B9??%*6;!= zET|loGPlr_(AjLYyLVs|DEdmu?|zM7e&4a*`wPAbJg&ON5wC<2xi){{rk#1kZM*DZ z=ttShHrLbCRS}>v6?ZksY+9~S5{i_H?oDzAf#w9nF!nxP*zRYa$ zKX}EpFO~NsZUVE2qmy5<_yr+}Tc+*dX_#K34^Ny!I%B|H(6)HVC~Y75X$AB<0tnO3 zeL^4_tRp0RnEnKbZ4t{}9NKB-JLms`216HTUb({AEo?Z17(JjMMca)L&!>>~e88hI zg*N`zOH7RXM~LcUHwdRFtZViQPDV~B&PY0%+N1WxllmjyQEtrSCuSdOa(CV E2TVZoBLDyZ delta 394 zcmXw#IZFdk5XXOSbG*%F6E)^G8jWWTk9apCiik~=pp9ib3NeUrHes!8ZERFn zMZv<-%F@qbAY`jb`&wGh7FEZ8iviz?AT=^6DPfg&ahc8W1!FL9yQdW#Rg=vw&&W91QF%^+%0;VuQfQ%SQilr1qiK}E~w;5JtuL 16 28 <-> 17 34 <-> 23 -42 <-> 42 -47 <-> 31 -52 <-> 36 +44 <-> 44 +49 <-> 33 +54 <-> 38 diff --git a/testData/results/TestTryCatchFinally.dec b/testData/results/TestTryCatchFinally.dec index 1524da8..9840bfc 100644 --- a/testData/results/TestTryCatchFinally.dec +++ b/testData/results/TestTryCatchFinally.dec @@ -1,6 +1,21 @@ package pkg; 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) { try { int var2 = Integer.parseInt(var1); diff --git a/testData/src/pkg/TestClassSimpleBytecodeMapping.java b/testData/src/pkg/TestClassSimpleBytecodeMapping.java index bc07e46..0b9df2e 100644 --- a/testData/src/pkg/TestClassSimpleBytecodeMapping.java +++ b/testData/src/pkg/TestClassSimpleBytecodeMapping.java @@ -34,6 +34,8 @@ public class TestClassSimpleBytecodeMapping { Integer.parseInt(a); } catch (Exception e) { System.out.println(e); + } finally { + System.out.println("Finally"); } } diff --git a/testData/src/pkg/TestTryCatchFinally.java b/testData/src/pkg/TestTryCatchFinally.java index 2e244be..da3588a 100644 --- a/testData/src/pkg/TestTryCatchFinally.java +++ b/testData/src/pkg/TestTryCatchFinally.java @@ -16,6 +16,22 @@ package pkg; 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) { try { return Integer.parseInt(a);