Class Roaster

java.lang.Object
org.jboss.forge.roaster.Roaster

public final class Roaster extends Object
Responsible for parsing data into new JavaType instances.
Author:
Lincoln Baxter, III
  • Method Details

    • create

      public static <T extends JavaSource<?>> T create(Class<T> type)
      Create a new empty JavaSource instance.
      Type Parameters:
      T - the java type
      Parameters:
      type - the type of the source
      Returns:
      a new JavaType instance of the given type
      Throws:
      IllegalStateException - if no parser is available in the classPath
      ParserException - if no parser is capable of parsing the provided data
    • parse

      public static JavaType<?> parse(File file) throws IOException
      Open the given File, parsing its contents into a new JavaType instance.
      Parameters:
      file - the file to read from
      Returns:
      a the new JavaType instance
      Throws:
      IOException - if the reading of the file fails
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static JavaType<?> parse(URL url) throws IOException
      Parse the given URL data into a new JavaType instance.
      Parameters:
      url - the url to read from
      Returns:
      a the new JavaType instance
      Throws:
      IOException - if the reading fails
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static JavaType<?> parse(InputStream stream)
      Read the given InputStream and parse the data into a new JavaType instance. The caller is responsible to close the stream.
      Parameters:
      stream - the stream to read from
      Returns:
      a new JavaType instance
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static JavaType<?> parse(char[] data)
      Parse the given character array into a new JavaType instance.
      Parameters:
      data - the characters to parse
      Returns:
      a the new JavaType instance
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static JavaType<?> parse(String data)
      Parse the given String data into a new JavaType instance.
      Parameters:
      data - the data to parse
      Returns:
      the new JavaType instance
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static <T extends JavaType<?>> T parse(Class<T> type, URL url) throws IOException
      Read the given URL and parse its data into a new JavaType instance of the given type.
      Type Parameters:
      T - the java type
      Parameters:
      type - the type of the source
      url - the url to read from
      Returns:
      a new JavaType instance of the given type
      Throws:
      IOException - if a exception occurs while reading
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static <T extends JavaType<?>> T parse(Class<T> type, File file) throws FileNotFoundException, IOException
      Read the given File and parse its data into a new JavaType instance of the given type.
      Type Parameters:
      T - the java type
      Parameters:
      type - the type of the source
      file - the file to read from
      Returns:
      a new JavaType instance of the given type
      Throws:
      IOException - if a exception occurs while reading
      FileNotFoundException - if the file doesn't exists
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static <T extends JavaType<?>> T parse(Class<T> type, char[] data)
      Read the given character array and parse its data into a new JavaType instance of the given type.
      Type Parameters:
      T - the java type
      Parameters:
      type - the type of the source
      data - the characters to parse
      Returns:
      a new JavaType instance of the given type
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • validateSnippet

      public static List<Problem> validateSnippet(String snippet) throws ParserException
      Validates a code snippet and returns a List of Problem. Never returns null.
      Parameters:
      snippet - any Java code
      Returns:
      a list of problems (maybe empty)
      Throws:
      ParserException - if no JavaParser implementation could be found
    • parse

      public static <T extends JavaType<?>> T parse(Class<T> type, String data)
      Read the given string and parse its data into a new JavaType instance of the given type.
      Type Parameters:
      T - the java type
      Parameters:
      type - the type of the source
      data - the data to parse
      Returns:
      a new JavaType instance of the given type
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parse

      public static <T extends JavaType<?>> T parse(Class<T> type, InputStream stream)
      Read the given InputStream and parse its data into a new JavaType instance of the given type. The caller is responsible for closing the stream.
      Type Parameters:
      T - the java type
      Parameters:
      stream - the stream to read from
      type - the type of the source
      Returns:
      a new JavaType instance of the given type
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • parseUnit

      public static JavaUnit parseUnit(String data)
      Read the given String and parse its data into a new JavaUnit instance of the given type.
      Parameters:
      data - the data to parse
      Returns:
      a new JavaUnit instance of the given type
      Throws:
      ParserException - if no parser is capable of parsing the requested data
      IllegalStateException - if no parser is available in the classPath
    • parseUnit

      public static JavaUnit parseUnit(InputStream data)
      Read the given InputStream and parse its data into a new JavaUnit instance of the given type. The caller is responsible for closing the stream.
      Parameters:
      data - the stream to read from
      Returns:
      a new JavaUnit instance of the given type
      Throws:
      ParserException - if no parser is capable of parsing the provided data
      IllegalStateException - if no parser is available in the classPath
    • format

      public static String format(String source)
      Format the given String as a Java source file, using the built in code format style.
      Parameters:
      source - a java source code
      Returns:
      the formatted source code
      Throws:
      IllegalStateException - if no formatter is available in the classPath
    • format

      public static String format(Properties properties, String source)
      Format the given String as a Java source type, using the given code format Properties
      Parameters:
      properties - the properties to use to format
      source - a java source code
      Returns:
      the formatted source code
      Throws:
      IllegalStateException - if no formatter is available in the classPath