mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix counting parameters when doing @NotNull instrumentation (IDEA-134703)
This commit is contained in:
+10
-4
@@ -75,14 +75,20 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode
|
||||
final Map<Integer, String> names = new LinkedHashMap<Integer, String>();
|
||||
final Type[] args = Type.getArgumentTypes(desc);
|
||||
methodParamNames.put(methodName, names);
|
||||
|
||||
|
||||
final boolean isStatic = (access & ACC_STATIC) != 0;
|
||||
return new MethodVisitor(api) {
|
||||
int varIndex = 0;
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(String name2, String desc, String signature, Label start, Label end, int index) {
|
||||
int parameterIndex = getParameterIndex(index, access, args);
|
||||
if (parameterIndex >= 0) {
|
||||
names.put(parameterIndex, name2);
|
||||
if (!isStatic && index == 0) {
|
||||
return; //'this' variable
|
||||
}
|
||||
if (varIndex >= args.length) {
|
||||
return; // no parameters anymore
|
||||
}
|
||||
names.put(varIndex++, name2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LongParameter {
|
||||
|
||||
public static void foo(long a, @NotNull String b, @NotNull String c) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -126,6 +126,12 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
verifyCallThrowsException("Argument for @NotNull parameter 'x' of UseParameterNames.instanceMethod must not be null", instance, instanceMethod, (Object)null);
|
||||
}
|
||||
|
||||
public void testLongParameter() throws Exception {
|
||||
Class<?> testClass = prepareTest(true);
|
||||
Method staticMethod = testClass.getMethod("foo", long.class, String.class, String.class);
|
||||
verifyCallThrowsException("Argument for @NotNull parameter 'c' of LongParameter.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