summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/jetbrains/java/decompiler/main')
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassWriter.java13
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassesProcessor.java3
-rw-r--r--src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java25
-rw-r--r--src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java2
4 files changed, 32 insertions, 11 deletions
diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
index 830e668..0383dd4 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
@@ -182,8 +182,8 @@ public class ClassWriter {
int start_class_def = buffer.length();
writeClassDefinition(node, buffer, indent);
- // count lines in class definition the easiest way
- total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
+// // count lines in class definition the easiest way
+// total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
boolean hasContent = false;
@@ -220,6 +220,9 @@ public class ClassWriter {
buffer.append(lineSeparator);
}
+ // FIXME: fields don't matter at the moment
+ total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
+
// methods
for (StructMethod mt : cl.getMethods()) {
boolean hide = mt.isSynthetic() && DecompilerContext.getOption(IFernflowerPreferences.REMOVE_SYNTHETIC) ||
@@ -237,7 +240,7 @@ public class ClassWriter {
hasContent = true;
DecompilerContext.getBytecodeSourceMapper().addTracer(cl.qualifiedName,
InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor()), method_tracer);
- total_offset_lines = method_tracer.getCurrentSourceline();
+ total_offset_lines = (method_tracer.getCurrentSourceLine() + 1); // zero-based line index
}
else {
buffer.setLength(position);
@@ -805,7 +808,7 @@ public class ClassWriter {
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
try {
- tracer.setCurrentSourceline(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
+ tracer.incrementCurrentSourceLine(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
String code = root.toJava(indent + 1, tracer);
@@ -836,7 +839,7 @@ public class ClassWriter {
// save total lines
// TODO: optimize
- tracer.setCurrentSourceline(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
+ tracer.setCurrentSourceLine(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
return !hideMethod;
}
diff --git a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
index bab6976..c79e355 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
@@ -268,7 +268,7 @@ public class ClassesProcessor {
int index = cl.qualifiedName.lastIndexOf("/");
if (index >= 0) {
- total_offset_lines++;
+ total_offset_lines+=2;
String packageName = cl.qualifiedName.substring(0, index).replace('/', '.');
buffer.append("package ");
@@ -283,6 +283,7 @@ public class ClassesProcessor {
buffer.append(lineSeparator);
total_offset_lines += import_lines_written + 1;
}
+ //buffer.append(lineSeparator);
buffer.append(classBuffer);
diff --git a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java
index 95321e5..20af427 100644
--- a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java
+++ b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java
@@ -1,6 +1,7 @@
package org.jetbrains.java.decompiler.main.collectors;
import java.util.HashMap;
+import java.util.Map.Entry;
import java.util.Set;
public class BytecodeMappingTracer {
@@ -16,14 +17,20 @@ public class BytecodeMappingTracer {
current_sourceline = initial_source_line;
}
- public void incrementSourceLine() {
+ public void incrementCurrentSourceLine() {
current_sourceline++;
}
- public void incrementSourceLine(int number_lines) {
+ public void incrementCurrentSourceLine(int number_lines) {
current_sourceline += number_lines;
}
+ public void shiftSourceLines(int shift) {
+ for(Entry<Integer, Integer> entry : mapping.entrySet()) {
+ entry.setValue(entry.getValue() + shift);
+ }
+ }
+
public void addMapping(int bytecode_offset) {
if(!mapping.containsKey(bytecode_offset)) {
mapping.put(bytecode_offset, current_sourceline);
@@ -38,15 +45,25 @@ public class BytecodeMappingTracer {
}
}
+ public void addTracer(BytecodeMappingTracer tracer) {
+ if(tracer != null) {
+ for(Entry<Integer, Integer> entry : tracer.mapping.entrySet()) {
+ if(!mapping.containsKey(entry.getKey())) {
+ mapping.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
+
public HashMap<Integer, Integer> getMapping() {
return mapping;
}
- public int getCurrentSourceline() {
+ public int getCurrentSourceLine() {
return current_sourceline;
}
- public void setCurrentSourceline(int current_sourceline) {
+ public void setCurrentSourceLine(int current_sourceline) {
this.current_sourceline = current_sourceline;
}
diff --git a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
index f31394b..53f92b2 100644
--- a/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
+++ b/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
@@ -59,7 +59,7 @@ public class BytecodeSourceMapper {
buffer.append(indentstr1 + "method " + method_entry.getKey() + "{" + lineSeparator);
for(Entry<Integer, Integer> line : method_mapping.entrySet()) {
- buffer.append(indentstr2 + line.getKey() + indentstr2 + line.getValue() + lineSeparator);
+ buffer.append(indentstr2 + line.getKey() + indentstr2 + (line.getValue() +offset_total) + lineSeparator);
}
buffer.append(indentstr1 + "}" + lineSeparator);
is_first_method = false;