public byte[] createTokenizer(final String[] httpVerbs, String[] httpVersions, String[] standardHeaders) { final String className = existingClassName + CLASS_NAME_SUFFIX; final ClassFile file = new ClassFile(className, existingClassName); final ClassMethod ctor = file.addMethod(AccessFlag.PUBLIC, "<init>", "V", DescriptorUtils.parameterDescriptors(constructorDescriptor)); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().loadMethodParameters(); ctor.getCodeAttribute().invokespecial(existingClassName, "<init>", constructorDescriptor); ctor.getCodeAttribute().returnInstruction(); final ClassMethod sctor = file.addMethod(AccessFlag.PUBLIC | AccessFlag.STATIC, "<clinit>", "V"); final AtomicInteger fieldCounter = new AtomicInteger(1); sctor.getCodeAttribute().invokestatic(existingClassName, "httpStrings", "()" + DescriptorUtils.makeDescriptor(Map.class)); sctor.getCodeAttribute().astore(CONSTRUCTOR_HTTP_STRING_MAP_VAR); createStateMachines(httpVerbs, httpVersions, standardHeaders, className, file, sctor, fieldCounter); sctor.getCodeAttribute().returnInstruction(); return file.toBytecode(); }
final CodeAttribute ca = asm.addMethod(m).getCodeAttribute(); ca.aload(0); ca.ldc(idlName); ca.getstatic(asm.getName(), strategyField, StubStrategy.class); if (!type.isPrimitive()) { ca.aload(index); } else if (type.equals(double.class)) { ca.dload(index); ca.checkcast(returnType); ca.returnInstruction(); final CodeAttribute init = asm.addMethod(Modifier.PRIVATE + Modifier.STATIC,initMethod, "V").getCodeAttribute(); int i; int len; init.putstatic(asm.getName(), strategyField, StubStrategy.class); init.returnInstruction();
/** * This method must be called by subclasses after they have finished generating the class. */ protected void finalizeStaticConstructor() { setupCachedProxyFields(); staticConstructor.getCodeAttribute().returnInstruction(); }
/** * Client proxies use the following hashCode: * <code>MyProxyName.class.hashCode()</code> */ @Override protected void generateHashCodeMethod(ClassFile proxyClassType) { final ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, HASH_CODE_METHOD, BytecodeUtils.INT_CLASS_DESCRIPTOR); final CodeAttribute b = method.getCodeAttribute(); // MyProxyName.class.hashCode() b.loadClass(proxyClassType.getName()); // now we have the class object on top of the stack b.invokevirtual("java.lang.Object", HASH_CODE_METHOD, EMPTY_PARENTHESES + BytecodeUtils.INT_CLASS_DESCRIPTOR); // now we have the hashCode b.returnInstruction(); }
@Override public void getDeclaredMethod(final ClassMethod classMethod, final String declaringClass, final String methodName, final String[] parameterTypes, ClassMethod staticConstructor) { String weldMemberName = WELD_MEMBER_PREFIX + METHOD_COUNT.incrementAndGet(); staticConstructor.getClassFile().addField(AccessFlag.PRIVATE | AccessFlag.STATIC, weldMemberName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = staticConstructor.getCodeAttribute(); addInitMethod(declaringClass, methodName, parameterTypes, weldMemberName, staticConstructor.getClassFile()); code.invokestatic(staticConstructor.getClassFile().getName(), weldMemberName, "()Ljava/lang/reflect/Method;"); code.putstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); CodeAttribute methodCode = classMethod.getCodeAttribute(); methodCode.getstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); }
/** * Client proxies are equal to other client proxies for the same bean. * <p/> * The corresponding java code: <code> * return other instanceof MyProxyClassType.class * </code> */ @Override protected void generateEqualsMethod(ClassFile proxyClassType) { ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, "equals", BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR, LJAVA_LANG_OBJECT); CodeAttribute b = method.getCodeAttribute(); b.aload(1); b.instanceofInstruction(proxyClassType.getName()); b.returnInstruction(); }
final CodeAttribute codeAttribute = method.getCodeAttribute(); codeAttribute.aload(1); codeAttribute.invokevirtual("java/io/ObjectInputStream", "readObject", "()Ljava/lang/Object;"); codeAttribute.returnInstruction(); ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().invokespecial(SerializationHackProxy.class.getName(), "<init>", "()V"); ctor.getCodeAttribute().returnInstruction();
/** * Client proxies use the following hashCode: * <code>MyProxyName.class.hashCode()</code> */ @Override protected void generateHashCodeMethod(ClassFile proxyClassType) { final ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, HASH_CODE_METHOD, BytecodeUtils.INT_CLASS_DESCRIPTOR); final CodeAttribute b = method.getCodeAttribute(); // MyProxyName.class.hashCode() b.loadClass(proxyClassType.getName()); // now we have the class object on top of the stack b.invokevirtual("java.lang.Object", HASH_CODE_METHOD, EMPTY_PARENTHESES + BytecodeUtils.INT_CLASS_DESCRIPTOR); // now we have the hashCode b.returnInstruction(); }
@Override public void getDeclaredMethod(final ClassMethod classMethod, final String declaringClass, final String methodName, final String[] parameterTypes, ClassMethod staticConstructor) { String weldMemberName = WELD_MEMBER_PREFIX + METHOD_COUNT.incrementAndGet(); staticConstructor.getClassFile().addField(AccessFlag.PRIVATE | AccessFlag.STATIC, weldMemberName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = staticConstructor.getCodeAttribute(); addInitMethod(declaringClass, methodName, parameterTypes, weldMemberName, staticConstructor.getClassFile()); code.invokestatic(staticConstructor.getClassFile().getName(), weldMemberName, "()Ljava/lang/reflect/Method;"); code.putstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); CodeAttribute methodCode = classMethod.getCodeAttribute(); methodCode.getstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); }
private static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }
/** * Client proxies are equal to other client proxies for the same bean. * <p/> * The corresponding java code: <code> * return other instanceof MyProxyClassType.class * </code> */ @Override protected void generateEqualsMethod(ClassFile proxyClassType) { ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, "equals", BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR, LJAVA_LANG_OBJECT); CodeAttribute b = method.getCodeAttribute(); b.aload(1); b.instanceofInstruction(proxyClassType.getName()); b.returnInstruction(); }
ctor.getCodeAttribute().aload(0); ctor.getCodeAttribute().invokespecial(superclass.getName(), "<init>", "()V"); ctor.getCodeAttribute().returnInstruction(); final CodeAttribute idMethod = asm.addMethod(Modifier.PUBLIC + Modifier.FINAL, "_ids", "[Ljava/lang/String;").getCodeAttribute(); idMethod.getstatic(stubClassName, ID_FIELD_NAME, "[Ljava/lang/String;"); idMethod.returnInstruction(); final CodeAttribute clinit = asm.addMethod(Modifier.STATIC, "<clinit>", "V").getCodeAttribute(); clinit.iconst(ids.length); clinit.anewarray(String.class.getName()); clinit.invokestatic(stubClassName, init(methodIndex), "()V"); clinit.returnInstruction();
/** * Client proxies use the following hashCode: * <code>MyProxyName.class.hashCode()</code> */ @Override protected void generateHashCodeMethod(ClassFile proxyClassType) { final ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, HASH_CODE_METHOD, BytecodeUtils.INT_CLASS_DESCRIPTOR); final CodeAttribute b = method.getCodeAttribute(); // MyProxyName.class.hashCode() b.loadClass(proxyClassType.getName()); // now we have the class object on top of the stack b.invokevirtual("java.lang.Object", HASH_CODE_METHOD, EMPTY_PARENTHESES + BytecodeUtils.INT_CLASS_DESCRIPTOR); // now we have the hashCode b.returnInstruction(); }
@Override public void getDeclaredMethod(final ClassMethod classMethod, final String declaringClass, final String methodName, final String[] parameterTypes, ClassMethod staticConstructor) { String weldMemberName = WELD_MEMBER_PREFIX + METHOD_COUNT.incrementAndGet(); staticConstructor.getClassFile().addField(AccessFlag.PRIVATE | AccessFlag.STATIC, weldMemberName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = staticConstructor.getCodeAttribute(); addInitMethod(declaringClass, methodName, parameterTypes, weldMemberName, staticConstructor.getClassFile()); code.invokestatic(staticConstructor.getClassFile().getName(), weldMemberName, "()Ljava/lang/reflect/Method;"); code.putstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); CodeAttribute methodCode = classMethod.getCodeAttribute(); methodCode.getstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); }
private static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }
/** * Client proxies are equal to other client proxies for the same bean. * <p/> * The corresponding java code: <code> * return other instanceof MyProxyClassType.class * </code> */ @Override protected void generateEqualsMethod(ClassFile proxyClassType) { ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, "equals", BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR, LJAVA_LANG_OBJECT); CodeAttribute b = method.getCodeAttribute(); b.aload(1); b.instanceofInstruction(proxyClassType.getName()); b.returnInstruction(); }
private static void generateGetTargetInstanceBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); b.aload(0); b.returnInstruction(); }
/** * Client proxies use the following hashCode: * <code>MyProxyName.class.hashCode()</code> */ @Override protected void generateHashCodeMethod(ClassFile proxyClassType) { final ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, HASH_CODE_METHOD, BytecodeUtils.INT_CLASS_DESCRIPTOR); final CodeAttribute b = method.getCodeAttribute(); // MyProxyName.class.hashCode() b.loadClass(proxyClassType.getName()); // now we have the class object on top of the stack b.invokevirtual("java.lang.Object", HASH_CODE_METHOD, EMPTY_PARENTHESES + BytecodeUtils.INT_CLASS_DESCRIPTOR); // now we have the hashCode b.returnInstruction(); }
@Override public void getDeclaredMethod(final ClassMethod classMethod, final String declaringClass, final String methodName, final String[] parameterTypes, ClassMethod staticConstructor) { String weldMemberName = WELD_MEMBER_PREFIX + METHOD_COUNT.incrementAndGet(); staticConstructor.getClassFile().addField(AccessFlag.PRIVATE | AccessFlag.STATIC, weldMemberName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = staticConstructor.getCodeAttribute(); addInitMethod(declaringClass, methodName, parameterTypes, weldMemberName, staticConstructor.getClassFile()); code.invokestatic(staticConstructor.getClassFile().getName(), weldMemberName, "()Ljava/lang/reflect/Method;"); code.putstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); CodeAttribute methodCode = classMethod.getCodeAttribute(); methodCode.getstatic(classMethod.getClassFile().getName(), weldMemberName, LJAVA_LANG_REFLECT_METHOD); }
private static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }