Class JavacParse

java.lang.Object
org.plumelib.javacparse.JavacParse

public final class JavacParse extends Object
This class contains static methods parseJavaFile(java.lang.String) and parseJavaCode(java.lang.String) that parse Java code into a JCCompilationUnit.

Internally, this class calls the javac parser from the JDK.

  • Method Details

    • parseJavaFile

      public static JavacParseResult parseJavaFile(String filename) throws IOException
      Parse a Java file.
      Parameters:
      filename - the file to parse
      Returns:
      a (parsed) compilation unit, or null if there is a parse error
      Throws:
      IOException - if there is trouble reading the file
    • parseJavaCode

      public static JavacParseResult parseJavaCode(String javaCode)
      Parse a Java file's contents.
      Parameters:
      javaCode - the contents of a Java file
      Returns:
      a (parsed) compilation unit, or null if there is a parse error
    • parseJavaFileObject

      public static JavacParseResult parseJavaFileObject(JavaFileObject source) throws IOException
      Parse a the contents of a JavaFileObject. Returns null if there was a parse error (even if the javac parser could create a CompilationUnit, some of whose subcomponents are erroneous).
      Parameters:
      source - a JavaFileObject
      Returns:
      a compilation unit and the parse errors encountered in it
      Throws:
      IOException - if there is trouble reading the file