List of usage examples for org.objectweb.asm Opcodes ARETURN
int ARETURN
To view the source code for org.objectweb.asm Opcodes ARETURN.
Click Source Link
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates code://www . j a v a 2 s . c o m * * public Class<?>[] _asActionInterceptors(String name) { * return _asInterceptors.get(name); * } */ public void createActionInterceptorsMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asActionInterceptors", "(Ljava/lang/String;)[Ljava/lang/Class;", null, null); Label l0 = new Label(); Label l1 = new Label(); mv.visitLabel(l0); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asInterceptors", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;"); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l1); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l1, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates the code://w w w. ja v a 2 s .c o m * public Map<String, Class<?>> _asParameters() { * return _asParameters; * } */ private void createParametersMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asParameters", "()Ljava/util/Map;", "()Ljava/util/Map<Ljava/lang/String;Ljava/lang/Class<*>;>;", null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters", "Ljava/util/Map;"); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates the _asParameter() getter as * // w w w. j a v a2s . c o m * public Object _asParameter(String name) { * if(name.equals("name")) * return getName(); * if(name.equals("date")) * return getDate(); * ... * return null; * } */ private void createParametersGetterMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asParameter", "(Ljava/lang/String;)Ljava/lang/Object;", null, null); Label start = new Label(); Label next = new Label(); Label variable = new Label(); boolean first = true; for (String name : reflector.getParameters().keySet()) { Label l0 = null; Label l1 = new Label(); if (first) { l0 = new Label(); first = false; } else { l0 = next; next = new Label(); } mv.visitLabel(l0); if (!first) mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(name); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); mv.visitJumpInsn(Opcodes.IFEQ, next); String methodGetterName = reflector.getGetters().get(name).getName(); String methodGetterDesc = "()" + Type.getDescriptor(reflector.getParameters().get(name)); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), methodGetterName, methodGetterDesc, false); mv.visitInsn(Opcodes.ARETURN); } mv.visitLabel(next); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(variable); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, start, variable, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, start, variable, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * public Class<?> _asParameterConverter(String name) { * return _asConverters.get(name);/*from w w w .ja v a 2 s .c o m*/ * } */ public void createParameterConverterMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asParameterConverter", "(Ljava/lang/String;)Ljava/lang/Class;", null, null); Label l0 = new Label(); mv.visitLabel(l0); mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Class"); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l1, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OControllerClassVisitor.java
License:Apache License
/** * Generates the _asUrl() method with using a constant string * public String _asUrl() { return "/*"; } *///from ww w .jav a 2 s.c o m public void createUrlMethod() { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asUrl", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(reflector.getUrl()); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLocalVariable("this", Type.getDescriptor(reflector.getClazz()), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java
License:Apache License
/** * Generates the code:/*from w w w . j a va2 s . c o m*/ * * public Result _asAfter() { * return after(); * } */ public void createAfterMethod() { String signature = "()" + Type.getDescriptor(Result.class); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asAfter", signature, null, null); Label l0 = new Label(); if (reflector.getAfter() != null) { mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "after", signature, false); mv.visitInsn(Opcodes.ARETURN); } else { mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); } Label l1 = new Label(); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java
License:Apache License
/** * Generates the code:/* w w w. j a v a 2 s . com*/ * * public Result _asBefore() { * return before(); * } */ public void createBeforeMethod() { String signature = "()" + Type.getDescriptor(Result.class); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asBefore", signature, null, null); Label l0 = new Label(); if (reflector.getAfter() != null) { mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "before", signature, false); mv.visitInsn(Opcodes.ARETURN); } else { mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); } Label l1 = new Label(); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:jasy.lang.ASMCompiler.java
private static boolean isReturn(int opcode) { switch (opcode) { case Opcodes.ARETURN: case Opcodes.DRETURN: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.RET: case Opcodes.RETURN: return true; }// ww w . jav a 2s.c o m return false; }
From source file:jasy.lang.ASMCompiler.java
private static int getReturn(Class<?> type) { String typeDescriptor = Type.getDescriptor(type); switch (typeDescriptor) { case "V": return Opcodes.RETURN; case "J": return Opcodes.LRETURN; case "D": return Opcodes.DRETURN; case "F": return Opcodes.FRETURN; case "I": case "Z": case "B": case "C": case "S": return Opcodes.IRETURN; default://from w w w . j ava 2 s. co m return Opcodes.ARETURN; } }
From source file:jerl.bcm.inj.InjectionMethodAdapter.java
License:Apache License
@Override public void visitInsn(int opcode) { incByteCodeCounter();//w w w. j ava2 s . co m if (opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) { for (int i = 0; i < exitInjections.size(); i++) { InjectionMethodExit ime = (InjectionMethodExit) exitInjections.elementAt(i); ime.inject(mv); if (isDebugMode) { System.out.println("\t**Inject: " + ime); } } } mv.visitInsn(opcode); }