fix extra semicolon in decompiled empty blocks IDEA-196314 #843

master
temp1011 6 years ago committed by Egor Ushakov
parent 8824c20cbb
commit 02fdbec132
  1. 6
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
  2. 12
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/DoStatement.java
  3. 14
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/IfStatement.java
  4. 1
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  5. BIN
      testData/classes/pkg/TestEmptyBlocks.class
  6. 1
      testData/obfuscated/bc.java
  7. 2
      testData/obfuscated/bd.java
  8. 15
      testData/results/TestClassVar.dec
  9. 47
      testData/results/TestEmptyBlocks.dec
  10. 5
      testData/results/TestMissingConstructorCallBad.dec
  11. 5
      testData/results/TestMissingConstructorCallGood.dec
  12. 75
      testData/results/TestTryCatchFinally.dec
  13. 48
      testData/src/pkg/TestEmptyBlocks.java

@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.CodeConstants;
@ -171,7 +169,7 @@ public class CatchStatement extends Statement {
buf.append(vars.get(i - 1).toJava(indent, tracer));
buf.append(") {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, true, tracer)).appendIndent(indent)
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false, tracer)).appendIndent(indent)
.append("}");
}
buf.appendLineSeparator();

@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.util.TextBuffer;
@ -93,21 +91,21 @@ public class DoStatement extends Statement {
case LOOP_DO:
buf.appendIndent(indent).append("while(true) {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, false, tracer));
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
case LOOP_DOWHILE:
buf.appendIndent(indent).append("do {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, false, tracer));
buf.appendIndent(indent).append("} while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
case LOOP_WHILE:
buf.appendIndent(indent).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, false, tracer));
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
break;
@ -120,7 +118,7 @@ public class DoStatement extends Statement {
.append(conditionExprent.get(0).toJava(indent, tracer)).append("; ").append(incExprent.get(0).toJava(indent, tracer)).append(") {")
.appendLineSeparator();
tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, false, tracer));
buf.appendIndent(indent).append("}").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.util.TextBuffer;
@ -204,25 +202,27 @@ public class IfStatement extends Statement {
tracer.incrementCurrentSourceLine();
if (ifstat == null) {
buf.appendIndent(indent + 1);
boolean semicolon = false;
if (ifedge.explicit) {
semicolon = true;
if (ifedge.getType() == StatEdge.TYPE_BREAK) {
// break
buf.append("break");
buf.appendIndent(indent + 1).append("break");
}
else {
// continue
buf.append("continue");
buf.appendIndent(indent + 1).append("continue");
}
if (ifedge.labeled) {
buf.append(" label").append(ifedge.closure.id.toString());
}
}
if(semicolon) {
buf.append(";").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
}
else {
buf.append(ExprProcessor.jmpWrapper(ifstat, indent + 1, true, tracer));
}

@ -107,6 +107,7 @@ public class SingleClassesTest {
@Test public void testSuperInner() { doTest("pkg/TestSuperInner", "pkg/TestSuperInnerBase"); }
@Test public void testMissingConstructorCallGood() { doTest("pkg/TestMissingConstructorCallGood"); }
@Test public void testMissingConstructorCallBad() { doTest("pkg/TestMissingConstructorCallBad"); }
@Test public void testEmptyBlocks() { doTest("pkg/TestEmptyBlocks"); }
// TODO: fix all below

@ -150,7 +150,6 @@ public class bc extends DefaultHandler {
var4.setContentHandler(this);
var4.parse(new InputSource(var1));
} catch (a_ var8) {
;
} finally {
var1.close();
}

@ -236,7 +236,6 @@ public class bd {
try {
b.update(var0.getBytes(j));
} catch (UnsupportedEncodingException var4) {
;
}
byte[] var2 = b.digest();
@ -260,7 +259,6 @@ public class bd {
try {
var2 = (var0 + a).getBytes(j);
} catch (UnsupportedEncodingException var9) {
;
}
b.update(var2);

@ -28,7 +28,6 @@ public class TestClassVar {
while(var1 < 10) {// 47
int var2;
for(var2 = var1; var1 < 10 && var1 == 0; ++var1) {// 49 51
;
}
if (var2 != var1) {// 54
@ -72,10 +71,10 @@ class 'pkg/TestClassVar' {
d 29
11 29
14 29
1c 33
1f 34
22 34
28 38
1c 32
1f 33
22 33
28 37
}
}
@ -90,8 +89,8 @@ Lines mapping:
47 <-> 28
49 <-> 30
51 <-> 30
54 <-> 34
55 <-> 35
58 <-> 39
54 <-> 33
55 <-> 34
58 <-> 38
Not mapped:
57

@ -0,0 +1,47 @@
import java.util.Random;
public class TestEmptyBlocks {
public static void foo() {
try {
boolean var0 = false;// 22
} catch (Exception var1) {// 23
}
for(int i = 0; i < 5; ++i) {// 27
}
while((new Random()).nextBoolean()) {// 31
}
if ((new Random()).nextBoolean()) {// 35
}
}// 38
}
class 'TestEmptyBlocks' {
method 'foo ()V' {
0 5
1 5
5 6
6 9
7 9
9 9
a 9
d 9
1a 12
2a 15
2d 15
30 18
}
}
Lines mapping:
22 <-> 6
23 <-> 7
27 <-> 10
31 <-> 13
35 <-> 16
38 <-> 19
Not mapped:
25

@ -10,7 +10,6 @@ public class TestMissingConstructorCallBad {
try {
new TestMissingConstructorCallBad();
} catch (Throwable var2) {// 37
;
}
}// 39
@ -28,7 +27,7 @@ class 'pkg/TestMissingConstructorCallBad' {
method 'main ([Ljava/lang/String;)V' {
b 11
c 15
c 14
}
}
@ -40,7 +39,7 @@ Lines mapping:
20 <-> 6
21 <-> 7
37 <-> 12
39 <-> 16
39 <-> 15
Not mapped:
18
28

@ -13,7 +13,6 @@ public class TestMissingConstructorCallGood {
try {
new TestMissingConstructorCallGood();
} catch (Throwable var2) {// 45
;
}
}// 47
@ -35,7 +34,7 @@ class 'pkg/TestMissingConstructorCallGood' {
method 'main ([Ljava/lang/String;)V' {
b 14
c 18
c 17
}
}
@ -48,7 +47,7 @@ Lines mapping:
28 <-> 9
29 <-> 10
45 <-> 15
47 <-> 19
47 <-> 18
Not mapped:
14
15

@ -8,7 +8,6 @@ public class TestTryCatchFinally {
try {
System.out.println("sout2");// 27
} catch (Exception var8) {// 28
;
}
} finally {
System.out.println("finally");// 34
@ -49,36 +48,36 @@ class 'pkg/TestTryCatchFinally' {
17 8
19 8
1f 9
2b 13
2d 13
30 13
38 16
2b 12
2d 12
30 12
38 15
}
method 'foo (I)I' {
1 19
2 19
c 20
e 21
f 21
13 22
1b 24
1 18
2 18
c 19
e 20
f 20
13 21
1b 23
}
method 'test (Ljava/lang/String;)I' {
1 30
4 30
e 31
f 32
10 33
1a 33
23 33
26 33
31 38
34 35
35 35
38 35
3f 38
1 29
4 29
e 30
f 31
10 32
1a 32
23 32
26 32
31 37
34 34
35 34
38 34
3f 37
}
}
@ -86,19 +85,19 @@ Lines mapping:
24 <-> 6
27 <-> 9
28 <-> 10
34 <-> 14
36 <-> 17
39 <-> 20
40 <-> 21
41 <-> 22
42 <-> 23
45 <-> 25
51 <-> 31
52 <-> 33
53 <-> 34
55 <-> 36
56 <-> 39
57 <-> 39
34 <-> 13
36 <-> 16
39 <-> 19
40 <-> 20
41 <-> 21
42 <-> 22
45 <-> 24
51 <-> 30
52 <-> 32
53 <-> 33
55 <-> 35
56 <-> 38
57 <-> 38
Not mapped:
25
32

@ -0,0 +1,48 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Random;
public class TestEmptyBlocks {
public static void foo() {
try {
int a = 0; //make sure whole try/catch not removed by compiler
} catch(Exception e) {
}
for(int i = 0; i < 5; i++) {
}
while(new Random().nextBoolean()) {
}
if(new Random().nextBoolean()) {
}
}
}
Loading…
Cancel
Save