<s> package org . eclipse . jdt . internal . core . eval ; import java . util . Locale ; import java . util . Map ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . eval . ICodeSnippetRequestor ; import org . eclipse . jdt . core . eval . IEvaluationContext ; import org . eclipse . jdt . core . eval . IGlobalVariable ; import org . eclipse . jdt . internal . compiler . IProblemFactory ; import org . eclipse . jdt . internal . compiler . env . INameEnvironment ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . core . * ; import org . eclipse . jdt . internal . core . builder . NameEnvironment ; import org . eclipse . jdt . internal . core . builder . ProblemFactory ; import org . eclipse . jdt . internal . eval . EvaluationContext ; import org . eclipse . jdt . internal . eval . GlobalVariable ; import org . eclipse . jdt . internal . eval . IRequestor ; import org . eclipse . jdt . internal . eval . InstallException ; public class EvaluationContextWrapper implements IEvaluationContext { protected EvaluationContext context ; protected JavaProject project ; public EvaluationContextWrapper ( EvaluationContext context , JavaProject project ) { this . context = context ; this . project = project ; } public IGlobalVariable [ ] allVariables ( ) { GlobalVariable [ ] vars = this . context . allVariables ( ) ; int length = vars . length ; GlobalVariableWrapper [ ] result = new GlobalVariableWrapper [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { result [ i ] = new GlobalVariableWrapper ( vars [ i ] ) ; } return result ; } protected void checkBuilderState ( ) { return ; } public void codeComplete ( String codeSnippet , int position , ICompletionRequestor requestor ) throws JavaModelException { codeComplete ( codeSnippet , position , requestor , DefaultWorkingCopyOwner . PRIMARY ) ; } public void codeComplete ( String codeSnippet , int position , ICompletionRequestor requestor , WorkingCopyOwner owner ) throws JavaModelException { if ( requestor == null ) { throw new IllegalArgumentException ( "" ) ; } codeComplete ( codeSnippet , position , new org . eclipse . jdt . internal . codeassist . CompletionRequestorWrapper ( requestor ) , owner ) ; } public void codeComplete ( String codeSnippet , int position , CompletionRequestor requestor ) throws JavaModelException { codeComplete ( codeSnippet , position , requestor , DefaultWorkingCopyOwner . PRIMARY ) ; } public void codeComplete ( String codeSnippet , int position , CompletionRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { codeComplete ( codeSnippet , position , requestor , DefaultWorkingCopyOwner . PRIMARY , null ) ; } public void codeComplete ( String codeSnippet , int position , CompletionRequestor requestor , WorkingCopyOwner owner ) throws JavaModelException { codeComplete ( codeSnippet , position , requestor , owner , null ) ; } public void codeComplete ( String codeSnippet , int position , CompletionRequestor requestor , WorkingCopyOwner owner , IProgressMonitor monitor ) throws JavaModelException { SearchableEnvironment environment = this . project . newSearchableNameEnvironment ( owner ) ; this . context . complete ( codeSnippet . toCharArray ( ) , position , environment , requestor , this . project . getOptions ( true ) , this . project , owner , monitor ) ; } public IJavaElement [ ] codeSelect ( String codeSnippet , int offset , int length ) throws JavaModelException { return codeSelect ( codeSnippet , offset , length , DefaultWorkingCopyOwner . PRIMARY ) ; } public IJavaElement [ ] codeSelect ( String codeSnippet , int offset , int length , WorkingCopyOwner owner ) throws JavaModelException { SearchableEnvironment environment = this . project . newSearchableNameEnvironment ( owner ) ; SelectionRequestor requestor = new SelectionRequestor ( environment . nameLookup , null ) ; this . context . select ( codeSnippet . toCharArray ( ) , offset , offset + length - 1 , environment , requestor , this . project . getOptions ( true ) , owner ) ; return requestor . getElements ( ) ; } public void deleteVariable ( IGlobalVariable variable ) { if ( variable instanceof GlobalVariableWrapper ) { GlobalVariableWrapper wrapper = ( GlobalVariableWrapper ) variable ; this . context . deleteVariable ( wrapper . variable ) ; } else { throw new Error ( "" ) ; } } public void evaluateCodeSnippet ( String codeSnippet , String [ ] localVariableTypeNames , String [ ] localVariableNames , int [ ] localVariableModifiers , IType declaringType , boolean isStatic , boolean isConstructorCall , ICodeSnippetRequestor requestor , IProgressMonitor progressMonitor ) throws org . eclipse . jdt . core . JavaModelException { checkBuilderState ( ) ; int length = localVariableTypeNames . length ; char [ ] [ ] varTypeNames = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { varTypeNames [ i ] = localVariableTypeNames [ i ] . toCharArray ( ) ; } length = localVariableNames . length ; char [ ] [ ] varNames = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { varNames [ i ] = localVariableNames [ i ] . toCharArray ( ) ; } Map options = this . project . getOptions ( true ) ; if ( declaringType != null ) { this . context . setPackageName ( declaringType . getPackageFragment ( ) . getElementName ( ) . toCharArray ( ) ) ; ICompilationUnit compilationUnit = declaringType . getCompilationUnit ( ) ; if ( compilationUnit != null ) { IImportDeclaration [ ] imports = compilationUnit . getImports ( ) ; int importsLength = imports . length ; if ( importsLength != 0 ) { char [ ] [ ] importsNames = new char [ importsLength ] [ ] ; for ( int i = 0 ; i < importsLength ; i ++ ) { importsNames [ i ] = imports [ i ] . getElementName ( ) . toCharArray ( ) ; } this . context . setImports ( importsNames ) ; options . put ( CompilerOptions . OPTION_ReportUnusedImport , CompilerOptions . IGNORE ) ; } } else { SourceMapper sourceMapper = ( ( ClassFile ) declaringType . getClassFile ( ) ) . getSourceMapper ( ) ; if ( sourceMapper != null ) { char [ ] [ ] imports = sourceMapper . getImports ( ( BinaryType ) declaringType ) ; if ( imports != null ) { this . context . setImports ( imports ) ; options . put ( CompilerOptions . OPTION_ReportUnusedImport , CompilerOptions . IGNORE ) ; } } } } INameEnvironment environment = null ; try { this . context . evaluate ( codeSnippet . toCharArray ( ) , varTypeNames , varNames , localVariableModifiers , declaringType == null ? null : declaringType . getFullyQualifiedName ( ) . toCharArray ( ) , isStatic , isConstructorCall , environment = getBuildNameEnvironment ( ) , options , getInfrastructureEvaluationRequestor ( requestor ) , getProblemFactory ( ) ) ; } catch ( InstallException e ) { handleInstallException ( e ) ; } finally { if ( environment != null ) environment . cleanup ( ) ; } } public void evaluateCodeSnippet ( String codeSnippet , ICodeSnippetRequestor requestor , IProgressMonitor progressMonitor ) throws JavaModelException { checkBuilderState ( ) ; INameEnvironment environment = null ; try { this . context . evaluate ( codeSnippet . toCharArray ( ) , environment = getBuildNameEnvironment ( ) , this . project . getOptions ( true ) , getInfrastructureEvaluationRequestor ( requestor ) , getProblemFactory ( ) ) ; } catch ( InstallException e ) { handleInstallException ( e ) ; } finally { if ( environment != null ) environment . cleanup ( ) ; } } public void evaluateVariable ( IGlobalVariable variable , ICodeSnippetRequestor requestor , IProgressMonitor progressMonitor ) throws JavaModelException { checkBuilderState ( ) ; INameEnvironment environment = null ; try { this . context . evaluateVariable ( ( ( GlobalVariableWrapper ) variable ) . variable , environment = getBuildNameEnvironment ( ) , this . project . getOptions ( true ) , getInfrastructureEvaluationRequestor ( requestor ) , getProblemFactory ( ) ) ; } catch ( InstallException e ) { handleInstallException ( e ) ; } finally { if ( environment != null ) environment . cleanup ( ) ; } } protected INameEnvironment getBuildNameEnvironment ( ) { return new NameEnvironment ( getProject ( ) ) ; } public char [ ] getVarClassName ( ) { return this . context . getVarClassName ( ) ; } public String [ ] getImports ( ) { char [ ] [ ] imports = this . context . getImports ( ) ; int length = imports . length ; String [ ] result = new String [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { result [ i ] = new String ( imports [ i ] ) ; } return result ; } public EvaluationContext getInfrastructureEvaluationContext ( ) { return this . context ; } protected IRequestor getInfrastructureEvaluationRequestor ( ICodeSnippetRequestor requestor ) { return new RequestorWrapper ( requestor ) ; } public String getPackageName ( ) { return new String ( this . context . getPackageName ( ) ) ; } protected IProblemFactory getProblemFactory ( ) { return ProblemFactory . getProblemFactory ( Locale . getDefault ( ) ) ; } public IJavaProject getProject ( ) { return this . project ; } protected void handleInstallException ( InstallException e ) throws JavaModelException { throw new JavaModelException ( new JavaModelStatus ( IJavaModelStatusConstants . EVALUATION_ERROR , e . toString ( ) ) ) ; } public IGlobalVariable newVariable ( String typeName , String name , String initializer ) { GlobalVariable newVar = this . context . newVariable ( typeName . toCharArray ( ) , name . toCharArray ( ) , ( initializer == null ) ? null : initializer . toCharArray ( ) ) ; return new GlobalVariableWrapper ( newVar ) ; } public void setImports ( String [ ] imports ) { int length = imports . length ; char [ ] [ ] result = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { result [ i ] = imports [ i ] . toCharArray ( ) ; } this . context . setImports ( result ) ; } public void setPackageName ( String packageName ) { this . context . setPackageName ( packageName . toCharArray ( ) ) ; } public void validateImports ( ICodeSnippetRequestor requestor ) { checkBuilderState ( ) ; INameEnvironment environment = null ; try { this . context . evaluateImports ( environment = getBuildNameEnvironment ( ) , getInfrastructureEvaluationRequestor ( requestor ) , getProblemFactory ( ) ) ; } finally { if ( environment != null ) environment . cleanup ( ) ; } } public void codeComplete ( String codeSnippet , int position , final org . eclipse . jdt . core . ICodeCompletionRequestor requestor ) throws JavaModelException { if ( requestor == null ) { codeComplete ( codeSnippet , position , ( ICompletionRequestor ) null ) ; return ; } codeComplete ( codeSnippet , position , new ICompletionRequestor ( ) { public void acceptAnonymousType ( char [ ] superTypePackageName , char [ ] superTypeName , char [ ] [ ] parameterPackageNames , char [ ] [ ] parameterTypeNames , char [ ] [ ] parameterNames , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { } public void acceptClass ( char [ ] packageName , char [ ] className , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { requestor . acceptClass ( packageName , className , completionName , modifiers , completionStart , completionEnd ) ; } public void acceptError ( IProblem error ) { } public void acceptField ( char [ ] declaringTypePackageName , char [ ] declaringTypeName , char [ ] name , char [ ] typePackageName , char [ ] typeName , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { requestor . acceptField ( declaringTypePackageName , declaringTypeName , name , typePackageName , typeName , completionName , modifiers , completionStart , completionEnd ) ; } public void acceptInterface ( char [ ] packageName , char [ ] interfaceName , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { requestor . acceptInterface ( packageName , interfaceName , completionName , modifiers , completionStart , completionEnd ) ; } public void acceptKeyword ( char [ ] keywordName , int completionStart , int completionEnd , int relevance ) { requestor . acceptKeyword ( keywordName , completionStart , completionEnd ) ; } public void acceptLabel ( char [ ] labelName , int completionStart , int completionEnd , int relevance ) { requestor . acceptLabel ( labelName , completionStart , completionEnd ) ; } public void acceptLocalVariable ( char [ ] name , char [ ] typePackageName , char [ ] typeName , int modifiers , int completionStart , int completionEnd , int relevance ) { } public void acceptMethod ( char [ ] declaringTypePackageName , char [ ] declaringTypeName , char [ ] selector , char [ ] [ ] parameterPackageNames , char [ ] [ ] parameterTypeNames , char [ ] [ ] parameterNames , char [ ] returnTypePackageName , char [ ] returnTypeName , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { requestor . acceptMethod ( declaringTypePackageName , declaringTypeName , selector , parameterPackageNames , parameterTypeNames , returnTypePackageName , returnTypeName , completionName , modifiers , completionStart , completionEnd ) ; } public void acceptMethodDeclaration ( char [ ] declaringTypePackageName , char [ ] declaringTypeName , char [ ] selector , char [ ] [ ] parameterPackageNames , char [ ] [ ] parameterTypeNames , char [ ] [ ] parameterNames , char [ ] returnTypePackageName , char [ ] returnTypeName , char [ ] completionName , int modifiers , int completionStart , int completionEnd , int relevance ) { } public void acceptModifier ( char [ ] modifierName , int completionStart , int completionEnd , int relevance ) { requestor . acceptModifier ( modifierName , completionStart , completionEnd ) ; } public void acceptPackage ( char [ ] packageName , char [ ] completionName , int completionStart , int completionEnd , int relevance ) { requestor . acceptPackage ( packageName , completionName , completionStart , completionEnd ) ; } public void acceptType ( char [ ] packageName , char [ ] typeName , char [ ] completionName , int completionStart , int completionEnd , int relevance ) { requestor . acceptType ( packageName , typeName , completionName , completionStart , completionEnd ) ; } public void acceptVariableName ( char [ ] typePackageName , char [ ] typeName , char [ ] name , char [ ] completionName , int completionStart , int completionEnd , int relevance ) { } } ) ; } } </s>