SDA SE Wiki

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

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
research:jtransformer:tutorial:developer_perspective [2015/03/01 00:35]
127.0.0.1 external edit
research:jtransformer:tutorial:developer_perspective [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== Developer Perspective ======
 +
 +For extending JTransformer use the **JTransformer Developer Perspective**. It can be opend via the menu //​JTransformer -> JT Developer Perspective//​. ​
 +
 +{{:​research:​jtransformer:​tutorial:​jt_adv_01_perspective.png|}}
 +
 +After activating the Developer Perspective you will see two views: ​
 +  * the JT Control Center((see [[getting_started|Getting Started]] and [[control_center|Control Center]])), which is also part of the JT User Perspective,​ and in addition  ​
 +  * the Prolog console. ​
 +If you followed the [[getting_started|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|Getting Started]] section.
 +
 +
 +===== Queries in the Prolog console =====
 +{{:​research:​jtransformer:​tutorial:​jt_adv_02_console_selection.png|}}
 +
 +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. ((If you want to know more about the Prolog console and the other items, please have a look at the PDT documentation.)) Now you should see the prompt "''?​-''"​ that invites you to enter a query.
 +
 +Type the following query in the console (( without the ?- )) and hit <''​Enter''>​. You always have to add a dot at the end, otherwise the query won't be executed.
 +<​Code>​
 +classT(Id, Parent, Name, ParamRef, Defs).
 +</​Code>​
 +
 +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: 
 +
 +{{:​research:​jtransformer:​tutorial:​jt_adv_03_console_first_result.png|}}
 +
 +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 unit((A compilation unit is the set of all classes defined in the same Java source file.)) containing the class definition.  ​
 +  * "​Name"​ is the simple name of the class (not the fully qualified name).
 +  * "​TypeParams"​ is a list ((Syntax: Square braces indicate lists.)) 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 [[:​research:​jtransformer:​api:​java:​prologast|the Java AST]]  are documented [[:​research:​jtransformer:​api:​java:​pefs:​4.0:​java_pef_overview|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 ((__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**.)): ​  
 +
 +<Code lang-prolog>?​- classT(Id, Parent, '​MrX',​ TypeParams, Members).</​Code>​
 +
 +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.:
 +
 +<Code lang-prolog>?​- classT(Id, _, 'MrX, _, _).</​Code>​
 +
 +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 ",":​
 +
 +<Code lang-prolog>?​- classT(Id, Parent, Name, TypeParams, Members), not(externalT(Id)).</​Code>​
 +
 +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|Analysis]] section.
 +
 +==== Completion ====
 +{{:​research:​jtransformer:​tutorial:​jt_adv_04_completion.png|}}
 +
 +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''​.
 +
 +==== Navigating ====
 +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:
 +  * navigating to the [[factbase_inspector|Factbase inspector]]
 +  * navigating to the source code
 +
 +{{:​research:​jtransformer:​tutorial:​jt_adv_05_openin.png|}}
 +
 +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|transformation]]).
  
research/jtransformer/tutorial/developer_perspective.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019