org.aspectj.org.eclipse.jdt.internal.core.eval
Class EvaluationContextWrapper

java.lang.Object
  extended by org.aspectj.org.eclipse.jdt.internal.core.eval.EvaluationContextWrapper
All Implemented Interfaces:
IEvaluationContext

public class EvaluationContextWrapper
extends java.lang.Object
implements IEvaluationContext

A wrapper around the infrastructure evaluation context.


Field Summary
protected  EvaluationContext context
           
protected  JavaProject project
           
 
Constructor Summary
EvaluationContextWrapper(EvaluationContext context, JavaProject project)
          Creates a new wrapper around the given infrastructure evaluation context and project.
 
Method Summary
 IGlobalVariable[] allVariables()
          Returns the global variables declared in this evaluation context.
protected  void checkBuilderState()
          Checks to ensure that there is a previously built state.
 void codeComplete(java.lang.String codeSnippet, int position, CompletionRequestor requestor)
          Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.
 void codeComplete(java.lang.String codeSnippet, int position, CompletionRequestor requestor, IProgressMonitor monitor)
          Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.
 void codeComplete(java.lang.String codeSnippet, int position, CompletionRequestor requestor, WorkingCopyOwner owner, IProgressMonitor monitor)
          Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.
 void codeComplete(java.lang.String codeSnippet, int position, ICodeCompletionRequestor requestor)
          Deprecated. - use codeComplete(String, int, ICompletionRequestor) instead
 void codeComplete(java.lang.String codeSnippet, int position, ICompletionRequestor requestor)
          Deprecated.  
 void codeComplete(java.lang.String codeSnippet, int position, ICompletionRequestor requestor, WorkingCopyOwner owner)
          Deprecated.  
 IJavaElement[] codeSelect(java.lang.String codeSnippet, int offset, int length)
          Resolves and returns a collection of Java elements corresponding to the source code at the given positions in the given code snippet.
 IJavaElement[] codeSelect(java.lang.String codeSnippet, int offset, int length, WorkingCopyOwner owner)
          Resolves and returns a collection of Java elements corresponding to the source code at the given positions in the given code snippet.
 void deleteVariable(IGlobalVariable variable)
          Deletes the given variable from this evaluation context.
 void evaluateCodeSnippet(java.lang.String codeSnippet, ICodeSnippetRequestor requestor, IProgressMonitor progressMonitor)
          Evaluates the given code snippet.
 void evaluateCodeSnippet(java.lang.String codeSnippet, java.lang.String[] localVariableTypeNames, java.lang.String[] localVariableNames, int[] localVariableModifiers, IType declaringType, boolean isStatic, boolean isConstructorCall, ICodeSnippetRequestor requestor, IProgressMonitor progressMonitor)
          Evaluates the given code snippet in the context of a suspended thread.
 void evaluateVariable(IGlobalVariable variable, ICodeSnippetRequestor requestor, IProgressMonitor progressMonitor)
          Evaluates the given global variable.
protected  INameEnvironment getBuildNameEnvironment()
          Returns a name environment for the last built state.
 java.lang.String[] getImports()
          Returns the import declarations for this evaluation context.
 EvaluationContext getInfrastructureEvaluationContext()
          Returns the infrastructure evaluation context.
protected  IRequestor getInfrastructureEvaluationRequestor(ICodeSnippetRequestor requestor)
          Returns a new infrastructure evaluation requestor instance.
 java.lang.String getPackageName()
          Returns the name of the package in which code snippets are to be compiled and run.
protected  IProblemFactory getProblemFactory()
          Returns the problem factory to be used during evaluation.
 IJavaProject getProject()
          Returns the Java project this evaluation context was created for.
 char[] getVarClassName()
           
protected  void handleInstallException(InstallException e)
          Handles an install exception by throwing a Java Model exception.
 IGlobalVariable newVariable(java.lang.String typeName, java.lang.String name, java.lang.String initializer)
          Creates a new global variable with the given name, type, and initializer.
 void setImports(java.lang.String[] imports)
          Sets the import declarations for this evaluation context.
 void setPackageName(java.lang.String packageName)
          Sets the dot-separated name of the package in which code snippets are to be compiled and run.
 void validateImports(ICodeSnippetRequestor requestor)
          Validates this evaluation context's import declarations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected EvaluationContext context

project

protected JavaProject project
Constructor Detail

EvaluationContextWrapper

public EvaluationContextWrapper(EvaluationContext context,
                                JavaProject project)
Creates a new wrapper around the given infrastructure evaluation context and project.

Method Detail

allVariables

public IGlobalVariable[] allVariables()
Description copied from interface: IEvaluationContext
Returns the global variables declared in this evaluation context. The variables are maintained in the order they are created in.

Specified by:
allVariables in interface IEvaluationContext
Returns:
the list of global variables
See Also:
IEvaluationContext.allVariables()

checkBuilderState

protected void checkBuilderState()
Checks to ensure that there is a previously built state.


codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         ICompletionRequestor requestor)
                  throws JavaModelException
Deprecated. 

Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.

Note that code completion does not involve evaluation.

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, ICompletionRequestor)

codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         ICompletionRequestor requestor,
                         WorkingCopyOwner owner)
                  throws JavaModelException
Deprecated. 

Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

Note that code completion does not involve evaluation.

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
owner - the owner of working copies that take precedence over their original compilation units
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, ICompletionRequestor, WorkingCopyOwner)

codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         CompletionRequestor requestor)
                  throws JavaModelException
Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.

Note that code completion does not involve evaluation.

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, CompletionRequestor)

codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         CompletionRequestor requestor,
                         IProgressMonitor monitor)
                  throws JavaModelException
Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.

Note that code completion does not involve evaluation.

If IProgressMonitor is not null then some proposals which can be very long to compute are proposed. To avoid that the code assist operation take too much time a IProgressMonitor which automatically cancel the code assist operation when a specified amount of time is reached could be used.

 new IProgressMonitor() {
     private final static int TIMEOUT = 500; //ms
     private long endTime;
     public void beginTask(String name, int totalWork) {
         fEndTime= System.currentTimeMillis() + TIMEOUT;
     }
     public boolean isCanceled() {
         return endTime <= System.currentTimeMillis();
     }
     ...
 };
 

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
monitor - the progress monitor used to report progress
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, CompletionRequestor, IProgressMonitor)

codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         CompletionRequestor requestor,
                         WorkingCopyOwner owner,
                         IProgressMonitor monitor)
                  throws JavaModelException
Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

Note that code completion does not involve evaluation.

If IProgressMonitor is not null then some proposals which can be very long to compute are proposed. To avoid that the code assist operation take too much time a IProgressMonitor which automatically cancel the code assist operation when a specified amount of time is reached could be used.

 new IProgressMonitor() {
     private final static int TIMEOUT = 500; //ms
     private long endTime;
     public void beginTask(String name, int totalWork) {
         fEndTime= System.currentTimeMillis() + TIMEOUT;
     }
     public boolean isCanceled() {
         return endTime <= System.currentTimeMillis();
     }
     ...
 };
 

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
owner - the owner of working copies that take precedence over their original compilation units
monitor - the progress monitor used to report progress
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, CompletionRequestor, WorkingCopyOwner, IProgressMonitor)

codeSelect

public IJavaElement[] codeSelect(java.lang.String codeSnippet,
                                 int offset,
                                 int length)
                          throws JavaModelException
Description copied from interface: IEvaluationContext
Resolves and returns a collection of Java elements corresponding to the source code at the given positions in the given code snippet.

Note that code select does not involve evaluation, and problems are never reported.

Specified by:
codeSelect in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to resolve in
offset - the position in the code snippet of the first character of the code to resolve
length - the length of the selected code to resolve
Returns:
the (possibly empty) list of selection Java elements
Throws:
JavaModelException - if code resolve could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeSelect(String, int, int)

codeSelect

public IJavaElement[] codeSelect(java.lang.String codeSnippet,
                                 int offset,
                                 int length,
                                 WorkingCopyOwner owner)
                          throws JavaModelException
Description copied from interface: IEvaluationContext
Resolves and returns a collection of Java elements corresponding to the source code at the given positions in the given code snippet. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

Note that code select does not involve evaluation, and problems are never reported.

Specified by:
codeSelect in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to resolve in
offset - the position in the code snippet of the first character of the code to resolve
length - the length of the selected code to resolve
owner - the owner of working copies that take precedence over their original compilation units
Returns:
the (possibly empty) list of selection Java elements
Throws:
JavaModelException - if code resolve could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeSelect(String, int, int, WorkingCopyOwner)

deleteVariable

public void deleteVariable(IGlobalVariable variable)
Description copied from interface: IEvaluationContext
Deletes the given variable from this evaluation context. Does nothing if the given variable has already been deleted.

Specified by:
deleteVariable in interface IEvaluationContext
Parameters:
variable - the global variable
See Also:
IEvaluationContext.deleteVariable(IGlobalVariable)

evaluateCodeSnippet

public void evaluateCodeSnippet(java.lang.String codeSnippet,
                                java.lang.String[] localVariableTypeNames,
                                java.lang.String[] localVariableNames,
                                int[] localVariableModifiers,
                                IType declaringType,
                                boolean isStatic,
                                boolean isConstructorCall,
                                ICodeSnippetRequestor requestor,
                                IProgressMonitor progressMonitor)
                         throws JavaModelException
Description copied from interface: IEvaluationContext
Evaluates the given code snippet in the context of a suspended thread. The code snippet is compiled along with this context's package declaration, imports, and global variables. The given requestor's acceptProblem method is called for each compilation problem that is detected. Then the resulting class files are handed to the given requestor's acceptClassFiles method to deploy and run.

The requestor is expected to:

  1. send the class files to the target VM,
  2. load them (starting with the code snippet class),
  3. create a new instance of the code snippet class,
  4. run the method run() of the code snippet,
  5. retrieve the values of the local variables,
  6. retrieve the returned value of the code snippet

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
evaluateCodeSnippet in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet
localVariableTypeNames - the dot-separated fully qualified names of the types of the local variables.
localVariableNames - the names of the local variables as they are declared in the user's code.
localVariableModifiers - the modifiers of the local variables (default modifier or final modifier).
declaringType - the type in which the code snippet is evaluated.
isStatic - whether the code snippet is evaluated in a static member of the declaring type.
isConstructorCall - whether the code snippet is evaluated in a constructor of the declaring type.
requestor - the code snippet requestor
progressMonitor - a progress monitor
Throws:
JavaModelException - if a runtime problem occurred or if this context's project has no build state
See Also:
IEvaluationContext.evaluateCodeSnippet(String, String[], String[], int[], IType, boolean, boolean, ICodeSnippetRequestor, IProgressMonitor)

evaluateCodeSnippet

public void evaluateCodeSnippet(java.lang.String codeSnippet,
                                ICodeSnippetRequestor requestor,
                                IProgressMonitor progressMonitor)
                         throws JavaModelException
Description copied from interface: IEvaluationContext
Evaluates the given code snippet. The code snippet is compiled along with this context's package declaration, imports, and global variables. The given requestor's acceptProblem method is called for each compilation problem that is detected. Then the resulting class files are handed to the given requestor's acceptClassFiles method to deploy and run. The requestor is also responsible for getting the result back.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
evaluateCodeSnippet in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet
requestor - the code snippet requestor
progressMonitor - a progress monitor
Throws:
JavaModelException - if a runtime problem occurred or if this context's project has no build state
See Also:
IEvaluationContext.evaluateCodeSnippet(String, ICodeSnippetRequestor, IProgressMonitor)

evaluateVariable

public void evaluateVariable(IGlobalVariable variable,
                             ICodeSnippetRequestor requestor,
                             IProgressMonitor progressMonitor)
                      throws JavaModelException
Description copied from interface: IEvaluationContext
Evaluates the given global variable. During this operation, this context's package declaration, imports, and all its declared variables are verified. The given requestor's acceptProblem method will be called for each problem that is detected.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
evaluateVariable in interface IEvaluationContext
Parameters:
variable - the global variable
requestor - the code snippet requestor
progressMonitor - a progress monitor
Throws:
JavaModelException - if a runtime problem occurred or if this context's project has no build state
See Also:
IEvaluationContext.evaluateVariable(IGlobalVariable, ICodeSnippetRequestor, IProgressMonitor)

getBuildNameEnvironment

protected INameEnvironment getBuildNameEnvironment()
Returns a name environment for the last built state.


getVarClassName

public char[] getVarClassName()

getImports

public java.lang.String[] getImports()
Description copied from interface: IEvaluationContext
Returns the import declarations for this evaluation context. Returns and empty list if there are no imports (the default if the imports have never been set). The syntax for the import corresponds to a fully qualified type name, or to an on-demand package name as defined by ImportDeclaration (JLS2 7.5). For example, "java.util.Hashtable" or "java.util.*".

Specified by:
getImports in interface IEvaluationContext
Returns:
the list of import names
See Also:
IEvaluationContext.getImports()

getInfrastructureEvaluationContext

public EvaluationContext getInfrastructureEvaluationContext()
Returns the infrastructure evaluation context.


getInfrastructureEvaluationRequestor

protected IRequestor getInfrastructureEvaluationRequestor(ICodeSnippetRequestor requestor)
Returns a new infrastructure evaluation requestor instance.


getPackageName

public java.lang.String getPackageName()
Description copied from interface: IEvaluationContext
Returns the name of the package in which code snippets are to be compiled and run. Returns an empty string for the default package (the default if the package name has never been set). For example, "com.example.myapp".

Specified by:
getPackageName in interface IEvaluationContext
Returns:
the dot-separated package name, or the empty string indicating the default package
See Also:
IEvaluationContext.getPackageName()

getProblemFactory

protected IProblemFactory getProblemFactory()
Returns the problem factory to be used during evaluation.


getProject

public IJavaProject getProject()
Description copied from interface: IEvaluationContext
Returns the Java project this evaluation context was created for.

Specified by:
getProject in interface IEvaluationContext
Returns:
the Java project
See Also:
IEvaluationContext.getProject()

handleInstallException

protected void handleInstallException(InstallException e)
                               throws JavaModelException
Handles an install exception by throwing a Java Model exception.

Throws:
JavaModelException

newVariable

public IGlobalVariable newVariable(java.lang.String typeName,
                                   java.lang.String name,
                                   java.lang.String initializer)
Description copied from interface: IEvaluationContext
Creates a new global variable with the given name, type, and initializer.

The typeName and initializer are interpreted in the context of this context's package and import declarations.

The syntax for a type name corresponds to Type in Field Declaration (JLS2 8.3).

Specified by:
newVariable in interface IEvaluationContext
Parameters:
typeName - the type name
name - the name of the global variable
initializer - the initializer expression, or null if the variable is not initialized
Returns:
a new global variable with the given name, type, and initializer
See Also:
IEvaluationContext.newVariable(String, String, String)

setImports

public void setImports(java.lang.String[] imports)
Description copied from interface: IEvaluationContext
Sets the import declarations for this evaluation context. An empty list indicates there are no imports. The syntax for the import corresponds to a fully qualified type name, or to an on-demand package name as defined by ImportDeclaration (JLS2 7.5). For example, "java.util.Hashtable" or "java.util.*".

Specified by:
setImports in interface IEvaluationContext
Parameters:
imports - the list of import names
See Also:
IEvaluationContext.setImports(String[])

setPackageName

public void setPackageName(java.lang.String packageName)
Description copied from interface: IEvaluationContext
Sets the dot-separated name of the package in which code snippets are to be compiled and run. For example, "com.example.myapp".

Specified by:
setPackageName in interface IEvaluationContext
Parameters:
packageName - the dot-separated package name, or the empty string indicating the default package
See Also:
IEvaluationContext.setPackageName(String)

validateImports

public void validateImports(ICodeSnippetRequestor requestor)
Description copied from interface: IEvaluationContext
Validates this evaluation context's import declarations. The given requestor's acceptProblem method is called for each problem that is detected.

Specified by:
validateImports in interface IEvaluationContext
Parameters:
requestor - the code snippet requestor
See Also:
IEvaluationContext.validateImports(ICodeSnippetRequestor)

codeComplete

public void codeComplete(java.lang.String codeSnippet,
                         int position,
                         ICodeCompletionRequestor requestor)
                  throws JavaModelException
Deprecated. - use codeComplete(String, int, ICompletionRequestor) instead

Description copied from interface: IEvaluationContext
Performs a code completion at the given position in the given code snippet, reporting results to the given completion requestor.

Note that code completion does not involve evaluation.

Specified by:
codeComplete in interface IEvaluationContext
Parameters:
codeSnippet - the code snippet to complete in
position - the character position in the code snippet to complete at, or -1 indicating the beginning of the snippet
requestor - the code completion requestor capable of accepting all possible types of completions
Throws:
JavaModelException - if code completion could not be performed. Reasons include:
  • The position specified is less than -1 or is greater than the snippet's length (INDEX_OUT_OF_BOUNDS)
See Also:
IEvaluationContext.codeComplete(String, int, ICodeCompletionRequestor)