From bf9ec3d91a79414deac039f7bf83352a9b0a9a85 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 29 Sep 2021 18:48:59 -0400 Subject: Update to Org 9.5 --- lisp/org/ob-java.el | 480 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 442 insertions(+), 38 deletions(-) (limited to 'lisp/org/ob-java.el') diff --git a/lisp/org/ob-java.el b/lisp/org/ob-java.el index b1d517e94aa..60ef33bc6e4 100644 --- a/lisp/org/ob-java.el +++ b/lisp/org/ob-java.el @@ -1,8 +1,10 @@ -;;; ob-java.el --- Babel Functions for Java -*- lexical-binding: t; -*- +;;; ob-java.el --- org-babel functions for java evaluation -*- lexical-binding: t -*- ;; Copyright (C) 2011-2021 Free Software Foundation, Inc. -;; Author: Eric Schulte +;; Authors: Eric Schulte +;; Dan Davison +;; Maintainer: Ian Martins ;; Keywords: literate programming, reproducible research ;; Homepage: https://orgmode.org @@ -23,8 +25,7 @@ ;;; Commentary: -;; Currently this only supports the external compilation and execution -;; of java code blocks (i.e., no session support). +;; Org-Babel support for evaluating java source code. ;;; Code: (require 'ob) @@ -32,52 +33,455 @@ (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("java" . "java")) +(defvar org-babel-temporary-directory) ; from ob-core + +(defvar org-babel-default-header-args:java '((:results . "output") + (:dir . ".")) + "Default header args for java source blocks. +The docs say functional mode should be the default [1], but +ob-java didn't originally support functional mode, so we keep +scripting mode as the default for now to maintain previous +behavior. + +Most languages write tempfiles to babel's temporary directory, +but ob-java originally had to write them to the current +directory, so we keep that as the default behavior. + +[1] https://orgmode.org/manual/Results-of-Evaluation.html") + +(defconst org-babel-header-args:java '((imports . :any)) + "Java-specific header arguments.") + (defcustom org-babel-java-command "java" "Name of the java command. -May be either a command in the path, like java -or an absolute path name, like /usr/local/bin/java -parameters may be used, like java -verbose" +May be either a command in the path, like java or an absolute +path name, like /usr/local/bin/java. Parameters may be used, +like java -verbose." :group 'org-babel - :version "24.3" + :package-version '(Org . "9.5") :type 'string) (defcustom org-babel-java-compiler "javac" "Name of the java compiler. -May be either a command in the path, like javac -or an absolute path name, like /usr/local/bin/javac -parameters may be used, like javac -verbose" +May be either a command in the path, like javac or an absolute +path name, like /usr/local/bin/javac. Parameters may be used, +like javac -verbose." + :group 'org-babel + :package-version '(Org . "9.5") + :type 'string) + +(defcustom org-babel-java-hline-to "null" + "Replace hlines in incoming tables with this when translating to java." :group 'org-babel - :version "24.3" + :package-version '(Org . "9.5") :type 'string) +(defcustom org-babel-java-null-to 'hline + "Replace `null' in java tables with this before returning." + :group 'org-babel + :package-version '(Org . "9.5") + :type 'symbol) + +(defconst org-babel-java--package-re (rx line-start (0+ space) "package" + (1+ space) (group (1+ (in alnum ?_ ?.))) ; capture the package name + (0+ space) ?\; line-end) + "Regexp for the package statement.") +(defconst org-babel-java--imports-re (rx line-start (0+ space) "import" + (opt (1+ space) "static") + (1+ space) (group (1+ (in alnum ?_ ?. ?*))) ; capture the fully qualified class name + (0+ space) ?\; line-end) + "Regexp for import statements.") +(defconst org-babel-java--class-re (rx line-start (0+ space) (opt (seq "public" (1+ space))) + "class" (1+ space) + (group (1+ (in alnum ?_))) ; capture the class name + (0+ space) ?{) + "Regexp for the class declaration.") +(defconst org-babel-java--main-re (rx line-start (0+ space) "public" + (1+ space) "static" + (1+ space) "void" + (1+ space) "main" + (0+ space) ?\( + (0+ space) "String" + (0+ space) (1+ (in alnum ?_ ?\[ ?\] space)) ; "[] args" or "args[]" + (0+ space) ?\) + (0+ space) (opt "throws" (1+ (in alnum ?_ ?, ?. space))) + ?{) + "Regexp for the main method declaration.") +(defconst org-babel-java--any-method-re (rx line-start + (0+ space) (opt (seq (1+ alnum) (1+ space))) ; visibility + (opt (seq "static" (1+ space))) ; binding + (1+ (in alnum ?_ ?\[ ?\])) ; return type + (1+ space) (1+ (in alnum ?_)) ; method name + (0+ space) ?\( + (0+ space) (0+ (in alnum ?_ ?\[ ?\] ?, space)) ; params + (0+ space) ?\) + (0+ space) (opt "throws" (1+ (in alnum ?_ ?, ?. space))) + ?{) + "Regexp for any method.") +(defconst org-babel-java--result-wrapper "\n public static String __toString(Object val) { + if (val instanceof String) { + return \"\\\"\" + val + \"\\\"\"; + } else if (val == null) { + return \"null\"; + } else if (val.getClass().isArray()) { + StringBuffer sb = new StringBuffer(); + Object[] vals = (Object[])val; + sb.append(\"[\"); + for (int ii=0; ii