List of usage examples for org.objectweb.asm MethodVisitor visitFrame
public void visitFrame(final int type, final int numLocal, final Object[] local, final int numStack, final Object[] stack)
From source file:net.wpm.reflectasm.ClassAccess.java
License:Open Source License
static private void insertGetPrimitive(ClassWriter cw, String classNameInternal, List<Field> fields, Type primitiveType, String getterMethodName, int returnValueInstruction) { int maxStack = 6; final String typeNameInternal = primitiveType.getDescriptor(); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, getterMethodName, "(Ljava/lang/Object;I)" + typeNameInternal, null, null);/*from ww w . j ava 2 s . co m*/ mv.visitCode(); mv.visitVarInsn(ILOAD, 2); if (!fields.isEmpty()) { maxStack--; Label[] labels = new Label[fields.size()]; Label labelForInvalidTypes = new Label(); boolean hasAnyBadTypeLabel = false; for (int i = 0, n = labels.length; i < n; i++) { if (Type.getType(fields.get(i).getType()).equals(primitiveType)) labels[i] = new Label(); else { labels[i] = labelForInvalidTypes; hasAnyBadTypeLabel = true; } } Label defaultLabel = new Label(); mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels); for (int i = 0, n = labels.length; i < n; i++) { Field field = fields.get(i); if (!labels[i].equals(labelForInvalidTypes)) { mv.visitLabel(labels[i]); mv.visitFrame(F_SAME, 0, null, 0, null); if (isStatic(field.getModifiers())) { mv.visitFieldInsn(GETSTATIC, classNameInternal, field.getName(), typeNameInternal); } else { mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, classNameInternal); mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), typeNameInternal); } mv.visitInsn(returnValueInstruction); } } // Rest of fields: different type if (hasAnyBadTypeLabel) { mv.visitLabel(labelForInvalidTypes); mv.visitFrame(F_SAME, 0, null, 0, null); insertThrowExceptionForFieldType(mv, primitiveType.getClassName()); } // Default: field not found mv.visitLabel(defaultLabel); mv.visitFrame(F_SAME, 0, null, 0, null); } mv = insertThrowExceptionForFieldNotFound(mv); mv.visitMaxs(maxStack, 3); mv.visitEnd(); }
From source file:org.apache.asterix.runtime.evaluators.staticcodegen.EvaluatorVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if (!METHOD_IDENTIFIER.equals(new MethodIdentifier(name, desc, signature))) { return mv; }/* w w w. j av a 2 s . c om*/ if (mv != null) { return new MethodVisitor(Opcodes.ASM5, mv) { private FieldInsnNode fieldAccessNode = null; private List<AbstractInsnNode> instructionsAfterFieldAccess = new ArrayList<>(); @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { mv.visitFieldInsn(opcode, owner, name, desc); fieldAccessNode = new FieldInsnNode(opcode, owner, name, desc); instructionsAfterFieldAccess.clear(); } @Override public void visitIincInsn(int var, int increment) { if (fieldAccessNode != null) { instructionsAfterFieldAccess.add(new IincInsnNode(var, increment)); } super.visitIincInsn(var, increment); } @Override public void visitInsn(int opcode) { if (fieldAccessNode != null) { instructionsAfterFieldAccess.add(new InsnNode(opcode)); } super.visitInsn(opcode); } @Override public void visitIntInsn(int opcode, int operand) { if (fieldAccessNode != null) { instructionsAfterFieldAccess.add(new IntInsnNode(opcode, operand)); } super.visitIntInsn(opcode, operand); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { mv.visitMethodInsn(opcode, owner, name, desc, itf); if (fieldAccessNode == null || !METHOD_IDENTIFIER.equals(new MethodIdentifier(name, desc, signature))) { return; } // Loads "this". mv.visitVarInsn(Opcodes.ALOAD, 0); // Replays the field access instruction. fieldAccessNode.accept(mv); // Replays other instruction between the field access and the evaluator call. for (AbstractInsnNode instruction : instructionsAfterFieldAccess) { instruction.accept(mv); } // Loads the result IPointable. mv.visitVarInsn(Opcodes.ALOAD, 2); // Invokes the null check method. mv.visitMethodInsn(Opcodes.INVOKESTATIC, TYPECHECK_CLASS, IS_NULL, TYPECHECK_METHOD_DESC, false); Label notNull = new Label(); // Adds the if branch. mv.visitJumpInsn(Opcodes.IFEQ, notNull); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(notNull); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } }; } return null; }
From source file:org.apache.asterix.runtime.evaluators.staticcodegen.RenameClassVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, name, applyMapping(desc), applyMapping(signature), exceptions); if (mv != null) { return new MethodVisitor(Opcodes.ASM5, mv) { @Override/*from w w w. ja v a 2 s . c o m*/ public void visitFieldInsn(int opcode, String owner, String name, String desc) { mv.visitFieldInsn(opcode, applyMapping(owner), applyMapping(name), applyMapping(desc)); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { mv.visitMethodInsn(opcode, applyMapping(owner), name, applyMapping(desc), itf); } @Override public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { mv.visitLocalVariable(name, applyMapping(desc), applyMapping(signature), start, end, index); } @Override public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) { if (local != null) { for (int index = 0; index < local.length; ++index) { if (local[index] instanceof String) { local[index] = applyMapping((String) local[index]); } } } mv.visitFrame(type, nLocal, local, nStack, stack); } @Override public void visitTypeInsn(int opcode, String type) { mv.visitTypeInsn(opcode, applyMapping(type)); } }; } return null; }
From source file:org.apache.s4.core.gen.OverloadDispatcherGenerator.java
License:Apache License
private void generateEventDispatchMethod(ClassWriter cw, String dispatchMethodName, List<Hierarchy> eventHierarchies, String processEventMethodName) { MethodVisitor mv2 = cw.visitMethod(ACC_PUBLIC, dispatchMethodName, "(" + Type.getType(ProcessingElement.class).getDescriptor() + Type.getType(Event.class).getDescriptor() + ")V", null, null);/*from w ww . j a va 2s. com*/ mv2.visitCode(); Label l3 = new Label(); mv2.visitLabel(l3); mv2.visitVarInsn(ALOAD, 1); mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(targetClass)); mv2.visitVarInsn(ASTORE, 3); boolean first = true; Label aroundLabel = new Label(); for (Hierarchy hierarchy : eventHierarchies) { if (first) { Label l4 = new Label(); mv2.visitLabel(l4); } mv2.visitVarInsn(ALOAD, 2); mv2.visitTypeInsn(INSTANCEOF, Type.getInternalName(hierarchy.getTop())); Label l5 = new Label(); mv2.visitJumpInsn(IFEQ, l5); Label l6 = new Label(); mv2.visitLabel(l6); mv2.visitVarInsn(ALOAD, 3); mv2.visitVarInsn(ALOAD, 2); mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(hierarchy.getTop())); mv2.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(targetClass), processEventMethodName, "(" + Type.getDescriptor(hierarchy.getTop()) + ")V"); mv2.visitJumpInsn(Opcodes.GOTO, aroundLabel); mv2.visitLabel(l5); if (first) { mv2.visitFrame(F_APPEND, 1, new Object[] { Type.getInternalName(targetClass) }, 0, null); first = false; } else { mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } } addErrorLogStatement(mv2); if (eventHierarchies.size() > 0) { mv2.visitLabel(aroundLabel); mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } mv2.visitInsn(RETURN); Label l8 = new Label(); mv2.visitLabel(l8); mv2.visitLocalVariable("pe", Type.getDescriptor(ProcessingElement.class), null, l3, l8, 1); mv2.visitLocalVariable("event", Type.getDescriptor(Event.class), null, l3, l8, 2); mv2.visitLocalVariable("typedPE", Type.getDescriptor(targetClass), null, l3, l8, 3); mv2.visitMaxs(4, 4); mv2.visitEnd(); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createMethodCheck(final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PRIVATE, Enhancer.METHOD_ENHANCED_CHECK, Enhancer.makeDescription(Void.TYPE), null, null); mv.visitCode();/* ww w . j a va2 s .c o m*/ final Label lCheckInternal = new Label(); final Label lCheckInitialized = new Label(); final Label lReturn = new Label(); final Label lFind = new Label(); final Label lInitialized = new Label(); final Label lChanged = new Label(); final Label lOut = new Label(); // if (!this.__enhanced__$$__internal) { return } mv.visitLabel(lCheckInternal); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFEQ, lCheckInitialized); mv.visitInsn(Opcodes.RETURN); // if (!this.__enhanced__$$__initialized) { mv.visitLabel(lCheckInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFNE, lChanged); // if (this.__enhanced_$$__session == null) mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNONNULL, lFind); // throw new PersistenceException("No session to initialize the instance"); mv.visitTypeInsn(Opcodes.NEW, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("No session to initialize the instance"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION, Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, String.class)); mv.visitInsn(Opcodes.ATHROW); // this.__enhanced_$$__session.getEntityManager().find(this.__enhanced_$$__type, this.__enhanced__$$__id); mv.visitLabel(lFind); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_SESSION, Enhancer.METHOD_GET_ENTITY_MANAGER, Enhancer.makeDescription(EntityManagerImpl.class)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE, Enhancer.DESCRIPTOR_CLASS); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID, Enhancer.DESCRIPTOR_OBJECT); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_ENTITY_MANAGER, Enhancer.METHOD_FIND, Enhancer.makeDescription(Object.class, Class.class, Object.class)); mv.visitInsn(Opcodes.POP); // this.__enhanced__$$__initialized = true; mv.visitLabel(lInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_1); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); // if (this.__enhanced_$$__session != null) mv.visitLabel(lChanged); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNULL, lReturn); // this.__enhanced__$$__managedInstance.changed(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE, Enhancer.DESCRIPTOR_MANAGED_INSTANCE); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_MANAGED_INSTANCE, Enhancer.METHOD_CHANGED, Enhancer.makeDescription(Void.TYPE)); // return; mv.visitLabel(lReturn); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(lOut); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, lCheckInternal, lOut, 0); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.boretti.drools.integration.drools5.DroolsClassVisitor.java
License:Open Source License
@Override public void visitEnd() { FieldVisitor fv = null;// www. j av a 2 s .c o m if (isNeedChangeForBoth()) { fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor(), null, null); if (fv != null) { AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); fv.visitEnd(); } } if (isNeedChangeForField()) { fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_RULE, Type.getType(RuleBase.class).getDescriptor(), null, null); if (fv != null) { AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); fv.visitEnd(); } MethodVisitor mv = super.visitMethod(Opcodes.ACC_PRIVATE, DROOLS_METHOD_RUN, "()V", null, null); AnnotationVisitor av = mv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true); AnnotationVisitor value = av.visitArray("value"); value.visit("", "Generated by Drools5IntegrationHelper Maven plugin"); value.visitEnd(); av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current)); av.visitEnd(); mv.visitCode(); Label start = new Label(); mv.visitLabel(start); Label doIt = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor()); mv.visitJumpInsn(Opcodes.IFEQ, doIt); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(doIt); mv.visitFrame(Opcodes.F_SAME, 1, new Object[] { Type.getObjectType(me).getInternalName() }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_RULE, Type.getType(RuleBase.class).getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(RuleBase.class).getInternalName(), "newStatelessSession", "()Lorg/drools/StatelessSession;"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(FIELD_NAME_LOGGER); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(Object.class).getInternalName(), "getClass", "()Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(org.apache.log4j.Logger.class).getInternalName(), "getLogger", "(Ljava/lang/Class;)Lorg/apache/log4j/Logger;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(), "setGlobal", "(Ljava/lang/String;Ljava/lang/Object;)V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(), "execute", "(Ljava/lang/Object;)V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_1); mv.visitFieldInsn(Opcodes.PUTFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor()); mv.visitInsn(Opcodes.RETURN); Label end = new Label(); mv.visitLabel(end); mv.visitLocalVariable("this", Type.getObjectType(me).getDescriptor(), null, start, end, 0); mv.visitMaxs(4, 1); mv.visitEnd(); } super.visitEnd(); }
From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java
License:Open Source License
/** * Generates:/*from w ww . ja v a2 s .c om*/ * * <pre> * public Context createConfigurationContext(Configuration configuration) { * // createConfigurationContext does not exist before API level 17. * if (Build.VERSION.SDK_INT < 17) return null; * if (!BuildHooksAndroid.isEnabled()) return super.createConfigurationContext(configuration); * return BuildHooksAndroid.createConfigurationContext( * super.createConfigurationContext(configuration)); * } * </pre> * } */ private void delegateCreateConfigurationContext() { String methodName = "createConfigurationContext"; String methodDescriptor = TypeUtils.getMethodDescriptor(CONTEXT, CONFIGURATION); MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "android/os/Build$VERSION", "SDK_INT", INT); mv.visitIntInsn(BIPUSH, 17); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l0); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false); Label l1 = new Label(); mv.visitJumpInsn(IFNE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false); mv.visitInsn(ARETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, TypeUtils.getMethodDescriptor(CONTEXT, CONTEXT), false); mv.visitInsn(ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java
License:Open Source License
/** * Generates:/*from ww w . j av a 2 s .co m*/ * * <pre> * public void setTheme(int theme) { * if (!BuildHooksAndroid.isEnabled()) { * super.setTheme(theme); * return; * } * BuildHooksAndroid.setTheme(this, theme); * } * </pre> */ private void delegateSetTheme() { String methodName = "setTheme"; String methodDescriptor = TypeUtils.getMethodDescriptor(VOID, INT); String buildHooksMethodDescriptor = TypeUtils.getMethodDescriptor(VOID, CONTEXT, INT); MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null); mv.visitCode(); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false); Label l0 = new Label(); mv.visitJumpInsn(IFNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false); mv.visitInsn(RETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, buildHooksMethodDescriptor, false); mv.visitInsn(RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java
License:Open Source License
/** * Generates:// www . j ava2 s . c om * * <pre> * public returnType methodName() { * if (!BuildHooksAndroid.isEnabled()) return super.methodName(); * return BuildHooksAndroid.methodName(this); * } * </pre> */ private void delegateGet(String methodName, String returnType) { String getMethodDescriptor = TypeUtils.getMethodDescriptor(returnType); String buildHooksGetMethodDescriptor = TypeUtils.getMethodDescriptor(returnType, CONTEXT); MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, getMethodDescriptor, null, null); mv.visitCode(); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false); Label l0 = new Label(); mv.visitJumpInsn(IFNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, getMethodDescriptor, false); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, buildHooksGetMethodDescriptor, false); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:org.eclipse.core.databinding.pojo.bindable.internal.asm.ClassBindable.java
License:Open Source License
/** * Add the implementation of the _bindable_getPropertyChangeSupport method * to the class. The result is a method that looks as follows: * /* w ww .j a v a 2s. c o m*/ * private PropertyChangeSupport _bindable_getPropertyChangeSupport() { if * (_bindable_propertyChangeSupport == null) { * this._bindable_propertyChangeSupport = new PropertyChangeSupport( this); * } return _bindable_propertyChangeSupport; } */ public void addGetPropertyChangeSupport() { // private PropertyChangeSupport _bindable_getPropertyChangeSupport() MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, PCS_GETTER, "()" + PCS_SIGNATURE, null, null); mv.visitCode(); // if (_bindable_propertyChangeSupport == null) mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, PCS_FIELD, PCS_SIGNATURE); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); // this._bindable_propertyChangeSupport = new PropertyChangeSupport( // this); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, PCS_SHORT_SIGNATURE); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, PCS_SHORT_SIGNATURE, "<init>", "(Ljava/lang/Object;)V"); mv.visitFieldInsn(PUTFIELD, className, PCS_FIELD, PCS_SIGNATURE); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); // return _bindable_propertyChangeSupport; mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, PCS_FIELD, PCS_SIGNATURE); mv.visitInsn(ARETURN); mv.visitMaxs(4, 1); }