ma.glasnost.orika.impl.generator
Class EclipseJdtCompiler

java.lang.Object
  extended by ma.glasnost.orika.impl.generator.EclipseJdtCompiler

public class EclipseJdtCompiler
extends java.lang.Object

EclipseJdtCompiler leverages the eclipse jdt core to compile source code provided in String format.
It can also make use of the source formatter tool to format source.

Author:
matt.deboer@gmail.com

Constructor Summary
EclipseJdtCompiler()
           
EclipseJdtCompiler(java.lang.ClassLoader parentLoader)
           
 
Method Summary
 void assertTypeAccessible(java.lang.Class<?> type)
           
 java.lang.ClassLoader compile(java.io.File sourceDir, java.lang.ClassLoader parent)
          Compiles a set of files contained in source directory directly to bytes in memory, returning a ClassLoader which is able to access them.
 void compile(java.io.File sourceDir, java.io.File binDir)
          Compiles a set of files contained in source directory, writing the class files to binDir
 byte[] compile(java.lang.String source, java.lang.String packageName, java.lang.String classSimpleName)
          Compile and return the raw bytes of the class file.
 java.lang.Class<?> compileAndLoad(java.lang.String source, java.lang.String packageName, java.lang.String classSimpleName)
          Compile and return the (generated) class.
 java.lang.String formatSource(java.lang.String code)
          Format the source code using the Eclipse text formatter
 byte[] getBytes(java.lang.String className)
          Gets the raw bytes of the classFile that was defined for the given className by this compiler.
 java.lang.Class<?> load(java.lang.String className, byte[] data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EclipseJdtCompiler

public EclipseJdtCompiler()

EclipseJdtCompiler

public EclipseJdtCompiler(java.lang.ClassLoader parentLoader)
Method Detail

formatSource

public java.lang.String formatSource(java.lang.String code)
Format the source code using the Eclipse text formatter


assertTypeAccessible

public void assertTypeAccessible(java.lang.Class<?> type)
                          throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

compileAndLoad

public java.lang.Class<?> compileAndLoad(java.lang.String source,
                                         java.lang.String packageName,
                                         java.lang.String classSimpleName)
                                  throws java.lang.ClassNotFoundException
Compile and return the (generated) class.

Parameters:
source -
packageName -
classSimpleName -
Returns:
the (generated) compiled class
Throws:
java.lang.ClassNotFoundException

compile

public byte[] compile(java.lang.String source,
                      java.lang.String packageName,
                      java.lang.String classSimpleName)
Compile and return the raw bytes of the class file.

Parameters:
source -
packageName -
classSimpleName -
Returns:
the raw bytes of the class file

compile

public java.lang.ClassLoader compile(java.io.File sourceDir,
                                     java.lang.ClassLoader parent)
                              throws java.io.IOException
Compiles a set of files contained in source directory directly to bytes in memory, returning a ClassLoader which is able to access them.

Parameters:
sourceDir - the directory (base) from which to find the java source files
parent - the parent ClassLoader to be set for the returned loader
Throws:
java.io.IOException

compile

public void compile(java.io.File sourceDir,
                    java.io.File binDir)
             throws java.io.IOException
Compiles a set of files contained in source directory, writing the class files to binDir

Parameters:
sourceDir -
binDir -
Throws:
java.io.IOException

load

public java.lang.Class<?> load(java.lang.String className,
                               byte[] data)
                        throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getBytes

public byte[] getBytes(java.lang.String className)
Gets the raw bytes of the classFile that was defined for the given className by this compiler.

Parameters:
className -
Returns:


Copyright © 2012 Glasnost. All Rights Reserved.