fix extra semicolon in decompiled empty blocks IDEA-196314 #843
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
/*
|
// 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.
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.code.CodeConstants;
|
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(vars.get(i - 1).toJava(indent, tracer));
|
||||||
buf.append(") {").appendLineSeparator();
|
buf.append(") {").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
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("}");
|
.append("}");
|
||||||
}
|
}
|
||||||
buf.appendLineSeparator();
|
buf.appendLineSeparator();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/*
|
// 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.
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.util.TextBuffer;
|
import org.jetbrains.java.decompiler.util.TextBuffer;
|
||||||
@@ -93,21 +91,21 @@ public class DoStatement extends Statement {
|
|||||||
case LOOP_DO:
|
case LOOP_DO:
|
||||||
buf.appendIndent(indent).append("while(true) {").appendLineSeparator();
|
buf.appendIndent(indent).append("while(true) {").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
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();
|
buf.appendIndent(indent).append("}").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
break;
|
break;
|
||||||
case LOOP_DOWHILE:
|
case LOOP_DOWHILE:
|
||||||
buf.appendIndent(indent).append("do {").appendLineSeparator();
|
buf.appendIndent(indent).append("do {").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
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();
|
buf.appendIndent(indent).append("} while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(");").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
break;
|
break;
|
||||||
case LOOP_WHILE:
|
case LOOP_WHILE:
|
||||||
buf.appendIndent(indent).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").appendLineSeparator();
|
buf.appendIndent(indent).append("while(").append(conditionExprent.get(0).toJava(indent, tracer)).append(") {").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
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();
|
buf.appendIndent(indent).append("}").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
break;
|
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(") {")
|
.append(conditionExprent.get(0).toJava(indent, tracer)).append("; ").append(incExprent.get(0).toJava(indent, tracer)).append(") {")
|
||||||
.appendLineSeparator();
|
.appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
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();
|
buf.appendIndent(indent).append("}").appendLineSeparator();
|
||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/*
|
// 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.
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
package org.jetbrains.java.decompiler.modules.decompiler.stats;
|
||||||
|
|
||||||
import org.jetbrains.java.decompiler.util.TextBuffer;
|
import org.jetbrains.java.decompiler.util.TextBuffer;
|
||||||
@@ -204,24 +202,26 @@ public class IfStatement extends Statement {
|
|||||||
tracer.incrementCurrentSourceLine();
|
tracer.incrementCurrentSourceLine();
|
||||||
|
|
||||||
if (ifstat == null) {
|
if (ifstat == null) {
|
||||||
buf.appendIndent(indent + 1);
|
boolean semicolon = false;
|
||||||
|
|
||||||
if (ifedge.explicit) {
|
if (ifedge.explicit) {
|
||||||
|
semicolon = true;
|
||||||
if (ifedge.getType() == StatEdge.TYPE_BREAK) {
|
if (ifedge.getType() == StatEdge.TYPE_BREAK) {
|
||||||
// break
|
// break
|
||||||
buf.append("break");
|
buf.appendIndent(indent + 1).append("break");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// continue
|
// continue
|
||||||
buf.append("continue");
|
buf.appendIndent(indent + 1).append("continue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifedge.labeled) {
|
if (ifedge.labeled) {
|
||||||
buf.append(" label").append(ifedge.closure.id.toString());
|
buf.append(" label").append(ifedge.closure.id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.append(";").appendLineSeparator();
|
if(semicolon) {
|
||||||
tracer.incrementCurrentSourceLine();
|
buf.append(";").appendLineSeparator();
|
||||||
|
tracer.incrementCurrentSourceLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
buf.append(ExprProcessor.jmpWrapper(ifstat, indent + 1, true, tracer));
|
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 testSuperInner() { doTest("pkg/TestSuperInner", "pkg/TestSuperInnerBase"); }
|
||||||
@Test public void testMissingConstructorCallGood() { doTest("pkg/TestMissingConstructorCallGood"); }
|
@Test public void testMissingConstructorCallGood() { doTest("pkg/TestMissingConstructorCallGood"); }
|
||||||
@Test public void testMissingConstructorCallBad() { doTest("pkg/TestMissingConstructorCallBad"); }
|
@Test public void testMissingConstructorCallBad() { doTest("pkg/TestMissingConstructorCallBad"); }
|
||||||
|
@Test public void testEmptyBlocks() { doTest("pkg/TestEmptyBlocks"); }
|
||||||
|
|
||||||
|
|
||||||
// TODO: fix all below
|
// TODO: fix all below
|
||||||
|
|||||||
BIN
testData/classes/pkg/TestEmptyBlocks.class
Normal file
BIN
testData/classes/pkg/TestEmptyBlocks.class
Normal file
Binary file not shown.
@@ -150,7 +150,6 @@ public class bc extends DefaultHandler {
|
|||||||
var4.setContentHandler(this);
|
var4.setContentHandler(this);
|
||||||
var4.parse(new InputSource(var1));
|
var4.parse(new InputSource(var1));
|
||||||
} catch (a_ var8) {
|
} catch (a_ var8) {
|
||||||
;
|
|
||||||
} finally {
|
} finally {
|
||||||
var1.close();
|
var1.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,7 +236,6 @@ public class bd {
|
|||||||
try {
|
try {
|
||||||
b.update(var0.getBytes(j));
|
b.update(var0.getBytes(j));
|
||||||
} catch (UnsupportedEncodingException var4) {
|
} catch (UnsupportedEncodingException var4) {
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] var2 = b.digest();
|
byte[] var2 = b.digest();
|
||||||
@@ -260,7 +259,6 @@ public class bd {
|
|||||||
try {
|
try {
|
||||||
var2 = (var0 + a).getBytes(j);
|
var2 = (var0 + a).getBytes(j);
|
||||||
} catch (UnsupportedEncodingException var9) {
|
} catch (UnsupportedEncodingException var9) {
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.update(var2);
|
b.update(var2);
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class TestClassVar {
|
|||||||
while(var1 < 10) {// 47
|
while(var1 < 10) {// 47
|
||||||
int var2;
|
int var2;
|
||||||
for(var2 = var1; var1 < 10 && var1 == 0; ++var1) {// 49 51
|
for(var2 = var1; var1 < 10 && var1 == 0; ++var1) {// 49 51
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var2 != var1) {// 54
|
if (var2 != var1) {// 54
|
||||||
@@ -72,10 +71,10 @@ class 'pkg/TestClassVar' {
|
|||||||
d 29
|
d 29
|
||||||
11 29
|
11 29
|
||||||
14 29
|
14 29
|
||||||
1c 33
|
1c 32
|
||||||
1f 34
|
1f 33
|
||||||
22 34
|
22 33
|
||||||
28 38
|
28 37
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +89,8 @@ Lines mapping:
|
|||||||
47 <-> 28
|
47 <-> 28
|
||||||
49 <-> 30
|
49 <-> 30
|
||||||
51 <-> 30
|
51 <-> 30
|
||||||
54 <-> 34
|
54 <-> 33
|
||||||
55 <-> 35
|
55 <-> 34
|
||||||
58 <-> 39
|
58 <-> 38
|
||||||
Not mapped:
|
Not mapped:
|
||||||
57
|
57
|
||||||
|
|||||||
47
testData/results/TestEmptyBlocks.dec
Normal file
47
testData/results/TestEmptyBlocks.dec
Normal file
@@ -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 {
|
try {
|
||||||
new TestMissingConstructorCallBad();
|
new TestMissingConstructorCallBad();
|
||||||
} catch (Throwable var2) {// 37
|
} catch (Throwable var2) {// 37
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}// 39
|
}// 39
|
||||||
@@ -28,7 +27,7 @@ class 'pkg/TestMissingConstructorCallBad' {
|
|||||||
|
|
||||||
method 'main ([Ljava/lang/String;)V' {
|
method 'main ([Ljava/lang/String;)V' {
|
||||||
b 11
|
b 11
|
||||||
c 15
|
c 14
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ Lines mapping:
|
|||||||
20 <-> 6
|
20 <-> 6
|
||||||
21 <-> 7
|
21 <-> 7
|
||||||
37 <-> 12
|
37 <-> 12
|
||||||
39 <-> 16
|
39 <-> 15
|
||||||
Not mapped:
|
Not mapped:
|
||||||
18
|
18
|
||||||
28
|
28
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public class TestMissingConstructorCallGood {
|
|||||||
try {
|
try {
|
||||||
new TestMissingConstructorCallGood();
|
new TestMissingConstructorCallGood();
|
||||||
} catch (Throwable var2) {// 45
|
} catch (Throwable var2) {// 45
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}// 47
|
}// 47
|
||||||
@@ -35,7 +34,7 @@ class 'pkg/TestMissingConstructorCallGood' {
|
|||||||
|
|
||||||
method 'main ([Ljava/lang/String;)V' {
|
method 'main ([Ljava/lang/String;)V' {
|
||||||
b 14
|
b 14
|
||||||
c 18
|
c 17
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ Lines mapping:
|
|||||||
28 <-> 9
|
28 <-> 9
|
||||||
29 <-> 10
|
29 <-> 10
|
||||||
45 <-> 15
|
45 <-> 15
|
||||||
47 <-> 19
|
47 <-> 18
|
||||||
Not mapped:
|
Not mapped:
|
||||||
14
|
14
|
||||||
15
|
15
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ public class TestTryCatchFinally {
|
|||||||
try {
|
try {
|
||||||
System.out.println("sout2");// 27
|
System.out.println("sout2");// 27
|
||||||
} catch (Exception var8) {// 28
|
} catch (Exception var8) {// 28
|
||||||
;
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
System.out.println("finally");// 34
|
System.out.println("finally");// 34
|
||||||
@@ -49,36 +48,36 @@ class 'pkg/TestTryCatchFinally' {
|
|||||||
17 8
|
17 8
|
||||||
19 8
|
19 8
|
||||||
1f 9
|
1f 9
|
||||||
2b 13
|
2b 12
|
||||||
2d 13
|
2d 12
|
||||||
30 13
|
30 12
|
||||||
38 16
|
38 15
|
||||||
}
|
}
|
||||||
|
|
||||||
method 'foo (I)I' {
|
method 'foo (I)I' {
|
||||||
1 19
|
1 18
|
||||||
2 19
|
2 18
|
||||||
c 20
|
c 19
|
||||||
e 21
|
e 20
|
||||||
f 21
|
f 20
|
||||||
13 22
|
13 21
|
||||||
1b 24
|
1b 23
|
||||||
}
|
}
|
||||||
|
|
||||||
method 'test (Ljava/lang/String;)I' {
|
method 'test (Ljava/lang/String;)I' {
|
||||||
1 30
|
1 29
|
||||||
4 30
|
4 29
|
||||||
e 31
|
e 30
|
||||||
f 32
|
f 31
|
||||||
10 33
|
10 32
|
||||||
1a 33
|
1a 32
|
||||||
23 33
|
23 32
|
||||||
26 33
|
26 32
|
||||||
31 38
|
31 37
|
||||||
34 35
|
34 34
|
||||||
35 35
|
35 34
|
||||||
38 35
|
38 34
|
||||||
3f 38
|
3f 37
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,19 +85,19 @@ Lines mapping:
|
|||||||
24 <-> 6
|
24 <-> 6
|
||||||
27 <-> 9
|
27 <-> 9
|
||||||
28 <-> 10
|
28 <-> 10
|
||||||
34 <-> 14
|
34 <-> 13
|
||||||
36 <-> 17
|
36 <-> 16
|
||||||
39 <-> 20
|
39 <-> 19
|
||||||
40 <-> 21
|
40 <-> 20
|
||||||
41 <-> 22
|
41 <-> 21
|
||||||
42 <-> 23
|
42 <-> 22
|
||||||
45 <-> 25
|
45 <-> 24
|
||||||
51 <-> 31
|
51 <-> 30
|
||||||
52 <-> 33
|
52 <-> 32
|
||||||
53 <-> 34
|
53 <-> 33
|
||||||
55 <-> 36
|
55 <-> 35
|
||||||
56 <-> 39
|
56 <-> 38
|
||||||
57 <-> 39
|
57 <-> 38
|
||||||
Not mapped:
|
Not mapped:
|
||||||
25
|
25
|
||||||
32
|
32
|
||||||
|
|||||||
48
testData/src/pkg/TestEmptyBlocks.java
Normal file
48
testData/src/pkg/TestEmptyBlocks.java
Normal file
@@ -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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user