Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 132   Methods: 2
NCLOC: 92   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ImporterClassBodyEvaluator.java 20% 56.2% 50% 47.7%
coverage coverage
 1    package org.drools.semantics.java;
 2   
 3    import java.io.IOException;
 4    import java.util.ArrayList;
 5    import java.util.Iterator;
 6    import java.util.List;
 7    import java.util.Set;
 8    import java.util.StringTokenizer;
 9   
 10    import org.codehaus.janino.DebuggingInformation;
 11    import org.codehaus.janino.EvaluatorBase;
 12    import org.codehaus.janino.Java;
 13    import org.codehaus.janino.Location;
 14    import org.codehaus.janino.Parser;
 15    import org.codehaus.janino.Scanner;
 16    import org.codehaus.janino.Java.CompileException;
 17    import org.codehaus.janino.Parser.ParseException;
 18    import org.codehaus.janino.Scanner.ScanException;
 19    import org.drools.spi.Importer;
 20   
 21    /**
 22    * Class body evaluator that pays attention to imports defined outside the class
 23    * body. Made from <code>net.janino.ClassBodyEvaluator</code> and
 24    * <code>org.drools.semantics.java.JavaScriptEvaluator</code>.
 25    *
 26    * @author kdx
 27    */
 28    public class ImporterClassBodyEvaluator extends EvaluatorBase
 29    {
 30    private final Class clazz;
 31   
 32    /**
 33    * Construct.
 34    *
 35    * @param imports
 36    * <code>Set&lt;String&gt;</code> of imported java classes and
 37    * packages.
 38    * @param scanner
 39    * The lexer.
 40    * @param classLoader
 41    * Class loader for resolving other classes referred to by the
 42    * currently constructed class.
 43    * @throws IOException
 44    * @throws ScanException
 45    * @throws ParseException
 46    * @throws CompileException
 47    */
 48  1 public ImporterClassBodyEvaluator(Importer importer,
 49    String className,
 50    Scanner scanner,
 51    ClassLoader classLoader) throws ScanException,
 52    IOException,
 53    CompileException,
 54    ParseException,
 55    ClassNotFoundException
 56    {
 57  1 super( classLoader );
 58   
 59  1 Class optionalExtendedType = (Class) null;
 60  1 Class[] implementedTypes = new Class[0];
 61   
 62  1 Java.CompilationUnit compilationUnit = new Java.CompilationUnit( scanner.peek( ).getLocation( ).getFileName( ) );
 63   
 64    // Parse import declarations.
 65  1 Parser parser = new Parser( scanner );
 66  1 this.parseImportDeclarations( compilationUnit,
 67    scanner );
 68   
 69    // The difference from plain ClassBodyEvaluator: add extra imports.
 70  1 Location loc = scanner.peek( ).getLocation( );
 71  1 Set imports = importer.getImports( );
 72  1 Iterator it = imports.iterator( );
 73  1 String type;
 74  1 List list;
 75  1 StringTokenizer st;
 76  1 String token;
 77  1 boolean importOnDemand;
 78  1 while ( it.hasNext( ) )
 79    {
 80  0 importOnDemand = false;
 81  0 list = new ArrayList( );
 82  0 type = (String) it.next( );
 83  0 st = new StringTokenizer( type,
 84    "." );
 85  0 while ( st.hasMoreTokens( ) )
 86    {
 87  0 token = st.nextToken( );
 88  0 if ( !token.equals( "*" ) )
 89    {
 90  0 list.add( token );
 91    }
 92    else
 93    {
 94  0 importOnDemand = true;
 95    }
 96    }
 97  0 if ( importOnDemand )
 98    {
 99  0 compilationUnit.addImportDeclaration( new Java.TypeImportOnDemandDeclaration( loc,
 100    (String[]) list.toArray( new String[list.size( )] ) ) );
 101    }
 102    else
 103    {
 104  0 compilationUnit.addImportDeclaration( new Java.SingleTypeImportDeclaration( loc,
 105    (String[]) list.toArray( new String[list.size( )] ) ) );
 106    }
 107    }
 108   
 109    // Add class declaration.
 110  1 Java.ClassDeclaration cd = this.addPackageMemberClassDeclaration( scanner.peek( ).getLocation( ),
 111    compilationUnit,
 112    className,
 113    optionalExtendedType,
 114    implementedTypes );
 115   
 116    // Parse class body declarations (member declarations) until EOF.
 117  1 while ( !scanner.peek( ).isEOF( ) )
 118    {
 119  1 parser.parseClassBodyDeclaration( cd );
 120    }
 121   
 122  0 this.clazz = this.compileAndLoad( compilationUnit, // compilationUnit
 123    DebuggingInformation.SOURCE.add( DebuggingInformation.LINES ), // debuggingInformation
 124    className );
 125    }
 126   
 127  0 public Class evaluate()
 128    {
 129  0 return clazz;
 130    }
 131   
 132    }