Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350781

Compiler Implementation of Module Import Declarations

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • tools
    • None
    • source
    • minimal
    • Java API, Language construct
    • SE

      Summary

      We propose to finalize the module imports Java feature. Currently, there are no non-editorial change to the specification under consideration.

      Problem

      The module imports Java feature have been through two rounds of preview. The experience suggests we can make the feature final and permanent.

      Solution

      The following will happen for finalization of this feature:

      • the preview addendums for the JLS and JVMS will be folded into the corresponding main, non-preview specifications, mostly as is. Specifications will undergo editorial changes.
      • javac will no longer require --enable-preview command line option for the use of import module <module-name>; and requires transitive java.base;.
      • both javac and the JDK runtime will accept module-info classfiles with requires transitive java.base;.
      • relevant API methods currently marked with @PreviewFeature will be made final and permanent by removing this annotation
      • the default startup script for JShell will be adjusted based on the current JShell's behavior when --enable-preview is specified

      Specification

      The use of import module ... and requires transitive java.base; in source code will no longer requires --enable-preview from Java compilers. The use of the requires transitive java.base; directive in module-info.class will no longer require --enable-preview, at compile time and at runtime.

      The updated specifications will be uploaded before Finalization of this request.

      For convenience, the specifications for the previous round are:

      The copies of the specifications are attached.

      The removal of the @PreviewFeature annotations:

      diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/ImportTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/ImportTree.java
      index 83a6c3eb87b..ac4dc6258ac 100644
      --- a/src/jdk.compiler/share/classes/com/sun/source/tree/ImportTree.java
      +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ImportTree.java
      @@ -25,8 +25,6 @@
      
       package com.sun.source.tree;
      
      -import jdk.internal.javac.PreviewFeature;
      -
       /**
        * A tree node for an import declaration.
        *
      @@ -49,11 +47,11 @@ public interface ImportTree extends Tree {
            * @return true if this is a static import
            */
           boolean isStatic();
      +
           /**
            * {@return true if this is an module import declaration.}
      -     * @since 23
      +     * @since 25
            */
      -    @PreviewFeature(feature=PreviewFeature.Feature.MODULE_IMPORTS, reflective=true)
           boolean isModule();
      
           /**
      diff --git a/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java b/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
      index 4e72fed10fc..8e5971bedf8 100644
      --- a/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
      +++ b/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
      @@ -28,7 +28,6 @@
       import java.util.Collection;
       import java.util.Collections;
       import java.util.List;
      -import jdk.internal.javac.PreviewFeature;
      
       /**
        * A Snippet represents a snippet of Java source code as passed to
      @@ -219,9 +218,8 @@ public enum SubKind {
                * Import Module Declaration.
                * An import declaration of a module.
                * @jls 7.5.5 Import Module Declarations
      -         * @since 23
      +         * @since 25
                */
      -        @PreviewFeature(feature=PreviewFeature.Feature.MODULE_IMPORTS, reflective=true)
               MODULE_IMPORT_SUBKIND(Kind.IMPORT),
      
               /**

      JShell

      The default startup script for JShell currently differs depending on whether the --enable-preview command line option is used.

      If the --enable-preview command line option is not used, the default script lists a hard-coded list of packages. If the --enable-preview command line option is used, the JShell's default startup script is:

      import module java.base;
      import static java.io.IO.*;

      This will be changed as follows:

      When there's no --enable-preview command line option and source level is greater of equal to 25:

      The default startup script will be:

      import module java.base;

      When there's the --enable-preview command line option:

      Until https://openjdk.org/jeps/8344699 is integrated, the default startup script will be:

      import module java.base;
      import static java.io.IO.*;

      When https://openjdk.org/jeps/8344699 is integrated, the default startup script will be:

      import module java.base;

      When source level is lower than 25:

      The default startup script will be:

      import java.io.*;
      import java.math.*;
      import java.net.*;
      import java.nio.file.*;
      import java.util.*;
      import java.util.concurrent.*;
      import java.util.function.*;
      import java.util.prefs.*;
      import java.util.regex.*;
      import java.util.stream.*;

      Which is the current default without the --enable-preview command line option.

            jlahoda Jan Lahoda
            gbierman Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: