Commit 4a185e2d authored by Eric Bruneton's avatar Eric Bruneton

Add more tests to make sure visitLdcInsn() is updated when new constant types are added.

parent e7173998
Pipeline #2810 passed with stage
in 7 minutes
......@@ -146,10 +146,10 @@ public abstract class Remapper {
}
/**
* Returns the given value, remapped with this remapper. Possible values are {@link String},
* {@link Boolean}, {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long},
* {@link Double}, {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link
* ConstantDynamic} or arrays of primitive types .
* Returns the given value, remapped with this remapper. Possible values are {@link Boolean},
* {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double},
* {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays
* of primitive types .
*
* @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values
* are remapped.
......
......@@ -37,9 +37,12 @@ import org.junit.jupiter.params.provider.ValueSource;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest;
/**
......@@ -397,6 +400,28 @@ public class AdviceAdapterTest extends AsmTest {
new AdviceAdapter(
Opcodes.ASM7, methodVisitor, Opcodes.ACC_PUBLIC, "<init>", descriptor) {
@Override
public void visitLdcInsn(final Object value) {
if (value instanceof Boolean
|| value instanceof Byte
|| value instanceof Short
|| value instanceof Character
|| value instanceof Integer
|| value instanceof Long
|| value instanceof Double
|| value instanceof Float
|| value instanceof String
|| value instanceof Type
|| value instanceof Handle
|| value instanceof ConstantDynamic) {
super.visitLdcInsn(value);
} else {
// If this happens, add support for the new type in
// AdviceAdapter.visitLdcInsn(), if needed.
throw new IllegalArgumentException("Unsupported type of value: " + value);
}
}
@Override
protected void onMethodEnter() {
generateAdvice(this, /* enter= */ true);
......
......@@ -230,8 +230,7 @@ public class ClassRemapperTest extends AsmTest {
@Override
public Object mapValue(Object value) {
if (value instanceof String
|| value instanceof Boolean
if (value instanceof Boolean
|| value instanceof Byte
|| value instanceof Short
|| value instanceof Character
......@@ -239,13 +238,14 @@ public class ClassRemapperTest extends AsmTest {
|| value instanceof Long
|| value instanceof Double
|| value instanceof Float
|| value instanceof String
|| value instanceof Type
|| value instanceof Handle
|| value instanceof ConstantDynamic
|| value.getClass().isArray()) {
return super.mapValue(value);
}
// If this fails, add support for the new type in Remapper.mapValue(), if needed.
// If this happens, add support for the new type in Remapper.mapValue(), if needed.
throw new IllegalArgumentException("Unsupported type of value: " + value);
}
}
......
......@@ -36,8 +36,11 @@ import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest;
/**
......@@ -69,6 +72,29 @@ public class CodeSizeEvaluatorTest extends AsmTest {
MethodVisitor methodVisitor =
super.visitMethod(access, name, descriptor, signature, exceptions);
return new CodeSizeEvaluator(api, methodVisitor) {
@Override
public void visitLdcInsn(final Object value) {
if (value instanceof Boolean
|| value instanceof Byte
|| value instanceof Short
|| value instanceof Character
|| value instanceof Integer
|| value instanceof Long
|| value instanceof Double
|| value instanceof Float
|| value instanceof String
|| value instanceof Type
|| value instanceof Handle
|| value instanceof ConstantDynamic) {
super.visitLdcInsn(value);
} else {
// If this happens, add support for the new type in
// CodeSizeEvaluator.visitLdcInsn(), if needed.
throw new IllegalArgumentException("Unsupported type of value: " + value);
}
}
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
Label end = new Label();
......
......@@ -663,8 +663,25 @@ public class ClassWriterTest extends AsmTest {
@Override
public void visitLdcInsn(final Object value) {
if (value instanceof Boolean
|| value instanceof Byte
|| value instanceof Short
|| value instanceof Character
|| value instanceof Integer
|| value instanceof Long
|| value instanceof Double
|| value instanceof Float
|| value instanceof String
|| value instanceof Type
|| value instanceof Handle
|| value instanceof ConstantDynamic) {
super.visitLdcInsn(value);
maybeInsertDeadCode();
} else {
// If this happens, add support for the new type in
// MethodWriter.visitLdcInsn(), if needed.
throw new IllegalArgumentException("Unsupported type of value: " + value);
}
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment