fix counting parameters when doing @NotNull instrumentation (IDEA-134703)

This commit is contained in:
peter
2015-01-02 15:32:49 +01:00
parent 12b7a03e2f
commit ad56e84d88
3 changed files with 25 additions and 4 deletions
@@ -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) {
}
}
@@ -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");