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

TypeKindVisitor needs to handle modules

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 10
    • core-libs
    • None
    • behavioral
    • minimal
    • Adding new methods to a class hierarchy, removing the potential for assertion errors when running the TypeKind visitors.
    • Java API
    • SE

      Summary

      Methods to handle module pseudo-types are added to the TypeKind family of concrete visitors in javax.lang.model.util.

      Problem

      The TypeKind visitors as of JDK 9 omitted support for the module pseudo-type. This support should have been added in the same release as modules.

      Solution

      Add the methods in question, TypeKindVisitor6.visitNoTypeAsModule which calls visitUnknown and TypeKindVisitor9.visitNoTypeAsModule which calls defaultAction.

      Specification

      diff -r 5cc5b8270cad src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor6.java
      --- a/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor6.java   Mon Nov 20 20:33:51 2017 -0800
      +++ b/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor6.java   Mon Nov 20 22:06:30 2017 -0800
      @@ -257,7 +257,7 @@
            *
            * @implSpec This implementation dispatches to the visit method for
            * the specific {@linkplain TypeKind kind} of pseudo-type:
      -     * {@code VOID}, {@code PACKAGE}, or {@code NONE}.
      +     * {@code VOID}, {@code PACKAGE}, {@code MODULE}, or {@code NONE}.
            *
            * @param t {@inheritDoc}
            * @param p {@inheritDoc}
      @@ -273,6 +273,9 @@
               case PACKAGE:
                   return visitNoTypeAsPackage(t, p);
      
      +        case MODULE:
      +            return visitNoTypeAsModule(t, p);
      +
               case NONE:
                   return visitNoTypeAsNone(t, p);
      
      @@ -308,6 +311,21 @@
           }
      
           /**
      +     * Visits a {@link TypeKind#MODULE MODULE} pseudo-type.
      +     *
      +     * @implSpec This implementation calls {@code visitUnknown}.
      +     *
      +     * @param t the type to visit
      +     * @param p a visitor-specified parameter
      +     * @return  the result of {@code visitUnknown}
      +     *
      +     * @since 10
      +     */
      +    public R visitNoTypeAsModule(NoType t, P p) {
      +        return visitUnknown(t, p);
      +    }
      +
      +    /**
            * Visits a {@link TypeKind#NONE NONE} pseudo-type.
            *
            * @implSpec This implementation calls {@code defaultAction}.
      
      diff -r 5cc5b8270cad src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor9.java
      --- a/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor9.java   Mon Nov 20 20:33:51 2017 -0800
      +++ b/src/java.compiler/share/classes/javax/lang/model/util/TypeKindVisitor9.java   Mon Nov 20 22:06:30 2017 -0800
      @@ -93,4 +93,20 @@
           protected TypeKindVisitor9(R defaultValue) {
               super(defaultValue);
           }
      +
      +    /**
      +     * {@inheritDoc}
      +     *
      +     * @implSpec This implementation calls {@code defaultAction}.
      +     *
      +     * @param t {@inheritDoc}
      +     * @param p {@inheritDoc}
      +     * @return  the result of {@code defaultAction}
      +     *
      +     * @since 10
      +     */
      +    @Override
      +    public R visitNoTypeAsModule(NoType t, P p) {
      +        return defaultAction(t, p);
      +    }
       }

            darcy Joe Darcy
            darcy Joe Darcy
            Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: