Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Developer Perspective

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:

  • the JT Control Center1), which is also part of the JT User Perspective, and in addition
  • the Prolog console.

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.

Queries in the Prolog console

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

  • “Id” is the internal ID of the fact that represents the class “Object”.
  • “Parent” is the ID of the fact that represents the parent element of the class, in this case a compilation unit4) containing the class definition.
  • “Name” is the simple name of the class (not the fully qualified name).
  • “TypeParams” is a list 5) containing the IDs of the type parameters for a class. In this case the list is empty, since Object has no type parameters.
  • “Members” is a list of IDs of member elements (fields, methods, nested classes).

All the predicates that represent the Java AST are documented here.

The yellow background of the Prolog Console indicates that the query is not completed yet – there might be more results:

  • To see the next result type ';' (semicolon) or hit <Space>
  • To abort the query type 'a' or <Enter>

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).

If you want to know more about the Prolog console and the other items, please have a look at the PDT documentation.
without the ?-
A compilation unit is the set of all classes defined in the same Java source file.
Syntax: Square braces indicate lists.
Syntax: A parameter starting with a capital letter or an underscore (_) represents a variable. One starting with a lower-case letter or enclosed in simple quotes represents a constant.
research/jtransformer/tutorial/developer_perspective.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024