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

User Tools

Site Tools

Example: Object-based inheritance

We illustrate the use of pattern predicates with a simple example. Assume we want to select all method calls within the following Java program that invoke a method of their enclosing class C.

<code Java 1|Listing 1: Simple Java class> class C{

void x ( ){
  A.a(42, 43);
C y(){
 return this ;

} </Code>

Figure 6 shows a predicate to express this analysis. The use of the pattern predicate in Lines 2- 3 binds method calls to the variable ?call. The second one (Lines 6-10) matches public methods. Line 5 uses the unification operator ‘=’ to expresses that the method invoked by ?call must be the public one matched by the second concrete syntax pattern. If evaluated on the program from Figure 4 public self calls binds its argument tuple (?expr, ?name) to the result tuples (this, y), (y,y) and (this, y).

<code GenTL 1|Self-defined predicate using two pattern predicates> public_self_calls(?call, ?method):−

?call is [[
?method = ?call::decl
?method is [[
  public ?type ?name(??params){
]] .


In this example we present the implementation of object-based inheritance in GenTL. The following listing shows the pattern predicate, the necessary two conditional transformations and the CT sequence combining them.

<code GenTL 1|GenTL transformation >

ct add self parameter (?method, ?selfType) :

?method is [[ public ?type ?name(??params){ ??statements } ]] ,
?type = ?method::encl::type ,

replaceable ( ?type , ?sel fType ) , −> add Example: Object-based inheritance before ??params .

ct redirect_self_calls_in(?calledMethod):

public_self_call(?call, ?calledMethod),
?call is [[ ?recv.?name(??params) ]]
replace ?recv with [[ self ]] .

ctseq use_self_param(?method, ?selfType):

add self_parameter(?method, ?selfType) and
redirect_self_calls_in(?method) .


research/gentl/example.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2021