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 { ...@@ -146,10 +146,10 @@ public abstract class Remapper {
} }
/** /**
* Returns the given value, remapped with this remapper. Possible values are {@link String}, * Returns the given value, remapped with this remapper. Possible values are {@link Boolean},
* {@link Boolean}, {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, * {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double},
* {@link Double}, {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link * {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays
* ConstantDynamic} or arrays of primitive types . * of primitive types .
* *
* @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values * @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values
* are remapped. * are remapped.
......
...@@ -37,9 +37,12 @@ import org.junit.jupiter.params.provider.ValueSource; ...@@ -37,9 +37,12 @@ import org.junit.jupiter.params.provider.ValueSource;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest; import org.objectweb.asm.test.AsmTest;
/** /**
...@@ -397,6 +400,28 @@ public class AdviceAdapterTest extends AsmTest { ...@@ -397,6 +400,28 @@ public class AdviceAdapterTest extends AsmTest {
new AdviceAdapter( new AdviceAdapter(
Opcodes.ASM7, methodVisitor, Opcodes.ACC_PUBLIC, "<init>", descriptor) { 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 @Override
protected void onMethodEnter() { protected void onMethodEnter() {
generateAdvice(this, /* enter= */ true); generateAdvice(this, /* enter= */ true);
......
...@@ -230,8 +230,7 @@ public class ClassRemapperTest extends AsmTest { ...@@ -230,8 +230,7 @@ public class ClassRemapperTest extends AsmTest {
@Override @Override
public Object mapValue(Object value) { public Object mapValue(Object value) {
if (value instanceof String if (value instanceof Boolean
|| value instanceof Boolean
|| value instanceof Byte || value instanceof Byte
|| value instanceof Short || value instanceof Short
|| value instanceof Character || value instanceof Character
...@@ -239,13 +238,14 @@ public class ClassRemapperTest extends AsmTest { ...@@ -239,13 +238,14 @@ public class ClassRemapperTest extends AsmTest {
|| value instanceof Long || value instanceof Long
|| value instanceof Double || value instanceof Double
|| value instanceof Float || value instanceof Float
|| value instanceof String
|| value instanceof Type || value instanceof Type
|| value instanceof Handle || value instanceof Handle
|| value instanceof ConstantDynamic || value instanceof ConstantDynamic
|| value.getClass().isArray()) { || value.getClass().isArray()) {
return super.mapValue(value); 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); throw new IllegalArgumentException("Unsupported type of value: " + value);
} }
} }
......
...@@ -36,8 +36,11 @@ import org.objectweb.asm.Attribute; ...@@ -36,8 +36,11 @@ import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest; import org.objectweb.asm.test.AsmTest;
/** /**
...@@ -69,6 +72,29 @@ public class CodeSizeEvaluatorTest extends AsmTest { ...@@ -69,6 +72,29 @@ public class CodeSizeEvaluatorTest extends AsmTest {
MethodVisitor methodVisitor = MethodVisitor methodVisitor =
super.visitMethod(access, name, descriptor, signature, exceptions); super.visitMethod(access, name, descriptor, signature, exceptions);
return new CodeSizeEvaluator(api, methodVisitor) { 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 @Override
public void visitMaxs(final int maxStack, final int maxLocals) { public void visitMaxs(final int maxStack, final int maxLocals) {
Label end = new Label(); Label end = new Label();
......
...@@ -663,8 +663,25 @@ public class ClassWriterTest extends AsmTest { ...@@ -663,8 +663,25 @@ public class ClassWriterTest extends AsmTest {
@Override @Override
public void visitLdcInsn(final Object value) { public void visitLdcInsn(final Object value) {
super.visitLdcInsn(value); if (value instanceof Boolean
maybeInsertDeadCode(); || 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 @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