Package org.jboss.forge.roaster
Class Roaster
- java.lang.Object
-
- org.jboss.forge.roaster.Roaster
-
public final class Roaster extends java.lang.Object
Responsible for parsing data into newJavaType
instances.- Author:
- Lincoln Baxter, III
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends JavaSource<?>>
Tcreate(java.lang.Class<T> type)
Create a new emptyJavaSource
instance.static java.lang.String
format(java.lang.String source)
Format the givenString
as a Java source file, using the built in code format style.static java.lang.String
format(java.util.Properties properties, java.lang.String source)
Format the givenString
as a Java source type, using the given code formatProperties
static JavaType<?>
parse(char[] data)
Parse the given character array into a newJavaType
instance.static JavaType<?>
parse(java.io.File file)
Open the givenFile
, parsing its contents into a newJavaType
instance.static JavaType<?>
parse(java.io.InputStream stream)
Read the givenInputStream
and parse the data into a newJavaType
instance.static <T extends JavaType<?>>
Tparse(java.lang.Class<T> type, char[] data)
Read the given character array and parse its data into a newJavaType
instance of the given type.static <T extends JavaType<?>>
Tparse(java.lang.Class<T> type, java.io.File file)
Read the givenFile
and parse its data into a newJavaType
instance of the given type.static <T extends JavaType<?>>
Tparse(java.lang.Class<T> type, java.io.InputStream stream)
Read the givenInputStream
and parse its data into a newJavaType
instance of the given type.static <T extends JavaType<?>>
Tparse(java.lang.Class<T> type, java.lang.String data)
Read the given string and parse its data into a newJavaType
instance of the given type.static <T extends JavaType<?>>
Tparse(java.lang.Class<T> type, java.net.URL url)
Read the givenURL
and parse its data into a newJavaType
instance of the given type.static JavaType<?>
parse(java.lang.String data)
Parse the given String data into a newJavaType
instance.static JavaType<?>
parse(java.net.URL url)
Parse the givenURL
data into a newJavaType
instance.static JavaUnit
parseUnit(java.io.InputStream data)
Read the givenInputStream
and parse its data into a newJavaUnit
instance of the given type.static JavaUnit
parseUnit(java.lang.String data)
Read the givenString
and parse its data into a newJavaUnit
instance of the given type.static java.util.List<Problem>
validateSnippet(java.lang.String snippet)
Validates a code snippet and returns aList
ofProblem
.
-
-
-
Method Detail
-
create
public static <T extends JavaSource<?>> T create(java.lang.Class<T> type)
Create a new emptyJavaSource
instance.- Type Parameters:
T
- the java type- Parameters:
type
- the type of the source- Returns:
- a new
JavaType
instance of the given type - Throws:
java.lang.IllegalStateException
- if no parser is available in the classPathParserException
- if no parser is capable of parsing the provided data
-
parse
public static JavaType<?> parse(java.io.File file) throws java.io.IOException
Open the givenFile
, parsing its contents into a newJavaType
instance.- Parameters:
file
- the file to read from- Returns:
- a the new
JavaType
instance - Throws:
java.io.IOException
- if the reading of the file failsParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static JavaType<?> parse(java.net.URL url) throws java.io.IOException
Parse the givenURL
data into a newJavaType
instance.- Parameters:
url
- the url to read from- Returns:
- a the new
JavaType
instance - Throws:
java.io.IOException
- if the reading failsParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static JavaType<?> parse(java.io.InputStream stream)
Read the givenInputStream
and parse the data into a newJavaType
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 datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static JavaType<?> parse(char[] data)
Parse the given character array into a newJavaType
instance.- Parameters:
data
- the characters to parse- Returns:
- a the new
JavaType
instance - Throws:
ParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static JavaType<?> parse(java.lang.String data)
Parse the given String data into a newJavaType
instance.- Parameters:
data
- the data to parse- Returns:
- the new
JavaType
instance - Throws:
ParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static <T extends JavaType<?>> T parse(java.lang.Class<T> type, java.net.URL url) throws java.io.IOException
Read the givenURL
and parse its data into a newJavaType
instance of the given type.- Type Parameters:
T
- the java type- Parameters:
type
- the type of the sourceurl
- the url to read from- Returns:
- a new
JavaType
instance of the given type - Throws:
java.io.IOException
- if a exception occurs while readingParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static <T extends JavaType<?>> T parse(java.lang.Class<T> type, java.io.File file) throws java.io.FileNotFoundException, java.io.IOException
Read the givenFile
and parse its data into a newJavaType
instance of the given type.- Type Parameters:
T
- the java type- Parameters:
type
- the type of the sourcefile
- the file to read from- Returns:
- a new
JavaType
instance of the given type - Throws:
java.io.IOException
- if a exception occurs while readingjava.io.FileNotFoundException
- if the file doesn't existsParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static <T extends JavaType<?>> T parse(java.lang.Class<T> type, char[] data)
Read the given character array and parse its data into a newJavaType
instance of the given type.- Type Parameters:
T
- the java type- Parameters:
type
- the type of the sourcedata
- the characters to parse- Returns:
- a new
JavaType
instance of the given type - Throws:
ParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
validateSnippet
public static java.util.List<Problem> validateSnippet(java.lang.String snippet) throws ParserException
- Parameters:
snippet
- any Java code- Returns:
- a list of problems (maybe empty)
- Throws:
ParserException
- if noJavaParser
implementation could be found
-
parse
public static <T extends JavaType<?>> T parse(java.lang.Class<T> type, java.lang.String data)
Read the given string and parse its data into a newJavaType
instance of the given type.- Type Parameters:
T
- the java type- Parameters:
type
- the type of the sourcedata
- the data to parse- Returns:
- a new
JavaType
instance of the given type - Throws:
ParserException
- if no parser is capable of parsing the provided datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parse
public static <T extends JavaType<?>> T parse(java.lang.Class<T> type, java.io.InputStream stream)
Read the givenInputStream
and parse its data into a newJavaType
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 fromtype
- 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 datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parseUnit
public static JavaUnit parseUnit(java.lang.String data)
Read the givenString
and parse its data into a newJavaUnit
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 datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
parseUnit
public static JavaUnit parseUnit(java.io.InputStream data)
Read the givenInputStream
and parse its data into a newJavaUnit
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 datajava.lang.IllegalStateException
- if no parser is available in the classPath
-
format
public static java.lang.String format(java.lang.String source)
Format the givenString
as a Java source file, using the built in code format style.- Parameters:
source
- a java source code- Returns:
- the formatted source code
- Throws:
java.lang.IllegalStateException
- if no formatter is available in the classPath
-
format
public static java.lang.String format(java.util.Properties properties, java.lang.String source)
Format the givenString
as a Java source type, using the given code formatProperties
- Parameters:
properties
- the properties to use to formatsource
- a java source code- Returns:
- the formatted source code
- Throws:
java.lang.IllegalStateException
- if no formatter is available in the classPath
-
-