Use mapped local variable names from the OriginalPcTable

master
Graham 5 years ago
parent b7ff940440
commit 2bf9bb4e9b
  1. 5
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java
  2. 28
      src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java

@ -123,6 +123,11 @@ public class VarExprent extends Exprent {
buffer.append('(');
buffer.append(Integer.toString(pc));
buffer.append(") ");
if (originalPcTable.hasName(pc) && processor != null) {
name = originalPcTable.getName(pc);
processor.setVarName(varVersion, name);
}
}
}

@ -1,6 +1,7 @@
package org.jetbrains.java.decompiler.struct.attr;
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant;
import org.jetbrains.java.decompiler.util.DataInputFullStream;
import java.io.IOException;
@ -9,16 +10,31 @@ import java.util.Map;
public final class StructOriginalPcTableAttribute extends StructGeneralAttribute {
private final Map<Integer, Integer> pcs = new HashMap<>();
private final Map<Integer, String> names = new HashMap<>();
@Override
public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
int len = data.readUnsignedShort();
int pcsLen = data.readUnsignedShort();
for (int i = 0; i < len; i++) {
for (int i = 0; i < pcsLen; i++) {
int pc = data.readUnsignedShort();
int originalPc = data.readUnsignedShort();
pcs.put(pc, originalPc);
}
int namesLen = data.readUnsignedShort();
for (int i = 0; i < namesLen; i++) {
int originalPc = data.readUnsignedShort();
PrimitiveConstant constant = pool.getPrimitiveConstant(data.readUnsignedShort());
if (constant.type != PrimitiveConstant.CONSTANT_Utf8) {
throw new IllegalArgumentException();
}
String name = (String) constant.value;
names.put(originalPc, name);
}
}
public boolean hasOriginalPc(int pc) {
@ -28,4 +44,12 @@ public final class StructOriginalPcTableAttribute extends StructGeneralAttribute
public int getOriginalPc(int pc) {
return pcs.get(pc);
}
public boolean hasName(int originalPc) {
return names.containsKey(originalPc);
}
public String getName(int originalPc) {
return names.get(originalPc);
}
}

Loading…
Cancel
Save