Each class file can have a SourceFile
attribute which contains the name of the source code file. Since this is an arbitrary string, it’s a bit about conventions, e.g. for Java source code, it usually contains the file name only, without any package specific directories.
So there still is bit of interpretation of the information, e.g. if the specified name ends with .java
, an IDE has to look up the known source tree for a matching file in sub directories matching the actual package.
Determining that the source file is not Java is as simple as recognizing that it has a different file name ending, then, whatever convention is used for the particular language may be used, if a plugin knowing it has been installed. Otherwise, most IDEs will simply look for any text file of that name and display it. There might be LineNumberTable
attributes, telling how bytecode instructions map to source line numbers, allowing debuggers to step through the code even without understanding the source code syntax. I already stepped through code compiled from an XSLT file that way.
Of course, the pattern of the specified source code file name may also be used to decide which decompiler to use when the source file has not been found.