1

In Java, it's possible to compile and load classes at runtime from source code contained in strings (e.g. using javax.tools.JavaCompiler, EclipseCompiler, or Janino). This process can be entirely in-memory, without writing any temporary files.

The Xtend language works by transforming Xtend source code into Java source code and then compiling that. (Correct me if I'm wrong.) Is it possible to transform a string containing Xtend source code into a string containing Java source code, so that I can then use my favorite dynamic compiler? I'd like to turn Xtend sources into loadable classes at runtime*. If it is possible, what functions/classes do you need to call to do it?

*Runtime = no Eclipse-IDE, no JDK (JRE only), using just the Xtend dependencies.

Seki
  • 11,135
  • 7
  • 46
  • 70
Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47

1 Answers1

1

Xtend has a Maven Plugin. It leverages XtendBatchCompiler. It should be possible to call it from pure Java, ANT etc.

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • Yeah, I know (thanks, though). I was hoping someone could tell me in more detail--- this API works by mutating state (for example, the "compile" function returns a boolean, not compiled code), so the functions must be called in some order and not some other order. Also, the default mode of the Maven plugin would generate files and I'd like to do it all in-memory (necessary for some environments, such as Google App Engine). – Jim Pivarski Feb 06 '14 at 03:33
  • I thought you would be able to use the filesystem as temporary storage to read / write from/to for usage have a look at org.eclipse.xtend.core.compiler.batch.Main.main(String[]) – Christian Dietrich Feb 07 '14 at 12:31
  • Maybe you can Leverage the XtendCompilerTest from Xtends own tests – Christian Dietrich Feb 07 '14 at 12:39