RFR: 8236842: Surprising 'multiple elements' behaviour from getTypeElement when cross-compiling with --release
Vicente Romero
vromero at openjdk.java.net
Wed Sep 16 19:41:49 UTC 2020
On Wed, 16 Sep 2020 07:57:30 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Unqualified Elements.getTypeElement(CharSequence) and Elements.getPackageElement(CharSequence) search for elements
> across all modules in the module graph, and only return a value when they find exactly one element. This is
> troublesome, as an element (uniquely) visible from a root module may be "hidden" by an element that is not visible from
> any root module (i.e. is internal to some module that is not in the root module set). The idea proposed here is that
> these unqualified methods would first look for elements visible from the root modules, and would search the internals
> of other modules only if nothing would be found in the first round. The draft of the corresponding CSR is here:
> https://bugs.openjdk.java.net/browse/JDK-8253168.
I have also made some small edits to the CSR and added myself as reviewer
src/java.compiler/share/classes/javax/lang/model/util/Elements.java line 59:
> 57: * If running with modules, packages of the given name are searched in a
> 58: * two-stage process:
> 59: * -find non-empty packages with the given name returned by {@link #getPackageElement(ModuleElement,
> CharSequence)}, where the provided ModuleSymbol is any root module,
it would be nice to try to keep the line width as close as possible to 80 chars, same for the CSR
src/java.compiler/share/classes/javax/lang/model/util/Elements.java line 134:
> 132: * If running with modules, type elements of the given name are searched in a
> 133: * two-stage process:
> 134: * -find type elements with the given name returned by {@link #getTypeElement(ModuleElement, CharSequence)},
> where the provided ModuleSymbol is any root module,
same comment as above
src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java line 203:
> 201: Set<S> found = new LinkedHashSet<>();
> 202:
> 203: for (Set<ModuleSymbol> allModules : Arrays.asList(modules.getRootModules(), modules.allModules())) {
does it make sense to obtain a diff between the the root modules and the all-modules set in order to avoid searching
twice in the root modules if the symbol is not found there in the first try?
src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java line 237:
> 235: return Optional.empty();
> 236: } else {
> 237: //not found, try another option
probably this else {} can be removed right?
-------------
PR: https://git.openjdk.java.net/jdk/pull/200
More information about the compiler-dev
mailing list