Example usage for javax.tools JavaFileManager getJavaFileForInput

List of usage examples for javax.tools JavaFileManager getJavaFileForInput

Introduction

In this page you can find the example usage for javax.tools JavaFileManager getJavaFileForInput.

Prototype

JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException;

Source Link

Document

Returns a JavaFileObject file object for input representing the specified class of the specified kind in the given package-oriented location.

Usage

From source file:org.cdmckay.coffeep.Program.java

private static JavaFileObject getFileObject(String className) throws IOException {
    final Context context = new Context();
    final JavaFileManager fileManager = new JavacFileManager(context, true, null);

    JavaFileObject fileObject;/*from   w  w  w  .  j  ava 2 s  .c o  m*/

    fileObject = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className,
            JavaFileObject.Kind.CLASS);
    if (fileObject != null)
        return fileObject;

    fileObject = fileManager.getJavaFileForInput(StandardLocation.CLASS_PATH, className,
            JavaFileObject.Kind.CLASS);
    if (fileObject != null)
        return fileObject;

    final StandardJavaFileManager standardFileManager = (StandardJavaFileManager) fileManager;
    return standardFileManager.getJavaFileObjects(className).iterator().next();
}