Question about "sourcefile"

Archie Cobbs archie.cobbs at gmail.com
Thu Jan 30 16:18:26 UTC 2025


In JavaCompiler.java, there is code that looks like this:

        JavaFileObject prev = log.useSource(

*env.enclClass.sym.sourcefile != null ?
        env.enclClass.sym.sourcefile :
      env.toplevel.sourcefile*);
        try {
            ... do something ...
        } finally {
            log.useSource(prev);
        }

I don't understand why the boldface part is needed. How would it ever be
possible for a class A to have an enclosing class B that exists in a
different source file?

Put another way, isn't env.toplevel.sourcefile always the source file that
corresponds to any class being compiled?

Thanks for any clarifications.

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250130/57136250/attachment.htm>


More information about the compiler-dev mailing list