Interface ICodeSnippetRequestor
Clients may implement this interface to provide a bridge a running Java VM.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Indicates a compilation problem related to a code snippet.static final String
The name of the field that represent 'this' in a snippet class instance.static final int
Indicates a compilation problem related to an import declaration.static final int
Indicates an internal problem.static final String
The prefix of fields that represent the local variables in a snippet class.static final int
Indicates a compilation problem related to a package declaration.static final String
The field of type java.lang.Class on the code snippet instance that contains the type of the returned value.static final String
The name of the field (of typejava.lang.Object
) on the code snippet instance that contains the returned value.static final String
The name of the instance method in the snippet class that runs the code snippet.static final int
Indicates a compilation problem related to a global variable. -
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptClassFiles
(byte[][] classFileBytes, String[][] classFileCompoundNames, String codeSnippetClassName) Sends the given class files to the target and loads them.void
acceptProblem
(org.eclipse.core.resources.IMarker problemMarker, String fragmentSource, int fragmentKind) Notifies of an evaluation problem.
-
Field Details
-
LOCAL_VAR_PREFIX
The prefix of fields that represent the local variables in a snippet class. -
DELEGATE_THIS
The name of the field that represent 'this' in a snippet class instance. -
RUN_METHOD
The name of the instance method in the snippet class that runs the code snippet.- See Also:
-
RESULT_VALUE_FIELD
The name of the field (of typejava.lang.Object
) on the code snippet instance that contains the returned value.- See Also:
-
RESULT_TYPE_FIELD
The field of type java.lang.Class on the code snippet instance that contains the type of the returned value. The name of the field (of typejava.lang.Class
) on the code snippet instance that contains the runtime type of the returned value.- See Also:
-
VARIABLE
static final int VARIABLEIndicates a compilation problem related to a global variable.Note: if the problem is on the type of the variable, the marker source line number is -1; if the name of the variable, line number is 0; otherwise, the marker source line number is relative to the initializer code.
-
CODE_SNIPPET
static final int CODE_SNIPPETIndicates a compilation problem related to a code snippet. -
IMPORT
static final int IMPORTIndicates a compilation problem related to an import declaration. -
PACKAGE
static final int PACKAGEIndicates a compilation problem related to a package declaration. -
INTERNAL
static final int INTERNALIndicates an internal problem.
-
-
Method Details
-
acceptClassFiles
boolean acceptClassFiles(byte[][] classFileBytes, String[][] classFileCompoundNames, String codeSnippetClassName) Sends the given class files to the target and loads them. If the given class name is notnull
, run the code snippet with this class name. Returns whether the code snippet could be deployed. Note it must returntrue
even if running the code snippet threw an exception.The details of sending and loading the class files are left up to implementations.
To run a code snippet, an implementation should create a new instance of the given code snippet class and call (directly or using another means) its
RUN_METHOD
.Also before the call, the implementation should copy the values of the local variables (if any) into the corresponding fields of the code snippet instance. A field name is formed of
LOCAL_VAR_PREFIX
preceded the name of the local variable. For example, the field name for local variable"myLocal"
is"val$myLocal"
(assuming the value ofLOCAL_VAR_PREFIX
is "val$"). In the same way, the implementation should copy the value of the 'this' object into the field calledDELEGATE_THIS
.After calling the
RUN_METHOD
, the values of the local variables may have been modified. The implementation must copy the values of the fields back into the local variables.Finally, the overall value returned by the code snippet can be retrieved from the special field
RESULT_VALUE_FIELD
on the code snippet instance. TheClass
that is the runtime type of the returned value can be retrieved from the special fieldRESULT_TYPE_FIELD
.- Parameters:
classFileBytes
- the list of class file bytesclassFileCompoundNames
- the corresponding list of class file type compound names (example of a compound name: {"java", "lang", "Object"})codeSnippetClassName
- name of the actual class to instantiate and run, ornull
if none- Returns:
true
if the code snippet was successfully deployed
-
acceptProblem
void acceptProblem(org.eclipse.core.resources.IMarker problemMarker, String fragmentSource, int fragmentKind) Notifies of an evaluation problem. Problems can arise for source of the following kinds:- global variable (
VARIABLE
) - fragment source is name of variable - code snippet (
CODE_SNIPPET
) - fragment source is code snippet - import declaration (
IMPORT
) - fragment source is import - package declaration (
PACKAGE
) - fragment source is package declaration - other (
INTERNAL
) - no fragment source is involved, internal error occurred.
- Parameters:
problemMarker
- the problem marker (cannot be null)fragmentSource
- the fragment sourcefragmentKind
- the kind of source fragment; one of:VARIABLE
,CODE_SNIPPET
,IMPORT
,PACKAGE
, orINTERNAL
- global variable (
-