mbien commented on code in PR #6213:
URL: https://github.com/apache/netbeans/pull/6213#discussion_r1359308004
##########
java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/J2SEPlatformDefaultJavadocImpl.java:
##########
@@ -116,6 +77,43 @@ public Collection<URI> getDefaultJavadoc(@NonNull final
JavaPlatform platform) {
return Collections.emptyList();
}
+ private static String computeJavaDocURL(String version) {
+ switch (version) {
+ case "1.0": // NOI18N
+ case "1.1": // NOI18N
+ case "1.2": // NOI18N
+ case "1.3": // NOI18N
+ case "1.4": return null; // NOI18N
+ case "1.5": return
"https://docs.oracle.com/javase/1.5.0/docs/api/"; // NOI18N
+ case "1.6": return "https://docs.oracle.com/javase/6/docs/api/";
// NOI18N
+ case "1.7": return "https://docs.oracle.com/javase/7/docs/api/";
// NOI18N
+ case "1.8": return "https://docs.oracle.com/javase/8/docs/api/";
// NOI18N
+ }
+ try {
+ int feature = Integer.parseInt(version);
+ if (feature >= 9) {
+ int latestGA = computeLatestGAVersion();
+ if (feature <= latestGA) {
+ return "https://docs.oracle.com/en/java/javase/" + feature
+ "/docs/api/"; // NOI18N
+ } else if (feature <= latestGA + 3) {
+ return "https://download.java.net/java/early_access/jdk" +
feature + "/docs/api/"; // NOI18N
+ }
+ }
+ } catch (IllegalArgumentException ignore) {}
+ LOG.log(Level.WARNING, "unrecognized Java spec version: {0}",
version); // NOI18N
+ return null;
+ }
+
+ /**
+ * Computes the feature version of the latest generally available JDK
release.
+ */
+ private static int computeLatestGAVersion() {
+ // timezone shouldn't matter since the accuracy is worse than a day
+ LocalDate jdk9 = LocalDate.of(2017, Month.SEPTEMBER, 21); // start of
6 month schedule
+ int latest = 9 + (int) (ChronoUnit.MONTHS.between(jdk9,
LocalDate.now()) / 6);
+ return Math.max(latest, SourceVersion.latest().ordinal()); // in case
system time is wrong, use nb-javac version as lower bound
+ }
Review Comment:
the proper way of doing this IMO would be to simply ask the JDK:
```
bin/java -version
openjdk version "22-ea" 2024-03-19
```
or:
`System.out.println(Runtime.version().pre());`
```
--- exec:3.1.0:exec (default-cli) @ lambda_expressions ---
Optional[ea]
```
but until then we can stick to the calendar version since I believe it is
working pretty well as workaround
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists