Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extracting javadoc HTML files generated by Javadoc 17 #1200

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions native/java/org/jpype/javadoc/JavadocExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static Javadoc getDocumentation(Class cls)
}
} catch (Exception ex)
{
System.err.println("Failed to extract javadoc for " + cls);
System.err.println("Failed to extract javadoc for " + cls + ", caught " + ex);
if (failures)
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -117,8 +117,12 @@ public static Javadoc extractDocument(Class cls, Document doc)
XPath xPath = XPathFactory.newInstance().newXPath();
// Javadoc 8-13
Node n = (Node) xPath.compile("//div[@class='description']/ul/li").evaluate(doc, XPathConstants.NODE);
if (n == null) // Javadoc 14+
if (n == null) { // Javadoc 14+
n = (Node) xPath.compile("//section[@class='description']").evaluate(doc, XPathConstants.NODE);
}
if (n == null) { // Javadoc 17+
n = (Node) xPath.compile("//section[@class='class-description']").evaluate(doc, XPathConstants.NODE);
}
Node description = toFragment(n);
if (description != null)
{
Expand All @@ -129,12 +133,20 @@ public static Javadoc extractDocument(Class cls, Document doc)
documentation.description = renderer.render(description);
}

Node ctorRoot = ((Node) xPath.compile("//li/a[@name='constructor.detail' or @id='constructor.detail']")
Node ctorRoot = ((Node) xPath.compile("//li/a[@name='constructor.detail' or @id='constructor.detail']") // Javadoc before 17
.evaluate(doc, XPathConstants.NODE));
if (ctorRoot == null) { // Javadoc 17+
ctorRoot = ((Node) xPath.compile("//section[@class='constructor-details']/ul")
.evaluate(doc, XPathConstants.NODE));
}
if (ctorRoot != null)
{
List<Node> set = convertNodes((NodeList) xPath.compile("./ul/li")
List<Node> set = convertNodes((NodeList) xPath.compile("./li/section") // Javadoc 17+
.evaluate(ctorRoot, XPathConstants.NODESET));
if (set.isEmpty()) { // Javadoc before 17
set = convertNodes((NodeList) xPath.compile("./ul/li")
.evaluate(ctorRoot.getParentNode(), XPathConstants.NODESET));
}
documentation.ctorsNode = set;
StringBuilder sb = new StringBuilder();
for (Node ctor : set)
Expand All @@ -147,12 +159,20 @@ public static Javadoc extractDocument(Class cls, Document doc)
documentation.ctors = sb.toString();
}

Node methodRoot = ((Node) xPath.compile("//li/a[@name='method.detail' or @id='method.detail']")
Node methodRoot = ((Node) xPath.compile("//li/a[@name='method.detail' or @id='method.detail']") // Javadoc before 17
.evaluate(doc, XPathConstants.NODE));
if (methodRoot == null) { // Javadoc 17+
methodRoot = ((Node) xPath.compile("//section[@class='method-details']/ul")
.evaluate(doc, XPathConstants.NODE));
}
if (methodRoot != null)
{
List<Node> set = convertNodes((NodeList) xPath.compile("./ul/li")
.evaluate(methodRoot.getParentNode(), XPathConstants.NODESET));
List<Node> set = convertNodes((NodeList) xPath.compile("./li/section") // Javadoc 17+
.evaluate(methodRoot, XPathConstants.NODESET));
if (set.isEmpty()) { // Javadoc before 17
set = convertNodes((NodeList) xPath.compile("./ul/li")
.evaluate(methodRoot.getParentNode(), XPathConstants.NODESET));
}
documentation.methodNodes = set;
for (Node method : set)
{
Expand All @@ -178,12 +198,20 @@ public static Javadoc extractDocument(Class cls, Document doc)
// NodeList set = (NodeList) xPath.compile("./ul/li").evaluate(inner.getParentNode(), XPathConstants.NODESET);
// documentation.innerNode = convertNodes(set);
// }
Node fieldRoot = ((Node) xPath.compile("//li/a[@name='field.detail' or @id='field.detail']")
Node fieldRoot = ((Node) xPath.compile("//li/a[@name='field.detail' or @id='field.detail']") // Javadoc before 17
.evaluate(doc, XPathConstants.NODE));
if (fieldRoot == null) { // Javadoc 17+
fieldRoot = ((Node) xPath.compile("//section[@class='field-details']/ul")
.evaluate(doc, XPathConstants.NODE));
}
if (fieldRoot != null)
{
List<Node> set = convertNodes((NodeList) xPath.compile("./ul/li")
.evaluate(fieldRoot.getParentNode(), XPathConstants.NODESET));
List<Node> set = convertNodes((NodeList) xPath.compile("./li/section") // Javadoc 17+
.evaluate(fieldRoot, XPathConstants.NODESET));
if (set.isEmpty()) { // Javadoc before 17
set = convertNodes((NodeList) xPath.compile("./ul/li")
.evaluate(fieldRoot.getParentNode(), XPathConstants.NODESET));
}
documentation.fieldNodes = set;
for (Node field : set)
{
Expand Down
8 changes: 5 additions & 3 deletions native/java/org/jpype/javadoc/JavadocTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void handleDescription(Node node, Workspace data)
{
data.hr = true;
parent.removeChild(node);
} else if (name.equals("pre"))
} else if (name.equals("pre") || // Javadoc pre-17
(name.equals("div") && e.getAttribute("class").equals("type-signature"))) // Javadoc 17+
{
DomUtilities.removeWhitespace(node);
doc.renameNode(node, null, "signature");
Expand All @@ -124,10 +125,11 @@ void handleMembers(Node node, Workspace ws)
String name = e.getTagName();
Document doc = e.getOwnerDocument();

if (name.equals("h4"))
if (name.equals("h4") || name.equals("h3")) // h4 for Javadoc pre-17, h3 for Javadoc 17+
{
doc.renameNode(node, null, "title");
} else if (name.equals("pre"))
} else if (name.equals("pre") || // Javadoc pre-17
(name.equals("div") && (e.getAttribute("class").equals("member-signature")))) // Javadoc 17+
{
doc.renameNode(node, null, "signature");
DomUtilities.traverseDFS(node, this::pass1, Node.ELEMENT_NODE, ws);
Expand Down
Loading