List of usage examples for org.objectweb.asm MethodVisitor visitLdcInsn
public void visitLdcInsn(final Object value)
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void firstCause(FirstCause firstCause, Class type, int param, int event, MethodVisitor visitor) { Label returnLabel = new Label(); Label continueLabel = new Label(); visitor.visitVarInsn(ALOAD, event);/*ww w . j ava 2 s .c o m*/ visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "cause", BytecodeEventListenerGeneration.eventCauseMethod.getDescriptor(), true); visitor.visitLdcInsn(Type.getType(type)); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.causeType.getInternalName(), "first", BytecodeEventListenerGeneration.causeFirstMethod.getDescriptor(), false); visitor.visitInsn(DUP); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false); visitor.visitJumpInsn(IFEQ, returnLabel); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false); BytecodeEventListenerGeneration.checkCast(Type.getType(type), visitor); visitor.visitVarInsn(ASTORE, param); visitor.visitJumpInsn(GOTO, continueLabel); visitor.visitLabel(returnLabel); visitor.visitInsn(RETURN); visitor.visitLabel(continueLabel); }
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void lastCause(LastCause lastCause, Class type, int param, int event, MethodVisitor visitor) { Label returnLabel = new Label(); Label continueLabel = new Label(); visitor.visitVarInsn(ALOAD, event);/* ww w . j ava 2 s .c o m*/ visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "cause", BytecodeEventListenerGeneration.eventCauseMethod.getDescriptor(), true); visitor.visitLdcInsn(Type.getType(type)); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.causeType.getInternalName(), "last", BytecodeEventListenerGeneration.causeLastMethod.getDescriptor(), false); visitor.visitInsn(DUP); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false); visitor.visitJumpInsn(IFEQ, returnLabel); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false); BytecodeEventListenerGeneration.checkCast(Type.getType(type), visitor); visitor.visitVarInsn(ASTORE, param); visitor.visitJumpInsn(GOTO, continueLabel); visitor.visitLabel(returnLabel); visitor.visitInsn(RETURN); visitor.visitLabel(continueLabel); }
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void getContext(GetContext getContext, String paramName, Class type, int param, int event, MethodVisitor visitor) { Label returnLabel = new Label(); Label continueLabel = new Label(); visitor.visitVarInsn(ALOAD, event);//from w ww .ja v a 2 s. co m visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true); visitor.visitLdcInsn(getContext.value().equals(GetContext.REFER_TO_PARAM) ? param : getContext.value()); visitor.visitLdcInsn(Type.getType(type)); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "get", BytecodeEventListenerGeneration.contextGetMethod.getDescriptor(), false); visitor.visitInsn(DUP); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false); visitor.visitJumpInsn(IFEQ, returnLabel); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false); BytecodeEventListenerGeneration.checkCast(Type.getType(type), visitor); visitor.visitVarInsn(ASTORE, param); visitor.visitJumpInsn(GOTO, continueLabel); visitor.visitLabel(returnLabel); visitor.visitInsn(RETURN); visitor.visitLabel(continueLabel); }
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void allContexts(AllContexts contexts, boolean asPair, Class type, int param, int event, MethodVisitor visitor) { visitor.visitVarInsn(ALOAD, event);/*from w ww. j a v a 2 s . c o m*/ visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true); visitor.visitLdcInsn(Type.getType(type)); if (asPair) { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "all", BytecodeEventListenerGeneration.allContextMethod.getDescriptor(), false); } else { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "allSimple", BytecodeEventListenerGeneration.allContextSimpleMethod.getDescriptor(), false); } visitor.visitVarInsn(ASTORE, param); }
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void firstContext(FirstContext firstContext, boolean asPair, Class type, int param, int event, MethodVisitor visitor) { Label returnLabel = new Label(); Label continueLabel = new Label(); visitor.visitVarInsn(ALOAD, event);// w ww .ja va 2s . c o m visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true); visitor.visitLdcInsn(Type.getType(type)); if (asPair) { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "first", BytecodeEventListenerGeneration.contextFirstMethod.getDescriptor(), false); } else { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "firstSimple", BytecodeEventListenerGeneration.contextSimpleFirstMethod.getDescriptor(), false); } visitor.visitInsn(DUP); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false); visitor.visitJumpInsn(IFEQ, returnLabel); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false); BytecodeEventListenerGeneration.checkCast(asPair ? Type.getType(Pair.class) : Type.getType(type), visitor); visitor.visitVarInsn(ASTORE, param); visitor.visitJumpInsn(GOTO, continueLabel); visitor.visitLabel(returnLabel); visitor.visitInsn(RETURN); visitor.visitLabel(continueLabel); }
From source file:com.gmail.socraticphoenix.nebula.event.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static void lastContext(LastContext lastContext, boolean asPair, Class type, int param, int event, MethodVisitor visitor) { Label returnLabel = new Label(); Label continueLabel = new Label(); visitor.visitVarInsn(ALOAD, event);/*from ww w . jav a 2s . c om*/ visitor.visitMethodInsn(INVOKEINTERFACE, BytecodeEventListenerGeneration.eventType.getInternalName(), "context", BytecodeEventListenerGeneration.eventContextMethod.getDescriptor(), true); visitor.visitLdcInsn(Type.getType(type)); if (asPair) { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "last", BytecodeEventListenerGeneration.contextLastMethod.getDescriptor(), false); } else { visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.contextType.getInternalName(), "lastSimple", BytecodeEventListenerGeneration.contextSimpleLastMethod.getDescriptor(), false); } visitor.visitInsn(DUP); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "isPresent", BytecodeEventListenerGeneration.isPresentMethod.getDescriptor(), false); visitor.visitJumpInsn(IFEQ, returnLabel); visitor.visitMethodInsn(INVOKEVIRTUAL, BytecodeEventListenerGeneration.optionalType.getInternalName(), "get", BytecodeEventListenerGeneration.getMethod.getDescriptor(), false); BytecodeEventListenerGeneration.checkCast(asPair ? Type.getType(Pair.class) : Type.getType(type), visitor); visitor.visitVarInsn(ASTORE, param); visitor.visitJumpInsn(GOTO, continueLabel); visitor.visitLabel(returnLabel); visitor.visitInsn(RETURN); visitor.visitLabel(continueLabel); }
From source file:com.gmail.socraticphoenix.occurence.wrappers.BytecodeEventListenerGeneration.java
License:Open Source License
public static String listener(EventListener eventListener, Class eventClass, Object listener, Method method, ClassVisitor visitor) {/*from w ww . j a v a2 s.c o m*/ Type listenerType = Type.getType(listener.getClass()); Type eventType = Type.getType(eventClass); String internalImplName = listenerType.getInternalName() + "$listener$" + method.getName() + "$" + BytecodeEventListenerGeneration.index++; String simpleName = listener.getClass().getName() + "#" + method.getName() + "(" + Stream.of(method.getParameters()).map(p -> p.getType().getSimpleName()) .reduce((a, b) -> a + ", " + b).orElse("") + ")"; visitor.visit(V1_8, ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL, internalImplName, null, BytecodeEventListenerGeneration.objectType.getInternalName(), new String[] { BytecodeEventListenerGeneration.eventWrapperType.getInternalName() }); visitor.visitField(ACC_PRIVATE | ACC_FINAL, "listener", listenerType.getDescriptor(), null, null) .visitEnd(); MethodVisitor constructor = visitor.visitMethod(ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class)), null, null); constructor.visitParameter("listener", ACC_FINAL); constructor.visitCode(); constructor.visitVarInsn(ALOAD, 0); constructor.visitMethodInsn(INVOKESPECIAL, BytecodeEventListenerGeneration.objectType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE), false); constructor.visitVarInsn(ALOAD, 0); constructor.visitVarInsn(ALOAD, 1); constructor.visitTypeInsn(CHECKCAST, listenerType.getInternalName()); constructor.visitFieldInsn(PUTFIELD, internalImplName, "listener", listenerType.getDescriptor()); constructor.visitInsn(RETURN); constructor.visitMaxs(0, 0); constructor.visitEnd(); MethodVisitor name = visitor.visitMethod(ACC_PUBLIC, "name", Type.getMethodDescriptor(Type.getType(String.class)), null, null); name.visitLdcInsn(simpleName); name.visitInsn(ARETURN); name.visitMaxs(0, 0); name.visitEnd(); MethodVisitor priority = visitor.visitMethod(ACC_PUBLIC | ACC_FINAL, "priority", BytecodeEventListenerGeneration.priorityMethod.getDescriptor(), null, null); priority.visitCode(); priority.visitLdcInsn(eventListener.value()); priority.visitInsn(IRETURN); priority.visitMaxs(0, 0); priority.visitEnd(); MethodVisitor getListener = visitor.visitMethod(ACC_PUBLIC | ACC_FINAL, "listener", BytecodeEventListenerGeneration.listenerMethod.getDescriptor(), null, null); getListener.visitVarInsn(ALOAD, 0); getListener.visitFieldInsn(GETFIELD, internalImplName, "listener", listenerType.getDescriptor()); getListener.visitInsn(ARETURN); getListener.visitMaxs(0, 0); getListener.visitEnd(); MethodVisitor event = visitor.visitMethod(ACC_PUBLIC | ACC_FINAL, "mainEvent", BytecodeEventListenerGeneration.mainEventMethod.getDescriptor(), null, null); event.visitCode(); event.visitLdcInsn(eventType); event.visitInsn(ARETURN); event.visitMaxs(0, 0); event.visitEnd(); return internalImplName; }
From source file:com.google.gag.agent.ThisHadBetterGenerator.java
License:Apache License
/** * The given Property needs to be either {@link Property#THE_BLUE_PILL} or * {@link Property#THE_RED_PILL}./* w w w . j ava 2s. c o m*/ */ private static void visitPill(MethodVisitor mv, boolean be, Property property, LocalVarInfo param, Label okay) { if (param.getType().getSort() != Type.OBJECT) { throw new AnnotationStateError("Unsupported type: " + param.getType()); } // TODO: Also handle if parameter is null. Label notOkay = new Label(); // See if the param type matches a Pill type mv.visitVarInsn(ALOAD, param.getIndex()); mv.visitMethodInsn(INVOKEVIRTUAL, param.getType().getInternalName(), "getClass", "()Ljava/lang/Class;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitLdcInsn("Pill|ThePill|.*[\\.$]Pill|.*[\\.$]ThePill"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "matches", "(Ljava/lang/String;)Z"); if (be) { // If the param type does not match a Pill type, that's not okay, go to exception. mv.visitJumpInsn(FALSE, notOkay); } else { // If the param type does not match a Pill type, then that's okay, skip exception. mv.visitJumpInsn(FALSE, okay); } // At this point, the param type matches a Pill type. // So check if the param type is an enum type. mv.visitVarInsn(ALOAD, param.getIndex()); mv.visitTypeInsn(INSTANCEOF, "java/lang/Enum"); if (be) { // If the param type is not an enum, that's not okay, go to exception. mv.visitJumpInsn(FALSE, notOkay); } else { // If the param type is not an enum, that's okay, skip exception. mv.visitJumpInsn(FALSE, okay); } // Check that the Pill type has the property specified in the annotation. // First try to match on "BLUE" (or "RED"). mv.visitVarInsn(ALOAD, param.getIndex()); mv.visitTypeInsn(CHECKCAST, "java/lang/Enum"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Enum", "name", "()Ljava/lang/String;"); mv.visitLdcInsn(property == Property.THE_BLUE_PILL ? "BLUE" : "RED"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); mv.visitJumpInsn(TRUE, be ? okay : notOkay); // Then try to see if the value ends with "BLUE_PILL" (or "RED_PILL"). mv.visitVarInsn(ALOAD, param.getIndex()); mv.visitTypeInsn(CHECKCAST, "java/lang/Enum"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Enum", "name", "()Ljava/lang/String;"); mv.visitLdcInsn(property == Property.THE_BLUE_PILL ? "BLUE_PILL" : "RED_PILL"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "endsWith", "(Ljava/lang/String;)Z"); mv.visitJumpInsn(be ? TRUE : FALSE, okay); mv.visitLabel(notOkay); }
From source file:com.google.gwtorm.jdbc.AccessGen.java
License:Apache License
private void implementGetString(final String methodName, final String returnValue) { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, methodName, Type.getMethodDescriptor(Type.getType(String.class), new Type[] {}), null, null); mv.visitCode();/* ww w. j av a 2s .c o m*/ mv.visitLdcInsn(returnValue); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); }
From source file:com.google.gwtorm.jdbc.AccessGen.java
License:Apache License
private void throwUnsupported(final MethodVisitor mv, final String message) { final Type eType = Type.getType(UnsupportedOperationException.class); mv.visitTypeInsn(NEW, eType.getInternalName()); mv.visitInsn(DUP);//from w w w . jav a 2 s . c o m mv.visitLdcInsn(message); mv.visitMethodInsn(INVOKESPECIAL, eType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class) })); mv.visitInsn(ATHROW); }