home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (SourceBaseTestCase.groovy)

This example Groovy source code file (SourceBaseTestCase.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

blockstatement, blockstatement, groovytestcase, script_, script_, sourcebasetestcase, sourcebasetestcase, sourceunit, sourceunit

The Groovy SourceBaseTestCase.groovy source code

package org.codehaus.groovy.ast.source

import org.codehaus.groovy.control.*
import org.codehaus.groovy.control.io.*
import org.codehaus.groovy.ast.stmt.*

class SourceBaseTestCase extends GroovyTestCase {

    private classNode
    public classNode() {
      if (classNode!=null) return node
      def cu = new CompilationUnit(null,null,this.class.classLoader)
      def source = new StringReaderSource(script,cu.configuration)
      def su = cu.addSource(new SourceUnit("Script_"+this.name, source, cu.configuration, cu.classLoader, cu.errorCollector))
      cu.compile(Phases.CONVERSION)
      classNode = cu.firstClassNode
      return classNode
    }
    
    def sourceInfo(expression) {
      return [  expression.lineNumber,
                expression.columnNumber,
                expression.lastLineNumber,
                expression.lastColumnNumber 
             ]
    }
    
    def statements(String method="run") {
      def ret = classNode().getMethod(method).code
      if (ret instanceof BlockStatement) return ret.statements
      if (ret==null) return null
      return [ret]
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy SourceBaseTestCase.groovy source code file:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.