Example usage for javax.tools StandardJavaFileManager list

List of usage examples for javax.tools StandardJavaFileManager list

Introduction

In this page you can find the example usage for javax.tools StandardJavaFileManager list.

Prototype

Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
        throws IOException;

Source Link

Document

Lists all file objects matching the given criteria in the given package-oriented location.

Usage

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

public static List<Class> getAllFhirResourceClasses(String packageName) throws IOException {

    // logger.trace("Running getAllFhirResourceClasses for:" +
    // packageName);
    List<Class> commands = new ArrayList<Class>();

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    Location location = StandardLocation.CLASS_PATH;

    Set<JavaFileObject.Kind> kinds = new HashSet<JavaFileObject.Kind>();
    kinds.add(JavaFileObject.Kind.CLASS);
    boolean recurse = false;

    Iterable<JavaFileObject> list = fileManager.list(location, packageName, kinds, recurse);

    for (JavaFileObject javaFileObject : list) {

        // commands.add(javaFileObject.getClass());
    }/*  www .j a  v a 2 s.  c  om*/

    Class c = null;

    for (String x : Arrays.asList(RESOURCE_LIST_REGEX.replace("(", "").replace(")", "").split("\\|")))

    {
        x = "org.hl7.fhir." + x;
        // logger.trace("X:"+x);
        c = Utils.getClassFromClassPath(x);
        if (c != null)
            commands.add(c);
    }
    // logger.trace(commands.toString());
    return commands;
}