From bc854a5af50bcd056c714fab11a2223d1150ce1a Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Wed, 21 Dec 2022 09:17:49 +0000 Subject: [PATCH 1/3] Fix parsing of JDK 17 Javadoc HTML. --- .../api/java/source/ui/HTMLJavadocParser.java | 39 ++- .../java/source/ui/HTMLJavadocParserTest.java | 60 +++- .../api/java/source/ui/Javadoc17Class.html | 226 +++++++++++++++ .../api/java/source/ui/Javadoc17Enum.html | 260 ++++++++++++++++++ .../api/java/source/ui/JavadocClass.txt | 59 ++++ .../api/java/source/ui/JavadocEnum.txt | 44 +++ 6 files changed, 681 insertions(+), 7 deletions(-) create mode 100644 java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Class.html create mode 100644 java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Enum.html create mode 100644 java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocClass.txt create mode 100644 java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocEnum.txt diff --git a/java/java.sourceui/src/org/netbeans/api/java/source/ui/HTMLJavadocParser.java b/java/java.sourceui/src/org/netbeans/api/java/source/ui/HTMLJavadocParser.java index 410da0a823fb..dd408f335dc3 100644 --- a/java/java.sourceui/src/org/netbeans/api/java/source/ui/HTMLJavadocParser.java +++ b/java/java.sourceui/src/org/netbeans/api/java/source/ui/HTMLJavadocParser.java @@ -247,16 +247,28 @@ private static int[] parseClass(Reader reader, final HTMLEditorKit.Parser parser int div_counter = 0; int li_counter = 0; + int section_counter = 0; int nextHRPos = -1; int lastHRPos = -1; @Override public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) { - if (t == HTML.Tag.HR){ - if (state[0] == TEXT_START){ + if (t == HTML.Tag.HR) { + if (state[0] == TEXT_START) { nextHRPos = pos; } lastHRPos = pos; + } else if (state[0] == AFTER_DIV + && t instanceof HTML.UnknownTag + && "section".equalsIgnoreCase(t.toString())) { + if (a.containsAttribute(HTML.Attribute.ENDTAG, "true")) { + if (--section_counter < 0) { + offset[3] = pos; + state[0] = INIT; + } + } else { + section_counter++; + } } } @@ -367,13 +379,34 @@ private static int[] parseMember(Reader reader, final Collection")); + + URL url = appendFragment(root, "(java.lang.String)"); + result = HTMLJavadocParser.getJavadocText(url, false); + assertTrue(result.contains("This is a constructor taking a single String parameter.")); + assertFalse(result.contains("")); + + url = appendFragment(root, "(java.lang.String,java.lang.String)"); + result = HTMLJavadocParser.getJavadocText(url, false); + assertTrue(result.contains("This is a constructor taking two String parameters.")); + assertFalse(result.contains("")); + + url = appendFragment(root, "hi()"); + result = HTMLJavadocParser.getJavadocText(url, false); + assertTrue(result.contains("A method.")); + assertFalse(result.contains("")); + } + + /** + * Test of getJavadocText method used with enum output from javadoc 17. + */ + public void testJavadoc17Enum() throws Exception { + URL root = HTMLJavadocParserTest.class.getResource("Javadoc17Enum.html"); + String result = HTMLJavadocParser.getJavadocText(root, false); + assertNotNull(result); + assertTrue(result.contains("This is an example enum.")); + assertFalse(result.contains("")); + + URL url = appendFragment(root, "FIRST"); + result = HTMLJavadocParser.getJavadocText(url, false); + assertTrue(result.contains("The first value.")); + assertFalse(result.contains("")); + + url = appendFragment(root, "hi()"); + result = HTMLJavadocParser.getJavadocText(url, false); + assertTrue(result.contains("A method.")); + assertFalse(result.contains("")); + + } + /** * Test of getJavadocText method used with class output from javadoc 11. */ @@ -151,6 +201,7 @@ public void testJavadoc8Enum() throws Exception { assertTrue(result.contains("A method.")); } +/* public void test199194() throws MalformedURLException { URL url = HTMLJavadocParserTest.class.getResource("JavaApplication1.html"); String result = HTMLJavadocParser.getJavadocText(url, false); @@ -173,6 +224,7 @@ public void test209707() throws MalformedURLException { assertNotNull(result); assertTrue(result.contains("the selected file or")); } +*/ private static URL appendFragment(URL root, String unencodedFragment) throws Exception { StringBuilder uri = new StringBuilder(root.toExternalForm()); diff --git a/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Class.html b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Class.html new file mode 100644 index 000000000000..4e26718de30e --- /dev/null +++ b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Class.html @@ -0,0 +1,226 @@ + + + + + +JavadocClass (TestJavadoc 1.0.0-SNAPSHOT API) + + + + + + + + + + + + + + + +
+ +
+
+ +
+

Class JavadocClass

+
+
java.lang.Object +
JavadocClass
+
+
+
+
public class JavadocClass +extends Object
+
This is an example class.
+
+
Since:
+
now
+
+
+
+ +
+
+
    + +
  • +
    +

    Constructor Details

    +
      +
    • +
      +

      JavadocClass

      +
      public JavadocClass()
      +
      This is the default constructor.
      +
      +
    • +
    • +
      +

      JavadocClass

      +
      public JavadocClass(String param)
      +
      This is a constructor taking a single String parameter.
      +
      +
      Parameters:
      +
      param - A parameter
      +
      +
      +
    • +
    • +
      +

      JavadocClass

      +
      public JavadocClass(String param1, + String param2)
      +
      This is a constructor taking two String parameters.
      +
      +
      Parameters:
      +
      param1 - Parameter one.
      +
      param2 - Parameter two.
      +
      +
      +
    • +
    +
    +
  • + +
  • +
    +

    Method Details

    +
      +
    • +
      +

      hi

      +
      public String hi()
      +
      A method.
      +
      +
      Returns:
      +
      "hi"
      +
      +
      +
    • +
    +
    +
  • +
+
+ +
+
+
+ +
+
+
+ + diff --git a/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Enum.html b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Enum.html new file mode 100644 index 000000000000..02d1794f4f8b --- /dev/null +++ b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/Javadoc17Enum.html @@ -0,0 +1,260 @@ + + + + + +JavadocEnum (TestJavadoc 1.0.0-SNAPSHOT API) + + + + + + + + + + + + + + + +
+ +
+
+ +
+

Enum Class JavadocEnum

+
+ +
+
+
All Implemented Interfaces:
+
Serializable, Comparable<JavadocEnum>, Constable
+
+
+
public enum JavadocEnum +extends Enum<JavadocEnum>
+
This is an example enum.
+
+
+ +
+
+
    + +
  • +
    +

    Enum Constant Details

    +
      +
    • +
      +

      FIRST

      +
      public static final JavadocEnum FIRST
      +
      The first value.
      +
      +
    • +
    • +
      +

      SECOND

      +
      public static final JavadocEnum SECOND
      +
      The second value.
      +
      +
    • +
    +
    +
  • + +
  • +
    +

    Method Details

    +
      +
    • +
      +

      values

      +
      public static JavadocEnum[] values()
      +
      Returns an array containing the constants of this enum class, in +the order they are declared.
      +
      +
      Returns:
      +
      an array containing the constants of this enum class, in the order they are declared
      +
      +
      +
    • +
    • +
      +

      valueOf

      +
      public static JavadocEnum valueOf(String name)
      +
      Returns the enum constant of this class with the specified name. +The string must match exactly an identifier used to declare an +enum constant in this class. (Extraneous whitespace characters are +not permitted.)
      +
      +
      Parameters:
      +
      name - the name of the enum constant to be returned.
      +
      Returns:
      +
      the enum constant with the specified name
      +
      Throws:
      +
      IllegalArgumentException - if this enum class has no constant with the specified name
      +
      NullPointerException - if the argument is null
      +
      +
      +
    • +
    • +
      +

      hi

      +
      public String hi()
      +
      A method.
      +
      +
      Returns:
      +
      "hi"
      +
      +
      +
    • +
    +
    +
  • +
+
+ +
+
+
+ +
+
+
+ + diff --git a/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocClass.txt b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocClass.txt new file mode 100644 index 000000000000..8f002743c76a --- /dev/null +++ b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocClass.txt @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * This is an example class. + * + * @since now + */ +public class JavadocClass { + + /** + * This is the default constructor. + */ + public JavadocClass() { + } + + /** + * This is a constructor taking a single String parameter. + * + * @param param A parameter + */ + public JavadocClass(String param) { + } + + /** + * This is a constructor taking two String parameters. + * + * @param param1 Parameter one. + * @param param2 Parameter two. + */ + public JavadocClass(String param1, String param2) { + } + + /** + * A method. + * + * @return "hi" + */ + public String hi() { + return "hi"; + } +} + diff --git a/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocEnum.txt b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocEnum.txt new file mode 100644 index 000000000000..012fb4b9fb85 --- /dev/null +++ b/java/java.sourceui/test/unit/src/org/netbeans/api/java/source/ui/JavadocEnum.txt @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * This is an example enum. + */ +public enum JavadocEnum { + + /** + * The first value. + */ + FIRST, + /** + * The second value. + */ + SECOND; + + /** + * A method. + * + * @return "hi" + */ + public String hi() { + return "hi"; + } + +} + From c03c84abfd80e58074c1636f76a8ebf4e10d482c Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Wed, 21 Dec 2022 09:20:14 +0000 Subject: [PATCH 2/3] Update JavadocHelper to provide correct external links for HTML5 format Javadoc. --- .../modules/java/source/JavadocHelper.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java index 070d925dafba..287a55eb5bcc 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java @@ -20,13 +20,13 @@ import com.sun.tools.javac.code.Symbol.ClassSymbol; import java.awt.EventQueue; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.InterruptedIOException; -import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URI; @@ -261,10 +261,21 @@ public URL getLocation(@NonNull final RemoteJavadocPolicy rjp) throws RemoteJava try { String charset = null; for (;;) { - try (Reader reader = charset == null? + try (BufferedReader reader = new BufferedReader(charset == null ? new InputStreamReader(this.openStream()) : - new InputStreamReader(this.openStream(), charset)){ + new InputStreamReader(this.openStream(), charset))) { if (urls.size() > 1) { + reader.mark(256); + String line = reader.readLine(); + if (line.contains("")) { + index = 2; + if (jdocRoot != null) { + jdocCache.put(jdocRoot,index); + } + break; + } else { + reader.reset(); + } final HTMLEditorKit.Parser parser = new ParserDelegator(); final int[] state = {-1}; try { @@ -936,10 +947,6 @@ private static final class FragmentBuilder { FragmentBuilder(@NonNull ElementKind kind) { int size = FILTERS.size(); - // JDK-8046068 changed the constructor format from "Name" to "" - if (kind == ElementKind.CONSTRUCTOR) { - size *= 2; - } this.sbs = new StringBuilder[size]; for (int i = 0; i < sbs.length; i++) { sbs[i] = new StringBuilder(); @@ -948,24 +955,18 @@ private static final class FragmentBuilder { @NonNull FragmentBuilder constructor(@NonNull final CharSequence text) { - CharSequence constructor = text; - for (int i = 0; i < sbs.length;) { - for (int j = 0; j < FILTERS.size(); j++) { - sbs[i].append(FILTERS.get(j).convert(constructor)); - i++; - } - constructor = ""; + for (int i = 0; i < sbs.length; i++) { + // JDK-8046068 changed the constructor format from "Name" to "" + CharSequence constructor = i >= 2 ? "" : text; + sbs[i].append(FILTERS.get(i).convert(constructor)); } return this; } @NonNull FragmentBuilder append(@NonNull final CharSequence text) { - for (int i = 0; i < sbs.length;) { - for (int j = 0; j < FILTERS.size(); j++) { - sbs[i].append(FILTERS.get(j).convert(text)); - i++; - } + for (int i = 0; i < sbs.length; i++) { + sbs[i].append(FILTERS.get(i).convert(text)); } return this; } From 6b70931d6f37d37782b24f7917a5f93a1d568c01 Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Wed, 21 Dec 2022 09:34:17 +0000 Subject: [PATCH 3/3] Enable (working) tests on java.sourceui module. --- .github/workflows/main.yml | 5 +++-- java/java.sourceui/nbproject/project.properties | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3e227c170583..fdce8c50e850 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1335,8 +1335,9 @@ jobs: - name: java.source.queriesimpl run: ant $OPTS -f java/java.source.queriesimpl test -# - name: java.sourceui -# run: ant $OPTS -f java/java.sourceui test + - name: java.sourceui + if: env.test_java == 'true' && success() + run: ant $OPTS -f java/java.sourceui test - name: java.testrunner run: ant $OPTS -f java/java.testrunner test diff --git a/java/java.sourceui/nbproject/project.properties b/java/java.sourceui/nbproject/project.properties index 86ba376d3384..b3bc847967ec 100644 --- a/java/java.sourceui/nbproject/project.properties +++ b/java/java.sourceui/nbproject/project.properties @@ -20,6 +20,11 @@ javac.source=1.8 javadoc.arch=${basedir}/arch.xml spec.version.base=1.67.0 +# failing or missing test files +test.config.default.excludes=\ + **/FastIndexTest.class,\ + **/MarkupTagProcessorTest.class + test.config.stableBTD.includes=**/*Test.class test.config.stableBTD.excludes=\ **/ElementHeadersTest.class