Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Acceleo/Migration From Acceleo 2"

(Miscellaneous)
m (Acceleo 2.x to 3.x equivalences)
Line 58: Line 58:
 
=== EObject Services ===
 
=== EObject Services ===
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
+
{| border="1" cellpadding="5" cellspacing="0"
  +================================================================+================================================================+
+
|-
  | <%x.eAllContents%>                                             | [x.eAllContents()/]                                           |
+
! style="background: #BCBCBC;" align="center"| Acceleo 2 Expression
 
+
! style="background: #BCBCBC;" align="center"| Acceleo 3 Expression (OCL)
  | <%x.eAllContents("EClass")%>                                   | [x.eAllContents(EClass)/]                                 |
+
|-
 
+
| <%x.eAllContents%>
  | <%x.eClass%>                                                   | [x.eClass()/]                                                 |
+
| [x.eAllContents()/]
 
+
|-
  | <%x.eContainer%>                                               | [x.eContainer()/]                                             |
+
| <%x.eAllContents("EClass")%>
 
+
| [x.eAllContents(EClass)/]
  | <%x.eContainer("EPackage")%>                                   | [x.eContainer(EPackage)/]                                     |
+
|-
 
+
| <%x.eClass%>
  | <%x.eContainingFeature%>                                       | [x.eContainingFeature()/]                                     |
+
| [x.eClass()/]
 
+
|-
  | <%x.eContainmentFeature%>                                     | [x.eContainmnentFeature()/]                                   |
+
| <%x.eContainer%>
 
+
| [x.eContainer()/]
  | <%x.eContents%>                                               | [x.eContents()/]                                               |
+
|-
 
+
| <%x.eContainer("EPackage")%>
  | <%x.eCrossReferences%>                                         | [x.eCrossReferences()/]                                       |
+
| [x.eContainer(EPackage)/]
 
+
|-
  | <%x.eResource%>                                               | [x.eResource()/]                                               |
+
| <%x.eContainingFeature%>
 
+
| [x.eContainingFeature()/]
  | <%x.eResourceName%>                                           |                                                                |
+
|-
 
+
| <%x.eContainmentFeature%>
  | <%x.getRootContainer%>                                         | [x.ancestors()->last()/]                                       |
+
| [x.eContainmnentFeature()/]
 
+
|-
  | <%load("//UML2_LIBRARIES/UML2PrimitiveTypes.library.uml2")%>   | No direct equivalent : Acceleo 3 accepts more than one model   |
+
| <%x.eContents%>
  |                                                                | element as arguments of a generation. An alternative would be |
+
| [x.eContents()/]
  |                                                                | to use a custom Java service for this need.                   |
+
|-
 +
| <%x.eCrossReferences%>
 +
| [x.eCrossReferences()/]
 +
|-
 +
| <%x.eResource%>
 +
| [x.eResource()/]
 +
|-
 +
| <%x.eResourceName%>
 +
|
 +
|-
 +
| <%x.getRootContainer%>
 +
| [x.ancestors()->last()/]
 +
|-
 +
| <%load("//UML2_LIBRARIES/UML2PrimitiveTypes.library.uml2")%>  
 +
| No direct equivalent : Acceleo 3 accepts more than one model element as arguments of a generation. An alternative would be to use a custom Java service for this need.
 +
|}
  
  

Revision as of 01:59, 20 January 2011

Migration Guide

Acceleo 2.x to 3.x equivalences

Miscellaneous

Acceleo 2 Expression Acceleo 3 Expression (OCL)
<%metamodel http://www.eclipse.org/uml2/2.0.0/UML%> [module module_name('http://www.eclipse.org/uml2/2.0.0/UML')/]
<%import module.mt%> [import module/] or [import org::eclipse::acceleo::mypackage::module/]
<%import service.java%> Services no longer need to be imported
<%list + object%> [list->including(object)/]
<%list1 + list2%> [list1->union(list2)/]
<%string + object%> [string + object/]
<%list - object%> [list->excluding(object)/]
<%list1 - list2%> [list1->asSet() - list2->asSet()/] (Note that this no longer keeps duplicates, which is not strictly equivalent to Acceleo 2)
<%list1 \p\p list2%> [list1->union(list2)/]
<%list && object%> element = object)/]
<%list1 && list2%> [list1->iterate(element; result : Sequence(T) = Sequence{} if list2->includes(element) then result->including(element) else result endif)/]
<%list1 == list2%> [list1 = list2/]
<%list1 != list2%> [list1 <> list2/]
<%object != object%> [object <> object/]
<%! boolean%> [not boolean/]

EObject Services

Acceleo 2 Expression Acceleo 3 Expression (OCL)
<%x.eAllContents%> [x.eAllContents()/]
<%x.eAllContents("EClass")%> [x.eAllContents(EClass)/]
<%x.eClass%> [x.eClass()/]
<%x.eContainer%> [x.eContainer()/]
<%x.eContainer("EPackage")%> [x.eContainer(EPackage)/]
<%x.eContainingFeature%> [x.eContainingFeature()/]
<%x.eContainmentFeature%> [x.eContainmnentFeature()/]
<%x.eContents%> [x.eContents()/]
<%x.eCrossReferences%> [x.eCrossReferences()/]
<%x.eResource%> [x.eResource()/]
<%x.eResourceName%>
<%x.getRootContainer%> [x.ancestors()->last()/]
<%load("//UML2_LIBRARIES/UML2PrimitiveTypes.library.uml2")%> No direct equivalent : Acceleo 3 accepts more than one model element as arguments of a generation. An alternative would be to use a custom Java service for this need.


Request Services

  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%list.select("eAttributes.nSize() > 0")%>                     | [list->select(eAttributes->size() > 0)/]                       |
  | <%list.select("eAttributes.nSize()", "0")%>                    | [list->select(eAttributes->size() = 0)/]                       |
  | <%list.delete("eAttributes.nSize() > 0")%>                     | [list->reject(eAttributes->size() > 0)/]                       |
  | <%list.delete("eAttributes.nSize()", "0")%>                    | [list->reject(eAttributes->size() = 0)/]                       |
  | <%evaluate("2 + 4")%>                                          |                                                                |


Resource Services

  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%getFileContent("C:/Obeo/models/MyModel.xmi")%>               |                                                                |
  | <%getChainPath%>                                               |                                                                |


String Services

  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%x.length%>                                                   | [x.size()/]                                                    |
  | <%x.toUpperCase%>                                              | [x.toUpper()/]                                                 |
  | <%x.toLowerCase%>                                              | [x.toLower()/]                                                 |
  | <%x.toU1Case%>                                                 | [x.toUpperFirst()/]                                            |
  | <%x.toL1Case%>                                                 | [x.toLowerFirst()/]                                            |
  | <%x.substring(1, 3)%>                                          | [x.substring(2, 3)/]                                           |
  | <%x.substring(1)%>                                             | [x.substring(2)/]                                              |
  | <%x.replaceAll("test", "replaced")%>                           | [x.replaceAll('test', 'replaced')/]                            |
  | <%x.replaceAll("\w", "$0")%>                                   | [x.replaceAll('\\w', '$0')/]                                   |
  | <%x.replaceFirst("test", "replaced")%>                         | [x.replace('test', 'replaced')/]                               |
  | <%x.replaceFirst("\w", "$0")%>                                 | [x.replace('\\w', '$0')/]                                      |
  | <%x.trim%>                                                     | [x.trim()/]                                                    |
  | <%x.startsWith(y)%>                                            | [x.startsWith(y)/]                                             |
  | <%x.endsWith(y)%>                                              | [x.endsWith(y)/]                                               |
  | <%x.equalsIgnoreCase(y)%>                                      | [x.equalsIgnoreCase(y)/]                                       |
  | <%x.matches(y)%>                                               | [x.matches(y)/]                                                |
  | <%x.charAt(4)%>                                                | [x.substring(5, 5)/]                                           |
  | <%x.indexOf(y)%>                                               | [x.index(y)/]                                                  |
  | <%x.indexOf(y, 4)%>                                            | [x.substring(5, x.size()).index(y) + 4/]                       |
  | <%x.lastIndexOf(y)%>                                           | [x.lastIndex(y)/]                                              |
  | <%x.lastIndexOf(y, 4)%>                                        | [x.substring(5, x.size()).lastIndex(y) + 4/]                   |
  | <%x.split(y)%>                                                 | No direct equivalent, use String::tokenize(String)             |
  | <%x.indentSpace%>                                              | [x.replaceAll('\r\n|\r|\n', '$0 ')/]                           |
  | <%x.indentTab%>                                                | [x.replaceAll('\r\n|\r|\n', '$0\t')/]                          |


System Services

  .. class:: exampletable
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%i()%>                                                        | [i/]                                                           |
  | <%args(0)%>                                                    | arguments are explicit and named in Acceleo 3                  |


XPath Services

  .. class:: exampletable
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%x.ancestor%>                                                 | [x.ancestors()/]                                               |
  | <%x.parent%>                                                   | [x.eContainer()/]                                              |
  | <%self%>                                                       | [self/]                                                        |
  | <%x.child%>                                                    | [x.eContents()/]                                               |
  | <%x.descendant%>                                               | [x.eAllContents()/]                                            |
  | <%x.precedingSibling%>                                         | [x.precedingSiblings()/]                                       |
  | <%x.preceding%>                                                |                                                                |
  | <%x.followingSibling%>                                         |[x.followingSiblings()/]                                        |
  | <%x.following%>                                                |                                                                |


ENode Services

  .. class:: exampletable
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                                                |
  +==========+
  | <%eObject.adapt("EObject")%>                                   | [eObject/]                                                                                |
  | <%eObject.adapt("ENodeList")%>                                 | [if (eObject.oclIsUndefined())][Sequence{}/][else][Sequence{eObject}/][/if]               |
  | <%eObject.adapt("String")%>                                    | [if (eObject.oclIsUndefined())][/][else][eObject.toString()/][/if]                      |
  | <%eObject.adapt("Boolean")%>                                   | [not eObject.oclIsUndefined()/]                                                           |
  | <%eObject.adapt("int")%>                                       | [eObject->size()/]                                                                        |
  | <%eObject.adapt("double")%>                                    | [eObject->size().toString().toReal()/]                                                    |
  | <%eObject.adapt("List")%>                                      | [if (eObject.oclIsUndefined())][Sequence{}/][else][Sequence{eObject}/][/if]               |
  | <%eObject.adapt("ENode")%>                                     | [eObject/]                                                                                |
  | <%list.adapt("EObject")%>                                      | [if (list.oclIsUndefined())][null/][elseif (list->size() == 0)][else][list.at(0)/][/if]   |
  | <%list.adapt("ENodeList")%>                                    | [if (list.oclIsUndefined())][Sequence{}/][else][list/][/if]                               |
  | <%list.adapt("String")%>                                       | [if (list.oclIsUndefined())][/][else][list.toString()/][/if]                            |
  | <%list.adapt("Boolean")%                                       | [list->size() > 0/]                                                                       |
  | <%list.adapt("int")%>                                          | [list->size()/]                                                                           |
  | <%list.adapt("double")%>                                       | [list->size().toString().toReal()/]                                                       |
  | <%list.adapt("List")%>                                         | [if (list.oclIsUndefined())][Sequence{}/][else][list/][/if]                               |
  | <%list.adapt("ENode")%>                                        | [list/]                                                                                   |
  | <%string.adapt("EObject")%>                                    | can only return empty enodes in Acceleo 2, so migration is simply "nothing"               |
  | <%string.adapt("ENodeList")%>                                  | [if (string.oclIsUndefined())][Sequence{}/][else][Sequence{string}/][/if]                 |
  | <%string.adapt("String")%>                                     | [string/]                                                                                 |
  | <%string.adapt("Boolean")%>                                    | [string.equalsIgnoreCase('true')/]                                                        |
  | <%string.adapt("int")%>                                        | [string.toInt()/]                                                                         |
  | <%string.adapt("double")%>                                     | [string.toReal()/]                                                                        |
  | <%string.adapt("List")%>                                       | [if (string.oclIsUndefined())][Sequence{}/][else][Sequence{string}/][/if]                 |
  | <%string.adapt("ENode")%>                                      | [string/]                                                                                 |
  | <%boolean.adapt("EObject")%>                                   | can only return empty enodes in Acceleo 2, so migration is simply "nothing"               |
  | <%boolean.adapt("ENodeList")%>                                 | [if (boolean.oclIsUndefined())][Sequence{}/][else][Sequence{boolean}/][/if]               |
  | <%boolean.adapt("String")%>                                    | [if (boolean.oclIsUndefined())][/][else][boolean.toString()/][/if]                      |
  | <%boolean.adapt("Boolean")%>                                   | [not boolean.oclIsUndefined() and boolean/]                                               |
  | <%boolean.adapt("int")%>                                       | [if (not boolean.oclIsUndefined() and boolean)][1/][else][0/][/if]                        |
  | <%boolean.adapt("double")%>                                    | [if (not boolean.oclIsUndefined() and boolean)][1.0/][else][0.0/][/if]                    |
  | <%boolean.adapt("List")%>                                      | [if (boolean.oclIsUndefined())][Sequence{}/][else][Sequence{boolean}/][/if]               |
  | <%boolean.adapt("ENode")%>                                     | [boolean/]                                                                                |
  | <%int.adapt("EObject")%>                                       | can only return empty enodes in Acceleo 2, so migration is simply "nothing"               |
  | <%int.adapt("ENodeList")%>                                     | [if (int.oclIsUndefined())][Sequence{}/][else][Sequence{int}/][/if]                       |
  | <%int.adapt("String")%>                                        | [if (int.oclIsUndefined())][/][else][int.toString()/][/if]                              |
  | <%int.adapt("Boolean")%>                                       | [not int.oclIsUndefined() and int > 0/]                                                   |
  | <%int.adapt("int")%>                                           | [if (int.oclIsUndefined())][0/][else][int/][/if]                                          |
  | <%int.adapt("double")%>                                        | [if (int.oclIsUndefined())][0.0/][else][int.toString().toReal()/][/if]                    |
  | <%int.adapt("List")%>                                          | [if (int.oclIsUndefined())][Sequence{}/][else][Sequence{int}/][/if]                       |
  | <%int.adapt("ENode")%>                                         | [int/]                                                                                    |
  | <%double.adapt("EObject")%>                                    | can only return empty enodes in Acceleo 2, so migration is simply "nothing"               |
  | <%double.adapt("ENodeList")%>                                  | [if (double.oclIsUndefined())][Sequence{}/][else][Sequence{double}/][/if]                 |
  | <%double.adapt("String")%>                                     | [if (double.oclIsUndefined())][/][else][double.toString()/][/if]                        |
  | <%double.adapt("Boolean")%>                                    | [not double.oclIsUndefined() and double > 0/]                                             |
  | <%double.adapt("int")%>                                        | [if (double.oclIsUndefined())][0/][else][double.toString().toInt()/][/if]                 |
  | <%double.adapt("double")%>                                     | [if (double.oclIsUndefined())][0.0/][else][double/][/if]                                  |
  | <%double.adapt("List")%>                                       | [if (double.oclIsUndefined())][Sequence{}/][else][Sequence{double}/][/if]                 |
  | <%double.adapt("ENode")%>                                      | [double/]                                                                                 |
  | <%list.cast("EClass")%>                                        | [list->select(not oclIsKindOf(EObject) or oclIsKindOf(EClass))/]                          |
  | <%list.filter("EClass")%>                                      | [list->select(not oclIsKindOf(EObject) or oclIsKindOf(EClass))/]                          |
  | <%current()%>                                                  | [self/]                                                                                   |
  | <%current(1)%>                                                 | iterator variables are named in Acceleo 3                                                 |
  | <%node.debug%>                                                 |                                                                                           |
  | <%node.trace%>                                                 |                                                                                           |
  | <%node.trace("name")%>                                         |                                                                                           |
  | <%nPut("key", object)%>                                        |                                                                                           |
  | <%nGet("key")%>                                                |                                                                                           |
  | <%nPeek%>                                                      |                                                                                           |
  | <%nPop%>                                                       |                                                                                           |
  | <%nPush%>                                                      |                                                                                           |
  | <%list.nMinimize%>                                             | [list->asOrderedSet()->asSequence()/]                                                     |
  | <%list.minimize%>                                              | [list->asOrderedSet()->asSequence()/]                                                     |
  | <%list.nContains(item)%>                                       | [list->includes(item)/]                                                                   |
  | <%list.nFirst%>                                                | [list->first()/]                                                                          |
  | <%list.nLast%>                                                 | [list->last()/]                                                                           |
  | <%list.nGet(0)%>                                               | [list->at(0)/]                                                                            |
  | <%list.nGet(0, 1)%>                                            | [list->subSequence(1, 2)/]                                                                |
  | <%list.nReverse%>                                              | [list->reverse()/]                                                                        |
  | <%list.reverse%>                                               | [list->reverse()/]                                                                        |
  | <%list.nSize%>                                                 | [list->size()/]                                                                           |
  | <%list.nSort%>                                                 | [list->sortedBy(toString())/]                                                             |
  | <%list.nSort(name)%>                                           | [list->sortedBy(name)/]                                                                   |
  | <%list.sort%>                                                  | [list->sortedBy(toString())->asOrderedSet()->asSequence()/]                               |
  | <%list.sort(name)%>                                            | [list->sortedBy(name)->asOrderedSet()->asSequence()/]                                     |
  | <%list.sep(",")%>                                              | [list->sep(',')/]                                                                         |
  | <%list.sepStr(",")%>                                           | [list->sep(',')/]                                                                         |
  | <%node.toString%>                                              | [node.toString()/]                                                                        |
  | <%eObject.until("eContainer", "EClass")%>                      |                                                                                           |


Context Services

  .. class:: exampletable
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%get("key")%>                                                 |                                                                |
  | <%peek%>                                                       |                                                                |
  | <%pop%>                                                        |                                                                |
  | <%push%>                                                       |                                                                |
  | <%put("key", object)                                           |                                                                |


Properties Services

  .. class:: exampletable
  
  | Acceleo 2 Expression                                           | Acceleo 3 Expression (OCL)                                     |
  +================================================================+================================================================+
  | <%getBestProperty("partial.key")%>                             |                                                                |
  | <%getProperty("key")%>                                         | [getProperty('key')/]                                          |
  | <%getProperty("propertiesFile", "key")%>                       | [getProperty('propertiesFile', 'key')/]                        |




Acceleo Portal
Project Project · Installation
Features Acceleo Features · Runtime · Acceleo editor · Views & Perspective · Interpreter · Maven
User documentation Getting Started · User Guide · Acceleo operations reference · OCL operations reference · Text Production Rules · Migration From Acceleo 2.x · Best Practices · Videos · FAQ
Developer documentation Source code · How to contribute · Compatibility · MOFM2T specification · OCL specification
Community Professional Support · Report a bug

Back to the top