For extending JTransformer use the JTransformer Developer Perspective. It can be opend via the menu JTransformer → JT Developer Perspective.
After activating the Developer Perspective you will see two views:
If you followed the Getting Started section, by now your workspace should contain the JT Tutorial Project, which should be selected in both views of the Developer Perspective, the Control center and the Prolog Console. If not, go back to the Getting Started section.
In the Prolog console you can send queries to the factbase. Make sure that you use the correct process (in our example:
SWI Prolog: JT_Tutorial (JTransformer)). You can change the current process by clicking the little arrow next to the first icon. 2) Now you should see the prompt “
?-” that invites you to enter a query.
Type the following query in the console 3) and hit <
Enter>. You always have to add a dot at the end, otherwise the query won't be executed.
classT(Id, Parent, Name, ParamRef, Defs).
This way you ask for any class in the current factbase. A query basically asks the system to find correct values for the variables in the query. The capital spelling of Id, CompilationUnit, Name and Members indicates that these are variables. In our example, the first tuple of correct values for the variables is displayed like this:
This tells us that the first class found is the class named “Object”. The values for the variable
The yellow background of the Prolog Console indicates that the query is not completed yet – there might be more results:
Try replacing the variable “Name” with a class name, e.g. 'MrX'. Be sure to surround the class name with simple quotes – otherwise it will be misinterpreted as a variable 6):
?- classT(Id, Parent, 'MrX', TypeParams, Members).
Now only one fact is matched: the fact that represents the “MrX” class.
If you just want to know which ID belongs to the class 'MrX' (and you are not interessted in the values Parent, TypeParams or Members) you can use an underscore “_” for this arguments.:
?- classT(Id, _, 'MrX, _, _).
Now the only result is the Class ID for Class 'MrX'.
If you just want to see your source-code classes (and not the ones from bytecode, like Object) you can connect two predicates with “,”:
?- classT(Id, Parent, Name, TypeParams, Members), not(externalT(Id)).
If you want to find more complex patterns in your source code (e.g. possible bugs, performance issues, metrics, design patters etc.) you should have a look at the Analysis section.
The Prolog console offers a very useful feature: code completion. For example: just type field, hit <
Tab> and select
fieldT/5 - user. This will automatically add the arguments to your query. Just add the dot at the end and hit <
Enter> to find all the fields in your factbase. If you want to find all field accesses, select
fieldAccessT/6 - user.
Just knowing the ID of a specific PEF usually is not enough. You want to see the code which is the result of a specific query. The console offers two ways to have a more detailed look at the results:
Just select an id in the console and right-click to open the context menu. Here you will find the entries “
Open in Factbase Inspector” and “
Open in Editor”. Click the one you want and JTransformer will automatically open the desired view and navigate to the element, that represents the selected id. Please note that “
Open id Editor” doesn't work for elements without source code (e.g. bytecode facts or facts that have just been created by a transformation).