IDEA-184560 Java decompiler doesn't use stored parameter names
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.code;
|
||||
|
||||
@SuppressWarnings({"unused", "SpellCheckingInspection"})
|
||||
@@ -70,6 +72,7 @@ public interface CodeConstants {
|
||||
int ACC_SYNTHETIC = 0x1000;
|
||||
int ACC_ANNOTATION = 0x2000;
|
||||
int ACC_ENUM = 0x4000;
|
||||
int ACC_MANDATED = 0x8000;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// CLASS FLAGS
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.main;
|
||||
|
||||
@@ -697,6 +697,15 @@ public class ClassWriter {
|
||||
}
|
||||
}
|
||||
|
||||
List<StructMethodParametersAttribute.Entry> methodParameters = null;
|
||||
if (DecompilerContext.getOption(IFernflowerPreferences.USE_METHOD_PARAMETERS)) {
|
||||
StructMethodParametersAttribute attr =
|
||||
(StructMethodParametersAttribute)mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS);
|
||||
if (attr != null) {
|
||||
methodParameters = attr.getEntries();
|
||||
}
|
||||
}
|
||||
|
||||
int index = isEnum && init ? 3 : thisVar ? 1 : 0;
|
||||
int start = isEnum && init ? 2 : 0;
|
||||
for (int i = start; i < md.params.length; i++) {
|
||||
@@ -707,7 +716,10 @@ public class ClassWriter {
|
||||
|
||||
appendParameterAnnotations(buffer, mt, paramCount);
|
||||
|
||||
if (methodWrapper.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarTypeProcessor.VAR_EXPLICIT_FINAL) {
|
||||
if (methodParameters != null && paramCount < methodParameters.size()) {
|
||||
appendModifiers(buffer, methodParameters.get(paramCount).myAccessFlags, CodeConstants.ACC_FINAL, isInterface, 0);
|
||||
}
|
||||
else if (methodWrapper.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarTypeProcessor.VAR_EXPLICIT_FINAL) {
|
||||
buffer.append("final ");
|
||||
}
|
||||
|
||||
@@ -741,7 +753,14 @@ public class ClassWriter {
|
||||
}
|
||||
|
||||
buffer.append(' ');
|
||||
String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
|
||||
|
||||
String parameterName;
|
||||
if (methodParameters != null && paramCount < methodParameters.size()) {
|
||||
parameterName = methodParameters.get(paramCount).myName;
|
||||
}
|
||||
else {
|
||||
parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
|
||||
}
|
||||
buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors
|
||||
|
||||
paramCount++;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.main.extern;
|
||||
|
||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||
@@ -25,6 +27,7 @@ public interface IFernflowerPreferences {
|
||||
String SYNTHETIC_NOT_SET = "nns";
|
||||
String UNDEFINED_PARAM_TYPE_OBJECT = "uto";
|
||||
String USE_DEBUG_VAR_NAMES = "udv";
|
||||
String USE_METHOD_PARAMETERS = "ump";
|
||||
String REMOVE_EMPTY_RANGES = "rer";
|
||||
String FINALLY_DEINLINE = "fdi";
|
||||
String IDEA_NOT_NULL_ANNOTATION = "inn";
|
||||
@@ -67,6 +70,7 @@ public interface IFernflowerPreferences {
|
||||
defaults.put(SYNTHETIC_NOT_SET, "0");
|
||||
defaults.put(UNDEFINED_PARAM_TYPE_OBJECT, "1");
|
||||
defaults.put(USE_DEBUG_VAR_NAMES, "1");
|
||||
defaults.put(USE_METHOD_PARAMETERS, "1");
|
||||
defaults.put(REMOVE_EMPTY_RANGES, "1");
|
||||
defaults.put(FINALLY_DEINLINE, "1");
|
||||
defaults.put(IDEA_NOT_NULL_ANNOTATION, "1");
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.struct.attr;
|
||||
|
||||
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
|
||||
@@ -33,6 +35,7 @@ public class StructGeneralAttribute {
|
||||
public static final String ATTRIBUTE_SYNTHETIC = "Synthetic";
|
||||
public static final String ATTRIBUTE_DEPRECATED = "Deprecated";
|
||||
public static final String ATTRIBUTE_LINE_NUMBER_TABLE = "LineNumberTable";
|
||||
public static final String ATTRIBUTE_METHOD_PARAMETERS = "MethodParameters";
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -81,6 +84,9 @@ public class StructGeneralAttribute {
|
||||
else if (ATTRIBUTE_LINE_NUMBER_TABLE.equals(name)) {
|
||||
attr = new StructLineNumberTableAttribute();
|
||||
}
|
||||
else if (ATTRIBUTE_METHOD_PARAMETERS.equals(name)) {
|
||||
attr = new StructMethodParametersAttribute();
|
||||
}
|
||||
else {
|
||||
// unsupported attribute
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.struct.attr;
|
||||
|
||||
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
|
||||
import org.jetbrains.java.decompiler.util.DataInputFullStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
u1 parameters_count;
|
||||
{ u2 name_index;
|
||||
u2 access_flags;
|
||||
} parameters[parameters_count];
|
||||
*/
|
||||
public class StructMethodParametersAttribute extends StructGeneralAttribute {
|
||||
private List<Entry> myEntries;
|
||||
|
||||
@Override
|
||||
public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException {
|
||||
int len = data.readUnsignedByte();
|
||||
List<Entry> entries;
|
||||
if (len > 0) {
|
||||
entries = new ArrayList<>(len);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
int nameIndex = data.readUnsignedShort();
|
||||
String name = nameIndex != 0 ? pool.getPrimitiveConstant(nameIndex).getString() : null;
|
||||
int access_flags = data.readUnsignedShort();
|
||||
entries.add(new Entry(name, access_flags));
|
||||
}
|
||||
}
|
||||
else {
|
||||
entries = Collections.emptyList();
|
||||
}
|
||||
myEntries = Collections.unmodifiableList(entries);
|
||||
}
|
||||
|
||||
public List<Entry> getEntries() {
|
||||
return myEntries;
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
public final String myName;
|
||||
public final int myAccessFlags;
|
||||
|
||||
public Entry(String name, int accessFlags) {
|
||||
myName = name;
|
||||
myAccessFlags = accessFlags;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user