From faae500768fcb52231d498882a36ad594d3e7b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Wed, 26 Jun 2024 12:56:49 +0200 Subject: [PATCH 1/3] print caught exception when failed to extract javadoc --- native/java/org/jpype/javadoc/JavadocExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/java/org/jpype/javadoc/JavadocExtractor.java b/native/java/org/jpype/javadoc/JavadocExtractor.java index dca342c45..fe98ae7e4 100644 --- a/native/java/org/jpype/javadoc/JavadocExtractor.java +++ b/native/java/org/jpype/javadoc/JavadocExtractor.java @@ -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); } From a4bb61d44a621fedf1dded6a4a0ba7c547898346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Fri, 28 Jun 2024 15:23:28 +0200 Subject: [PATCH 2/3] JavadocTransformer: add support for javadoc 17 --- native/java/org/jpype/javadoc/JavadocTransformer.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/native/java/org/jpype/javadoc/JavadocTransformer.java b/native/java/org/jpype/javadoc/JavadocTransformer.java index 83cc1d454..249b8c03c 100644 --- a/native/java/org/jpype/javadoc/JavadocTransformer.java +++ b/native/java/org/jpype/javadoc/JavadocTransformer.java @@ -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"); @@ -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); From 5bce891e65125ef8366ac7e8226b6c839592ffd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Fri, 28 Jun 2024 14:58:49 +0200 Subject: [PATCH 3/3] JavadocExtractor: add support for javadoc 17 --- .../org/jpype/javadoc/JavadocExtractor.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/native/java/org/jpype/javadoc/JavadocExtractor.java b/native/java/org/jpype/javadoc/JavadocExtractor.java index fe98ae7e4..7e00b2e45 100644 --- a/native/java/org/jpype/javadoc/JavadocExtractor.java +++ b/native/java/org/jpype/javadoc/JavadocExtractor.java @@ -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) { @@ -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 set = convertNodes((NodeList) xPath.compile("./ul/li") + List 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) @@ -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 set = convertNodes((NodeList) xPath.compile("./ul/li") - .evaluate(methodRoot.getParentNode(), XPathConstants.NODESET)); + List 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) { @@ -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 set = convertNodes((NodeList) xPath.compile("./ul/li") - .evaluate(fieldRoot.getParentNode(), XPathConstants.NODESET)); + List 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) {