/** * Defines the code that calls the builder factory method. */ private void invokeFactoryMethod(MethodDefinition read, Map<Short, LocalVariableDefinition> structData, LocalVariableDefinition instance) { if (metadata.getBuilderMethod().isPresent()) { ThriftMethodInjection builderMethod = metadata.getBuilderMethod().get(); read.loadVariable(instance); // push parameters on stack for (ThriftParameterInjection parameter : builderMethod.getParameters()) { read.loadVariable(structData.get(parameter.getId())); } // invoke the method read.invokeVirtual(builderMethod.getMethod()) .storeVariable(instance); } }
Method method = methodInjection.getMethod(); Type[] parameterTypes = method.getGenericParameterTypes(); for(int i = 0 ;i<parametersValues.length;++i){ instance = (T) builderMethod.getMethod().invoke(instance, parametersValues); if (instance == null) { throw new IllegalArgumentException("Builder method returned a null instance");
Method method = methodInjection.getMethod(); Type[] parameterTypes = method.getGenericParameterTypes(); for(int i = 0 ;i<parametersValues.length;++i){ instance = (T) builderMethod.getMethod().invoke(instance, parametersValues); if (instance == null) { throw new IllegalArgumentException("Builder method returned a null instance");
private void injectMethod(MethodDefinition read, ThriftMethodInjection methodInjection, LocalVariableDefinition instance, Map<Short, LocalVariableDefinition> structData) { // if any parameter is non-null, invoke the method String methodName = methodInjection.getMethod().toGenericString(); for (ThriftParameterInjection parameter : methodInjection.getParameters()) { if (!isParameterTypeJavaPrimitive(parameter)) { read.loadVariable(structData.get(parameter.getId())) .ifNotNullGoto("invoke_" + methodName); } else { read.gotoLabel("invoke_" + methodName); } } read.gotoLabel("skip_invoke_" + methodName); // invoke the method read.visitLabel("invoke_" + methodName) .loadVariable(instance); // push parameters on stack for (ThriftParameterInjection parameter : methodInjection.getParameters()) { read.loadVariable(structData.get(parameter.getId())); } // invoke the method read.invokeVirtual(methodInjection.getMethod()); // if method has a return, we need to pop it off the stack if (methodInjection.getMethod().getReturnType() != void.class) { read.pop(); } // skip invocation read.visitLabel("skip_invoke_" + methodName); }