mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly determine parameter names for long and double paremeters independently on local vars visiting order
This commit is contained in:
+14
-9
@@ -77,18 +77,23 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode
|
||||
methodParamNames.put(methodName, names);
|
||||
|
||||
final boolean isStatic = (access & ACC_STATIC) != 0;
|
||||
|
||||
final Map<Integer, Integer> paramSlots = new LinkedHashMap<Integer, Integer>(); // map: localVariableSlot -> methodParameterIndex
|
||||
int slotIndex = isStatic? 0 : 1;
|
||||
for (int paramIndex = 0; paramIndex < args.length; paramIndex++) {
|
||||
final Type arg = args[paramIndex];
|
||||
paramSlots.put(slotIndex, paramIndex);
|
||||
slotIndex += arg.getSize();
|
||||
}
|
||||
|
||||
return new MethodVisitor(api) {
|
||||
int varIndex = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(String name2, String desc, String signature, Label start, Label end, int index) {
|
||||
if (!isStatic && index == 0) {
|
||||
return; //'this' variable
|
||||
public void visitLocalVariable(String name2, String desc, String signature, Label start, Label end, int slotIndex) {
|
||||
final Integer paramIndex = paramSlots.get(slotIndex);
|
||||
if (paramIndex != null) {
|
||||
names.put(paramIndex, name2);
|
||||
}
|
||||
if (varIndex >= args.length) {
|
||||
return; // no parameters anymore
|
||||
}
|
||||
names.put(varIndex++, name2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DoubleParameter {
|
||||
|
||||
public static void foo(double a, @NotNull String b, @NotNull String c) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -132,6 +132,12 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
verifyCallThrowsException("Argument for @NotNull parameter 'c' of LongParameter.foo must not be null", null, staticMethod, new Long(2), "z", null);
|
||||
}
|
||||
|
||||
public void testDoubleParameter() throws Exception {
|
||||
Class<?> testClass = prepareTest(true);
|
||||
Method staticMethod = testClass.getMethod("foo", double.class, String.class, String.class);
|
||||
verifyCallThrowsException("Argument for @NotNull parameter 'c' of DoubleParameter.foo must not be null", null, staticMethod, new Long(2), "z", null);
|
||||
}
|
||||
|
||||
public void testEnumConstructor() throws Exception {
|
||||
Class testClass = prepareTest();
|
||||
Object field = testClass.getField("Value");
|
||||
|
||||
Reference in New Issue
Block a user