Package org.codehaus.groovy.control

Examples of org.codehaus.groovy.control.SourceUnit


     *         expression.
     */
    public Declaration[] analyze( String text,
                                  List availDecls ) throws Exception
    {
        SourceUnit unit = SourceUnit.create( "groovy.script", text );       
        unit.parse( );
        unit.nextPhase();
        unit.convert( );
        ModuleNode module = unit.getAST( );

        ClassNode classNode = ( ClassNode ) module.getClasses( ).get( 0 );
        List methods = classNode.getDeclaredMethods( "run" );
        MethodNode method = ( MethodNode ) methods.get( 0 );
        ASTNode expr = method.getCode( );
View Full Code Here


    }

    public void addError(String msg, ASTNode expr) {
        int line = expr.getLineNumber();
        int col = expr.getColumnNumber();
        SourceUnit source = sourceUnit();
        source.getErrorCollector().addErrorAndContinue(
                new SyntaxErrorMessage(new SyntaxException(msg + '\n', line, col), source)
        );
    }
View Full Code Here

        final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(pClassLoader);
        final CompilationUnit unit = new CompilationUnit(configuration, null, groovyClassLoader);
        final SourceUnit[] source = new SourceUnit[pResourceNames.length];
        for (int i = 0; i < source.length; i++) {
            final String resourceName = pResourceNames[i];
            source[i] = new SourceUnit(
                    ConversionUtils.convertResourceToClassName(resourceName),
                    new String(pReader.getBytes(resourceName)), // FIXME delay the read
                    configuration,
                    groovyClassLoader,
                    collector
View Full Code Here

* @version $Revision: 21515 $
*/
public abstract class TestParserSupport extends GroovyTestCase {

    public ModuleNode parse(String text, String description) throws Exception {
        SourceUnit unit = SourceUnit.create(description, text);
        unit.parse();
        unit.convert();

        return unit.getAST();
    }
View Full Code Here

        ClassNode stored = classes.get(name);
        if (stored != null && stored != node) {
            // we have a duplicate class!
            // One possibility for this is, that we declared a script and a
            // class in the same file and named the class like the file
            SourceUnit nodeSource = node.getModule().getContext();
            SourceUnit storedSource = stored.getModule().getContext();
            String txt = "Invalid duplicate class definition of class " + node.getName() + " : ";
            if (nodeSource == storedSource) {
                // same class in same source
                txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n";
                if (node.isScriptBody() || stored.isScriptBody()) {
                    txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" +
                            " the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
                }
            } else {
                txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " are containing both a class of the name " + node.getName() + ".\n";
            }
            nodeSource.getErrorCollector().addErrorAndContinue(
                    new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber()), nodeSource)
            );
        }
View Full Code Here

    }

    protected void addError(String msg, ASTNode expr) {
        int line = expr.getLineNumber();
        int col = expr.getColumnNumber();
        SourceUnit source = getSourceUnit();
        source.getErrorCollector().addErrorAndContinue(
                new SyntaxErrorMessage(new SyntaxException(msg + '\n', line, col), source)
        );
    }
View Full Code Here

* @version $Revision: 21516 $
*/
public abstract class TestParserSupport extends GroovyTestCase {

    public ModuleNode parse(String text, String description) throws Exception {
        SourceUnit unit = SourceUnit.create(description, text);
        unit.parse();
        unit.convert();

        return unit.getAST();
    }
View Full Code Here

* @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf</a>
*/
public class ASTTest extends TestCase {

    public ModuleNode getAST(String source, int untilPhase) {
        SourceUnit unit = SourceUnit.create("Test", source);
        CompilationUnit compUnit = new CompilationUnit();
        compUnit.addSource(unit);
        compUnit.compile(untilPhase);
        return unit.getAST();
    }
View Full Code Here

    public void testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated() {
        SyntaxException syntaxException = new SyntaxException(someString(), -1, -1);
        assertEquals("source locator", null, syntaxException.getSourceLocator());

        String sourceUnitName = someString();
        SourceUnit sourceUnit = SourceUnit.create(sourceUnitName, someString());

        new SyntaxErrorMessage(syntaxException, sourceUnit);
        assertEquals("source locator", sourceUnitName, syntaxException.getSourceLocator());
    }
View Full Code Here

   
   
    public void write( PrintWriter writer, Janitor janitor )
    {
        if (owner instanceof SourceUnit) {
            SourceUnit source = (SourceUnit) owner;

            String name   = source.getName();
            int    line   = context.getStartLine();
            int    column = context.getStartColumn();
            String sample = source.getSample( line, column, janitor );

            if( sample != null )
            {
                writer.println( source.getSample(line, column, janitor) );
            }

            writer.println( name + ": " + line + ": " + this.message );
            writer.println("");
        } else {
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.control.SourceUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.