emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-java.el: Add `:var' variables import
@ 2014-06-21 22:30 Bart Post
  2014-06-22  9:11 ` Thierry Banel
  2014-06-25  8:44 ` Bastien
  0 siblings, 2 replies; 6+ messages in thread
From: Bart Post @ 2014-06-21 22:30 UTC (permalink / raw)
  To: emacs-orgmode


* 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-variable-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 params)))))))
 
+(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 = %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-var-to-java var ", ") ")")
+    (if (equal var 'hline)
+	"null"
+      (format
+       (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S")
+       var))))
+
 (provide 'ob-java)
 
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ob-java.el: Add `:var' variables import
  2014-06-21 22:30 [PATCH] ob-java.el: Add `:var' variables import Bart Post
@ 2014-06-22  9:11 ` Thierry Banel
  2014-06-25  8:44 ` Bastien
  1 sibling, 0 replies; 6+ messages in thread
From: Thierry Banel @ 2014-06-22  9:11 UTC (permalink / raw)
  To: emacs-orgmode

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 écrit :
> * 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-variable-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 params)))))))
>  
> +(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 = %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-var-to-java var ", ") ")")
> +    (if (equal var 'hline)
> +	"null"
> +      (format
> +       (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S")
> +       var))))
> +
>  (provide 'ob-java)
>  
>  

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ob-java.el: Add `:var' variables import
  2014-06-21 22:30 [PATCH] ob-java.el: Add `:var' variables import Bart Post
  2014-06-22  9:11 ` Thierry Banel
@ 2014-06-25  8:44 ` Bastien
  2014-06-25 10:00   ` Bart Post
  1 sibling, 1 reply; 6+ messages in thread
From: Bastien @ 2014-06-25  8:44 UTC (permalink / raw)
  To: Bart Post; +Cc: emacs-orgmode

Hi Bart,

Thanks for the patch.  It is larger than what we can apply into Org's
core without a copyright assignment.  You can start the process of
signing by filling this form:

http://orgmode.org/cgit.cgi/org-mode.git/plain/request-assign-future.txt

In the meantime, if someone who speaks java can review the patch,
that'd be great!

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ob-java.el: Add `:var' variables import
  2014-06-25  8:44 ` Bastien
@ 2014-06-25 10:00   ` Bart Post
  2014-07-28 14:25     ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Post @ 2014-06-25 10:00 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

Hi Bastien,

Thanks for your reply! I already started the copyright assignment process,
for now I need to wait for a disclaimer form from my employer, but I will
notify you as soon as there is progress.

While discussing the patch with a roommate, we came to the conclusion that
a java class which implements, extends or throws, may not compile correctly
with the added data. So the patch will need some rework, or documentation
about (im-)possible usage situations.

In any way, there will be more!

Regards,
Bart


On Wed, Jun 25, 2014 at 10:44 AM, Bastien <bzg@gnu.org> wrote:

> Hi Bart,
>
> Thanks for the patch.  It is larger than what we can apply into Org's
> core without a copyright assignment.  You can start the process of
> signing by filling this form:
>
> http://orgmode.org/cgit.cgi/org-mode.git/plain/request-assign-future.txt
>
> In the meantime, if someone who speaks java can review the patch,
> that'd be great!
>
> Thanks,
>
> --
>  Bastien
>

[-- Attachment #2: Type: text/html, Size: 1554 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ob-java.el: Add `:var' variables import
  2014-06-25 10:00   ` Bart Post
@ 2014-07-28 14:25     ` Bastien
  2014-07-31  9:41       ` Bart Post
  0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2014-07-28 14:25 UTC (permalink / raw)
  To: Bart Post; +Cc: emacs-orgmode

Hi Bart,

Bart Post <bart.post@gmail.com> writes:

> Thanks for your reply! I already started the copyright assignment
> process, for now I need to wait for a disclaimer form from my
> employer, but I will notify you as soon as there is progress.

Did you get this sorted out?

> While discussing the patch with a roommate, we came to the conclusion
> that a java class which implements, extends or throws, may not
> compile correctly with the added data. So the patch will need some
> rework, or documentation about (im-)possible usage situations.

Thanks for letting us know -- thanks!

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ob-java.el: Add `:var' variables import
  2014-07-28 14:25     ` Bastien
@ 2014-07-31  9:41       ` Bart Post
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Post @ 2014-07-31  9:41 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

Hi Bastien,

On Mon, Jul 28, 2014 at 4:25 PM, Bastien <bzg@gnu.org> wrote:

> Bart Post <bart.post@gmail.com> writes:
>
> > Thanks for your reply! I already started the copyright assignment
> > process, for now I need to wait for a disclaimer form from my
> > employer, but I will notify you as soon as there is progress.
>
> Did you get this sorted out?
>

Not yet, sorry. But I'm on it!

> While discussing the patch with a roommate, we came to the conclusion
> > that a java class which implements, extends or throws, may not
> > compile correctly with the added data. So the patch will need some
> > rework, or documentation about (im-)possible usage situations.
>
> Thanks for letting us know -- thanks!
>

No problem, I hope to be able to help out there, too.

Best,
Bart

[-- Attachment #2: Type: text/html, Size: 1423 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-31  9:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-21 22:30 [PATCH] ob-java.el: Add `:var' variables import Bart Post
2014-06-22  9:11 ` Thierry Banel
2014-06-25  8:44 ` Bastien
2014-06-25 10:00   ` Bart Post
2014-07-28 14:25     ` Bastien
2014-07-31  9:41       ` Bart Post

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).