RingJavafor Ring

The generator

tools/javatools/GenRing.java makes the Ring classes.

tools/javatools/GenRing.java makes the Ring classes. It is a Java program that uses reflection, so the Ring classes always match the JDK that runs it.

cd tools/javatools
java GenRing.java ../../libraries/javalib/generated @javamanifest.txt
java GenRing.java ../../libraries/javalib/generated com.acme.tools --jar acme.jar          # the classes of a jar
ring checkgenerated.ring                                                                    # every generated file loads

The manifest has one package for each line, or module <name> for all the exported packages of a JDK module (java.base, java.desktop, java.sql ...). The files: <package>.ring for each package, and classindex.txt (the Java name, the Ring name, the package and the kind of every class).

What a generated class has#

Ring
Class ArrayList from AbstractList

	cJavaClass = "java.util.ArrayList"
	...
	if classname(self) = "arraylist"            # "new ArrayList" (no parentheses) or an object that came from Java
		...
	Func init P1                                # the constructor with the smallest number of values (one or more)
	Func add P1                                 # Java add(E) and add(int,E): a name with several arities has one parameter
	Func getText                                # Java getText() and getText(int,int): a name with a form without parameters is two methods:
	Func @getText P1                            #   getText() has no parameters, @getText(x) takes the others as one argument (a value, a list or a hash list)
	Func ensureCapacity P1                      # a name with one arity keeps its parameters
	Func @toString P1                           # toString() is the method of JavaObject; the forms with parameters are @toString
	Func GetSomeField / SetSomeField            # public fields (attributes)

Numbers#

The manifest of this step makes 181 packages and about 4,100 classes (233,000 lines) from 18 modules in about two seconds. More modules (jdk.*) can be added to the manifest, and the classes of Maven packages are made by jMavenClasses.

The class reference#

The generator also writes the class reference: --api names the folder for the pages, and --params the table of parameter names (bin/paramnames.txt, made by DumpParams.java from the source of the JDK), so the signatures show real names.

java GenRing.java ../../libraries/javalib/generated --api ../../docs/src --params ../../bin/paramnames.txt @javamanifest.txt

It writes api.html (the packages) and api-<package>.html (the classes of one package: constructors, fields, and each method with the way to call it from Ring and its Java overloads). The same code decides the Ring name and the form of a method for the class and for the page, so the page cannot disagree with the class. docs/tools/apidocs.ring (the :prebuild step of docproject.ring) adds the package pages to the manual as hidden pages: they are in the search, and the index links to them. Run it again when the manifest changes, then ringdoc build.

RingJava - use Java classes and methods from Ring programs.