Difference between revisions of "ATL Language Troubleshooter"

From Eclipsepedia

Jump to: navigation, search
('''Trouble''' '''Cause''' '''Solution(s)''')
('''Trouble''' '''Cause''' '''Solution(s)''')
Line 33: Line 33:
 
Let a simple lazy rule:  
 
Let a simple lazy rule:  
  
lazy rule getCross {
+
  lazy rule getCross {
  from
+
    from
    i: ecore!EObject
+
      i: ecore!EObject
  to  
+
    to  
    rel: metamodel!Relationship (
+
      rel: metamodel!Relationship (
    )
+
      )
}
+
  }
  
 
We can call it from a matched rule as follows:
 
We can call it from a matched rule as follows:
  
rule Example {
+
  rule Example {
  from  
+
    from  
    s : ecore!EObject
+
      s : ecore!EObject
  to  
+
    to  
    t : metamodel!Node (
+
      t : metamodel!Node (
      name <- s.toString(),
+
        name <- s.toString(),
      edges <- thisModule.getCross(s)
+
        edges <- thisModule.getCross(s)
}
+
  }
  
 
If we want to call lazy rule multiple times:
 
If we want to call lazy rule multiple times:
 
+
rule Example {
+
  rule Example {
  from  
+
    from  
    s : ecore!EObject
+
      s : ecore!EObject
  to  
+
    to  
    t : metamodel!Node (
+
      t : metamodel!Node (
      name <- s.toString(),
+
        name <- s.toString(),
      edges <- ecore!EClass.allInstancesFrom('yourmodel')->collect(e | thisModule.getCross(e))
+
        edges <- ecore!EClass.allInstancesFrom('yourmodel')->collect(e | thisModule.getCross(e))
}
+
  }
  
 
===UML2 Profiles===
 
===UML2 Profiles===

Revision as of 06:30, 19 January 2007

< To: ATL

Contents

Trouble Cause Solution(s)

ATL Virtual Machine Troubles

  • Trouble: NativeOperation public static org.atl.engine.vm.nativelib.ASMNumber org.atl.engine.vm.nativelib.ASMInteger.operatorMinus(org.atl.engine.vm.StackFrame,org.atl.engine.vm.nativelib.ASMInteger,org.atl.engine.vm.nativelib.ASMNumber)
    Cause: You use negative integer to compare
    e.g. if self.upper = -1 ...
    Solutions: Use (0-x) operation
    e.g. if self.upper = (0-1) ... or change your comparaison if it is possible: e.g. if self.upper < 0 ...


ATL Called Rules Troubles

  • Trouble: ERROR: could not find operation including on Module having supertypes: [OclAny]) on a called rule
    Cause: Your called rule doesn't return the good type (problably any)
    Solution: Add a return type on your called rule by adding the do clause
    e.g.
rule myCalledRule() {
 to
   out : XML!Element -- ...
 do {
   out;
 }
}


ATL matched, called and lazy rule: differences and howto

  • a matched rule is a declarative rule whose "from" pattern is automatically matched by the ATL engine
  • a lazy Rule is a declarative rule which is explicitely called
  • a called Rule is a imperative rule which is explicitely called

As ATL prefered coding style is declarative, you should better use matched and lazy rule.

How to call lazy rule ?=

Let a simple lazy rule:

 lazy rule getCross {
   from
     i: ecore!EObject
   to 
     rel: metamodel!Relationship (
     )
 }

We can call it from a matched rule as follows:

 rule Example {
   from 
     s : ecore!EObject
   to 
     t : metamodel!Node (
       name <- s.toString(),
       edges <- thisModule.getCross(s)
 }

If we want to call lazy rule multiple times:

 rule Example {
   from 
     s : ecore!EObject
   to 
     t : metamodel!Node (
       name <- s.toString(),
       edges <- ecore!EClass.allInstancesFrom('yourmodel')->collect(e | thisModule.getCross(e))
  }

UML2 Profiles

Eclipse UML2 Profiles and Stereotypes cannot be applied directly via ATL, but must use the native Java methods of the UML2 plug-in. See also atl_discussion message 1202.

The reason is that UML2 Profiles contain a small Ecore meta-model, with an EClass for each Stereotype defined. When a Profile is applied, this small meta-model is added to the set of available meta-models. Whenever a Stereotype is applied, an EAnnotation "appliedStereotypes" is created (or modified) and an instance of the EClass for that stereotype is added to the contents of the EAnnotation.

This can create problems with ATL, since ATL rules are intended to be confluent (i.e. execution order of rules does not matter). A Profile application basically changes the meta-model at run-time. Any Stereotype application can only happen after the Profile has been applied. Things become even more complex when unapplying Profiles/Stereotypes.