diff --git a/src/test/java/com/openpojo/validation/utils/AClassWithSyntheticStaticFieldDumper.java b/src/test/java/com/openpojo/validation/utils/AClassWithSyntheticStaticFieldDumper.java new file mode 100644 index 00000000..b5954ad9 --- /dev/null +++ b/src/test/java/com/openpojo/validation/utils/AClassWithSyntheticStaticFieldDumper.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010-2021 Osman Shoukry + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.openpojo.validation.utils; + + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +/** + * this class dumps a class that looks like this: + * + * public class AClassWithSytheticStringField { + * private static "synthetic" String syntheticStaticString; + * } + */ +public class AClassWithSyntheticStaticFieldDumper implements Opcodes { + public static byte[] dump(String className) { + ClassWriter cw = new ClassWriter(0); + FieldVisitor fv; + MethodVisitor mv; + + cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", null); + + { + fv = cw.visitField(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "syntheticStaticString", "Ljava/lang/String;", null, null); + fv.visitEnd(); + } + { + mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); + mv.visitCode(); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); + mv.visitInsn(RETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } + cw.visitEnd(); + + return cw.toByteArray(); + } +}