Function: org-babel-java--expand-for-evaluation
org-babel-java--expand-for-evaluation is a byte-compiled function
defined in ob-java.el.gz.
Signature
(org-babel-java--expand-for-evaluation BODY SUPPRESS-PACKAGE-P RESULT-TYPE RESULT-FILE)
Documentation
Expand source block for evaluation.
In order to return a value we have to add a __toString method.
In order to prevent classes without main methods from erroring we
add a dummy main method if one is not provided. These
manipulations are done outside of org-babel--expand-body so
that they are hidden from tangles.
BODY is the file content before instrumentation.
SUPPRESS-PACKAGE-P if true, suppress the package statement.
RESULT-TYPE is taken from params.
RESULT-FILE is the temp file to write the result.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-java.el.gz
(defun org-babel-java--expand-for-evaluation (body suppress-package-p result-type result-file)
"Expand source block for evaluation.
In order to return a value we have to add a __toString method.
In order to prevent classes without main methods from erroring we
add a dummy main method if one is not provided. These
manipulations are done outside of `org-babel--expand-body' so
that they are hidden from tangles.
BODY is the file content before instrumentation.
SUPPRESS-PACKAGE-P if true, suppress the package statement.
RESULT-TYPE is taken from params.
RESULT-FILE is the temp file to write the result."
(with-temp-buffer
(insert body)
;; suppress package statement
(goto-char (point-min))
(when (and suppress-package-p
(re-search-forward org-babel-java--package-re nil t))
(replace-match ""))
;; add a dummy main method if needed
(goto-char (point-min))
(when (not (re-search-forward org-babel-java--main-re nil t))
(org-babel-java--move-past org-babel-java--class-re)
(insert "\n public static void main(String[] args) {
System.out.print(\"success\");
}\n\n"))
;; special handling to return value
(when (eq result-type 'value)
(goto-char (point-min))
(org-babel-java--move-past org-babel-java--class-re)
(insert (format org-babel-java--result-wrapper
(org-babel-process-file-name result-file 'noquote)))
(search-forward "public static void main(") ; rename existing main
(replace-match "public static Object _main("))
;; add imports
(org-babel-java--import-maybe "java.util" "List")
(org-babel-java--import-maybe "java.util" "Arrays")
(org-babel-java--import-maybe "java.io" "BufferedWriter")
(org-babel-java--import-maybe "java.io" "FileWriter")
(org-babel-java--import-maybe "java.io" "IOException")
(buffer-string)))