--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java 2018-07-24 13:00:43.802000999 -0700 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java 2018-07-24 13:00:43.662000999 -0700 @@ -1,5 +1,5 @@ /* - * 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 @@ -170,6 +170,18 @@ e.accept(this, annotation); return annotatedElements; } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Set visitModule(ModuleElement e, TypeElement annotation) { + // Do not scan a module + return annotatedElements; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Set visitPackage(PackageElement e, TypeElement annotation) { + // Do not scan a package + return annotatedElements; + } } // Could be written as a local class inside getElementsAnnotatedWithAny @@ -193,6 +205,18 @@ e.accept(this, annotations); return annotatedElements; } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Set visitModule(ModuleElement e, Set annotations) { + // Do not scan a module + return annotatedElements; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Set visitPackage(PackageElement e, Set annotations) { + // Do not scan a package + return annotatedElements; + } } private static abstract class ElementScanningIncludingTypeParameters @@ -224,10 +248,22 @@ public Set getElementsAnnotatedWith(Class 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 @@ -242,9 +278,12 @@ for (Class 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]));