IDEA-166363 Support LocalVariableTypeTable attribute
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,14 +21,19 @@ import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
|
||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
||||
import org.jetbrains.java.decompiler.main.TextBuffer;
|
||||
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
|
||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
|
||||
import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarTypeProcessor;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;
|
||||
import org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute;
|
||||
import org.jetbrains.java.decompiler.struct.attr.StructLocalVariableTypeTableAttribute;
|
||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||
import org.jetbrains.java.decompiler.struct.gen.generics.GenericFieldDescriptor;
|
||||
import org.jetbrains.java.decompiler.struct.gen.generics.GenericMain;
|
||||
import org.jetbrains.java.decompiler.struct.match.MatchEngine;
|
||||
import org.jetbrains.java.decompiler.struct.match.MatchNode;
|
||||
import org.jetbrains.java.decompiler.struct.match.IMatchable.MatchProperties;
|
||||
import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue;
|
||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||
|
||||
@@ -101,7 +106,29 @@ public class VarExprent extends Exprent {
|
||||
if (processor != null && processor.getVarFinal(new VarVersionPair(index, version)) == VarTypeProcessor.VAR_EXPLICIT_FINAL) {
|
||||
buffer.append("final ");
|
||||
}
|
||||
buffer.append(ExprProcessor.getCastTypeName(getVarType())).append(" ");
|
||||
boolean generic = false;
|
||||
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
|
||||
MethodWrapper method = (MethodWrapper)DecompilerContext.getProperty(DecompilerContext.CURRENT_METHOD_WRAPPER);
|
||||
StructLocalVariableTypeTableAttribute attr = (StructLocalVariableTypeTableAttribute)method.methodStruct.getAttributes()
|
||||
.getWithKey(StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TYPE_TABLE);
|
||||
if (attr != null && processor != null) {
|
||||
Integer index = processor.getVarOriginalIndex(new VarVersionPair(this.index, version));
|
||||
if (index != null) {
|
||||
String signature = attr.getMapVarSignatures().get(index);
|
||||
if (signature != null) {
|
||||
GenericFieldDescriptor descriptor = GenericMain.parseFieldSignature(signature);
|
||||
if (descriptor != null) {
|
||||
buffer.append(GenericMain.getGenericCastTypeName(descriptor.type));
|
||||
generic = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!generic) {
|
||||
buffer.append(ExprProcessor.getCastTypeName(getVarType()));
|
||||
}
|
||||
buffer.append(" ");
|
||||
}
|
||||
buffer.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,14 @@ public class VarProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getVarOriginalIndex(VarVersionPair pair) {
|
||||
if (varVersions == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return varVersions.getMapOriginalVarIndices().get(pair.var);
|
||||
}
|
||||
|
||||
public void refreshVarNames(VarNamesCollector vc) {
|
||||
Map<VarVersionPair, String> tempVarNames = new HashMap<>(mapVarNames);
|
||||
for (Entry<VarVersionPair, String> ent : tempVarNames.entrySet()) {
|
||||
|
||||
Reference in New Issue
Block a user