Package org.codehaus.groovy.control
Class SourceUnit
- java.lang.Object
- 
- org.codehaus.groovy.control.ProcessingUnit
- 
- org.codehaus.groovy.control.SourceUnit
 
 
- 
 public class SourceUnit extends ProcessingUnit Provides an anchor for a single source unit (usually a script file) as it passes through the compiler system.
- 
- 
Field SummaryFields Modifier and Type Field Description protected ModuleNodeastThe root of the Abstract Syntax Tree for the sourceprotected ReductioncstA Concrete Syntax Tree of the sourceprotected java.lang.StringnameA descriptive name of the source unit.protected ReaderSourcesourceWhere we can get Readers for our source unit- 
Fields inherited from class org.codehaus.groovy.control.ProcessingUnitclassLoader, configuration, errorCollector, phase, phaseComplete
 
- 
 - 
Constructor SummaryConstructors Constructor Description SourceUnit(java.io.File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from the specified file.SourceUnit(java.lang.String name, java.lang.String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit for a string of source.SourceUnit(java.lang.String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from existing machinery.SourceUnit(java.net.URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from the specified URL.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddError(SyntaxException se)This method adds a SyntaxException to the error collector.voidaddErrorAndContinue(SyntaxException se)voidaddException(java.lang.Exception e)This method adds an exception to the error collector.voidconvert()Generates an AST from the CST.static SourceUnitcreate(java.lang.String name, java.lang.String source)A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.static SourceUnitcreate(java.lang.String name, java.lang.String source, int tolerance)A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.booleanfailedWithUnexpectedEOF()Convenience routine, primarily for use by the InteractiveShell, that returns true if parse() failed with an unexpected EOF.ModuleNodegetAST()Returns the Abstract Syntax Tree produced during convert()ing and expanded during later phases.ReductiongetCST()Returns the Concrete Syntax Tree produced during parse()ing.java.lang.StringgetName()Returns the name for the SourceUnit.java.lang.StringgetSample(int line, int column, Janitor janitor)Returns a sampling of the source at the specified line and column, or null if it is unavailable.ReaderSourcegetSource()protected booleanisEofToken(Token token)voidparse()Parses the source to a CST.- 
Methods inherited from class org.codehaus.groovy.control.ProcessingUnitcompletePhase, configure, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration
 
- 
 
- 
- 
- 
Field Detail- 
sourceprotected ReaderSource source Where we can get Readers for our source unit
 - 
nameprotected java.lang.String name A descriptive name of the source unit. This name shouldn't be used for controlling the SourceUnit, it is only for error messages and to determine the name of the class for a script.
 - 
cstprotected Reduction cst A Concrete Syntax Tree of the source
 - 
astprotected ModuleNode ast The root of the Abstract Syntax Tree for the source
 
- 
 - 
Constructor Detail- 
SourceUnitpublic SourceUnit(java.lang.String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from existing machinery.
 - 
SourceUnitpublic SourceUnit(java.io.File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from the specified file.
 - 
SourceUnitpublic SourceUnit(java.net.URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit from the specified URL.
 - 
SourceUnitpublic SourceUnit(java.lang.String name, java.lang.String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)Initializes the SourceUnit for a string of source.
 
- 
 - 
Method Detail- 
getNamepublic java.lang.String getName() Returns the name for the SourceUnit. This name shouldn't be used for controlling the SourceUnit, it is only for error messages
 - 
getCSTpublic Reduction getCST() Returns the Concrete Syntax Tree produced during parse()ing.
 - 
getASTpublic ModuleNode getAST() Returns the Abstract Syntax Tree produced during convert()ing and expanded during later phases.
 - 
failedWithUnexpectedEOFpublic boolean failedWithUnexpectedEOF() Convenience routine, primarily for use by the InteractiveShell, that returns true if parse() failed with an unexpected EOF.
 - 
isEofTokenprotected boolean isEofToken(Token token) 
 - 
createpublic static SourceUnit create(java.lang.String name, java.lang.String source) A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
 - 
createpublic static SourceUnit create(java.lang.String name, java.lang.String source, int tolerance) A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
 - 
parsepublic void parse() throws CompilationFailedExceptionParses the source to a CST. You can retrieve it with getCST().- Throws:
- CompilationFailedException
 
 - 
convertpublic void convert() throws CompilationFailedExceptionGenerates an AST from the CST. You can retrieve it with getAST().- Throws:
- CompilationFailedException
 
 - 
getSamplepublic java.lang.String getSample(int line, int column, Janitor janitor)Returns a sampling of the source at the specified line and column, or null if it is unavailable.
 - 
addExceptionpublic void addException(java.lang.Exception e) throws CompilationFailedExceptionThis method adds an exception to the error collector. The Exception most likely has no line number attached to it. For this reason you should use this method sparingly. Prefer using addError for syntax errors or add an error to theErrorCollectordirectly by retrieving it with getErrorCollector().- Parameters:
- e- the exception that occurred
- Throws:
- CompilationFailedException- on error
 
 - 
addErrorpublic void addError(SyntaxException se) throws CompilationFailedException This method adds a SyntaxException to the error collector. The exception should specify the line and column number of the error. This method should be reserved for real errors in the syntax of the SourceUnit. If your error is not in syntax, and is a semantic error, or more general error, then use addException or use the error collector directly by retrieving it with getErrorCollector().- Parameters:
- se- the exception, which should have line and column information
- Throws:
- CompilationFailedException- on error
 
 - 
addErrorAndContinuepublic void addErrorAndContinue(SyntaxException se) throws CompilationFailedException - Throws:
- CompilationFailedException
 
 - 
getSourcepublic ReaderSource getSource() 
 
- 
 
-