<div dir="ltr"><div>Hi Joe,</div><div><br></div><div>Thanks for the hint! Looking further it looks like "sourcefile" can derive from a class file, so what you're saying can actually happen.<br></div><div><br></div><div>But it also looks like for classes defined in actual source files being compiled, the two things are always the same. That happens <a href="https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java#L507">here</a>.</div><div><br></div><div>Thanks,<br></div><div>-Archie</div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Feb 2, 2025 at 4:52 AM Joseph D. Darcy <<a href="mailto:joe.darcy@oracle.com">joe.darcy@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p>Hi Archie,</p>
<p>Without actually checking if this is the case, if "sourcefile"
could also mean the class file a type was constructed from, then
nested types would have a different sourcefile field than the
top-level type.<br>
<br>
HTH,<br>
</p>
<p>-Joe<br>
</p>
<div>On 1/30/2025 8:18 AM, Archie Cobbs
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div>In JavaCompiler.java, there is code that looks like this:<br>
</div>
<div><br>
</div>
<div><span style="font-family:monospace">
JavaFileObject prev = log.useSource(<b>env.enclClass.sym.sourcefile
!= null ?<br>
env.enclClass.sym.sourcefile :<br>
env.toplevel.sourcefile</b>);</span></div>
<div><span style="font-family:monospace"> try {</span></div>
<div><span style="font-family:monospace"> ... do
something ...<br>
</span></div>
<div><span style="font-family:monospace"> } finally {<br>
</span></div>
<div><span style="font-family:monospace">
log.useSource(prev);<br>
</span></div>
<div><span style="font-family:monospace"> }</span></div>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>Put another way, isn't <span style="font-family:monospace">env.toplevel.sourcefile</span>
always the source file that corresponds to any class being
compiled?<br>
</div>
<div><br>
</div>
<div>Thanks for any clarifications.</div>
<div><br>
</div>
<div>-Archie<br>
</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote></div><div><br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>