IDEA-184560 Java decompiler doesn't use stored parameter names

This commit is contained in:
Egor Ushakov
2018-01-10 16:28:43 +03:00
parent 023bb2462a
commit 8b9687ed20
15 changed files with 279 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;
}
}
}