Intellij java editor: could not show interface parameter names in a lib jar. e.g.,
public interface Foo {
public Bar getBar(String name, int type);
public default Bar getBar(String name) {
return getBar(name, 1);
}
}
In java editor:
Foo foo = getFoo();
foo.
getBar(String s, int i)
getBar(String name)
When typing dot after foo, two methods show up. The first method shows parameter names as "s" and "i", could not show the original parameter names (name, type).
The second method is "default" method and its parameter names show up correctly.
Is there way for the editor to show the interface method parameter names ?
The lib jar source code is not available.
No#1(attaching javadoc) is the preferred solution. Option -parameters will make class file size bigger and may have performance overhead.
The class file doesn't store parameter names for non-default methods. So if you don't have the source code of that code, after the decompilation, the IDEA has no idea about the actual parameter names before.
If you use javap -verbose Foo.class
to check it, you can see the bytecode contains the parameter name for the default method but not for the normal method:
Constant pool:
#1 = InterfaceMethodref #2.#3 // Foo.getBar:(Ljava/lang/String;I)LBar;
#2 = Class #4 // Foo
#3 = NameAndType #5:#6 // getBar:(Ljava/lang/String;I)LBar;
#4 = Utf8 Foo
#5 = Utf8 getBar
#6 = Utf8 (Ljava/lang/String;I)LBar;
#7 = Class #8 // java/lang/Object
#8 = Utf8 java/lang/Object
#9 = Utf8 (Ljava/lang/String;)LBar;
#10 = Utf8 Code
#11 = Utf8 LineNumberTable
#12 = Utf8 LocalVariableTable
#13 = Utf8 this
#14 = Utf8 LFoo;
#15 = Utf8 name
#16 = Utf8 Ljava/lang/String;
#17 = Utf8 SourceFile
#18 = Utf8 Foo.java
{
public abstract Bar getBar(java.lang.String, int);
descriptor: (Ljava/lang/String;I)LBar;
flags: (0x0401) ACC_PUBLIC, ACC_ABSTRACT
public default Bar getBar(java.lang.String);
descriptor: (Ljava/lang/String;)LBar;
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=2, args_size=2
0: aload_0
1: aload_1
2: iconst_1
3: invokeinterface #1, 3 // InterfaceMethod getBar:(Ljava/lang/String;I)LBar;
8: areturn
LineNumberTable:
line 5: 0
LocalVariableTable:
Start Length Slot Name Signature
0 9 0 this LFoo;
0 9 1 name Ljava/lang/String;
}