changeset 57251:20dfe7974cc2

8224630: ElementScannerN, N > 9 should scan type parameters Reviewed-by: mcimadamore, erikj
author darcy
date Thu, 05 Dec 2019 14:14:06 -0800
parents fcd70fd2d3f6
children dda989866962
files make/autoconf/boot-jdk.m4 src/java.compiler/share/classes/javax/lang/model/util/ElementScanner14.java src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java
diffstat 3 files changed, 52 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/make/autoconf/boot-jdk.m4	Thu Dec 05 16:58:18 2019 -0500
+++ b/make/autoconf/boot-jdk.m4	Thu Dec 05 14:14:06 2019 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -345,7 +345,7 @@
 
   # When compiling code to be executed by the Boot JDK, force compatibility with the
   # oldest supported bootjdk.
-  BOOT_JDK_SOURCETARGET="-source 9 -target 9"
+  BOOT_JDK_SOURCETARGET="-source 13 -target 13"
   AC_SUBST(BOOT_JDK_SOURCETARGET)
 
   AC_SUBST(JAVAC_FLAGS)
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner14.java	Thu Dec 05 16:58:18 2019 -0500
+++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner14.java	Thu Dec 05 14:14:06 2019 -0800
@@ -25,6 +25,8 @@
 
 package javax.lang.model.util;
 
+import java.util.List;
+import java.util.ArrayList;
 import javax.lang.model.element.*;
 import javax.annotation.processing.SupportedSourceVersion;
 import javax.lang.model.SourceVersion;
@@ -123,6 +125,48 @@
     /**
      * {@inheritDoc}
      *
+     * @implSpec This implementation scans the type parameters, if
+     * any, and then the enclosed elements.
+     *
+     *
+     * @param e  {@inheritDoc}
+     * @param p  {@inheritDoc}
+     * @return the result of scanning
+     */
+    @Override
+    public R visitType(TypeElement e, P p) {
+        return scan(createScanningList(e, e.getEnclosedElements()), p);
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @implSpec This implementation first scans the type parameters, if any, and then
+     * the parameters.
+     *
+     * @param e  {@inheritDoc}
+     * @param p  {@inheritDoc}
+     * @return the result of scanning
+     */
+    public R visitExecutable(ExecutableElement e, P p) {
+        return scan(createScanningList(e, e.getParameters()), p);
+    }
+
+    private List<? extends Element> createScanningList(Parameterizable element,
+                                                       List<? extends Element> toBeScanned) {
+        var typeParameters = element.getTypeParameters();
+        if (typeParameters.isEmpty()) {
+            return toBeScanned;
+        } else {
+            List<Element> scanningList = new ArrayList<>(typeParameters);
+            scanningList.addAll(toBeScanned);
+            return scanningList;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
      * @implSpec This implementation scans the enclosed elements.
      *
      * @param e the element to visit
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java	Thu Dec 05 16:58:18 2019 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java	Thu Dec 05 14:14:06 2019 -0800
@@ -124,8 +124,7 @@
 
         Set<Element> result = Collections.emptySet();
         @SuppressWarnings("preview")
-        ElementScanner14<Set<Element>, TypeElement> scanner =
-            new AnnotationSetScanner(result);
+        var scanner = new AnnotationSetScanner(result);
 
         for (Element element : rootElements)
             result = scanner.scan(element, a);
@@ -146,8 +145,7 @@
 
         Set<Element> result = Collections.emptySet();
         @SuppressWarnings("preview")
-        ElementScanner14<Set<Element>, Set<TypeElement>> scanner =
-            new AnnotationSetMultiScanner(result);
+        var scanner = new AnnotationSetMultiScanner(result);
 
         for (Element element : rootElements)
             result = scanner.scan(element, annotationSet);
@@ -156,8 +154,9 @@
     }
 
     // Could be written as a local class inside getElementsAnnotatedWith
+    @SuppressWarnings("preview")
     private class AnnotationSetScanner extends
-        ElementScanningIncludingTypeParameters<Set<Element>, TypeElement> {
+        ElementScanner14<Set<Element>, TypeElement> {
         // Insertion-order preserving set
         private Set<Element> annotatedElements = new LinkedHashSet<>();
 
@@ -191,8 +190,9 @@
     }
 
     // Could be written as a local class inside getElementsAnnotatedWithAny
+    @SuppressWarnings("preview")
     private class AnnotationSetMultiScanner extends
-        ElementScanningIncludingTypeParameters<Set<Element>, Set<TypeElement>> {
+        ElementScanner14<Set<Element>, Set<TypeElement>> {
         // Insertion-order preserving set
         private Set<Element> annotatedElements = new LinkedHashSet<>();
 
@@ -225,29 +225,6 @@
         }
     }
 
-    @SuppressWarnings("preview")
-    private static abstract class ElementScanningIncludingTypeParameters<R, P>
-        extends ElementScanner14<R, P> {
-
-        protected ElementScanningIncludingTypeParameters(R defaultValue) {
-            super(defaultValue);
-        }
-
-        @Override @DefinedBy(Api.LANGUAGE_MODEL)
-        public R visitType(TypeElement e, P p) {
-            // Type parameters are not considered to be enclosed by a type
-            scan(e.getTypeParameters(), p);
-            return super.visitType(e, p);
-        }
-
-        @Override @DefinedBy(Api.LANGUAGE_MODEL)
-        public R visitExecutable(ExecutableElement e, P p) {
-            // Type parameters are not considered to be enclosed by an executable
-            scan(e.getTypeParameters(), p);
-            return super.visitExecutable(e, p);
-        }
-    }
-
     /**
      * {@inheritDoc}
      */