<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>A Solution to the Java Refactoring Case Study using eMoflon</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Sven Peldszus</string-name>
          <email>sven.peldszus@stud</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Ge´za Kulcsa´r</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Malte Lochau</string-name>
          <email>malte.lochau@es</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Technische Universita ̈t Darmstadt, Real-Time Systems Lab</institution>
          ,
          <addr-line>Merckstr. 25, 64283 Darmstadt</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Technische Universita ̈t Darmstadt, Real-Time Systems Lab</institution>
          ,
          <addr-line>Merckstr. 25, 64283 Darmstadt</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Technische Universita ̈t Darmstadt, Real-Time Systems Lab</institution>
          ,
          <addr-line>Merckstr. 25, 64283 Darmstadt</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2015</year>
      </pub-date>
      <abstract>
        <p>Our solution to the Java Refactoring case study of the Transformation Tool Contest (TTC 2015) is implemented using eMoflon, a meta-modeling and model transformation tool developed at the Real-Time Systems Lab at TU Darmstadt. The solution, available as a virtual machine hosted on SHARE [5] and at GitHub [6], includes a bidirectional synchronization between a Java model and an abstract program graph specified using Triple Graph Grammars (TGG) as well as a graph-based implementation for two refactoring operations using Story Driven Modeling (SDM).</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>The Solution using eMoflon, TGGs and SDM</title>
      <p>In the following, we give a detailed description of the steps of our solution.</p>
      <p>
        Java to JaMoPP. The Java source code is parsed and converted into an intermediate EMF
representation using the JaMoPP framework [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. To quote the website of JaMoPP: “JaMoPP is a set of Eclipse
plug-ins that can be used to parse Java source code into EMF-based models and vice versa.”2
      </p>
      <p>JaMoPP to PG. While working with the JaMoPP meta-model for Java, we have found out that
some parts of it do not comply with the PG meta-model and with some properties of the planned TGG
translation. Two preprocessing actions are necessary to make a JaMoPP model instance TGG-conform.</p>
      <p>Creating the package structure. JaMoPP encodes the package hierarchy of the program into dot
separated string or as array of strings. As it would require extra efforts and the usage of external hand-written
code to handle these constructs when specifying our TGG, we decided to implement this transformation
as a preprocessing step in order to keep our TGG clean and concise.</p>
      <p>Retaining the parameter order of methods. A transformation specified by a set of TGG rules is per
definition nondeterministic, i.e., if the source side of a rule has multiple matches in a source model, we
cannot be sure in which order they will be processed. To preserve the original order of a parameter list,
which is represented by independent child nodes of a method node, we have to turn the set of parameter
nodes into a list representation so that the parameter nodes can only be processed in the given order.</p>
      <p>TGGs describe a correspondence between instances of a source and a target meta-model, specified
by means of a mediating correspondence graph (hence the name Triple Graph Grammars). A TGG
specification consists of declarative rules. A transformation using TGGs consists in building up a target
model incrementally on the basis of a source model (or vice versa) using the correspondence links
between the elements of the models. Applying a TGG rule essentially means that a given structure in the
target model is built up which corresponds to a part of the source model which is matched by the source
side of the rule definition.</p>
      <p>
        Our TGG specification consists of 20 rules. We have identified 5 main components which have to
be considered: initialization of the PG, packages, classes, methods, and fields. In Figure 1, we show a
sample rule MethodNameCreate to introduce our visual TGG syntax and to give an idea about the rule
semantics. For further details of the TGG implementation, please refer to [
        <xref ref-type="bibr" rid="ref5 ref6">5, 6</xref>
        ].
      </p>
      <p>By convention, the source node part is on the left and the target node side is on the right, with the
correspondence graph (hexagonal boxes) in between. Boxes and edges marked with ++ (highlighted
in green) are the elements created by the rule application. All other boxes and edges represent the
context (elements which have to be present for the rule to be applied). A crossed-out box denotes a
negative application condition: the object must not be part of the context. The box with an expression
and two outgoing edges (in the middle) is a constraint, which ensures that the name attributes of the
referred elements have the same value (here, the built-in eq function is used; however, there are various
other built-in functions and the developer can also create custom ones). The meaning of this rule is the
following: whenever there is a class in the source with a corresponding class in the target, if a method of
the source class is not yet translated (thus, processed at application time, hence its green color), and the
target PG does not have a method with the same name, then a new method and a corresponding method
definition are created in the target.</p>
      <p>
        Refactoring of the PG. The refactoring rules Pull Up Method and Create Superclass have
been implemented using Story Driven Modeling (SDM) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. As these operations do not have to be
bidirectional, it was a convenient choice to use SDMs which comprise a more flexible way of specifying
transformations compared to TGGs.
      </p>
      <p>SDMs provide a way to implement methods of classes of a meta-model (similar to object-oriented
programming) in a visual manner based on graph transformation, combining declarative graph
transformation rules with an imperative control flow. The basic building blocks of an SDM specification are the
story nodes. Each story node contains a single graph transformation operation, which is applied
according to the standard graph transformation principles (i.e., nondeterministically on a matching part of the
model) when the story node is activated. The story nodes are activated as determined by the control flow,
with the additional possibilities of adding if-else conditions and for each loops.</p>
      <p>There are two methods implemented for both refactoring operations in the corresponding classes of
the PG meta-model. The isApplicable methods simply check the feasibility of the rule application
to prevent the modification of the PG if a refactoring is not even executable. Thereupon, the Perform
methods perform the actual refactorings if possible.</p>
      <p>
        In this paper, we omit an elaborated presentation of all our SDM methods; instead we show an
example method, introduce our visual SDM syntax, give an intuition about how the method works and
refer the reader to [
        <xref ref-type="bibr" rid="ref5 ref6">5, 6</xref>
        ] for further details.
      </p>
      <p>Figure 2 shows an example SDM method csc Perform which implements the actual application of
the Create Superclass after the preconditions have been checked. The execution starts with the start
node (black circle on top left) and follows the arrows. The larger rounded boxes denote story nodes; each
story node contains a graph transformation rule which is applied as the containing story node is activated.
A rule application consists in finding a match for the depicted graph pattern in the model where the SDM
method has been called, deleting the elements marked with -- (highlighted in red) and creating the ones
marked with ++ (highlighted in green). Boxes with a thick edge correspond to bound object variables that
are matched to a fixed object in the model. A story node may have two outgoing edges: the execution
continues through Success if the application was successful and through Failure if not. Story nodes
can alternatively contain external method calls. Cascaded-style boxes represent for each loops, where
the rule is applied to each possible match in the model with a loop body executed after each match (Each
Time edge). After all the matches have been processed, the loop is exited (End edge).
childs:
TClassContainer
+tClass
tChildClass:</p>
      <p>TClass
[End]
[Each Time]</p>
      <p>[Failure]
tChildClass:</p>
      <p>TClass
+childClasses
+parentClass
tParent:
TClass
tParent:</p>
      <p>TClass
+parentClass
-+childClasses
tChildClass:</p>
      <p>TClass
[Success]
tNewParent:</p>
      <p>TClass
+parentClass
+childClasses ++
tChildClass:</p>
      <p>TClass
+tClass ++</p>
      <p>container:</p>
      <p>TClassContainer</p>
      <p>The depicted rule, csc Perform, does the following: after putting the new parent class into the PG
by creating the corresponding edge, the old parent of the child classes is identified. Afterwards, in a loop,
the parent reference of each child class is newly created to point to the parent created by the refactoring
and the old reference is deleted.</p>
      <p>PG to JaMoPP. As our TGG describes both a forward and a backward transformation, this step of
the transformation requires no extra development efforts. TGGs in eMoflon provide a synchronisation
algorithm based on model deltas: whenever one side of a TGG (in our case, the PG instance) is changed,
the modification delta is calculated and the TGG mechanism is able to update the other side of the model
in correspondence with the change delta. Multiple refactoring operations are performed as a single batch
after all the preconditions have been checked by using a bookkeeping mechanism.</p>
      <p>JaMoPP to Java. Similar to the first step, the translation of the EMF model to Java code belongs to
the central functionality of JaMoPP.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Evaluation</title>
      <p>Correctness and performance. The case study contains 20 test cases, in which one or more refactorings
have to be performed. The feasibility of the given refactoring operations is correctly determined in all test
cases. Most of the execution time (60 %) is spent with the Java-to-PG transformation, where JaMoPP
consumes almost 30 % of the overall time; although we expected the TGG execution to be the most
expensive step, it only takes about 14 % of the whole process (together in both directions). The average
execution time for one test case is 0.3367 sec.</p>
      <p>Soft aspects. Utilizing TGGs for the synchronization part is responsible for the greatest advantages
and disadvantages at once. TGGs provide a powerful declarative language, where the resulting
transformations between the source and the target models are consistent regarding the correspondence specified
by the TGG. Moreover, by using TGGs, the synchronization part of the challenge requires no extra efforts
as a model synchronization algorithm for TGG specifications is already part of eMoflon. The price to
pay for those formal and algorithmic properties is the slower execution time compared to task-optimized,
imperative solutions. Extending a TGG might also become problematic as new rules might overlap with
old ones, thus, possibly altering the behavior of the core specification.</p>
      <p>By using SDMs for specifying refactorings, we have an approach based on graph transformation
to handle the PG-based refactoring scenario of the challenge. In addition, the visual specification style
facilitates the understanding of the refactoring conditions and operations. Naturally, the resulting
generated Java code might fall short in terms of performance if compared to an equivalent hand-written
implementation from an experienced Java developer.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusion and Future Work</title>
      <p>In this paper, we presented our solution for the object-oriented Java refactoring case study of the
Transformation Tool Contest 2015. Our solution is implemented using the eMoflon meta-modeling and graph
transformation tool, developed at the Real-Time Systems Lab of the TU Darmstadt.</p>
      <p>
        We conclude that both of the transformation languages supported by eMoflon, namely TGGs and
SDMs can be utilized for different subtasks of the required transformation chain. TGGs in eMoflon
also provide a synchronization algorithm which makes eMoflon a highly adequate tool to deal with
bidirectional model synchronization problems similar to the one described in the challenge. With SDMs,
we have the possibility to specify the actual refactoring operations in a visual and graph-based manner.
(For more information about the difference between TGG and SDM as well as their interplay in the
present refactoring scenario, we refer the interested reader to [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].)
      </p>
      <p>Our future work includes the examination of the tool MoDisco3 (having similar functionality to
JaMoPP) in order to potentially reduce the need for pre- and postprocessing and to define a more
structured and sophisticated TGG. Moreover, we would like to conduct experiments on real-life Java inputs
to evaluate the practical relevance of our approach.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>T.</given-names>
            <surname>Fischer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Niere</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Torunski</surname>
          </string-name>
          &amp;
          <string-name>
            <surname>A. Zu</surname>
          </string-name>
          <article-title>¨ndorf (</article-title>
          <year>2000</year>
          )
          <article-title>: Story Diagrams: A New Graph Grammar Language Based on the Unified Modelling Language and Java</article-title>
          .
          <source>In: TAGT, LNCS 1764</source>
          , Springer, pp.
          <fpage>157</fpage>
          -
          <lpage>167</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>F.</given-names>
            <surname>Heidenreich</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Johannes</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Seifert</surname>
          </string-name>
          &amp;
          <string-name>
            <surname>C. Wende</surname>
          </string-name>
          (
          <year>2010</year>
          )
          <article-title>: Closing the Gap between Modelling and Java</article-title>
          .
          <source>In: Software Language Engineering, LNCS 5969</source>
          , Springer, pp.
          <fpage>374</fpage>
          -
          <lpage>383</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>G. Kulcsa´</given-names>
            r, S. Peldszus &amp;
            <surname>M. Lochau</surname>
          </string-name>
          <article-title>: Case Study: Object-oriented Refactoring of Java Programs using Graph Transformation</article-title>
          .
          <source>In: Transformation Tool Contest</source>
          <year>2015</year>
          . Available at https://github.com/ Echtzeitsysteme/java-refactoring-ttc/.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>E.</given-names>
            <surname>Leblebici</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Anjorin</surname>
          </string-name>
          &amp;
          <string-name>
            <surname>A. Schu</surname>
          </string-name>
          <article-title>¨rr (</article-title>
          <year>2014</year>
          ):
          <article-title>Developing eMoflon with eMoflon</article-title>
          .
          <source>In: Theory and Practice of Model Transformations, LNCS 8568</source>
          , Springer, pp.
          <fpage>138</fpage>
          -
          <lpage>145</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>S.</given-names>
            <surname>Peldszus</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. Kulcsa´</given-names>
            r &amp; M.
            <surname>Lochau</surname>
          </string-name>
          (
          <year>2015</year>
          )
          <article-title>: SHARE Image</article-title>
          . Available at http://is.ieis.tue.nl/ staff/pvgorp/share/?page=ConfigureNewSession&amp;vdi
          <string-name>
            <surname>=</surname>
          </string-name>
          XP-TUe_
          <fpage>TTC15</fpage>
          -Refactoring.vdi.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>S.</given-names>
            <surname>Peldszus</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. Kulcsa´</given-names>
            r &amp; M.
            <surname>Lochau</surname>
          </string-name>
          (
          <year>2015</year>
          ): Source Code at GitHub. Available at https://github.com/ SvenPeldszus/GravityTTC.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>S.</given-names>
            <surname>Peldszus</surname>
          </string-name>
          , G. Kulcsa´r, M. Lochau &amp; S.
          <string-name>
            <surname>Schulze</surname>
          </string-name>
          (
          <year>2015</year>
          )
          <article-title>: Incremental Co-Evolution of Java Programs Based on Bidirectional Graph Transformation</article-title>
          .
          <source>In: PPPJ'15</source>
          , ACM, NY, USA, pp.
          <fpage>138</fpage>
          -
          <lpage>151</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>A.</given-names>
            <surname>Schu</surname>
          </string-name>
          <article-title>¨rr (</article-title>
          <year>1994</year>
          )
          <article-title>: Specification of Graph Translators with Triple Graph Grammars</article-title>
          .
          <source>In: 20th Int. Workshop on Graph-Theoretic Concepts in Computer Science, LNCS 903</source>
          , Springer, pp.
          <fpage>151</fpage>
          -
          <lpage>163</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>