Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is the basis for all these neat code metrics and style checking. Anchorcode_manipulatorcode_manipulator

Janino as a Code Manipulator

...

The UnparseVisitor (http://dist.codehaus.org/janino/javadoc/org/codehaus/janino/UnparseVisitor.html#main%28java.lang.String\[\]%29) class demostrates how to do this.

Alternative Compiler Implementations

JANINO can be configured to use not its own Java™ compiler, but an alternative implementation. Alternative implementations must basically implement the interface ICompilerFactory. One such alternative implementation is based on the javax.tools API (available since JDK 1.6), and is shipped as part of the JANINO distribution: commons-compiler-jdk.jar.

Basically there are two ways to switch implementations:

  • Use org.codehaus.commons.compiler.jdk.ExpressionEvaluator and consorts instead of org.codehaus.janino.ExpressionEvaluator; put commons-compiler-jdk.jar instead of janino.jar on your compile-time and runtime classpath. (commons-compiler.jar must always be on the classpath, because it contains the basic classes that every implementation requires.)
  • Use org.codehaus.commons.compiler.CompilerFactoryFactory.getDefaultFactory().newExpressionEvaluator() and compile only against commons-compiler.jar (and no concrete implementation). At runtime, add one implementation (janino.jar or commons-compiler-jdk.jar) to the class path, and getDefaultFactory() will find it at runtime.