2

I'm trying to extract all (but I'm mostly interested in classes/objects) symbols defined in a scala source file from a Java app using Scala Compiler API.

I'm able to compile a source file using scala.tools.nsc.Global.Run.compileSources, but how to extract all symbols that were defined there?

 import scala.tools.nsc.Global;     
 import scala.tools.nsc.Settings;
 import scala.reflect.internal.util.SourceFile;
 import scala.collection.immutable.Nil$;
 ...

 Global global = new Global(settings);
 SourceFile src = global.newSourceFile("object test {}", "<src>");
 Global.Run run = global.new Run();
 run.compileSources(Nil$.MODULE$.$colon$colon(src));

None of Run, CompilationUnit and Global provide an API to retrieve all symbols.

Am I trying to solve a problem using a wrong way? :)

Filipp
  • 859
  • 1
  • 6
  • 20
  • 1
    Using compile-time reflection you can get the AST. It can be done either from macro or compiler plugin. – cchantep May 20 '15 at 11:09

0 Answers0