private static void printParameterChecks( PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos, Mode mode, final boolean generate_error_checks) { if (mode == Mode.NORMAL) { final GenerateAutos gen_autos_annotation = method.getAnnotation(GenerateAutos.class); if (gen_autos_annotation != null && gen_autos_annotation.sizeVariables().length > 0) { // For the auto-generated parameters, declare and init a size variable (that can be reused // by @Code) for (final VariableElement param : method.getParameters()) { if (Arrays.binarySearch( gen_autos_annotation.sizeVariables(), param.getSimpleName().toString()) >= 0) { final int shifting = getBufferElementSizeExponent(typeinfos.get(param).getType()); final Check check_annotation = param.getAnnotation(Check.class); writer.print("\t\tlong " + param.getSimpleName() + "_size = "); if (check_annotation == null || !check_annotation.canBeNull()) { writer.println(param.getSimpleName() + ".remaining() << " + shifting + ";"); } else { writer.println( param.getSimpleName() + " == null ? 0 : " + param.getSimpleName() + ".remaining() << " + shifting + ";"); } } } } } for (VariableElement param : method.getParameters()) { Class java_type = Utils.getJavaType(param.asType()); if (java_type.isArray() || (Utils.isAddressableType(java_type) && (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) && (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) && param.getAnnotation(Result.class) == null && !Utils.isReturnParameter(method, param))) { String check_value = null; boolean can_be_null = false; Check check_annotation = param.getAnnotation(Check.class); if (check_annotation != null) { check_value = check_annotation.value(); can_be_null = check_annotation.canBeNull(); } if ((Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null) { TypeInfo typeinfo = typeinfos.get(param); printParameterCheck( writer, method, param.getSimpleName().toString(), typeinfo.getType().getSimpleName(), check_value, can_be_null, param.getAnnotation(NullTerminated.class), generate_error_checks); } else if (String.class.equals(java_type)) { if (!can_be_null) { writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");"); } } else if (java_type.isArray()) { printArrayParameterCheck( writer, param.getSimpleName().toString(), check_value, can_be_null); } } } if (method.getAnnotation(CachedResult.class) != null) { printParameterCheck( writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, generate_error_checks); } }
private static boolean generateParametersJava( PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) { boolean first_parameter = true; for (VariableElement param : method.getParameters()) { if (native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative())) { continue; } final Constant constant_annotation = param.getAnnotation(Constant.class); if (constant_annotation != null && constant_annotation.isNative()) { continue; } AnnotationMirror auto_annotation_mirror = Utils.getParameterAutoAnnotation(param); boolean hide_auto_parameter = mode == Mode.NORMAL && !native_stub && auto_annotation_mirror != null; if (hide_auto_parameter) { AutoType auto_type_annotation = param.getAnnotation(AutoType.class); if (auto_type_annotation != null) { VariableElement auto_parameter = Utils.findParameter(method, auto_type_annotation.value()); TypeInfo auto_param_type_info = typeinfos_instance.get(auto_parameter); if (auto_param_type_info.getSignedness() == Signedness.BOTH) { if (!first_parameter) { writer.print(", "); } first_parameter = false; if (printTypes) { writer.print("boolean "); } writer.print(TypeInfo.UNSIGNED_PARAMETER_NAME); } } } else if (param.getAnnotation(Result.class) == null && (native_stub || ((param.getAnnotation(Constant.class) == null || param.getAnnotation(Constant.class).keepParam()) && !Utils.isReturnParameter(method, param))) && (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)) { first_parameter = generateParameterJava( writer, param, typeinfos_instance.get(param), native_stub, printTypes, first_parameter, mode); } } CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class); TypeMirror result_type = Utils.getMethodReturnType(method); if ((native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method)) { AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class); if (auto_size_annotation == null || !auto_size_annotation.isNative()) { if (cached_result_annotation == null || !cached_result_annotation.isRange()) { if (!first_parameter) { writer.print(", "); } first_parameter = false; if (printTypes) { writer.print("long "); } writer.print(Utils.RESULT_SIZE_NAME); } } } if (cached_result_annotation != null) { if (!first_parameter) { writer.print(", "); } if (mode == Mode.CACHEDRESULT) { if (printTypes) { writer.print("long "); } writer.print(Utils.CACHED_BUFFER_LENGTH_NAME + ", "); } first_parameter = false; if (printTypes) { writer.print(getResultType(method, native_stub)); } writer.print(" " + Utils.CACHED_BUFFER_NAME); } return first_parameter; }