Package org.codehaus.groovy.control
Class SourceUnit
java.lang.Object
org.codehaus.groovy.control.ProcessingUnit
org.codehaus.groovy.control.SourceUnit
Provides an anchor for a single source unit (usually a script file)
 as it passes through the compiler system.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ModuleNodeThe root of the Abstract Syntax Tree for the sourceprotected ReductionA Concrete Syntax Tree of the sourceprotected StringA descriptive name of the source unit.protected ReaderSourceWhere we can get Readers for our source unitFields inherited from class org.codehaus.groovy.control.ProcessingUnitclassLoader, configuration, errorCollector, phase, phaseComplete
- 
Constructor SummaryConstructorsConstructorDescriptionSourceUnit(File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from the specified file.SourceUnit(String name, String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit for a string of source.SourceUnit(String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from existing machinery.SourceUnit(URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from the specified URL.
- 
Method SummaryModifier and TypeMethodDescriptionvoidThis method adds a SyntaxException to the error collector.voidvoidThis method adds an exception to the error collector.voidaddFatalError(String text, ASTNode node) Convenience wrapper forErrorCollector.addFatalError(org.codehaus.groovy.control.messages.Message).voidaddWarning(String text, ASTNode node) buildAST()Builds the AST.voidconvert()Generates an AST from the CST.static SourceUnitA convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.static SourceUnitA convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.booleanConvenience routine, primarily for use by the InteractiveShell, that returns true if parse() failed with an unexpected EOF.getAST()Returns the Abstract Syntax Tree produced during convert()ing and expanded during later phases.getCST()Returns the Concrete Syntax Tree produced during parse()ing.getName()Returns the name for the SourceUnit.Returns a sampling of the source at the specified line and column, or null if it is unavailable.voidparse()Parses the source to a CST.voidsetSource(ReaderSource source) Methods inherited from class org.codehaus.groovy.control.ProcessingUnitcompletePhase, configure, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration
- 
Field Details- 
sourceWhere we can get Readers for our source unit
- 
nameA 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.
- 
cstA Concrete Syntax Tree of the source
- 
astThe root of the Abstract Syntax Tree for the source
 
- 
- 
Constructor Details- 
SourceUnitpublic SourceUnit(String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from existing machinery.
- 
SourceUnitpublic SourceUnit(File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from the specified file.
- 
SourceUnitpublic SourceUnit(URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit from the specified URL.
- 
SourceUnitpublic SourceUnit(String name, String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er) Initializes the SourceUnit for a string of source.
 
- 
- 
Method Details- 
getNameReturns the name for the SourceUnit. This name shouldn't be used for controlling the SourceUnit, it is only for error messages
- 
getCSTReturns the Concrete Syntax Tree produced during parse()ing.
- 
getASTReturns 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.
- 
createA convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
- 
createA convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
- 
parseParses the source to a CST. You can retrieve it with getCST().- Throws:
- CompilationFailedException
 
- 
convertGenerates an AST from the CST. You can retrieve it with getAST().- Throws:
- CompilationFailedException
 
- 
buildASTBuilds the AST.
- 
getSampleReturns a sampling of the source at the specified line and column, or null if it is unavailable.
- 
addExceptionThis 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
 
- 
addErrorThis 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
 
- 
addFatalErrorConvenience wrapper forErrorCollector.addFatalError(org.codehaus.groovy.control.messages.Message).- Parameters:
- text- the error message
- node- for locating the offending code
- Throws:
- CompilationFailedException- on error
- Since:
- 3.0.0
 
- 
addWarning- Since:
- 4.0.7
 
- 
addErrorAndContinue
- 
getSource
- 
setSource
 
-