[java decompiler] adds an empty line before local classes

master
Roman Shevchenko 7 years ago
parent a3332a5f31
commit 45486cd4d4
  1. 1
      src/org/jetbrains/java/decompiler/main/TextBuffer.java
  2. 10
      src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
  3. 49
      testData/results/TestLocalClass.dec

@ -10,6 +10,7 @@ import java.util.*;
* *
* @author egor * @author egor
*/ */
@SuppressWarnings("UnusedReturnValue")
public class TextBuffer { public class TextBuffer {
private final String myLineSeparator = DecompilerContext.getNewLineSeparator(); private final String myLineSeparator = DecompilerContext.getNewLineSeparator();
private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING); private final String myIndent = (String)DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING);

@ -731,8 +731,7 @@ public class ExprProcessor implements CodeConstants {
return !(type == Exprent.EXPRENT_SWITCH || return !(type == Exprent.EXPRENT_SWITCH ||
type == Exprent.EXPRENT_MONITOR || type == Exprent.EXPRENT_MONITOR ||
type == Exprent.EXPRENT_IF || type == Exprent.EXPRENT_IF ||
(type == Exprent.EXPRENT_VAR && ((VarExprent)expr) (type == Exprent.EXPRENT_VAR && ((VarExprent)expr).isClassDef()));
.isClassDef()));
} }
private static void addDeletedGotoInstructionMapping(Statement stat, BytecodeMappingTracer tracer) { private static void addDeletedGotoInstructionMapping(Statement stat, BytecodeMappingTracer tracer) {
@ -803,7 +802,14 @@ public class ExprProcessor implements CodeConstants {
TextBuffer buf = new TextBuffer(); TextBuffer buf = new TextBuffer();
for (Exprent expr : lst) { for (Exprent expr : lst) {
if (buf.length() > 0 && expr.type == Exprent.EXPRENT_VAR && ((VarExprent)expr).isClassDef()) {
// separates local class definition from previous statements
buf.appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
TextBuffer content = expr.toJava(indent, tracer); TextBuffer content = expr.toJava(indent, tracer);
if (content.length() > 0) { if (content.length() > 0) {
if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassDef()) { if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassDef()) {
buf.appendIndent(indent); buf.appendIndent(indent);

@ -3,6 +3,7 @@ package pkg;
public abstract class TestLocalClass { public abstract class TestLocalClass {
void foo() { void foo() {
boolean var1 = true;// 8 boolean var1 = true;// 8
class Local { class Local {
void foo() { void foo() {
boolean var1 = true;// 11 boolean var1 = true;// 11
@ -25,11 +26,11 @@ public abstract class TestLocalClass {
class 'pkg/TestLocalClass$1Local' { class 'pkg/TestLocalClass$1Local' {
method 'foo ()V' { method 'foo ()V' {
0 7 0 8
1 7 1 8
2 8 2 9
3 8 3 9
4 9 4 10
} }
} }
@ -37,33 +38,33 @@ class 'pkg/TestLocalClass' {
method 'foo ()V' { method 'foo ()V' {
0 4 0 4
1 4 1 4
a 12 a 13
c 13 c 14
f 14 f 15
} }
method 'boo ()V' { method 'boo ()V' {
0 17 0 18
1 17 1 18
2 18 2 19
} }
method 'zoo ()V' { method 'zoo ()V' {
0 21 0 22
1 21 1 22
2 22 2 23
} }
} }
Lines mapping: Lines mapping:
8 <-> 5 8 <-> 5
11 <-> 8 11 <-> 9
12 <-> 9 12 <-> 10
13 <-> 10 13 <-> 11
15 <-> 13 15 <-> 14
16 <-> 14 16 <-> 15
17 <-> 15 17 <-> 16
20 <-> 18 20 <-> 19
21 <-> 19 21 <-> 20
24 <-> 22 24 <-> 23
25 <-> 23 25 <-> 24

Loading…
Cancel
Save