|
|
# Shows you how to use the AmbientTalk inspector.
|
|
|
|
|
|
**WORK IN PROGRESS**
|
|
|
|
|
|
# Introduction
|
|
|
|
|
|
This page gives you a short introduction of how to use the AmbientTalk Inspector.
|
|
|
The inspector allows you to obtain a graphical representation of your AmbientTalk objects.
|
|
|
Further it allows you to change fields and methods of your objects.
|
|
|
By using the reflective capabilities of AmbientTalk the inspector will update the GUI as the objects fields and methods change.
|
|
|
|
|
|
# Quick Overview
|
|
|
|
|
|
The inspector is implemented in AmbientTalk by means of reflection.
|
|
|
In order to be able to inspect AmbientTalk objects, they need to have a costume mirror installed.
|
|
|
This can easily be achieved by importing the following statement in your init.at file ( atlib/at/init/init.at ).
|
|
|
|
|
|
```
|
|
|
import /.at.support.inspector.inspectorMirrors;
|
|
|
```
|
|
|
|
|
|
After restarting the interpreter, the inspector will be able to inspect all your objects.
|
|
|
Starting the inspector is done in two steps, first you have import the inspector GUI as shown below.
|
|
|
```
|
|
|
import /.at.support.inspector.inspectorGUI;
|
|
|
```
|
|
|
After importing the inspectorGUI you can go ahead and start inspecting your objects by invoking the inspect function on them.
|
|
|
```
|
|
|
inspect(object);
|
|
|
```
|
|
|
|
|
|
# Example
|
|
|
|
|
|
In order to get a feeling of what the inspector offers consider the following example where we define two objects `foo` and `bar`. foo has two fields `x` and `y`. `bar` has one field which is a reference to the object `foo`. By importing the special mirror in the init.at file both objects will have a customized mirror which allows the inspector to be notified when the fields of an object change. The inspector is very experimental and it should be noted that it has not been used excessively.
|
|
|
|
|
|
```
|
|
|
import /.at.support.inspector.inspectorGUI;
|
|
|
|
|
|
|
|
|
def foo := object: {
|
|
|
def x;
|
|
|
def y;
|
|
|
};
|
|
|
|
|
|
def bar := object: {
|
|
|
def myReference := foo;
|
|
|
};
|
|
|
```
|
|
|
|
|
|
## Open Inspector Window
|
|
|
|
|
|
In order to see the graphical representation of a the object bar we can simply invoke the inspect function and pass it the object `bar` as an argument.
|
|
|
```
|
|
|
inspect(bar);
|
|
|
```
|
|
|
|
|
|
|
|
|
## Inspector Layout
|
|
|
|
|
|
This should open a window similar to the one below.
|
|
|
All inspector windows are divided into three regions.
|
|
|
The top region lists all the fields and methods of the object.
|
|
|
On the left of this region the name of the field or method is shown.
|
|
|
On the right it gives a textual description of the field.
|
|
|
For example the myReference field shows that this field points to an object which has two fields `x` and `y`.
|
|
|
|
|
|
The middle region is an evaluation window where you can type AmbientTalk expressions which when executed will be evaluated in the context of the inspected object. This has the consequence that a variable definition will result into the addition of a field to the inspected object.
|
|
|
|
|
|
Finally the bottom region of the inspector window will show the interpreter output after evaluating AmbientTalk code.
|
|
|
|
|
|
Inspector/bar.png
|
|
|
|
|
|
|
|
|
## Adding Fields and Methods
|
|
|
|
|
|
In order to add a new field (myNewField) to the bar object it is sufficient to type the definition of this new field into the evaluation window and press F5 (on a mac this might be fn+F5 according to your settings). We could for example define a new field (`myNewField`) and initialize it to `24` as shown below.
|
|
|
```
|
|
|
def myNewField := 24;
|
|
|
```
|
|
|
After evaluation the main output window will show the result. And the top region will show that the object now has an additional field initialized with `24`. This is also shown in the following figure.
|
|
|
The addition of a method is analog to the addition of a field. To add a method `myMethod` you could type in the following expression into the evaluation window (not reflected in the pictures below).
|
|
|
|
|
|
```
|
|
|
def myMethod( ) {
|
|
|
//myMethod implementation
|
|
|
};
|
|
|
```
|
|
|
|
|
|
Inspector/bar_field.png
|
|
|
|
|
|
|
|
|
## Reflecting Field Changes
|
|
|
|
|
|
The newly created field can be used as any normal field. Moreover the inspector will update the graphical user interface anytime a field of the object is changed. In order to clarify this, open the terminal and change the value of `myNewField` to `42`. As can be seen in the pictures below the value of the `myNewField` in the inspector window is also changed accordingly.
|
|
|
|
|
|
```
|
|
|
bar.myNewField := 42;
|
|
|
```
|
|
|
|
|
|
Inspector/terminal.png
|
|
|
|
|
|
Inspector/bar_changed.png
|
|
|
|
|
|
## Changing Field Values and Method Bodies
|
|
|
|
|
|
Next to changing the values of a field from the terminal, the inspector allows you to change fields by double clicking on the value in the inspector window. For example in order to change the value of `myNewField` to `1024` double click on the value and type in `1024`. This feature is especially useful to change the body of a method. Finally double clicking on an object will open a new inspector window for the clicked object.
|
|
|
|
|
|
Inspector/change_field_inspector.png
|
|
|
|
|
|
# Known Issues
|
|
|
|
|
|
Unlike inspectors in languages like smalltalk changes to the object from within the inspector will not be reflected to the actual program text. This means that restarting the interpreter will result into the loss of all the modifications you made to the object.
|
|
|
|
|
|
Native object do not have a costume mirror installed.
|
|
|
|
|
|
The inspector has not been tested for distribution.
|
|
|
|
|
|
Changes to the mirror of the inspector itself will not be reflected in the graphical user interface. |