Overview | Package | Class
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.control
Class SourceUnit

Provides an anchor for a single source unit (usually a script file) as it passes through the compiler system.

author:
  Chris Poirier

author:
  Bing Ran

version:
  $Id: SourceUnit.java 11673 2008-04-17 00:40:31Z paulk $

Field Summary
`ModuleNode` | `ast`
`Reduction` | `cst`
`String` | `name`
`ParserPlugin` | `parserPlugin`
`ReaderSource` | `source`

Constructor Summary
`SourceUnit(String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er)` The pluggable parser used to generate the AST - we allow pluggability currently as we need to have Classic and JSR support
`SourceUnit(File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)` Initializes the SourceUnit from the specified file.
`SourceUnit(URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)` Initializes the SourceUnit from the specified URL.
`SourceUnit(String name, String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)` Initializes the SourceUnit for a string of source.

Method Summary
`void` | `addError(SyntaxException se)`
`void` | `addException(Exception e)`
`void` | `convert()` Generates an AST from the CST.
`static SourceUnit` | `create(String name, String source)` A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
`static SourceUnit` | `create(String name, String source, int tolerance)` A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.
`boolean` | `failedWithUnexpectedEOF()` Convenience routine, primarily for use by the InteractiveShell, that returns true if parse() failed with an unexpected EOF.
`ModuleNode` | `getAST()` Returns the Abstract Syntax Tree produced during convert()ing and expanded during later phases.
`Reduction` | `getCST()` Returns the Concrete Syntax Tree produced during parse()ing.
`String` | `getName()` Returns the name for the SourceUnit.
`String` | `getSample(int line, int column, Janitor janitor)` Returns a sampling of the source at the specified line and column, of null if it is unavailable.
`boolean` | `isEofToken(def token)`
`void` | `parse()` Parses the source to a CST.
`void` | `saveAsXML(String name, ModuleNode ast)`

Constructor Detail

### SourceUnit

    public SourceUnit(String name, ReaderSource source, CompilerConfiguration flags, GroovyClassLoader loader, ErrorCollector er)

  The pluggable parser used to generate the AST - we allow pluggability currently as we need to have Classic and JSR support

### SourceUnit

    public SourceUnit(File source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)

  Initializes the SourceUnit from the specified file.

### SourceUnit

    public SourceUnit(URL source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)

  Initializes the SourceUnit from the specified URL.

### SourceUnit

    public SourceUnit(String name, String source, CompilerConfiguration configuration, GroovyClassLoader loader, ErrorCollector er)

  Initializes the SourceUnit for a string of source.

Method Detail

### addError

    public void addError(SyntaxException se)

### addException

    public void addException(Exception e)

### convert

    public void convert()

  Generates an AST from the CST. You can retrieve it with getAST().

### create

    public static SourceUnit create(String name, String source)

  A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.

### create

    public static SourceUnit create(String name, String source, int tolerance)

  A convenience routine to create a standalone SourceUnit on a String with defaults for almost everything that is configurable.

### failedWithUnexpectedEOF

    public boolean failedWithUnexpectedEOF()

  Convenience routine, primarily for use by the InteractiveShell, that returns true if parse() failed with an unexpected EOF.

### getAST

    public ModuleNode getAST()

  Returns the Abstract Syntax Tree produced during convert()ing and expanded during later phases.

### getCST

    public Reduction getCST()

  Returns the Concrete Syntax Tree produced during parse()ing.

### getName

    public String getName()

  Returns the name for the SourceUnit. This name shouldn't be used for controlling the SourceUnit, it is only for error messages

### getSample

    public String getSample(int line, int column, Janitor janitor)

  Returns a sampling of the source at the specified line and column, of null if it is unavailable.

### isEofToken

    boolean isEofToken(def token)

### parse

    public void parse()

  Parses the source to a CST. You can retrieve it with getCST().

### saveAsXML

    void saveAsXML(String name, ModuleNode ast)