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

Acceleo/Migration From Acceleo 2

< Acceleo
Revision as of 04:07, 20 January 2011 by Stephane.begaudeau.obeo.fr (Talk | contribs) (Formatting)

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%> \r|\n', '$0 ')/]
<%x.indentTab%> \r|\n', '$0\t')/]


System Services

Acceleo 2 Expression Acceleo 3 Expression (OCL)
<%i()%> [i/]
<%args(0)%> arguments are explicit and named in Acceleo 3


XPath Services

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

Acceleo 2 Expression Acceleo 3 Expression (OCL)
[eObject/] | [if (eObject.oclIsUndefined())][Sequence{}/][else][Sequence{eObject}/][/if] | [if (eObject.oclIsUndefined())][/][else][eObject.toString()/][/if] | [not eObject.oclIsUndefined()/] | [eObject->size()/] | [eObject->size().toString().toReal()/] | [if (eObject.oclIsUndefined())][Sequence{}/][else][Sequence{eObject}/][/if] | [eObject/] | [if (list.oclIsUndefined())][null/][elseif (list->size() == 0)][else][list.at(0)/][/if] | [if (list.oclIsUndefined())][Sequence{}/][else][list/][/if] | [if (list.oclIsUndefined())][/][else][list.toString()/][/if] | [list->size() > 0/] | [list->size()/] | [list->size().toString().toReal()/] | [if (list.oclIsUndefined())][Sequence{}/][else][list/][/if] | [list/] | can only return empty enodes in Acceleo 2, so migration is simply "nothing" | [if (string.oclIsUndefined())][Sequence{}/][else][Sequence{string}/][/if] | [string/] | [string.equalsIgnoreCase('true')/] | [string.toInt()/] | [string.toReal()/] | [if (string.oclIsUndefined())][Sequence{}/][else][Sequence{string}/][/if] | [string/] | can only return empty enodes in Acceleo 2, so migration is simply "nothing" | [if (boolean.oclIsUndefined())][Sequence{}/][else][Sequence{boolean}/][/if] | [if (boolean.oclIsUndefined())][/][else][boolean.toString()/][/if] | [not boolean.oclIsUndefined() and boolean/] | [if (not boolean.oclIsUndefined() and boolean)][1/][else][0/][/if] | [if (not boolean.oclIsUndefined() and boolean)][1.0/][else][0.0/][/if] | [if (boolean.oclIsUndefined())][Sequence{}/][else][Sequence{boolean}/][/if] | [boolean/] | can only return empty enodes in Acceleo 2, so migration is simply "nothing" | [if (int.oclIsUndefined())][Sequence{}/][else][Sequence{int}/][/if] | [if (int.oclIsUndefined())][/][else][int.toString()/][/if] | [not int.oclIsUndefined() and int > 0/] | [if (int.oclIsUndefined())][0/][else][int/][/if] | [if (int.oclIsUndefined())][0.0/][else][int.toString().toReal()/][/if] | [if (int.oclIsUndefined())][Sequence{}/][else][Sequence{int}/][/if] | [int/] | can only return empty enodes in Acceleo 2, so migration is simply "nothing" | [if (double.oclIsUndefined())][Sequence{}/][else][Sequence{double}/][/if] | [if (double.oclIsUndefined())][/][else][double.toString()/][/if] | [not double.oclIsUndefined() and double > 0/] | [if (double.oclIsUndefined())][0/][else][double.toString().toInt()/][/if] | [if (double.oclIsUndefined())][0.0/][else][double/][/if] | [if (double.oclIsUndefined())][Sequence{}/][else][Sequence{double}/][/if] | [double/] | [list->select(not oclIsKindOf(EObject) or oclIsKindOf(EClass))/] | [list->select(not oclIsKindOf(EObject) or oclIsKindOf(EClass))/] | [self/] | iterator variables are named in Acceleo 3 | | | | | | | | | [list->asOrderedSet()->asSequence()/] | [list->asOrderedSet()->asSequence()/] | [list->includes(item)/] | [list->first()/] | [list->last()/] | [list->at(0)/] | [list->subSequence(1, 2)/] | [list->reverse()/] | [list->reverse()/] | [list->size()/] | [list->sortedBy(toString())/] | [list->sortedBy(name)/] | [list->sortedBy(toString())->asOrderedSet()->asSequence()/] | [list->sortedBy(name)->asOrderedSet()->asSequence()/] | [list->sep(',')/] | [list->sep(',')/] | [node.toString()/] | |


Context Services

Acceleo 2 Expression Acceleo 3 Expression (OCL)
<%get("key")%>
<%peek%>
<%pop%>
<%push%>
<%put("key", object)%>


Properties Services

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