associatedFile
returns the source file that the symbol is defined in - this is used in macros, runtime reflection doesn't have such information and that's why you are getting null
s.
If you are using Scala runtime reflection, you can get the corresponding java.lang.Class
object:
import scala.reflect.runtime.universe._
val mirror = runtimeMirror(getClass.getClassLoader)
val clazz = mirror.runtimeClass(typeOf[List[_]])
Fully qualified class name should map to relative classfile path in rather straightforward way:
clazz.getName.replace('.', '/') + ".class"
but you should be aware that runtime classes aren't always loaded from classfiles, various class loaders may fetch them from many different sources in many ways (for example, generate them on the fly in runtime). Also, the exact location of the classfile is a ClassLoader
's implementation detail that you can't know in general case.