From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: [PATCH] ob-java.el: Add `:var' variables import Date: Sun, 22 Jun 2014 11:11:58 +0200 Message-ID: <53A69DDE.3000907@free.fr> References: <87fvixdhfz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wydof-0004zo-JS for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wydoe-0006AO-Kp for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:12:01 -0400 Received: from smtp3-g21.free.fr ([2a01:e0c:1:1599::12]:29040) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wydoe-0006AE-ED for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:12:00 -0400 Received: from [IPv6:2a01:e35:2e21:def0:28a2:60a9:4884:7d67] (unknown [IPv6:2a01:e35:2e21:def0:28a2:60a9:4884:7d67]) by smtp3-g21.free.fr (Postfix) with ESMTP id CF714A61EE for ; Sun, 22 Jun 2014 11:11:58 +0200 (CEST) In-Reply-To: <87fvixdhfz.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi Bart Good, this was a missing feature. Is there any reason to embed variables in an inner "Data" class ? Regards Thierry Le 22/06/2014 00:30, Bart Post a =E9crit : > * lisp/ob-java.el: (org-babel-execute:java): Inject a private static > class inside the Java class designated by > `:classname'. > (org-babel-variable-assignments:java): Assign the header variables to > static fields in a private static class > `Data'. > (org-babel-java-var-to-java): Translate string to String, list to > java.util.List, float to double and others to int. > --- > lisp/ob-java.el | 39 ++++++++++++++++++++++++++++++++++++++- > 1 file changed, 38 insertions(+), 1 deletion(-) > > diff --git a/lisp/ob-java.el b/lisp/ob-java.el > index 8c64171..a2a1f40 100644 > --- a/lisp/ob-java.el > +++ b/lisp/ob-java.el > @@ -58,7 +58,13 @@ parameters may be used, like javac -verbose" > (src-file (concat classname ".java")) > (cmpflag (or (cdr (assoc :cmpflag params)) "")) > (cmdline (or (cdr (assoc :cmdline params)) "")) > - (full-body (org-babel-expand-body:generic body params)) > + (split-body > + (split-string body (concat classname "[\n\t ]*{"))) > + (full-body > + (org-babel-expand-body:generic > + (concat (car split-body) (concat classname " {\n") (org-babel-vari= able-assignments:java params) > + (mapconcat 'identity (cdr split-body) (concat classname " {"))) > + params)) > (compile > (progn (with-temp-file src-file (insert full-body)) > (org-babel-eval > @@ -80,6 +86,37 @@ parameters may be used, like javac -verbose" > (org-babel-pick-name > (cdr (assoc :rowname-names params)) (cdr (assoc :rownames para= ms))))))) > =20 > +(defun org-babel-variable-assignments:java (params) > + "Return an internal Java class assigning the block's variables." > + (concat " private static class Data {\n" > + (mapconcat 'identity > + (mapcar > + (lambda (pair) > + (format " public static %s %s =3D %s;" > + (cond > + ((stringp (cdr pair)) "String") > + ((listp (cdr pair)) "java.util.List") > + ((floatp (cdr pair)) "double") > + (t "int")) > + (car pair) > + (org-babel-java-var-to-java (cdr pair)))) > + (mapcar #'cdr (org-babel-get-header params :var))) > + "\n") > + "\n }") > + ) > + > +(defun org-babel-java-var-to-java (var) > + "Convert an elisp value to a java string. > +Convert an elisp value, VAR, into a string of Java source code > +specifying a variable of the same value." > + (if (listp var) > + (concat "java.util.Arrays.asList(" (mapconcat #'org-babel-java-v= ar-to-java var ", ") ")") > + (if (equal var 'hline) > + "null" > + (format > + (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"= " "%S") > + var)))) > + > (provide 'ob-java) > =20 > =20