<s> package org . eclipse . jdt . internal . eval ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . Map ; import org . eclipse . jdt . core . compiler . * ; import org . eclipse . jdt . internal . compiler . ClassFile ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . Compiler ; import org . eclipse . jdt . internal . compiler . DefaultErrorHandlingPolicies ; import org . eclipse . jdt . internal . compiler . ICompilerRequestor ; import org . eclipse . jdt . internal . compiler . IProblemFactory ; import org . eclipse . jdt . internal . compiler . env . ICompilationUnit ; import org . eclipse . jdt . internal . compiler . env . INameEnvironment ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . core . util . Util ; public abstract class Evaluator { EvaluationContext context ; INameEnvironment environment ; Map options ; IRequestor requestor ; IProblemFactory problemFactory ; Evaluator ( EvaluationContext context , INameEnvironment environment , Map options , IRequestor requestor , IProblemFactory problemFactory ) { this . context = context ; this . environment = environment ; this . options = options ; this . requestor = requestor ; this . problemFactory = problemFactory ; } protected abstract void addEvaluationResultForCompilationProblem ( Map resultsByIDs , CategorizedProblem problem , char [ ] cuSource ) ; protected EvaluationResult [ ] evaluationResultsForCompilationProblems ( CompilationResult result , char [ ] cuSource ) { CategorizedProblem [ ] problems = result . getAllProblems ( ) ; HashMap resultsByIDs = new HashMap ( 5 ) ; for ( int i = 0 ; i < problems . length ; i ++ ) { addEvaluationResultForCompilationProblem ( resultsByIDs , problems [ i ] , cuSource ) ; } int size = resultsByIDs . size ( ) ; EvaluationResult [ ] evalResults = new EvaluationResult [ size ] ; Iterator results = resultsByIDs . values ( ) . iterator ( ) ; for ( int i = 0 ; i < size ; i ++ ) { evalResults [ i ] = ( EvaluationResult ) results . next ( ) ; } return evalResults ; } ClassFile [ ] getClasses ( ) { final char [ ] source = getSource ( ) ; final ArrayList classDefinitions = new ArrayList ( ) ; class CompilerRequestor implements ICompilerRequestor { boolean hasErrors = false ; public void acceptResult ( CompilationResult result ) { if ( result . hasProblems ( ) ) { EvaluationResult [ ] evalResults = evaluationResultsForCompilationProblems ( result , source ) ; for ( int i = 0 ; i < evalResults . length ; i ++ ) { EvaluationResult evalResult = evalResults [ i ] ; CategorizedProblem [ ] problems = evalResult . getProblems ( ) ; for ( int j = 0 ; j < problems . length ; j ++ ) { Evaluator . this . requestor . acceptProblem ( problems [ j ] , evalResult . getEvaluationID ( ) , evalResult . getEvaluationType ( ) ) ; } } } if ( result . hasErrors ( ) ) { this . hasErrors = true ; } else { ClassFile [ ] classFiles = result . getClassFiles ( ) ; for ( int i = 0 ; i < classFiles . length ; i ++ ) { ClassFile classFile = classFiles [ i ] ; classDefinitions . add ( classFile ) ; } } } } CompilerRequestor compilerRequestor = new CompilerRequestor ( ) ; Compiler compiler = getCompiler ( compilerRequestor ) ; compiler . compile ( new ICompilationUnit [ ] { new ICompilationUnit ( ) { public char [ ] getFileName ( ) { return CharOperation . concat ( Evaluator . this . getClassName ( ) , Util . defaultJavaExtension ( ) . toCharArray ( ) ) ; } public char [ ] getContents ( ) { return source ; } public char [ ] getMainTypeName ( ) { return Evaluator . this . getClassName ( ) ; } public char [ ] [ ] getPackageName ( ) { return null ; } } } ) ; if ( compilerRequestor . hasErrors ) { return null ; } else { ClassFile [ ] result = new ClassFile [ classDefinitions . size ( ) ] ; classDefinitions . toArray ( result ) ; return result ; } } protected abstract char [ ] getClassName ( ) ; Compiler getCompiler ( ICompilerRequestor compilerRequestor ) { CompilerOptions compilerOptions = new CompilerOptions ( this . options ) ; compilerOptions . performMethodsFullRecovery = true ; compilerOptions . performStatementsRecovery = true ; return new Compiler ( this . environment , DefaultErrorHandlingPolicies . exitAfterAllProblems ( ) , compilerOptions , compilerRequestor , this . problemFactory ) ; } protected abstract char [ ] getSource ( ) ; } </s>