-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/com/openpojo/validation/utils/AClassWithSyntheticFieldDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "synthetic" String syntheticString; | ||
* } | ||
*/ | ||
public class AClassWithSyntheticFieldDumper 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_SYNTHETIC, "syntheticString", "Ljava/lang/String;", null, null); | ||
fv.visitEnd(); | ||
} | ||
{ | ||
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); | ||
mv.visitCode(); | ||
mv.visitVarInsn(ALOAD, 0); | ||
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); | ||
mv.visitInsn(RETURN); | ||
mv.visitMaxs(1, 1); | ||
mv.visitEnd(); | ||
} | ||
cw.visitEnd(); | ||
|
||
return cw.toByteArray(); | ||
} | ||
} |