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 loadsThe 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#
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)- the class extends the Ring class of its nearest public super class of a generated package (else
JavaObject); - a method is written in the class that first has it (the class of the super class has it already when it has the same Ring name and number of parameters); the methods of the interfaces of a class are in the class;
- a method that returns a primitive (a number, a yes/no) returns the Java answer as it is;
voidmethods return the object (so calls can be chained); - names that Ring reserves get a
_at the end; - two classes with the same name in different packages: the package that comes first in the manifest keeps the name.
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.txtIt 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.