Summary
-------
Add explicit constructors to API classes of `jdk.compiler` that have default constructors.
Problem
-------
Default constructors are not recommended for classes that are parts of a formal API.
Solution
--------
Add explicit no-arg constructors. For the `com.sun.source` classes, as those classes intend to allow instantiation of themselves or subclasses, equivalent public no-arg constructors are added. In contrast, for `com.sun.tools.javac.Main` the constructor seems unintended as all the members of the class are static. Therefore, the no-arg constructor is added and terminally deprecated.
Specification
-------------
--- old/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePathScanner.java 2020-07-27 09:20:26.556000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePathScanner.java 2020-07-27 09:20:25.476000000 -0700
@@ -39,6 +39,11 @@
*/
public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
/**
+ * Constructs a {@code DocTreePathScanner}.
+ */
+ public DocTreePathScanner() {}
+
+ /**
* Scans a tree from a position identified by a tree path.
* @param path the path
* @param p a value to be passed to visitor methods
--- old/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java 2020-07-27 09:20:28.600000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java 2020-07-27 09:20:27.504000000 -0700
@@ -68,6 +68,10 @@
* @since 1.8
*/
public class DocTreeScanner<R,P> implements DocTreeVisitor<R,P> {
+ /**
+ * Constructs a {@code DocTreeScanner}.
+ */
+ public DocTreeScanner() {}
/**
* Scans a single node.
--- old/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java 2020-07-27 09:20:30.312000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java 2020-07-27 09:20:29.492000000 -0700
@@ -47,6 +47,11 @@
*/
public abstract class DocTrees extends Trees {
/**
+ * Constructor for subclasses to call.
+ */
+ public DocTrees() {}
+
+ /**
* Returns a DocTrees object for a given CompilationTask.
* @param task the compilation task for which to get the Trees object
* @return the DocTrees object
--- old/src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java 2020-07-27 09:20:32.088000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java 2020-07-27 09:20:31.224000000 -0700
@@ -50,6 +50,10 @@
* @since 1.6
*/
public abstract class JavacTask implements CompilationTask {
+ /**
+ * Constructor for subclasses to call.
+ */
+ public JavacTask() {}
/**
* Returns the {@code JavacTask} for a {@code ProcessingEnvironment}.
--- old/src/jdk.compiler/share/classes/com/sun/source/util/TreePathScanner.java 2020-07-27 09:20:33.688000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/TreePathScanner.java 2020-07-27 09:20:32.804000000 -0700
@@ -43,6 +43,10 @@
* @since 1.6
*/
public class TreePathScanner<R, P> extends TreeScanner<R, P> {
+ /**
+ * Constructs a {@code TreePathScanner}.
+ */
+ public TreePathScanner() {}
/**
* Scans a tree from a position identified by a TreePath.
--- old/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java 2020-07-27 09:20:35.172000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java 2020-07-27 09:20:34.448000000 -0700
@@ -75,6 +75,10 @@
* @since 1.6
*/
public class TreeScanner<R,P> implements TreeVisitor<R,P> {
+ /**
+ * Constructs a {@code TreeScanner}.
+ */
+ public TreeScanner() {}
/**
* Scans a single node.
--- old/src/jdk.compiler/share/classes/com/sun/source/util/Trees.java 2020-07-27 09:20:36.912000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/source/util/Trees.java 2020-07-27 09:20:36.004000000 -0700
@@ -53,6 +53,11 @@
*/
public abstract class Trees {
/**
+ * Constructor for subclasses to call.
+ */
+ public Trees() {}
+
+ /**
* Returns a Trees object for a given CompilationTask.
* @param task the compilation task for which to get the Trees object
* @throws IllegalArgumentException if the task does not support the Trees API.
--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java 2020-07-27 09:20:38.680000000 -0700
+++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java 2020-07-27 09:20:37.764000000 -0700
@@ -34,6 +34,11 @@
* module for details on replacement APIs.
*/
public class Main {
+ /**
+ * Do not call.
+ */
+ @Deprecated(since="16", forRemoval=true)
+ public Main(){}
/** Main entry point for the launcher.
* Note: This method calls System.exit.