use of org.mvel2.asm.FieldVisitor in project drools by kiegroup.
the class DefaultEnumClassBuilder method buildLiterals.
protected void buildLiterals(ClassWriter cw, EnumClassDefinition classDef) {
FieldVisitor fv;
for (EnumLiteralDefinition lit : classDef.getEnumLiterals()) {
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, lit.getName(), BuildUtils.getTypeDescriptor(classDef.getClassName()), null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "$VALUES", "[" + BuildUtils.getTypeDescriptor(classDef.getClassName()), null, null);
fv.visitEnd();
}
}
use of org.mvel2.asm.FieldVisitor in project mvel by mvel.
the class CheckClassAdapter method visitField.
@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
checkState();
checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
0x40000);
CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
CheckMethodAdapter.checkDesc(desc, false);
if (signature != null) {
checkFieldSignature(signature);
}
if (value != null) {
CheckMethodAdapter.checkConstant(value);
}
FieldVisitor av = super.visitField(access, name, desc, signature, value);
return new CheckFieldAdapter(av);
}
use of org.mvel2.asm.FieldVisitor in project mvel by mvel.
the class TraceClassVisitor method visitField.
@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
Printer p = this.p.visitField(access, name, desc, signature, value);
FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc, signature, value);
return new TraceFieldVisitor(fv, p);
}
use of org.mvel2.asm.FieldVisitor in project drools by kiegroup.
the class TraitMapProxyClassBuilderImpl method buildClass.
public byte[] buildClass(ClassDefinition core, ClassLoader classLoader) throws IOException, SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
FieldVisitor fv;
MethodVisitor mv;
// get the method bitmask
BitSet mask = traitRegistry.getFieldMask(getTrait().getName(), core.getDefinedClass().getName());
String name = TraitFactory.getPropertyWrapperName(getTrait(), core);
String masterName = TraitFactory.getProxyName(getTrait(), core);
Class<?> traitClass = getTrait().getDefinedClass();
String internalWrapper = BuildUtils.getInternalType(name);
String internalProxy = BuildUtils.getInternalType(masterName);
String descrCore = Type.getDescriptor(core.getDefinedClass());
String internalCore = Type.getInternalName(core.getDefinedClass());
String internalTrait = Type.getInternalName(traitClass);
MixinInfo mixinInfo = findMixinInfo(traitClass);
ClassWriter cw = createClassWriter(classLoader, ACC_PUBLIC + ACC_SUPER, internalProxy, null, Type.getInternalName(proxyBaseClass), new String[] { internalTrait, Type.getInternalName(Serializable.class) });
{
fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, TraitType.traitNameField, Type.getDescriptor(String.class), null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PUBLIC, "object", descrCore, null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PUBLIC, "map", Type.getDescriptor(Map.class), "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null);
fv.visitEnd();
}
if (mixinInfo != null) {
for (Class<?> mixinClass : mixinInfo.mixinClasses) {
{
fv = cw.visitField(ACC_PRIVATE, getMixinName(mixinClass), BuildUtils.getTypeDescriptor(mixinClass.getName()), null, null);
fv.visitEnd();
}
}
}
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(" + descrCore + Type.getDescriptor(Map.class) + Type.getDescriptor(BitSet.class) + Type.getDescriptor(BitSet.class) + Type.getDescriptor(boolean.class) + ")V", "(" + descrCore + "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;" + Type.getDescriptor(BitSet.class) + Type.getDescriptor(BitSet.class) + Type.getDescriptor(boolean.class) + ")V", null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(proxyBaseClass), "<init>", "()V", false);
mv.visitVarInsn(ALOAD, 2);
Label l0 = new Label();
mv.visitJumpInsn(IFNONNULL, l0);
mv.visitTypeInsn(NEW, Type.getInternalName(ExternalizableLinkedHashMap.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(ExternalizableLinkedHashMap.class), "<init>", "()V", false);
mv.visitVarInsn(ASTORE, 2);
mv.visitLabel(l0);
if (mixinInfo != null) {
for (Class<?> mixinClass : mixinInfo.mixinClasses) {
String mixin = getMixinName(mixinClass);
try {
Class actualArg = getPossibleConstructor(mixinClass, trait.getDefinedClass());
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, Type.getInternalName(mixinClass));
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(mixinClass), "<init>", "(" + Type.getDescriptor(actualArg) + ")V", false);
mv.visitFieldInsn(PUTFIELD, internalProxy, mixin, Type.getDescriptor(mixinClass));
} catch (NoSuchMethodException nsme) {
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, Type.getInternalName(mixinClass));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(mixinClass), "<init>", "()V", false);
mv.visitFieldInsn(PUTFIELD, internalProxy, mixin, Type.getDescriptor(mixinClass));
}
}
}
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitFieldInsn(PUTFIELD, internalProxy, "object", descrCore);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 2);
mv.visitFieldInsn(PUTFIELD, internalProxy, "map", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 3);
mv.visitMethodInsn(INVOKEVIRTUAL, internalProxy, "setTypeCode", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(BitSet.class)), false);
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, internalWrapper);
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESPECIAL, internalWrapper, "<init>", "(" + descrCore + Type.getDescriptor(Map.class) + ")V", false);
mv.visitFieldInsn(PUTFIELD, internalProxy, "fields", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "_getDynamicProperties", "()" + Type.getDescriptor(Map.class), false);
Label l1 = new Label();
mv.visitJumpInsn(IFNONNULL, l1);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "_setDynamicProperties", "(" + Type.getDescriptor(Map.class) + ")V", false);
mv.visitLabel(l1);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "_getTraitMap", "()" + Type.getDescriptor(Map.class), false);
Label l2 = new Label();
mv.visitJumpInsn(IFNONNULL, l2);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(NEW, Type.getInternalName(TraitTypeMap.class));
mv.visitInsn(DUP);
mv.visitTypeInsn(NEW, Type.getInternalName(ExternalizableLinkedHashMap.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(ExternalizableLinkedHashMap.class), "<init>", "()V", false);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(TraitTypeMap.class), "<init>", "(" + Type.getDescriptor(Map.class) + ")V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "_setTraitMap", "(" + Type.getDescriptor(Map.class) + ")V", false);
mv.visitLabel(l2);
// core._setBottomTypeCode()
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 4);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "_setBottomTypeCode", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(BitSet.class)), false);
// core.addTrait
mv.visitVarInsn(ALOAD, 1);
mv.visitLdcInsn(trait.getName().endsWith(TraitFactory.SUFFIX) ? trait.getName().replace(TraitFactory.SUFFIX, "") : trait.getName());
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, internalCore, "addTrait", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class), Type.getType(Thing.class)), false);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ILOAD, 5);
mv.visitMethodInsn(INVOKESPECIAL, internalProxy, "synchFields", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false);
mv.visitInsn(RETURN);
// mv.visitMaxs( 5, 3 );
mv.visitMaxs(0, 0);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "writeExternal", "(" + Type.getDescriptor(ObjectOutput.class) + ")V", null, new String[] { Type.getInternalName(IOException.class) });
mv.visitCode();
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, internalProxy, "getObject", "()" + Type.getDescriptor(TraitableBean.class), false);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(ObjectOutput.class), "writeObject", "(" + Type.getDescriptor(Object.class) + ")V", true);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, internalProxy, "map", Type.getDescriptor(Map.class));
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(ObjectOutput.class), "writeObject", "(" + Type.getDescriptor(Object.class) + ")V", true);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(proxyBaseClass), "writeExternal", "(" + Type.getDescriptor(ObjectOutput.class) + ")V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "readExternal", "(" + Type.getDescriptor(ObjectInput.class) + ")V", null, new String[] { Type.getInternalName(IOException.class), Type.getInternalName(ClassNotFoundException.class) });
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(ObjectInput.class), "readObject", "()" + Type.getDescriptor(Object.class), true);
mv.visitTypeInsn(CHECKCAST, internalCore);
mv.visitFieldInsn(PUTFIELD, internalProxy, "object", descrCore);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(ObjectInput.class), "readObject", "()" + Type.getDescriptor(Object.class), true);
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Map.class));
mv.visitFieldInsn(PUTFIELD, internalProxy, "map", Type.getDescriptor(Map.class));
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(proxyBaseClass), "readExternal", "(" + Type.getDescriptor(ObjectInput.class) + ")V", false);
mv.visitInsn(RETURN);
// mv.visitMaxs( 3, 2 );
mv.visitMaxs(0, 0);
mv.visitEnd();
}
helpBuildClass(core, cw, internalProxy, descrCore, mask);
buildFields(core, mask, masterName, mixinInfo, cw);
buildKeys(core, masterName, cw);
buildMixinMethods(masterName, mixinInfo, cw);
buildCommonMethods(cw, masterName);
buildExtendedMethods(cw, trait, core);
buildShadowMethods(cw, trait, core);
cw.visitEnd();
return cw.toByteArray();
}
use of org.mvel2.asm.FieldVisitor in project drools by kiegroup.
the class DefaultBeanClassBuilder method buildFieldAnnotations.
protected void buildFieldAnnotations(FieldDefinition fieldDef, FieldVisitor fv) {
if (fieldDef.getAnnotations() != null) {
for (AnnotationDefinition ad : fieldDef.getAnnotations()) {
AnnotationVisitor av = fv.visitAnnotation("L" + BuildUtils.getInternalType(ad.getName()) + ";", true);
addAnnotationAttribute(ad, av);
av.visitEnd();
}
}
}
Aggregations