From 6d03229b91838f741cd2a1b32ce67a3d155501f1 Mon Sep 17 00:00:00 2001 From: Stiver Date: Wed, 15 Oct 2014 08:35:45 +0200 Subject: [PATCH] Unit test --- .../main/collectors/BytecodeSourceMapper.java | 14 +++++-- .../pkg/TestClassSimpleBytecodeMapping.class | Bin 0 -> 675 bytes .../TestClassSimpleBytecodeMapping.dec | 36 ++++++++++++++++++ .../pkg/TestClassSimpleBytecodeMapping.java | 20 ++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 testData/classes/pkg/TestClassSimpleBytecodeMapping.class create mode 100644 testData/results/TestClassSimpleBytecodeMapping.dec create mode 100644 testData/src/pkg/TestClassSimpleBytecodeMapping.java diff --git a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java index ca37b5b..6cbaa83 100644 --- a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java +++ b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java @@ -1,6 +1,9 @@ package org.jetbrains.java.decompiler.main.collectors; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map.Entry; import org.jetbrains.java.decompiler.main.DecompilerContext; @@ -55,9 +58,14 @@ public class BytecodeSourceMapper { } buffer.appendIndent(1).append("method " + method_entry.getKey() + "{" + lineSeparator); - for(Entry line : method_mapping.entrySet()) { - String strOffset = offsetsToHex ? Integer.toHexString(line.getKey()): line.getKey().toString(); - buffer.appendIndent(2).append(strOffset).appendIndent(2).append((line.getValue() + offset_total) + lineSeparator); + List lstBytecodeOffsets = new ArrayList(method_mapping.keySet()); + Collections.sort(lstBytecodeOffsets); + + for(Integer offset : lstBytecodeOffsets) { + Integer line = method_mapping.get(offset); + + String strOffset = offsetsToHex ? Integer.toHexString(offset): line.toString(); + buffer.appendIndent(2).append(strOffset).appendIndent(2).append((line + offset_total) + lineSeparator); } buffer.appendIndent(1).append("}").appendLineSeparator(); is_first_method = false; diff --git a/testData/classes/pkg/TestClassSimpleBytecodeMapping.class b/testData/classes/pkg/TestClassSimpleBytecodeMapping.class new file mode 100644 index 0000000000000000000000000000000000000000..1313994dfa069c3433c8fc4d216502d1d754329d GIT binary patch literal 675 zcmah`%We}v5UjB`*|k|G#vu^QGmZf}NGwR)j5rX4gyaCyM!t_XgER5Iv^z%1mvG|? za)AShIPd{{6ryIa6d@tF^kcfas;2wL&u`xWJjFv7HGy6}p9Kf1G<&fu%TOnItX`ZL z6=jENU*@?^XD%Fp_ObjRgIK1s;O+ESMMhxtnNGENE>Ir~Cj!nMN1CXk;bR4>0_$U) zsyB;ds)_?Sjg>%WoJBI8$U@tE`RJG37VO;|SK4(Jyeo8SLQ^Q2j67W97pCfcR#5eI+;Gtq*!WAUkDIt9;O2HZP6;^p zjaY4iaNN;oIBDVzwq4v6Si9KOzBETZde|XXA=ASwskFcJa8E!y_V9r2i9jnfGMaPY z%cV5KY*9q&m9}f!`S*PuSvqWk$UH1iW5ff{y37K4LBFzl2JdrKZqnK^A90D+U&cOK z%%~shw03w7r>gb8pxwFp6 0.0D) { + System.out.println("0"); + return 0; + } else { + System.out.println("1"); + return 1; + } + } +} + +class test/TestClassSimpleBytecodeMapping{ + method test ()I{ + 0 4 + 3 4 + 5 4 + 8 5 + b 5 + c 5 + d 5 + 10 6 + 13 6 + 15 6 + 18 7 + 19 7 + 1a 9 + 1d 9 + 1f 9 + 22 10 + 23 10 + } +} diff --git a/testData/src/pkg/TestClassSimpleBytecodeMapping.java b/testData/src/pkg/TestClassSimpleBytecodeMapping.java new file mode 100644 index 0000000..8233fa9 --- /dev/null +++ b/testData/src/pkg/TestClassSimpleBytecodeMapping.java @@ -0,0 +1,20 @@ +package pkg; + +public class TestClassSimpleBytecodeMapping { + + public TestClassSimpleBytecodeMapping() {} + + public int test() { + + System.out.println("before"); + + if(Math.random() > 0) { + System.out.println("0"); + return 0; + } else { + System.out.println("1"); + return 1; + } + } + +}