All Manuals > LispWorks® User Guide and Reference Manual > 39 The LW-JI Package


write-java-class-definitions-to-stream Functions


Generate and output the definitions for a specified Java class.




write-java-class-definitions-to-file java-class-name filename &key lisp-name lisp-class-p package-name prefix name-constructor export-p create-defpackage lisp-supers add-in-package print-case if-exists => java-class-name

write-java-class-definitions-to-stream java-class-name stream &key lisp-name lisp-class-p package-name name-constructor prefix export-p create-defpackage lisp-supers add-in-package print-case => java-class-name

A string.
A pathname designator.
A symbol.
A generalized boolean.
A package designator.
A string or nil.
A function designator.
A generalized boolean.
A generalized boolean.
A list of symbols.
A generalized boolean.
One of the symbols :upcase, :downcase, or :capitalize.
One of the symbols :error, :new-version, :rename, :rename-and-delete, :overwrite, :append, :supersede, or nil.
An output stream.
A string.

The functions write-java-class-definitions-to-file and write-java-class-definitions-to-stream generate the definitions for the Java class named by java-class-name, and then write them to the destination specified by filename or stream.

The generation of forms as the same as generate-java-class-definitions does, except that when add-in-package is non-nil write-java-class-definitions-to-stream and write-java-class-definitions-to-file insert a cl:in-package form after the package manipulation forms. The default value of add-in-package is non-nil.

The arguments java-class-name, lisp-name, lisp-class-p, package-name, name-constructor, prefix, export-p, create-defpackage and lisp-supers are processed as described in the documentation for generate-java-class-definitions.

If add-in-package is non-nil, then after writing the package manipulation forms, a cl:in-package form is written with the package in which the definition names are interned, and the current package is bound to this package, which means the definition names do not need to be qualified with the package name.

print-case controls the binding of cl:*print-case* while outputting. The default value of print-case is :downcase.

if-exists is used by write-java-class-definitions-to-file when opening the file, in the same way as open.

write-java-class-definitions-to-stream generates the definitions for the class, and then writes all the definitions to the stream stream, with all the printer control variable set to the default except cl:*print-case* which takes its value from print-case, It adds some comments, as lines starting with ";;;".

write-java-class-definitions-to-file first open the file for output using filename and if-exists, and then calls write-java-class-definitions-to-stream with all the arguments except filename and if-exists.

write-java-class-definitions-to-stream and write-java-class-definitions-to-file return java-class-name.

  1. write-java-class-definitions-to-stream and write-java-class-definitions-to-file require Java running, that is a working Java Virtual Machine and access to the definition of the class.

    The generated code, however, is plain lisp, and can be compiled and loaded without Java. They allow you to use either of these functions once to generate the definitions, and add the output or file to your sources, and hence be able to compile and sources without running Java. Note that the output has no machine dependency at all. so as long as you can assume that the definition of the class does not change, you can output the definitions anywhere. For "globally public" classes (in the Java or Android packages), you can probably ask Lisp Support to generate the classes you need, and never bother with running Java on your development machine.

  2. The output of these functions is all "user code", that is it uses only exported functions and macros that are available to user. It can be edited as desired, and definitions from it can be copied and used elsewhere.
  3. write-java-class-definitions-to-stream is intended to allow writing the definitions of several classes to the same file. This especially useful when you write the definitions of several Java classes with the same package.
See also

15.2.1 Importing classes

LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:46