< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -168,10 +168,22 @@
                 }
             }
             e.accept(this, annotation);
             return annotatedElements;
         }
+
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
+        public Set<Element> visitModule(ModuleElement e, TypeElement annotation) {
+            // Do not scan a module
+            return annotatedElements;
+        }
+
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
+        public Set<Element> visitPackage(PackageElement e, TypeElement annotation) {
+            // Do not scan a package
+            return annotatedElements;
+        }
     }
 
     // Could be written as a local class inside getElementsAnnotatedWithAny
     private class AnnotationSetMultiScanner extends
         ElementScanningIncludingTypeParameters<Set<Element>, Set<TypeElement>> {

@@ -191,10 +203,22 @@
                 }
             }
             e.accept(this, annotations);
             return annotatedElements;
         }
+
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
+        public Set<Element> visitModule(ModuleElement e, Set<TypeElement> annotations) {
+            // Do not scan a module
+            return annotatedElements;
+        }
+
+        @Override @DefinedBy(Api.LANGUAGE_MODEL)
+        public Set<Element> visitPackage(PackageElement e, Set<TypeElement> annotations) {
+            // Do not scan a package
+            return annotatedElements;
+        }
     }
 
     private static abstract class ElementScanningIncludingTypeParameters<R, P>
         extends ElementScanner9<R, P> {
 

@@ -222,14 +246,26 @@
      */
     @DefinedBy(Api.ANNOTATION_PROCESSING)
     public Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a) {
         throwIfNotAnnotation(a);
         String name = a.getCanonicalName();
+        String moduleName = a.getModule().getName();
+
         if (name == null)
             return Collections.emptySet();
         else {
-            TypeElement annotationType = eltUtils.getTypeElement(name);
+            ModuleElement annotationModule = null;
+            if (moduleName != null) {
+                annotationModule = eltUtils.getModuleElement(moduleName);
+            } else {
+                // System.out.println("Trying to get the module of an unnamed module");
+                annotationModule = eltUtils.getModuleElement("");
+                // System.out.println("Is the unnamed module null? " + (annotationModule == null));
+            }
+
+            TypeElement annotationType = eltUtils.getTypeElement(annotationModule, name);
+
             if (annotationType == null)
                 return Collections.emptySet();
             else
                 return getElementsAnnotatedWith(annotationType);
         }

@@ -240,13 +276,16 @@
         List<TypeElement> annotationsAsElements = new ArrayList<>(annotations.size());
 
         for (Class<? extends Annotation> annotation : annotations) {
             throwIfNotAnnotation(annotation);
             String name = annotation.getCanonicalName();
+            String moduleName = annotation.getModule().getName();
             if (name == null)
                 continue;
-            annotationsAsElements.add(eltUtils.getTypeElement(name));
+            annotationsAsElements.add(eltUtils.getTypeElement(eltUtils.getModuleElement(moduleName == null ?
+                                                                                        "" : moduleName),
+                                                              name));
         }
 
         return getElementsAnnotatedWithAny(annotationsAsElements.toArray(new TypeElement[0]));
     }
 
< prev index next >