decompiler: fixed line mapping for try-catch and nested classes

master
Egor.Ushakov 10 years ago
parent 47fad13908
commit 0bcd7fba5c
  1. 7
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 1
      src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
  3. 1
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
  4. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class
  5. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class
  6. BIN
      testData/classes/pkg/TestClassSimpleBytecodeMapping.class
  7. 80
      testData/results/TestClassSimpleBytecodeMapping.dec
  8. 22
      testData/src/pkg/TestClassSimpleBytecodeMapping.java

@ -254,8 +254,11 @@ public class ClassWriter {
if (hasContent) { if (hasContent) {
buffer.appendLineSeparator(); buffer.appendLineSeparator();
startLine++;
} }
classToJava(inner, buffer, indent + 1, tracer); BytecodeMappingTracer class_tracer = new BytecodeMappingTracer(startLine);
classToJava(inner, buffer, indent + 1, class_tracer);
startLine = buffer.countLines();
hasContent = true; hasContent = true;
} }
@ -840,7 +843,7 @@ public class ClassWriter {
// save total lines // save total lines
// TODO: optimize // TODO: optimize
tracer.setCurrentSourceLine(buffer.countLines(start_index_method)); //tracer.setCurrentSourceLine(buffer.countLines(start_index_method));
return !hideMethod; return !hideMethod;
} }

@ -280,6 +280,7 @@ public class ClassesProcessor {
} }
//buffer.append(lineSeparator); //buffer.append(lineSeparator);
total_offset_lines = buffer.countLines();
buffer.append(classBuffer); buffer.append(classBuffer);
if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) { if (DecompilerContext.getOption(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING)) {

@ -187,7 +187,6 @@ public class CatchStatement extends Statement {
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
buf.append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true, tracer)).append(indstr) buf.append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true, tracer)).append(indstr)
.append("}"); .append("}");
tracer.incrementCurrentSourceLine();
} }
buf.append(new_line_separator); buf.append(new_line_separator);

@ -8,6 +8,7 @@ public class TestClassSimpleBytecodeMapping {
System.out.println("Runnable"); System.out.println("Runnable");
} }
}); });
this.test2("1");
if(Math.random() > 0.0D) { if(Math.random() > 0.0D) {
System.out.println("0"); System.out.println("0");
return 0; return 0;
@ -17,9 +18,30 @@ public class TestClassSimpleBytecodeMapping {
} }
} }
public void test2(String var1) {
try {
Integer.parseInt(var1);
} catch (Exception var3) {
System.out.println(var3);
}
}
void run(Runnable var1) { void run(Runnable var1) {
var1.run(); var1.run();
} }
public class InnerClass2 {
public void print() {
System.out.println("Inner2");
}
}
public class InnerClass {
public void print() {
System.out.println("Inner");
}
}
} }
class 'pkg/TestClassSimpleBytecodeMapping$1' { class 'pkg/TestClassSimpleBytecodeMapping$1' {
@ -36,24 +58,46 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
3 4 3 4
5 4 5 4
11 5 11 5
14 10 15 10
17 10 17 10
18 10 1a 11
19 10 1d 11
1c 11 1e 11
1f 11 1f 11
21 11 22 12
24 12
25 12 25 12
26 14 27 12
29 14 2a 13
2b 14 2b 13
2e 15 2c 15
2f 15 2f 15
31 15
34 16
35 16
}
method 'test2 (Ljava/lang/String;)V' {
1 22
} }
method 'run (Ljava/lang/Runnable;)V' { method 'run (Ljava/lang/Runnable;)V' {
1 20 1 30
}
}
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass2' {
method 'print ()V' {
0 35
3 35
5 35
}
}
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass' {
method 'print ()V' {
0 41
3 41
5 41
} }
} }
@ -62,8 +106,12 @@ Lines mapping:
14 <-> 6 14 <-> 6
17 <-> 8 17 <-> 8
21 <-> 11 21 <-> 11
22 <-> 12 23 <-> 12
23 <-> 13 24 <-> 13
25 <-> 15 25 <-> 14
26 <-> 16 27 <-> 16
31 <-> 21 28 <-> 17
34 <-> 23
42 <-> 42
47 <-> 31
52 <-> 36

@ -18,6 +18,8 @@ public class TestClassSimpleBytecodeMapping {
} }
}); });
test2("1");
if(Math.random() > 0) { if(Math.random() > 0) {
System.out.println("0"); System.out.println("0");
return 0; return 0;
@ -27,7 +29,27 @@ public class TestClassSimpleBytecodeMapping {
} }
} }
public void test2(String a) {
try {
Integer.parseInt(a);
} catch (Exception e) {
System.out.println(e);
}
}
public class InnerClass {
public void print() {
System.out.println("Inner");
}
}
void run(Runnable r) { void run(Runnable r) {
r.run(); r.run();
} }
public class InnerClass2 {
public void print() {
System.out.println("Inner2");
}
}
} }

Loading…
Cancel
Save