Where do empty compilation units belong?
Alex Buckley
alex.buckley at oracle.com
Tue Nov 20 18:54:59 UTC 2018
On 11/19/2018 9:27 PM, Jayaprakash Artanareeswaran wrote:
> I have the following folder structure in a module
>
> my.module
> -module-info.java
> - p
> -- C.java
> -- q
> --- D.java
>
> where C.java contains only the package declaration and D.java is
> empty.
>
> When I run javac with --module-source-path and all the individual
> files as arguments the compiler is happy and reports no error. This
> behavior is different from Eclipse compiler which reports an error
> about "declaring a named package because this compilation unit is
> associated to the named module". Is this because empty compilation
> units are considered to be part of unnamed modules or because the
> D.java and hence package q are omitted?
From the above, it's hard to understand for which file an error is
reported by Eclipse. In any case, as Jon indicated, if the file D.java
is empty, then there is no stream of tokens matching the JLS 7.3
production `CompilationUnit` and thus there is no compilation unit to
discuss.
In contrast, the file C.java does contain a compilation unit and I would
expect it to be "associated" (JLS 7.3 again) with the `my.module` module
like any other compilation unit contained in a file in the same
directory. It is legal to annotate the package declaration in the
compilation unit contained in C.java (let's not rathole into a
discussion about package-info.java), and the types that can be used in
the annotation are determined by what `my.module` reads.
Alex
More information about the jigsaw-dev
mailing list