<!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>Specification, Execution, and Detection of Refactorings for Software Models</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Philip Langer, Konrad Wieland, and Petra Brosch Business Informatics Group Institute for Software Systems and Interactive Systems Vienna University of Technology</institution>
          ,
          <country country="AT">Austria</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Predefined automatically applicable composite operations such as refactorings are a prerequisite for efficient software modeling. Some modeling environments provide an initial set of basic refactorings, but they hardly offer extension points for user-specified refactorings. Even if extension points exist, the introduction of new refactorings requires programming skills and deep knowledge of the respective metamodel of the used modeling language. We present EMF Modeling Operations, a JavaTM based framework for specifying and executing composite operations within the user's modeling language and editor of choice. The user demonstrates a composite operation on a concrete example from which a generic and executable operation specification is semi-automatically derived. Furthermore, we show how the resulting specification may be used to enable an a-posteriori detection of applications of the specified operations between two successive versions of a model, also in absence of a directly recorded change log.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        With the rise of model-driven development, software models are lifted to first-class
artifacts in software development. Like in the traditional code-oriented software
development, software models are iteratively refined and, therefore, heavily evolve during
their life cycle. During development, recurring composite operations such as refactorings
are applied on software artifacts to enhance the readability, maintainability and
extensibility. Consequently, for code artifacts several approaches have been realized in
practice to support the automatic execution of refactorings on existing code artifacts.
However, for software models such techniques are rare [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Although some modeling
environments provide a basic set of executable refactorings, they hardly offer any
extension points for adding user-specified refactorings. Even if extension points exist,
the introduction of new custom refactorings requires programming skills and deep
knowledge of the respective metamodel. As a consequence, the specification of new
refactorings is only practicable for experienced programmers.
      </p>
      <p>To open the specification to users without programming skills, we present EMF
Modeling Operations, a JavaTM based framework enabling the development of executable
composite operation specifications. Comparable to macro recording in Microsoft R
Office products, a new specification is created by demonstrating the composite
operation, fine-tuning the automatically derived operation’s pre- and postconditions, and,
if necessary, adding additional augmentations such as iterations.</p>
      <p>Once a model operation is specified, it may be recurrently applied to arbitrary
models using the Operation Execution Engine. This engine enables a time-saving
repetition of recurring refactoring in modeling environments. Moreover, to help
developers retrospectively understanding a model’s evolution, applications of specified
model operations, applied between two successive versions of an evolving model,
may be detected a posteriori using the Operation Detection Engine.</p>
      <p>EMF Modeling Operations is realized as an Eclipse plug-in and may be used for
any EMF-based models1. In the following, we outline the functioning of each
component, in particular, the Operation Recorder in Section 2, the Operation Execution
Engine in Section 3, and the Operation Detection Engine in Section 4.
2</p>
      <p>
        Operation Specification By Demonstration
Operations such as refactorings may be described by a set of atomic operations, namely,
create, update, delete, and move which are executed on a model adhering to specific
preconditions [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Furthermore, to allow for complex attribute value computations in the
target model as well as to enable the detection of occurrences of the specified
composite operation in generic change scripts (cf. Section 4), also postconditions are included
in the operation specification.
      </p>
      <p>
        A direct way to realize operation specification by demonstration is to record each user
interaction within the modeling environment as proposed in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] for programming
languages and in [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] for models. However, this would demand an intervention in
the modeling environment, and due to the multitude of modeling environments, we
refrain from this possibility. Instead, we apply a state-based comparison to determine
the executed operations after modeling the initial model and the final model. This
allows the use of any editor without depending on editor-specific change recording.
To overcome the imprecision of heuristic state-based approaches, a unique ID is
automatically assigned to each model element before the user illustrates the changes.
Moreover, the Operation Recorder is designed in such a way to be independent from
any specific modeling language, as long as it is based on EMF Ecore or the
metametamodel is mapped to Ecore.
      </p>
      <p>
        Following our design rationale, we propose a two-phase operation demonstration
process which is supported by the Operation Recorder (cf. Fig. 1). For a detailed
description of the underlying approach, we kindly refer to [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ].
      </p>
      <p>Phase 1: Modeling. First, the user creates the initial model containing all
essential model elements to apply the composite operation. Next, each element of the
initial model is automatically annotated with an ID, and a so-called working model, i.e.,
a copy of the initial model for demonstrating the composite operation, is created.
The IDs preserve the relationship of the original elements in the initial model and
the changed elements in the working model. Finally, the user performs the complete
composite operation on the working model in her familiar modeling environment by
applying all necessary atomic operations. The output of this step is the revised model,
which is together with the initial model the input for the second phase of the
operation specification process.</p>
      <p>Phase 2: Configuration &amp; Generation. Due to the unique IDs of the model
elements, the atomic operations of the operation may precisely be determined
automatDiff Model &amp;
Annotations</p>
      <p>Initial Model</p>
      <p>Revised Model
Preconditions</p>
      <p>Postconditions
ically using a state-based comparison. The results are saved in a diff model containing
all detected atomic changes. Subsequently, an initial version of the pre- and
postconditions (cf. lower right view in Fig. 1) of the operation is inferred by analyzing the
initial model and revised model, respectively. Sometimes, the automatically inferred
conditions do not completely express the intended pre- and postconditions of the
operation. Thus, they only act as a basis for accelerating the operation specification
process and may be refined by the user. In particular, conditions may be relaxed,
enforced, and modified and further annotations such as iterations and user inputs may
be specified (cf. upper left view in Fig. 1). Finally, the Operation Specification Model
is generated, which is a self-contained and complete description of the specified
operation consisting of the initial and revised model, the diff model, and the pre- and
postconditions.
3</p>
      <p>Execution of Operation Specifications
Once the Operation Specification Model is created, it may be applied to (parts of)
arbitrary models fulfilling to the operation’s preconditions. To start the execution, the
user selects a model element in an arbitrary model and provides a so-called
prebinding by linking the selected model element to the corresponding model element in the
operation specification’s example model. With this, the selected model element in the
arbitrary model is specified to be transformed equally to the linked model element in
the operation specification. Based on the operation’s preconditions, the Operation
Execution Engine automatically completes the provided prebinding and presents it—if
a valid and complete binding was found—to the user as depicted in Fig. 2a. Next, the
Operation Execution Engine queries the user for additionally configured user inputs
and finally performs the operation.</p>
      <p>To realize the Operation Execution Engine, we faced two major challenges. First,
the condition evaluation engine has to cope with cyclic condition dependencies.
There</p>
      <p>Arbitrary
Model Elements</p>
      <p>Operation‘s</p>
      <p>Model Elements
(a)
Input Diff
Model</p>
    </sec>
    <sec id="sec-2">
      <title>OOOpppeeerraraattitioioonnn</title>
    </sec>
    <sec id="sec-3">
      <title>SSSpppeeeccicififificicacaattitioioonnn</title>
      <p>Diff Model</p>
      <p>Preprocessing
Input
Signature</p>
    </sec>
    <sec id="sec-4">
      <title>OOOpppeeerraraattitioioonnn</title>
    </sec>
    <sec id="sec-5">
      <title>SSppeSecicgiifnfiicacatatutiioroenn</title>
      <p>Preselection
[nodiff match] [diffmatches]</p>
    </sec>
    <sec id="sec-6">
      <title>OOPppoeertraeatntitiooianl</title>
      <p>n</p>
    </sec>
    <sec id="sec-7">
      <title>SSppeOecpciifefiicrcaaatttiioioonnn</title>
      <p>Occurrence
fPoorteeanctihalOperationOccurrence
Potential
Operation
Occurrence
 fVoarliedaPcrheconditionBinding
Valid
Precondition</p>
      <p>Binding
DerivePrecondition</p>
      <p>Binding
Precondition</p>
      <p>Binding
Evaluate Binding
[invalid] [valid]</p>
    </sec>
    <sec id="sec-8">
      <title>OOppeeVrraaatltiidioonn</title>
    </sec>
    <sec id="sec-9">
      <title>SSPppreeeccciifofiiccaattiioonn</title>
      <p>ndition
Binding
DerivePostcondition</p>
      <p>Binding
Postcondition</p>
      <p>Binding
Evaluate Binding
[invalid]
[valid]
Operation
Occurrence</p>
    </sec>
    <sec id="sec-10">
      <title>1 ChangePattern Matching 2 PreconditionMatching 3 PostconditionMatching</title>
      <p>(b)
fore, we use a backtracking algorithm to explore all potentially valid combinations
of model element bindings based on the user-specified prebinding to finally find a
complete and valid binding. Second, the repeated execution of the detected atomic
changes poses some challenging issues. For instance, an added element might refer
to already existing model elements. Consequently, new elements may not simply be
copied to the target, otherwise the copy would still link to elements contained by the
operation’s example model. Instead, they have to be copied and accordingly rewired
to ensure that the new model element only refers to existing elements in the currently
transformed model.
4</p>
      <p>A-Posteriori Detection of Operation Applications
Given two successively modified versions of one model, we now aim to detect
applications of the defined operations. The detection process (cf. Fig. 2b) takes as input a
difference report (input diff model) obtained by a state-based comparison of two
successively modified model versions as well as the list of detectable operation
specifications. The process consists of three phases: (i) the preselection of potential operation
occurrences is accomplished by searching for the change patterns of the provided
operation specifications in the input diff model. Subsequently, for each potential
operation occurrence, (ii) the preconditions are evaluated, and finally, (iii) the
postconditions are checked. If both are valid, an application of an operation is detected.</p>
      <p>Change Pattern Matching. The goal of this phase is to enable an efficient and fast
triage of operation occurrence candidates that potentially may have been applied
according to the input diff model. To allow for a fast search, the diff models (input diff
model and the operation specification’s diff models) are translated into easily
processable signatures. For each provided operation specification we now check whether its
signature is contained in the input signature. If a match is found, the respective
operation has potentially been applied and we proceed with the condition matching in
the following phases.</p>
      <p>Precondition Matching. For each potential operation occurrence, the
preconditions of the respective operation specification are evaluated. For this, a binding of
affected model elements to the operation specification’s initial model elements has to
be derived (precondition binding in Fig. 2b) which is then evaluated using the
aforementioned condition evaluation engine (cf. Section 3). If one operation specification
has been applied more than once, the evaluation engine returns a valid precondition
binding for each potential occurrence. This list of valid precondition bindings serves
as input for the next phase.</p>
      <p>Postcondition Matching. For each valid precondition binding, a postcondition
binding, i.e., a binding of changed model elements to the corresponding operation
specification’s revised model elements is derived and evaluated. If a valid postcondition
binding is found, an occurrence of an operation application is at hand.
5</p>
      <p>Conclusions and Ongoing Work
In this paper, we outlined EMF Modeling Operations, a JavaTM based framework for
specifying and recurrently executing operations. With the Operation Detection
Engine, this framework allows to retrospectively detect applications of user-specified
operations. EMF Modeling Operations will soon be available from our project
homepage2 using the open source license EPL3.</p>
      <p>Ongoing work comprises optional changes allowing to specify parts of the
operation to be optional. Furthermore, we currently elaborate on computing the inverse of an
operation specification as well as its composition to enable the creation of new
(composite) composite operations from two or more existing ones. Finally, we plan to set
up a community server allowing to easily exchange existing operations.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Tom</given-names>
            <surname>Mens</surname>
          </string-name>
          , Michel Wermelinger, Stephane Ducasse, Serge Demeyer, Robert Hirschfeld, and
          <string-name>
            <given-names>Mehdi</given-names>
            <surname>Jazayeri</surname>
          </string-name>
          .
          <article-title>Challenges in Software Evolution</article-title>
          .
          <source>In Proceedings of the 8th International Workshop on Principles of Software Evolution (IWPSE'05)</source>
          , pages
          <fpage>13</fpage>
          -
          <lpage>22</lpage>
          . IEEE Computer Society,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Jing</given-names>
            <surname>Zhang</surname>
          </string-name>
          , Yuehua Lin, and
          <string-name>
            <given-names>Jeff</given-names>
            <surname>Gray</surname>
          </string-name>
          .
          <article-title>Generic and Domain-Specific Model Refactoring using a Model Transformation Engine</article-title>
          .
          <source>In Model-driven Software Development-Research and Practice in Software Engineering</source>
          , pages
          <fpage>199</fpage>
          -
          <lpage>217</lpage>
          . Springer,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Romain</given-names>
            <surname>Robbes</surname>
          </string-name>
          and
          <string-name>
            <given-names>Michele</given-names>
            <surname>Lanza</surname>
          </string-name>
          .
          <article-title>Example-Based Program Transformation</article-title>
          .
          <source>In Proceedings of the 11th International Conference on Model Driven Engineering Languages and Systems (MoDELS'08)</source>
          , pages
          <fpage>174</fpage>
          -
          <lpage>188</lpage>
          . Springer,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Yu</given-names>
            <surname>Sun</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Jules</given-names>
            <surname>White</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Jeff</given-names>
            <surname>Gray</surname>
          </string-name>
          .
          <article-title>Model transformation by demonstration</article-title>
          .
          <source>In Proceedings of the 12th International Conference on Model Driven Engineering Languages and Systems (MoDELS'09)</source>
          , pages
          <fpage>712</fpage>
          -
          <lpage>726</lpage>
          . Springer,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Petra</given-names>
            <surname>Brosch</surname>
          </string-name>
          , Philip Langer, Martina Seidl, Konrad Wieland, Manuel Wimmer, Gerti Kappel, Werner Retschitzegger, and
          <string-name>
            <given-names>Wieland</given-names>
            <surname>Schwinger</surname>
          </string-name>
          .
          <article-title>An Example Is Worth a Thousand Words: Composite Operation Modeling By-Example</article-title>
          .
          <source>In Proceedings of the 12th International Conference on Model Driven Engineering Languages and Systems (MoDELS'09)</source>
          , pages
          <fpage>271</fpage>
          -
          <lpage>285</lpage>
          . Springer,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>