[m-rev.] For review: Java implementation of library/dir.m
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Jan 14 00:54:01 AEDT 2004
On 13-Jan-2004, James Goddard <goddardjames at yahoo.com> wrote:
> Implement some library procedures for the Java back end.
Thanks, that looks good.
I do have a few comments.
> library/dir.m:
> Updated the imports so both interface and implementation include
> string and io.
In general, modules should only be imported in either the interface
or the implementation section, not both. Modules which are imported
in the interface are automatically visible in the implementation.
> :- implementation.
>
> -:- import_module char, enum, exception, int, list, require, string, std_util.
> +:- import_module io, char, enum, exception, int, list, require, string,
> + std_util.
If the imports don't fit on a single line, please use multiple
import_module declarations rather than a single one line-wrapped;
this makes them much easier to grep for.
> @@ -917,6 +929,35 @@
> }
> }").
>
> +:- pragma foreign_proc("Java",
> + dir__make_single_directory_2(ErrorIfExists::in, DirName::in,
> + Result::out, _IO0::di, _IO::uo),
> + [may_call_mercury, promise_pure, tabled_for_io, thread_safe],
> +"
> + try {
> + java.io.File newDir = new java.io.File(DirName);
> + java.io.File parent = newDir.getParentFile();
> +
> + if (parent == null) {
> + Result = make_mkdir_res_error_4_p_0(
> + new java.io.IOException(
> + ""can't create root directory""));
> + } else if (!parent.exists()) {
> + Result = make_mkdir_res_error_4_p_0(
> + new java.io.IOException(
> + ""parent directory does not exist""));
> + } else if (ErrorIfExists == 1 && newDir.exists()) {
> + Result = make_mkdir_res_error_4_p_0(
> + new java.io.IOException(
> + ""directory already exists""));
> + } else {
> + Result = make_mkdir_res_ok_0_f_0();
> + }
> + } catch (java.lang.Exception e) {
> + Result = make_mkdir_res_error_4_p_0(e);
> + }
> +").
Hmm... that looks like it has a bug:
when does the directory actually get created?
Please make sure that there is a test case which will check that
make_single_directory does actually create the directory.
Also, you should define a Java version of dir__make_directory,
using java.io.File.mkdirs().
> @@ -1273,6 +1315,30 @@
> +:- pragma foreign_proc("Java",
> + dir__open_2(DirName::in, Result::out, _IO0::di, _IO::uo),
> + [may_call_mercury, promise_pure, tabled_for_io, thread_safe],
> +"
> + try {
> + java.lang.String[] fileList =
> + (new java.io.File(DirName)).list();
> +
> + java.util.LinkedList ll = new java.util.LinkedList();
> + for (int i = 0; i < fileList.length; i++) {
> + ll.add(fileList[i]);
> + }
Why not use java.utils.Arrays.asList(fileList)?
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list